This commit is contained in:
2026-02-28 18:53:26 +01:00
parent 9eb7740027
commit d28f171263
11 changed files with 30 additions and 22 deletions

View File

@@ -99,4 +99,11 @@ class mcServApi {
return true;
}
public function generateSessionID() {
$num = rand(1, 999999);
$hash = hash("sha256", $num);
return $hash;
}
}

View File

@@ -1,8 +1,8 @@
<?php
require "../../main.php";
require "../api.php";
$mcServ = new mcServ();
$db = $mcServ->getDB();
$api = new mcServApi();
$db = $api->getDB();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!isset($_POST["username"]) || !isset($_POST["passwd"])) {
@@ -22,9 +22,9 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result) {
$config = $mcServ->getConf();
$config = $api->getConf();
$session["session_id"] = $mcServ->generateSessionID();
$session["session_id"] = $api->generateSessionID();
$device_id = rand(1, 999);
$json[$device_id] = $session;

View File

@@ -1,13 +1,13 @@
<?php
require "../../main.php";
require "../api.php";
$mcServ = new mcServ;
$api = new mcServApi;
if (!$mcServ->checkApiAuth()) {
if (!$api->checkAuth()) {
die('{"status":500, "error":"Unauthrized"}');
}
$db = $mcServ->getDB();
$db = $api->getDB();
$sql = "SELECT * FROM servers";
$stmt = $db->query($sql);

View File

@@ -1,5 +1,5 @@
<?php
require "../../main.php";
require "../api.php";
$admin_user = $_POST["admin_user"];
$admin_mail = $_POST["admin_mail"];
@@ -16,8 +16,8 @@ if ($admin_passwd_2 !== $admin_passwd_1) {
$admin_passwd = hash("sha256", $admin_passwd_2);
$mcServ = new mcServ();
$config = $mcServ->getConf();
$api = new mcServApi();
$config = $api->getConf();
$db = new PDO("sqlite:" . $config["DB_PATH"]);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
@@ -60,7 +60,7 @@ INSERT INTO users (username, mail, passwd) VALUES (:user, :mail, :passwd)
$stmt = $db->prepare($sql);
$stmt->execute([':user' => $admin_user, ':mail' => $admin_mail, ':passwd' => $admin_passwd]);
$session["session_id"] = $mcServ->generateSessionID();
$session["session_id"] = $api->generateSessionID();
$device_id = rand(1, 999);
$json[$device_id] = json_encode($session);

View File

@@ -10,7 +10,7 @@
* By marc-go
*/
require "../main.php";
require "main.php";
$mcServ = new mcServ();

View File

@@ -1,5 +1,5 @@
<?php
require "../main.php";
require "main.php";
$mcServ = new mcServ();

View File

@@ -27,7 +27,7 @@ class mcServ {
}
public function getConf() {
$env = parse_ini_file(__DIR__ . "/.env");
$env = parse_ini_file(__DIR__ . "/../.env");
return $env;
}

View File

@@ -1,3 +1,3 @@
<?php
echo "404";
require "";
?>

View File

@@ -3,15 +3,16 @@ ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
error_reporting(E_ALL);
/*foreach ($_SERVER as $key => $value) {
foreach ($_SERVER as $key => $value) {
echo $key . " = " . $value . "<br>";
}*/
}
/*require "../main.php";
/*
require "../main.php";
$mcServ = new mcServ();
echo $mcServ->checkApiAuth() ? "TRUE" : "FALSE";
*/
echo __DIR__;
//echo __DIR__;

BIN
mcServ.db

Binary file not shown.

View File

@@ -1 +1 @@
{"162":{"session_id":"a46d0e1ef15a9c36ef3cacfbedf8837a24021b31e7997718ef5b22cc3204b78d"}}
{"506":"{\"session_id\":\"7f2b74a916c471ccd03b866c991e5b86f8a28cc776b54c6d73f38956a926368d\"}","array":true}