Continue Setup

This commit is contained in:
marc-go
2026-02-05 19:56:52 +01:00
parent 0a0cacac3b
commit d04d005b1b
10 changed files with 90 additions and 25 deletions

2
.env Normal file
View File

@@ -0,0 +1,2 @@
PATH=/var/www/panel
DB_PATH=/var/www/panel/mcServ.db

View File

@@ -1,8 +1,14 @@
<?php <?php
$admin_user = $_GET["admin_user"]; require "../../main.php";
$admin_mail = $_GET["admin_mail"];
$admin_passwd_1 = $_GET["admin_passwd_1"]; ini_set("display_errors", 1);
$admin_passwd_2 = $_GET["admin_passwd_2"]; ini_set("display_startup_errors", 1);
error_reporting(E_ALL);
$admin_user = $_POST["admin_user"];
$admin_mail = $_POST["admin_mail"];
$admin_passwd_1 = $_POST["admin_passwd_1"];
$admin_passwd_2 = $_POST["admin_passwd_2"];
if (!isset($admin_user) || !isset($admin_mail) || !isset($admin_passwd_1) || !isset($admin_passwd_2)) { if (!isset($admin_user) || !isset($admin_mail) || !isset($admin_passwd_1) || !isset($admin_passwd_2)) {
die('{"status":500, "error":"Missing fields"}'); die('{"status":500, "error":"Missing fields"}');
@@ -12,14 +18,40 @@ if ($admin_passwd_2 !== $admin_passwd_1) {
die('{"status":500, "error":"Passwords do not match"}'); die('{"status":500, "error":"Passwords do not match"}');
} }
$db = new PDO("sqlite:mcserv.db"); $admin_passwd = hash("sha256", $admin_passwd_2);
$mcServ = new mcServ();
$config = $mcServ->getConf();
$db = new PDO("sqlite:" . $config["DB_PATH"]);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = " $sql = "
CREATE TABLE IF NOT EXISTS users ( CREATE TABLE IF NOT EXISTS users (
id INT(11) PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
username VARCHAR(30) PRIMARY KEY, username VARCHAR(30) UNIQUE NOT NULL,
mail VARCHAR(50), mail VARCHAR(50),
passwd VARCHAR(100) passwd VARCHAR(100)
) )
"; ";
$db->exec($sql);
$sql = "
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();
$device_id = rand(1, 999);
$json[$device_id] = json_encode($session);
$json["array"] = true;
file_put_contents($config["PATH"] . "/tmp/user_sessions/" . $admin_user . ".json", json_encode($json));
header("Location: /");
exit;
?>

View File

@@ -4,7 +4,7 @@ body {
place-items: center; place-items: center;
height: 100vh; height: 100vh;
overflow: hidden; overflow: hidden;
background-color: #fafafa; background-image: url("/css/setup.png");
} }
.page-content { .page-content {
@@ -69,6 +69,7 @@ button {
place-items: center; place-items: center;
text-align: center; text-align: center;
border: none; border: none;
border-radius: 20pt;
transition: all 0.3s ease-in-out; transition: all 0.3s ease-in-out;
} }

BIN
front/css/setup.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

View File

@@ -10,7 +10,7 @@
* By RootMarc * By RootMarc
*/ */
require "main.php"; require "../main.php";
$mcServ = new mcServ(); $mcServ = new mcServ();
@@ -18,3 +18,7 @@ if (!$mcServ->checkConf()) {
header("Location: /setup.html"); header("Location: /setup.html");
exit; exit;
} }
if (!$mcServ->checkLogin()) {
}

View File

@@ -1,14 +0,0 @@
<?php
class mcServ {
public function checkConf() {
if (!file_exists("../mgServ.db")) {
return false;
}
return true;
}
public function checkLogin() {
}
}

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>mgServ // Setup</title> <title>mcServ // Setup</title>
<link rel="stylesheet" type="text/css" href="css/setup.css"> <link rel="stylesheet" type="text/css" href="css/setup.css">
</head> </head>
<body> <body>

2
front/test.php Normal file
View File

@@ -0,0 +1,2 @@
<?php
echo __DIR__;

38
main.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
/*
_____ _____ _ _
/ ____| / ____| | | | |
_ __ ___ ___| (___ ___ _ ____ _| | ___ _ __ | |_ _ __ ___ | |
| '_ ` _ \ / __|\___ \ / _ \ '__\ \ / / | / _ \| '_ \| __| '__/ _ \| |
| | | | | | (__ ____) | __/ | \ V /| |___| (_) | | | | |_| | | (_) | |
|_| |_| |_|\___|_____/ \___|_| \_/ \_____\___/|_| |_|\__|_| \___/|_|
* By RootMarc
*/
class mcServ {
public function checkConf() {
if (!file_exists("../mcServ.db")) {
return false;
}
return true;
}
public function getConf() {
$env = parse_ini_file(__DIR__ . "/.env");
return $env;
}
public function checkLogin() {
if (!isset($_COOKIE["session_id"]) || !isset($_COOKIE["user_id"])) {
return false;
}
}
public function generateSessionID() {
$num = rand(1, 999999);
$hash = hash("sha256", $num);
return $hash;
}
}

BIN
mcServ.db Normal file

Binary file not shown.