|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2016 SURFnet. |
|
4
|
|
|
* |
|
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
7
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
8
|
|
|
* License, or (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU Affero General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace SURFnet\VPN\Server\Acl\Provider; |
|
20
|
|
|
|
|
21
|
|
|
use RuntimeException; |
|
22
|
|
|
|
|
23
|
|
|
class CurlVootClient implements VootClientInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var resource */ |
|
26
|
|
|
private $curlChannel; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct() |
|
29
|
|
|
{ |
|
30
|
|
|
if (false === $this->curlChannel = curl_init()) { |
|
31
|
|
|
throw new RuntimeException('unable to create cURL channel'); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function __destruct() |
|
36
|
|
|
{ |
|
37
|
|
|
curl_close($this->curlChannel); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function get($requestUri, $bearerToken) |
|
41
|
|
|
{ |
|
42
|
|
|
$curlOptions = [ |
|
43
|
|
|
CURLOPT_URL => $requestUri, |
|
44
|
|
|
// CURLOPT_USERPWD => sprintf('%s:%s', $this->authInfo[0], $this->authInfo[1]), |
|
|
|
|
|
|
45
|
|
|
CURLOPT_HEADER => 0, |
|
46
|
|
|
CURLOPT_RETURNTRANSFER => 1, |
|
47
|
|
|
CURLOPT_FOLLOWLOCATION => 0, |
|
48
|
|
|
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS, |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
if (false === curl_setopt_array($this->curlChannel, $curlOptions)) { |
|
52
|
|
|
throw new RuntimeException('unable to set cURL options'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
if (false === $responseData = curl_exec($this->curlChannel)) { |
|
56
|
|
|
throw new RuntimeException('failure performing the HTTP request'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return [ |
|
60
|
|
|
curl_getinfo($this->curlChannel, CURLINFO_HTTP_CODE), |
|
61
|
|
|
json_decode($responseData, true), |
|
62
|
|
|
]; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.