This commit is contained in:
OnlyTurtle committed 2026-01-13 13:02:09 +01:00
1 parent 5ed63249a4
commit e6d5e27c04
5 files changed
+46 -3

No files matched your search

+1 -1
View File
@@ -349,7 +349,7 @@ function form1(string) {
async function getUserData(couchDB) { async function getUserData(couchDB) {
let username = localStorage.getItem("user"); let username = sessionStorage.getItem("user");
const res = await couchDB.get("users"); const res = await couchDB.get("users");
if (!res) return null; if (!res) return null;
const data = res[username]; const data = res[username];
+1 -1
View File
@@ -145,7 +145,7 @@ async function login() {
return alert("Incorrect password!"); return alert("Incorrect password!");
} }
localStorage.setItem("user", username); sessionStorage.setItem("user", username);
if (user.role === "student") { if (user.role === "student") {
location.href = "./student/uebersicht.html"; location.href = "./student/uebersicht.html";
+14 -1
View File
@@ -1,7 +1,13 @@
<?php <?php
require_once './utils/url_handler.php'; require_once './utils/url_handler.php';
require_once './utils/couch.php'; require_once './utils/couch.php';
require_once './utils/real_server.php';
function main() {
if (!server_check()) {
echo 'Access denied';
return;
}
$path_info = new TurtlePathInfo(); $path_info = new TurtlePathInfo();
$path_info->filesDir = "./files/"; $path_info->filesDir = "./files/";
@@ -11,10 +17,17 @@ $path_info->notFoundFile = "./files/NOT-FOUND.html";
$url_obj = TurtleURLObject::create_from_server(false, false); $url_obj = TurtleURLObject::create_from_server(false, false);
$couchDB = new CouchDB("./data/couchdb.json", "./data/def_data.json", $url_obj);
if (str_starts_with($url_obj->url, "couchdb")) { if (str_starts_with($url_obj->url, "couchdb")) {
$couchDB = new CouchDB("./data/couchdb.json", "./data/def_data.json", $url_obj);
$couchDB->execute(); $couchDB->execute();
} else if ($url_obj->url == "reset") {
$url_obj->url = "";
$couchDB->resetFile();
$url_obj->handle_request($path_info);
} else { } else {
$url_obj->handle_request($path_info); $url_obj->handle_request($path_info);
} }
}
main();
+7
View File
@@ -33,6 +33,13 @@ class CouchDB {
file_put_contents($this->db_file, str_replace(" ", "\t", json_encode($content, JSON_PRETTY_PRINT))); file_put_contents($this->db_file, str_replace(" ", "\t", json_encode($content, JSON_PRETTY_PRINT)));
} }
public function resetFile() {
if (file_exists($this->db_file)) {
unlink($this->db_file);
}
$this->setFile($this->getFile());
}
public function sendError(string $msg, int $code = 404) :bool { public function sendError(string $msg, int $code = 404) :bool {
http_response_code($code); http_response_code($code);
$this->url_obj->send_json(["ok" => false, "reason" => $msg]); $this->url_obj->send_json(["ok" => false, "reason" => $msg]);
+23
View File
@@ -0,0 +1,23 @@
<?php
function server_check() :bool {
if (!is_online_server()) return true;
return allow_server_access();
}
function is_online_server() :bool {
$hostname = gethostname();
return $hostname == 'www531.your-server.de';
}
function allow_server_access() :bool {
date_default_timezone_set('Europe/Berlin');
$currentDay = date('N');// Wochentag (1 = Montag, 7 = Sonntag)
$currentTime = date('H');// Aktuelle Stunde im 24-Stunden-Format
return
($currentDay === '2') &&
($currentTime >= '08' && $currentTime < '12')
;
}