From 3a14eeb3c50a5a401110c1c3786df188bb3a0eb8 Mon Sep 17 00:00:00 2001 From: tracer Date: Tue, 25 Jan 2022 20:32:34 +0100 Subject: [PATCH] sendCommand now returns header (https response) and data Signed-off-by: tracer --- src/Controller/CheckController.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Controller/CheckController.php b/src/Controller/CheckController.php index 473cdff..dec42ff 100644 --- a/src/Controller/CheckController.php +++ b/src/Controller/CheckController.php @@ -14,13 +14,18 @@ class CheckController * @param int $versionIP * @param String $apiKey * @param String $command + * @param String $type * - * @return String + * @return array */ - function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command): String + function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command, String $type): array { $curl = curl_init(); - curl_setopt($curl, option: CURLOPT_URL, value: "https://$serverName/api/v2/" . $command); + if ($type == "panel") { + curl_setopt($curl, option: CURLOPT_URL, value: "https://$serverName/api/v2/" . $command); + } else { + curl_setopt($curl, option: CURLOPT_URL, value: "https://$serverName/api/" . $command); + } curl_setopt($curl, option: CURLOPT_RETURNTRANSFER, value: 1); curl_setopt($curl, option: CURLOPT_TIMEOUT_MS, value: 1000); @@ -42,7 +47,7 @@ class CheckController if ($apiResult->response == "pong") { $result = $apiResult->response; } else { - $result = $resultJSON; + $result = $apiResult; } } else { $result = $resultJSON; @@ -58,7 +63,10 @@ class CheckController $result = curl_error($curl); } curl_close($curl); - return $result; + return [ + 'data' => $result, + 'header' => $httpResponse ?? '' + ]; } }