-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-> Started a api rewrite -> Now using headers for api
- Loading branch information
Showing
21 changed files
with
268 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,32 @@ | ||
<?php | ||
if (isset($_GET['api_key'])) { | ||
if (!$_GET['api_key'] == "") { | ||
$api_key = mysqli_real_escape_string($conn,$_GET['api_key']); | ||
$query = "SELECT * FROM mythicaldash_apikeys WHERE `skey` = '$api_key'"; | ||
$result = mysqli_query($conn, $query); | ||
if (mysqli_num_rows($result) > 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)); | ||
} | ||
<?php | ||
include(__DIR__ . "/../base.php"); | ||
$headers = getallheaders(); | ||
|
||
if (isset($headers['Authorization']) && !$headers['Authorization'] == "") { | ||
$authorizationHeader = $headers['Authorization']; | ||
$api_key = mysqli_real_escape_string($conn, $authorizationHeader); | ||
$query = "SELECT * FROM mythicaldash_apikeys WHERE `skey` = '$api_key'"; | ||
$result = mysqli_query($conn, $query); | ||
if (mysqli_num_rows($result) > 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)); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,61 @@ | ||
<?php | ||
include(__DIR__ . '/../base.php'); | ||
include(__DIR__ . '/base.php'); | ||
include("base.php"); | ||
if ($_SERVER['REQUEST_METHOD'] === 'GET') { | ||
try { | ||
$userCountQuery = "SELECT COUNT(*) AS user_count FROM mythicaldash_users"; | ||
$userCountResult = $conn->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)); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
<?php | ||
header('Content-type: application/json'); | ||
ini_set("display_errors", 0); | ||
|
||
ini_set("display_startup_errors", 0); | ||
if (!is_writable(__DIR__)) { | ||
http_response_code(500); | ||
$rsp = array( | ||
"code" => 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)); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,3 @@ | ||
<?php | ||
if (isset($_GET['api_key'])) { | ||
if (!$_GET['api_key'] == "") { | ||
$api_key = mysqli_real_escape_string($conn, $_GET['api_key']); | ||
$query = "SELECT * FROM mythicaldash_users WHERE `api_key` = '$api_key'"; | ||
$result = mysqli_query($conn, $query); | ||
if (mysqli_num_rows($result) > 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)); | ||
} | ||
<?php | ||
include(__DIR__."/../base.php"); | ||
?> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
include('base.php'); | ||
if ($_SERVER['REQUEST_METHOD'] === 'GET') { | ||
$rsp = array( | ||
"code" => 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)); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
if (isset($_GET['api_key'])) { | ||
if (!$_GET['api_key'] == "") { | ||
$api_key = mysqli_real_escape_string($conn,$_GET['api_key']); | ||
$query = "SELECT * FROM mythicaldash_apikeys WHERE `skey` = '$api_key'"; | ||
$result = mysqli_query($conn, $query); | ||
if (mysqli_num_rows($result) > 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)); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
include(__DIR__ . '/../base.php'); | ||
include(__DIR__ . '/base.php'); | ||
|
||
$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']; | ||
|
||
$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)); | ||
?> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
header('Content-type: application/json'); | ||
ini_set("display_errors", 0); | ||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
if (isset($_GET['api_key'])) { | ||
if (!$_GET['api_key'] == "") { | ||
$api_key = mysqli_real_escape_string($conn, $_GET['api_key']); | ||
$query = "SELECT * FROM mythicaldash_users WHERE `api_key` = '$api_key'"; | ||
$result = mysqli_query($conn, $query); | ||
if (mysqli_num_rows($result) > 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)); | ||
} | ||
?> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
|
||
$router->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"); | ||
//}); | ||
?> |
Oops, something went wrong.