Continue Setup
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
<?php
|
||||
$admin_user = $_GET["admin_user"];
|
||||
$admin_mail = $_GET["admin_mail"];
|
||||
$admin_passwd_1 = $_GET["admin_passwd_1"];
|
||||
$admin_passwd_2 = $_GET["admin_passwd_2"];
|
||||
require "../../main.php";
|
||||
|
||||
ini_set("display_errors", 1);
|
||||
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)) {
|
||||
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"}');
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
$sql = "
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INT(11) PRIMARY KEY AUTOINCREMENT,
|
||||
username VARCHAR(30) PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username VARCHAR(30) UNIQUE NOT NULL,
|
||||
mail VARCHAR(50),
|
||||
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;
|
||||
?>
|
||||
@@ -4,7 +4,7 @@ body {
|
||||
place-items: center;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
background-color: #fafafa;
|
||||
background-image: url("/css/setup.png");
|
||||
}
|
||||
|
||||
.page-content {
|
||||
@@ -69,6 +69,7 @@ button {
|
||||
place-items: center;
|
||||
text-align: center;
|
||||
border: none;
|
||||
border-radius: 20pt;
|
||||
transition: all 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
|
||||
BIN
front/css/setup.png
Normal file
BIN
front/css/setup.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 MiB |
@@ -10,11 +10,15 @@
|
||||
* By RootMarc
|
||||
*/
|
||||
|
||||
require "main.php";
|
||||
require "../main.php";
|
||||
|
||||
$mcServ = new mcServ();
|
||||
|
||||
if (!$mcServ->checkConf()) {
|
||||
header("Location: /setup.html");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$mcServ->checkLogin()) {
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
class mcServ {
|
||||
public function checkConf() {
|
||||
if (!file_exists("../mgServ.db")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkLogin() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<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">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
2
front/test.php
Normal file
2
front/test.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo __DIR__;
|
||||
38
main.php
Normal file
38
main.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user