modified curl handling

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-29 14:56:07 +01:00
parent 1567520a5b
commit 1bf327cc00
1 changed files with 5 additions and 1 deletions

View File

@ -21,6 +21,7 @@ class CheckController
*/ */
function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command, String $type, bool $post = false, array $body = []): array function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command, String $type, bool $post = false, array $body = []): array
{ {
$error = false;
$curl = curl_init(); $curl = curl_init();
if ($type == "panel") { if ($type == "panel") {
curl_setopt(handle: $curl, option: CURLOPT_URL, value: "https://$serverName/api/v2/" . $command); curl_setopt(handle: $curl, option: CURLOPT_URL, value: "https://$serverName/api/v2/" . $command);
@ -28,7 +29,8 @@ class CheckController
curl_setopt(handle: $curl, option: CURLOPT_URL, value: "https://$serverName/api/" . $command); curl_setopt(handle: $curl, option: CURLOPT_URL, value: "https://$serverName/api/" . $command);
} }
curl_setopt(handle: $curl, option: CURLOPT_RETURNTRANSFER, value: 1); curl_setopt(handle: $curl, option: CURLOPT_RETURNTRANSFER, value: 1);
curl_setopt(handle: $curl, option: CURLOPT_TIMEOUT_MS, value: 1000); curl_setopt(handle: $curl, option: CURLOPT_TIMEOUT_MS, value: 3000);
curl_setopt(handle: $curl, option: CURLOPT_HTTP_VERSION, value: CURL_HTTP_VERSION_2TLS);
if ($versionIP == 4) { if ($versionIP == 4) {
curl_setopt(handle: $curl, option: CURLOPT_IPRESOLVE, value: CURL_IPRESOLVE_V4); curl_setopt(handle: $curl, option: CURLOPT_IPRESOLVE, value: CURL_IPRESOLVE_V4);
@ -66,10 +68,12 @@ class CheckController
$result = 'Unhandled error: ' . $httpResponse; $result = 'Unhandled error: ' . $httpResponse;
} }
} else { } else {
$error = true;
$result = curl_error(handle: $curl); $result = curl_error(handle: $curl);
} }
curl_close(handle: $curl); curl_close(handle: $curl);
return [ return [
'error' => true,
'data' => $result, 'data' => $result,
'header' => $httpResponse ?? '' 'header' => $httpResponse ?? ''
]; ];