Add API keys and server list api

This commit is contained in:
marc-go
2026-02-18 15:05:34 +01:00
parent 75899064c5
commit 4b4a46225f
5 changed files with 118 additions and 2 deletions

35
api/servers/list.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
require "../../main.php";
$mcServ = new mcServ;
if (!$mcServ->checkApiAuth()) {
die('{"status":500, "error":"Unauthrized"}');
}
$db = $mcServ->getDB();
$sql = "SELECT * FROM servers";
$stmt = $db->query($sql);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$servers = [];
if ($result) {
foreach ($result as $server_res) {
$server["name"] = $server_res["name"];
$server["uuid"] = $server_res["uuid"];
$servers[] = $server;
}
$json["servers"] = $servers;
}else{
$json["servers"] = [];
}
$json["status"] = 200;
echo json_encode($json);
?>

View File

@@ -33,6 +33,26 @@ CREATE TABLE IF NOT EXISTS users (
$db->exec($sql);
$sql = "
CREATE table IF NOT EXISTS servers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
uuid VARCHAR(50) UNIQUE NOT NULL,
name VARCHAR(30)
)
";
$db->exec($sql);
$sql = "
CREATE TABLE IF NOT EXISTS api_keys (
id INTEGER PRIMARY KEY AUTOINCREMENT,
key VARCHAR(100) UNIQUE NOT NULL,
user_id INTEGER
)
";
$db->exec($sql);
$sql = "
INSERT INTO users (username, mail, passwd) VALUES (:user, :mail, :passwd)
";