From e6d5e27c046bb525ffebff61aa0288f0f031a999 Mon Sep 17 00:00:00 2001 From: Gideon Kanz Date: Tue, 13 Jan 2026 13:02:09 +0100 Subject: [PATCH] g6.3 --- files/lib/basic.js | 2 +- files/login.html | 2 +- index.php | 43 ++++++++++++++++++++++++++++--------------- utils/couch.php | 7 +++++++ utils/real_server.php | 23 +++++++++++++++++++++++ 5 files changed, 60 insertions(+), 17 deletions(-) create mode 100644 utils/real_server.php diff --git a/files/lib/basic.js b/files/lib/basic.js index 4a027cf..216cce4 100644 --- a/files/lib/basic.js +++ b/files/lib/basic.js @@ -349,7 +349,7 @@ function form1(string) { async function getUserData(couchDB) { - let username = localStorage.getItem("user"); + let username = sessionStorage.getItem("user"); const res = await couchDB.get("users"); if (!res) return null; const data = res[username]; diff --git a/files/login.html b/files/login.html index a45742c..1b30d74 100644 --- a/files/login.html +++ b/files/login.html @@ -145,7 +145,7 @@ async function login() { return alert("Incorrect password!"); } - localStorage.setItem("user", username); + sessionStorage.setItem("user", username); if (user.role === "student") { location.href = "./student/uebersicht.html"; diff --git a/index.php b/index.php index 86285e1..17351ab 100644 --- a/index.php +++ b/index.php @@ -1,20 +1,33 @@ filesDir = "./files/"; -$path_info->contentDir = "./files/"; -$path_info->homeFile = "./files/START.html"; -$path_info->notFoundFile = "./files/NOT-FOUND.html"; - - -$url_obj = TurtleURLObject::create_from_server(false, false); - -if (str_starts_with($url_obj->url, "couchdb")) { +function main() { + if (!server_check()) { + echo 'Access denied'; + return; + } + + $path_info = new TurtlePathInfo(); + $path_info->filesDir = "./files/"; + $path_info->contentDir = "./files/"; + $path_info->homeFile = "./files/START.html"; + $path_info->notFoundFile = "./files/NOT-FOUND.html"; + + + $url_obj = TurtleURLObject::create_from_server(false, false); $couchDB = new CouchDB("./data/couchdb.json", "./data/def_data.json", $url_obj); - $couchDB->execute(); -} else { - $url_obj->handle_request($path_info); -} \ No newline at end of file + + if (str_starts_with($url_obj->url, "couchdb")) { + $couchDB->execute(); + } else if ($url_obj->url == "reset") { + $url_obj->url = ""; + $couchDB->resetFile(); + $url_obj->handle_request($path_info); + } else { + $url_obj->handle_request($path_info); + } +} + +main(); \ No newline at end of file diff --git a/utils/couch.php b/utils/couch.php index 8d88db8..4f5088f 100644 --- a/utils/couch.php +++ b/utils/couch.php @@ -33,6 +33,13 @@ class CouchDB { 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 { http_response_code($code); $this->url_obj->send_json(["ok" => false, "reason" => $msg]); diff --git a/utils/real_server.php b/utils/real_server.php new file mode 100644 index 0000000..ecb26cf --- /dev/null +++ b/utils/real_server.php @@ -0,0 +1,23 @@ += '08' && $currentTime < '12') + ; +} \ No newline at end of file