diff --git a/api/admin/base.php b/api/admin/base.php index 2727b625..834b1c7e 100644 --- a/api/admin/base.php +++ b/api/admin/base.php @@ -1,38 +1,32 @@ - 0) { - //CONTINUE CODE HERE - - } else { - $rsp = array( - "code" => 403, - "error" => "The server understood the request, but it refuses to authorize it.", - "message" => "Im sorry but the api key is wrong" - ); - http_response_code(403); - die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); - } + 0) { + //CONTINUE CODE HERE + } else { - $rsp = array( - "code" => 400, - "error" => "The server cannot understand the request due to a client error.", - "message" => "Please provide an api key" - ); - http_response_code(400); - die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + $response = [ + "code" => 403, + "error" => "Unauthorized", + "message" => "Please make sure your API key is valid." + ]; + http_response_code(403); + die(json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); } +} else { + $response = [ + "code" => 401, + "error" => "Authentication required", + "message" => "Please provide your API key." + ]; + http_response_code(401); + die(json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); } -else { - $rsp = array( - "code" => 400, - "error" => "The server cannot understand the request due to a client error.", - "message" => "Please provide an api key" - ); - http_response_code(400); - die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); -} + ?> \ No newline at end of file diff --git a/api/admin/statistics.php b/api/admin/statistics.php index a6e9c815..7da7e263 100644 --- a/api/admin/statistics.php +++ b/api/admin/statistics.php @@ -1,25 +1,61 @@ query($userCountQuery); + $userCount = $userCountResult->fetch_assoc()['user_count']; -$userCountQuery = "SELECT COUNT(*) AS user_count FROM mythicaldash_users"; -$userCountResult = $conn->query($userCountQuery); -$userCount = $userCountResult->fetch_assoc()['user_count']; + $ticketCountQuery = "SELECT COUNT(*) AS ticket_count FROM mythicaldash_tickets"; + $ticketCountResult = $conn->query($ticketCountQuery); + $ticketCount = $ticketCountResult->fetch_assoc()['ticket_count']; -$ticketCountQuery = "SELECT COUNT(*) AS ticket_count FROM mythicaldash_tickets"; -$ticketCountResult = $conn->query($ticketCountQuery); -$ticketCount = $ticketCountResult->fetch_assoc()['ticket_count']; + $serverCountQuery = "SELECT COUNT(*) AS servers FROM mythicaldash_servers"; + $serverCountResult = $conn->query($serverCountQuery); + $serverCount = $serverCountResult->fetch_assoc()['servers']; -$rsp = array( - "code" => 200, - "error" => null, - "message" => "Sure here you go:", - "statistics" => array( - "users" => $userCount, - "tickets" => $ticketCount - ) -); -http_response_code(200); -$conn->close(); -die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + $serverQueueQuery = "SELECT COUNT(*) AS serversq FROM mythicaldash_servers_queue"; + $serverQueueCountResult = $conn->query($serverQueueQuery); + $serverQueueCount = $serverQueueCountResult->fetch_assoc()['serversq']; + + $locationsQuery = "SELECT COUNT(*) AS locations FROM mythicaldash_locations"; + $locationsCountResult = $conn->query($locationsQuery); + $locationsCount = $locationsCountResult->fetch_assoc()['locations']; + + $eggsQuery = "SELECT COUNT(*) AS eggs FROM mythicaldash_eggs"; + $eggsCountResult = $conn->query($eggsQuery); + $eggCount = $eggsCountResult->fetch_assoc()['eggs']; + $rsp = array( + "code" => 200, + "error" => null, + "message" => null, + "data" => array( + "users" => $userCount, + "tickets" => $ticketCount, + "servers" => $serverCount, + "servers_queue" => $serverQueueCount, + "locations" => $locationsCount, + "eggs" => $eggCount, + ) + ); + http_response_code(200); + die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + } catch (Exception $e) { + $rsp = array( + "code" => 500, + "error" => "The server encountered a situation it doesn't know how to handle.", + "message" => "We are sorry, but our server can't handle this request. Please do not try again!" + ); + http_response_code(500); + die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + } +} else { + $rsp = array( + "code" => 405, + "error" => "A request was made of a page using a request method not supported by that page", + "message" => "Please use a get request" + ); + http_response_code(405); + die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); +} ?> \ No newline at end of file diff --git a/api/base.php b/api/base.php index 0afa1a9a..aeb1aede 100644 --- a/api/base.php +++ b/api/base.php @@ -1,6 +1,15 @@ 500, + "error" => "The server is not ready to handle the request.", + "message" => "We have no write permission for our home directory. Please update the permission by executing this in the server shell: chown -R www-data:www-data /var/www/client/ && chown -R www-data:www-data /var/www/client/*" + ); + die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); +} ?> \ No newline at end of file diff --git a/api/client/base.php b/api/client/base.php index df616eda..f6232d9e 100644 --- a/api/client/base.php +++ b/api/client/base.php @@ -1,37 +1,3 @@ - 0) { - //CONTINUE CODE HERE - - } else { - $rsp = array( - "code" => 403, - "error" => "The server understood the request, but it refuses to authorize it.", - "message" => "Im sorry but the api key is wrong" - ); - http_response_code(403); - die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); - } - } else { - $rsp = array( - "code" => 400, - "error" => "The server cannot understand the request due to a client error.", - "message" => "Please provide an api key" - ); - http_response_code(400); - die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); - } -} else { - $rsp = array( - "code" => 400, - "error" => "The server cannot understand the request due to a client error.", - "message" => "Please provide an api key" - ); - http_response_code(400); - die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); -} + \ No newline at end of file diff --git a/api/info.php b/api/info.php deleted file mode 100644 index e74a2956..00000000 --- a/api/info.php +++ /dev/null @@ -1,5 +0,0 @@ - 'error', 'message' => 'Hi this is a wrong api endpoint please check: https://github.com/MythicalLTD/MythicalDash#api-reference'),JSON_PRETTY_PRINT); -?> \ No newline at end of file diff --git a/api/main.php b/api/main.php new file mode 100644 index 00000000..4ea49940 --- /dev/null +++ b/api/main.php @@ -0,0 +1,20 @@ + 200, + "error" => null, + "message" => "Hi, and welcome to MythicalDash main api this is the main path of our API. Make sure to check our docs for the requests you can make!" + ); + http_response_code(200); + die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); +} else { + $rsp = array( + "code" => 405, + "error" => "A request was made of a page using a request method not supported by that page", + "message" => "Please use a get request" + ); + http_response_code(405); + die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); +} +?> \ No newline at end of file diff --git a/oldapi/admin/base.php b/oldapi/admin/base.php new file mode 100644 index 00000000..2727b625 --- /dev/null +++ b/oldapi/admin/base.php @@ -0,0 +1,38 @@ + 0) { + //CONTINUE CODE HERE + + } else { + $rsp = array( + "code" => 403, + "error" => "The server understood the request, but it refuses to authorize it.", + "message" => "Im sorry but the api key is wrong" + ); + http_response_code(403); + die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + } + } else { + $rsp = array( + "code" => 400, + "error" => "The server cannot understand the request due to a client error.", + "message" => "Please provide an api key" + ); + http_response_code(400); + die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + } +} +else { + $rsp = array( + "code" => 400, + "error" => "The server cannot understand the request due to a client error.", + "message" => "Please provide an api key" + ); + http_response_code(400); + die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); +} +?> \ No newline at end of file diff --git a/oldapi/admin/statistics.php b/oldapi/admin/statistics.php new file mode 100644 index 00000000..67d10f61 --- /dev/null +++ b/oldapi/admin/statistics.php @@ -0,0 +1,45 @@ +query($userCountQuery); +$userCount = $userCountResult->fetch_assoc()['user_count']; + +$ticketCountQuery = "SELECT COUNT(*) AS ticket_count FROM mythicaldash_tickets"; +$ticketCountResult = $conn->query($ticketCountQuery); +$ticketCount = $ticketCountResult->fetch_assoc()['ticket_count']; + +$Servers = "SELECT COUNT(*) AS servers FROM mythicaldash_servers"; +$serverCountResult = $conn->query($Servers); +$serverCount = $serverCountResult->fetch_assoc()['servers']; + +$servers_queue = "SELECT COUNT(*) AS serversq FROM mythicaldash_servers_queue"; +$serverqCountResult = $conn->query($servers_queue); +$servers_queueCount = $serverqCountResult->fetch_assoc()['serversq']; + +$locations = "SELECT COUNT(*) AS locations FROM mythicaldash_locations"; +$locationsCountResult = $conn->query($locations); +$locationsCount = $locationsCountResult->fetch_assoc()['locations']; + +$eggs = "SELECT COUNT(*) AS eggs FROM mythicaldash_eggs"; +$eggsCountResult = $conn->query($eggs); +$eggCount = $eggsCountResult->fetch_assoc()['eggs']; + +$rsp = array( + "code" => 200, + "error" => null, + "message" => null, + "statistics" => array( + "servers" => $serverCount, + "servers_queue" => $servers_queueCount, + "eggs" => $eggCount, + "locations" => $locationsCount, + "users" => $userCount, + "tickets" => $ticketCount, + ) +); +http_response_code(200); +$conn->close(); +die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); +?> \ No newline at end of file diff --git a/api/admin/user/ban.php b/oldapi/admin/user/ban.php similarity index 100% rename from api/admin/user/ban.php rename to oldapi/admin/user/ban.php diff --git a/api/admin/user/info.php b/oldapi/admin/user/info.php similarity index 100% rename from api/admin/user/info.php rename to oldapi/admin/user/info.php diff --git a/api/admin/users.php b/oldapi/admin/users.php similarity index 100% rename from api/admin/users.php rename to oldapi/admin/users.php diff --git a/oldapi/base.php b/oldapi/base.php new file mode 100644 index 00000000..0afa1a9a --- /dev/null +++ b/oldapi/base.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/oldapi/client/base.php b/oldapi/client/base.php new file mode 100644 index 00000000..df616eda --- /dev/null +++ b/oldapi/client/base.php @@ -0,0 +1,37 @@ + 0) { + //CONTINUE CODE HERE + + } else { + $rsp = array( + "code" => 403, + "error" => "The server understood the request, but it refuses to authorize it.", + "message" => "Im sorry but the api key is wrong" + ); + http_response_code(403); + die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + } + } else { + $rsp = array( + "code" => 400, + "error" => "The server cannot understand the request due to a client error.", + "message" => "Please provide an api key" + ); + http_response_code(400); + die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + } +} else { + $rsp = array( + "code" => 400, + "error" => "The server cannot understand the request due to a client error.", + "message" => "Please provide an api key" + ); + http_response_code(400); + die(json_encode($rsp, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); +} +?> \ No newline at end of file diff --git a/api/client/user/info.php b/oldapi/client/user/info.php similarity index 100% rename from api/client/user/info.php rename to oldapi/client/user/info.php diff --git a/api/encryptpwd.php b/oldapi/encryptpwd.php similarity index 100% rename from api/encryptpwd.php rename to oldapi/encryptpwd.php diff --git a/api/mysql.php b/oldapi/mysql.php similarity index 100% rename from api/mysql.php rename to oldapi/mysql.php diff --git a/api/ticket.php b/oldapi/ticket.php similarity index 100% rename from api/ticket.php rename to oldapi/ticket.php diff --git a/routes/api/admin/index.php b/routes/api/admin/index.php index bbb9abfa..914883e3 100644 --- a/routes/api/admin/index.php +++ b/routes/api/admin/index.php @@ -1,7 +1,7 @@ add("/api/admin/statistics", function () { - require("../include/main.php"); - require("../api/admin/statistics.php"); -}); +//$router->add("/api/admin/statistics", function () { +// require("../include/main.php"); +// require("../api/admin/statistics.php"); +//}); ?> \ No newline at end of file diff --git a/routes/api/admin/user.php b/routes/api/admin/user.php index a61978f3..91813ccb 100644 --- a/routes/api/admin/user.php +++ b/routes/api/admin/user.php @@ -1,12 +1,12 @@ add("/api/admin/user/info", function () { - require("../include/main.php"); - require("../api/admin/user/info.php"); -}); - -$router->add("/api/admin/user/list", function () { - require("../include/main.php"); - require("../api/admin/users.php"); -}); +//$router->add("/api/admin/user/info", function () { +// require("../include/main.php"); +// require("../api/admin/user/info.php"); +//}); +// +//$router->add("/api/admin/user/list", function () { +// require("../include/main.php"); +// require("../api/admin/users.php"); +//}); ?> \ No newline at end of file diff --git a/routes/api/client/user.php b/routes/api/client/user.php index 633deda1..a49f92c1 100644 --- a/routes/api/client/user.php +++ b/routes/api/client/user.php @@ -1,7 +1,7 @@ add("/api/client/user/info", function () { - require("../include/main.php"); - require("../api/client/user/info.php"); -}); +//$router->add("/api/client/user/info", function () { +// require("../include/main.php"); +// require("../api/client/user/info.php"); +//}); ?> \ No newline at end of file diff --git a/routes/api/index.php b/routes/api/index.php index c8e38026..c3e62180 100644 --- a/routes/api/index.php +++ b/routes/api/index.php @@ -1,6 +1,13 @@ add("/api/ticket", function () { +$router->add("/api", function () { require("../include/main.php"); - require("../api/ticket.php"); + require("../api/main.php"); }); + +$router->add("/api/admin/statistics", function () { + require("../include/main.php"); + require("../api/admin/statistics.php"); +}); + + ?> \ No newline at end of file