1 | <?php |
||||
2 | |||||
3 | namespace Puerari\Cwp; |
||||
4 | |||||
5 | use Exception; |
||||
6 | |||||
7 | /** |
||||
8 | * @class Cwpapi |
||||
9 | * @package Puerari\Cwp |
||||
10 | * @author Leandro Puerari <[email protected]> |
||||
11 | */ |
||||
12 | class Cwpapi |
||||
13 | { |
||||
14 | /** @var string Key authorized by API administrator */ |
||||
15 | private $apikey; |
||||
16 | |||||
17 | /** @var string URL for the CWP server */ |
||||
18 | private $cwpurl; |
||||
19 | |||||
20 | /** @var string URI for the API */ |
||||
21 | private $cwpuri; |
||||
22 | |||||
23 | /** @var bool defaults to false - Verify or not the SSL certificate */ |
||||
24 | private $sslverify; |
||||
25 | |||||
26 | /** @var array data to be passed to the API */ |
||||
27 | private $data; |
||||
28 | |||||
29 | /** @var int (0 / 1) Debug display file: /var/log/cwp/cwp_api.log */ |
||||
30 | private $debug; |
||||
31 | |||||
32 | /** use Traits */ |
||||
33 | use Account, Autossl, Cronjob, Domain, Email, Ftp, Mysql, Package, Server; |
||||
34 | |||||
35 | /** Cwpapi constructor. |
||||
36 | * @param string $cwpurl |
||||
37 | * @param string $apikey |
||||
38 | * @param bool $sslverify |
||||
39 | * @param bool $debug |
||||
40 | * @throws Exception |
||||
41 | */ |
||||
42 | public function __construct(string $cwpurl, string $apikey, bool $sslverify = false, bool $debug = false) |
||||
43 | { |
||||
44 | if (!filter_var($cwpurl, FILTER_VALIDATE_URL)) |
||||
45 | throw new Exception('Invalid URL!'); |
||||
46 | $urllen = strlen($cwpurl) - 1; |
||||
47 | $url = ($cwpurl[$urllen] == "/") ? mb_substr($cwpurl, 0, $urllen) : $cwpurl; |
||||
48 | |||||
49 | $this->cwpurl = $url . ':2304/v1/'; |
||||
50 | $this->apikey = $apikey; |
||||
51 | $this->sslverify = $sslverify; |
||||
52 | $this->debug = intval($debug); |
||||
53 | } |
||||
54 | |||||
55 | /** |
||||
56 | * @return bool|string |
||||
57 | */ |
||||
58 | protected function execCurl() |
||||
59 | { |
||||
60 | $this->data['key'] = $this->apikey; |
||||
61 | $url = $this->cwpurl . $this->cwpuri; |
||||
62 | |||||
63 | $ch = curl_init(); |
||||
64 | curl_setopt($ch, CURLOPT_URL, $url); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
65 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||||
66 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
||||
67 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->sslverify); |
||||
68 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->data)); |
||||
69 | curl_setopt($ch, CURLOPT_POST, 1); |
||||
70 | $response = curl_exec($ch); |
||||
0 ignored issues
–
show
It seems like
$ch can also be of type false ; however, parameter $ch of curl_exec() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
71 | curl_close($ch); |
||||
0 ignored issues
–
show
It seems like
$ch can also be of type false ; however, parameter $ch of curl_close() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
72 | |||||
73 | return $response; |
||||
74 | } |
||||
75 | |||||
76 | /** |
||||
77 | * @return bool |
||||
78 | */ |
||||
79 | public function getDebug(): bool |
||||
80 | { |
||||
81 | return $this->debug; |
||||
0 ignored issues
–
show
|
|||||
82 | } |
||||
83 | |||||
84 | /** |
||||
85 | * @param bool $debug |
||||
86 | */ |
||||
87 | public function setDebug(bool $debug) |
||||
88 | { |
||||
89 | $this->debug = intval($debug); |
||||
90 | } |
||||
91 | } |
||||
92 |