From 471dc0d8dafccb866230426986a6fbade5c79354 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Mon, 8 Feb 2021 16:08:27 +0100 Subject: [PATCH] Fixed scope issue --- api/endpoint/status.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/api/endpoint/status.php b/api/endpoint/status.php index 633634d..0c276b7 100644 --- a/api/endpoint/status.php +++ b/api/endpoint/status.php @@ -2,12 +2,13 @@ header("Content-Type: application/json"); - $api = $_GET["api"]; + $api = preg_replace("/[^a-z0-9]/i","-",$_GET["api"]); // Replace special chars - function response($online = false) { - $isError = $online ? true : false; - $message = $online ? "Online" : "Offline"; - $color = $online ? "green" : "lightgrey"; + // Return the API state + function online($online = false) { + $isError = $online === true ? true : false; + $message = $online === true ? "Online" : "Offline"; + $color = $online === true ? "green" : "lightgrey"; $response = [ "schemaVersion" => 1, @@ -20,13 +21,13 @@ echo json_encode($response); } - function getStatus() { - if(!is_dir($api)) { - response(false); + function checkStatus($api) { + if(!file_exists($api)) { + online(false); return false; } - response(true); + online(true); } - getStatus(); \ No newline at end of file + checkStatus($api); \ No newline at end of file