From 545e09636c72afacaafa89e185896e2515df100a Mon Sep 17 00:00:00 2001 From: tracer Date: Mon, 31 Jan 2022 20:59:36 +0100 Subject: [PATCH] changed some variables Signed-off-by: tracer --- src/Controller/CheckController.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Controller/CheckController.php b/src/Controller/CheckController.php index 29e47ad..2594ee9 100644 --- a/src/Controller/CheckController.php +++ b/src/Controller/CheckController.php @@ -11,19 +11,21 @@ class CheckController { /** + * @param String $requestType * @param String $serverName * @param int $versionIP * @param String $apiKey * @param String $command - * @param String $type + * @param String $serverType + * @param array $body * * @return array */ - function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command, String $type, bool $post = false, array $body = []): array + function sendCommand(String $requestType, String $serverName, int $versionIP, String $apiKey, String $command, String $serverType, array $body = []): array { $error = false; $curl = curl_init(); - if ($type == "panel") { + if ($serverType == "panel") { curl_setopt(handle: $curl, option: CURLOPT_URL, value: "https://$serverName/api/v2/" . $command); } else { curl_setopt(handle: $curl, option: CURLOPT_URL, value: "https://$serverName/api/" . $command); @@ -40,10 +42,13 @@ class CheckController curl_setopt(handle: $curl, option: CURLOPT_HTTPHEADER, value: ["X-API-Key:$apiKey"]); - if ($post) { - curl_setopt($curl, option: CURLOPT_POST, value: true); - curl_setopt($curl, option: CURLOPT_POSTFIELDS, value: $body); + if ($requestType == "POST") { + curl_setopt(handle: $curl, option: CURLOPT_POST, value: true); + curl_setopt(handle: $curl, option: CURLOPT_POSTFIELDS, value: $body); } + + curl_setopt(handle: $curl, option: CURLOPT_CUSTOMREQUEST, value: $requestType); + if ($resultJSON = curl_exec(handle: $curl)) { $httpResponse = curl_getinfo(handle: $curl)['http_code']; @@ -65,6 +70,7 @@ class CheckController break; case 404: $result = '404 Not Found'; + break; default: $result = 'Unhandled error: ' . $httpResponse; }