g6.3
This commit is contained in:
1 parent
5ed63249a4
commit
e6d5e27c04
5 files changed
+58
-15
No files matched your search
+1
-1
@@ -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
@@ -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";
|
||||||
|
|||||||
@@ -1,20 +1,33 @@
|
|||||||
<?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->filesDir = "./files/";
|
||||||
|
$path_info->contentDir = "./files/";
|
||||||
|
$path_info->homeFile = "./files/START.html";
|
||||||
|
$path_info->notFoundFile = "./files/NOT-FOUND.html";
|
||||||
|
|
||||||
|
|
||||||
$path_info = new TurtlePathInfo();
|
$url_obj = TurtleURLObject::create_from_server(false, false);
|
||||||
$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);
|
|
||||||
|
|
||||||
if (str_starts_with($url_obj->url, "couchdb")) {
|
|
||||||
$couchDB = new CouchDB("./data/couchdb.json", "./data/def_data.json", $url_obj);
|
$couchDB = new CouchDB("./data/couchdb.json", "./data/def_data.json", $url_obj);
|
||||||
$couchDB->execute();
|
|
||||||
} else {
|
if (str_starts_with($url_obj->url, "couchdb")) {
|
||||||
$url_obj->handle_request($path_info);
|
$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)));
|
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]);
|
||||||
|
|||||||
@@ -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