g6.3
This commit is contained in:
1 parent
5ed63249a4
commit
e6d5e27c04
5 files changed
+46
-3
No files matched your search
+1
-1
@@ -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];
|
||||
|
||||
+1
-1
@@ -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";
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
<?php
|
||||
require_once './utils/url_handler.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->filesDir = "./files/";
|
||||
@@ -11,10 +17,17 @@ $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);
|
||||
|
||||
if (str_starts_with($url_obj->url, "couchdb")) {
|
||||
$couchDB = new CouchDB("./data/couchdb.json", "./data/def_data.json", $url_obj);
|
||||
$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();
|
||||
@@ -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]);
|
||||
|
||||
@@ -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')
|
||||
;
|
||||
}
|
||||
Reference in new issue
Block a user