g6.2
This commit is contained in:
1 parent
f5704e87df
commit
96594641dc
11 files changed
+137
-103
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
Gruppe 14: SASSY
|
||||||
|
|
||||||
|
WebServer starten:
|
||||||
|
`php -qS localhost:8000`
|
||||||
|
|
||||||
|
WebServer (Debug) starten:
|
||||||
|
`php -S localhost:8000`
|
||||||
+1
-8
@@ -349,14 +349,7 @@ function form1(string) {
|
|||||||
|
|
||||||
|
|
||||||
async function getUserData(couchDB) {
|
async function getUserData(couchDB) {
|
||||||
let username = getURLArgsMap()["user"];
|
let username = localStorage.getItem("user");
|
||||||
if (!username) {
|
|
||||||
if (debug && typeof (debug_username) == "string") {
|
|
||||||
username = debug_username;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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];
|
||||||
|
|||||||
+8
-2
@@ -7,6 +7,7 @@
|
|||||||
<link rel="stylesheet" href="./lib/basic.css" />
|
<link rel="stylesheet" href="./lib/basic.css" />
|
||||||
<script src="./auth.js"></script>
|
<script src="./auth.js"></script>
|
||||||
<script src="./lib/basic.js"></script>
|
<script src="./lib/basic.js"></script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
* {
|
* {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
@@ -98,6 +99,7 @@
|
|||||||
autocomplete="username"
|
autocomplete="username"
|
||||||
autocapitalize="off"
|
autocapitalize="off"
|
||||||
autocorrect="off"
|
autocorrect="off"
|
||||||
|
onkeypress='if (event.key == "Enter") login()'
|
||||||
required
|
required
|
||||||
autofocus
|
autofocus
|
||||||
/>
|
/>
|
||||||
@@ -108,6 +110,7 @@
|
|||||||
id="password"
|
id="password"
|
||||||
name="password"
|
name="password"
|
||||||
autocomplete="current-password"
|
autocomplete="current-password"
|
||||||
|
onkeypress='if (event.key == "Enter") login()'
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -141,11 +144,14 @@ async function login() {
|
|||||||
if (user.password != password) {
|
if (user.password != password) {
|
||||||
return alert("Incorrect password!");
|
return alert("Incorrect password!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localStorage.setItem("user", username);
|
||||||
|
|
||||||
if (user.role === "student") {
|
if (user.role === "student") {
|
||||||
location.href = "./student/uebersicht.html?user=" + username;
|
location.href = "./student/uebersicht.html";
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
location.href = "./prof/uebersicht.html?user=" + username;
|
location.href = "./prof/uebersicht.html";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ button.navigation:hover {
|
|||||||
<div class="header_bar_1">
|
<div class="header_bar_1">
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<button onclick="location.href = './uebersicht.html?user=' + userData.name;" class="navigation">Meine Kurse</button>
|
<button onclick="location.href = './uebersicht.html';" class="navigation">Meine Kurse</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div><b>Auswertungen</b></div>
|
<div><b>Auswertungen</b></div>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ setUserData(couchDB);
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="header_bar_1">
|
<div class="header_bar_1">
|
||||||
<button class="back" onclick="location.href = './uebersicht.html?user=' + userData.name;">
|
<button class="back" onclick="location.href = './uebersicht.html';">
|
||||||
Übersicht
|
Übersicht
|
||||||
</button>
|
</button>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ setUserData(couchDB);
|
|||||||
Meine Kurse
|
Meine Kurse
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button class="auswertung" onclick='location.href = "./auswertung.html?user=" + userData.name'>
|
<button class="auswertung" onclick='location.href = "./auswertung.html";'>
|
||||||
Auswertungen
|
Auswertungen
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="header_bar_1">
|
<div class="header_bar_1">
|
||||||
<div>
|
<div>
|
||||||
<button onclick="location.href = './uebersicht.html?user=' + userData.name;" class="back">Meine
|
<button onclick="location.href = './uebersicht.html" class="back">Meine
|
||||||
Kurse</button>
|
Kurse</button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ async function startSurvey() {
|
|||||||
users[userData.name].courses.push(code);
|
users[userData.name].courses.push(code);
|
||||||
}
|
}
|
||||||
await couchDB.set("users", users);
|
await couchDB.set("users", users);
|
||||||
location.href = "./umfrage.html?user=" + userData.name + ",course=" + code;
|
location.href = "./umfrage.html?course=" + code;
|
||||||
} else {
|
} else {
|
||||||
alert("Umfrage nicht gefunden!");
|
alert("Umfrage nicht gefunden!");
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ async function setCourseView() {
|
|||||||
card.addEventListener("click", (e) => {
|
card.addEventListener("click", (e) => {
|
||||||
if (e.target.closest("button")) return;
|
if (e.target.closest("button")) return;
|
||||||
location.href =
|
location.href =
|
||||||
"./kursAnzeige.html?user=" + userData.name + ",course=" + courseId;
|
"./kursAnzeige.html?course=" + courseId;
|
||||||
});
|
});
|
||||||
|
|
||||||
const surveyUrl = (card.innerHTML = `
|
const surveyUrl = (card.innerHTML = `
|
||||||
@@ -240,7 +240,7 @@ async function setCourseView() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
${isExpired ? '': `
|
${isExpired ? '': `
|
||||||
<button class="action start" onclick='location.href = "./umfrage.html?user=${userData.name},course=${courseId.trim()}";'>
|
<button class="action start" onclick='location.href = "./umfrage.html?course=${courseId.trim()}";'>
|
||||||
Umfrage Starten
|
Umfrage Starten
|
||||||
</button>`
|
</button>`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ async function updateCourseAnswer(answer) {
|
|||||||
return kurs;
|
return kurs;
|
||||||
}
|
}
|
||||||
function close_page() {
|
function close_page() {
|
||||||
location.href = "./uebersicht.html?user=" + userData.name;
|
location.href = "./uebersicht.html";
|
||||||
}
|
}
|
||||||
|
|
||||||
function createNavBar(pos) {
|
function createNavBar(pos) {
|
||||||
@@ -287,7 +287,7 @@ async function onFinishEva() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function onEndEvent() {
|
async function onEndEvent() {
|
||||||
location.href = "./uebersicht.html?user=" + userData.name;
|
location.href = "./uebersicht.html";
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ require_once './utils/couch.php';
|
|||||||
|
|
||||||
|
|
||||||
$path_info = new TurtlePathInfo();
|
$path_info = new TurtlePathInfo();
|
||||||
$path_info->content = "./files/";
|
$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);
|
$url_obj = TurtleURLObject::create_from_server(false, false);
|
||||||
|
|
||||||
|
|||||||
+107
-83
@@ -1,12 +1,43 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class TurtlePathInfo {
|
class TurtlePathInfo {
|
||||||
public string $content;
|
public static function create_default(string $filesDir) :TurtlePathInfo {
|
||||||
|
$res = new TurtlePathInfo();
|
||||||
|
$res->filesDir = $filesDir;
|
||||||
|
$res->contentDir = "{$filesDir}content/";
|
||||||
|
$res->homeFile = "{$res->contentDir}HOME";
|
||||||
|
$res->notFoundFile = "{$res->contentDir}NOT-FOUND";
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string $filesDir;
|
||||||
|
public string $contentDir;
|
||||||
|
|
||||||
|
public string $homeFile;
|
||||||
|
public string $notFoundFile;
|
||||||
|
}
|
||||||
|
|
||||||
class TurtleURLObject {
|
class TurtleURLObject {
|
||||||
|
public static function parse_url_mark(array $urlParts) :object {
|
||||||
|
$res = (object) [];
|
||||||
|
if (count($urlParts) == 1) return $res;
|
||||||
|
foreach (explode('&', $urlParts[1]) as $part) {
|
||||||
|
$arr = explode('=', $part, 2);
|
||||||
|
$cnt = count($arr);
|
||||||
|
switch ($cnt) {
|
||||||
|
case 1:
|
||||||
|
$res->{$arr[0]} = 1;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$res->{$arr[0]} = $arr[1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
public static function create_from_server(bool $lowerCase = true, bool $alternativeURL = true) :TurtleURLObject {
|
public static function create_from_server(bool $lowerCase = true, bool $alternativeURL = true) :TurtleURLObject {
|
||||||
$urlParts = explode('?', trim($_SERVER['REQUEST_URI'], '/'));
|
$urlParts = explode('?', trim($_SERVER['REQUEST_URI'], '/'));
|
||||||
$urlMark = _parseUrlMark($urlParts);
|
$urlMark = TurtleURLObject::parse_url_mark($urlParts);
|
||||||
$request = str_replace("..", ".", $urlParts[0]);
|
$request = str_replace("..", ".", $urlParts[0]);
|
||||||
|
|
||||||
if ($lowerCase) $request = strtolower($request);
|
if ($lowerCase) $request = strtolower($request);
|
||||||
@@ -32,116 +63,109 @@ class TurtleURLObject {
|
|||||||
$bodyContent = file_get_contents("php://input");
|
$bodyContent = file_get_contents("php://input");
|
||||||
return $bodyContent;
|
return $bodyContent;
|
||||||
}
|
}
|
||||||
|
public function get_body_json() :mixed {
|
||||||
public function get_html_file(string $file_path): string {
|
$res = json_decode($this->get_body_text());
|
||||||
if (!file_exists($file_path)) {
|
return json_last_error() === JSON_ERROR_NONE ? $res: null;
|
||||||
return "Not found!";
|
|
||||||
} else {
|
|
||||||
return file_get_contents($file_path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public function send_text(string $text) :void {
|
public function send_text(string $text) :void {
|
||||||
header('Content-Type: text/plain');
|
$this->set_ext_header('txt');
|
||||||
echo $text;
|
echo $text;
|
||||||
}
|
}
|
||||||
public function send_json(mixed $data) :void {
|
public function send_json(mixed $data) :void {
|
||||||
header('Content-Type: application/json');
|
$this->set_ext_header('json');
|
||||||
echo json_encode($data);
|
echo json_encode($data);
|
||||||
}
|
}
|
||||||
public function send_image(string $path) :void {
|
|
||||||
|
//send custom content
|
||||||
|
|
||||||
|
public function send_file(string $path) :void {
|
||||||
$fileExt = pathinfo($path, PATHINFO_EXTENSION);
|
$fileExt = pathinfo($path, PATHINFO_EXTENSION);
|
||||||
if ($fileExt === "ico") {
|
$fileExt = strtolower(ltrim($fileExt, '.'));
|
||||||
|
$this->set_ext_header($fileExt);
|
||||||
|
|
||||||
|
if ($fileExt == "html") {
|
||||||
|
if (!is_file($path)) echo 'File not found!';
|
||||||
|
else echo $this->get_html_file($path);
|
||||||
|
} else {
|
||||||
|
if (!is_file($path)) echo '';
|
||||||
|
else readfile($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function allow_ext_referer(string $ext) :bool {
|
||||||
|
$types = $this->method_type;
|
||||||
|
if (isFileExtImage($ext)) {
|
||||||
|
foreach ($types as $i) if (str_starts_with($i, 'image/')) return true;
|
||||||
|
return false;
|
||||||
|
} else if ($ext == 'js') {
|
||||||
|
if (sizeof($types) == 1 && $types[0] == "*/*") return true;
|
||||||
|
return false;
|
||||||
|
} else if ($ext == 'css') {
|
||||||
|
foreach ($types as $i) if ($i == 'text/css') return true;
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function set_ext_header(string $ext) :void {
|
||||||
|
if (isFileExtImage($ext)) {
|
||||||
|
if ($ext === "ico") {
|
||||||
header("Cache-Control: no-cache, must-revalidate, max-age=0");
|
header("Cache-Control: no-cache, must-revalidate, max-age=0");
|
||||||
header("Content-Type: image/x-icon");
|
header("Content-Type: image/x-icon");
|
||||||
} else {
|
} else {
|
||||||
header("Content-Type: image/$fileExt");
|
header("Content-Type: image/$ext");
|
||||||
}
|
}
|
||||||
readfile($path);
|
return;
|
||||||
}
|
}
|
||||||
public function send_custom_file(string $path) :bool {
|
switch ($ext) {
|
||||||
$fileExt = pathinfo($path, PATHINFO_EXTENSION);
|
case 'html':
|
||||||
if (isFileExtImage($fileExt)) {
|
header('Content-Type: text/html'); break;
|
||||||
$this->send_image($path);
|
case 'json':
|
||||||
} else if ($fileExt == "json") {
|
header('Content-Type: application/json'); break;
|
||||||
$content = file_get_contents($path);
|
case 'css':
|
||||||
if ($content == false) return false;
|
header("Content-Type: text/css"); break;
|
||||||
header('Content-Type: application/json');
|
case 'js':
|
||||||
echo $content;
|
header('Content-Type: application/javascript; charset=utf-8'); break;
|
||||||
} else if ($fileExt == "txt") {
|
case 'md': case 'txt':
|
||||||
$content = file_get_contents($path);
|
header('Content-Type: text/plain'); break;
|
||||||
if ($content == false) return false;
|
case 'pdf':
|
||||||
$this->send_text($content);
|
header("Content-Type: application/$ext"); break;
|
||||||
} else if ($fileExt == "js") {
|
default:
|
||||||
header('Content-Type: text/javascript; charset=utf-8');
|
header('Content-Type: text/html'); break;
|
||||||
echo file_get_contents($path);
|
|
||||||
return true;
|
|
||||||
} else if ($fileExt == "css") {
|
|
||||||
header("Content-Type: text/css");
|
|
||||||
echo file_get_contents($path);
|
|
||||||
} else if ($fileExt == "html") {
|
|
||||||
echo $this->get_html_file($path);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function is_image_request() :bool {
|
//execution
|
||||||
foreach ($this->method_type as $type) {
|
|
||||||
if (!str_starts_with($type, "image/")) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private function get_html_file(string $file_path): string {
|
||||||
|
return file_get_contents($file_path);
|
||||||
|
}
|
||||||
|
private function _get_path(string|null $path, string $filesDir = "") :string {
|
||||||
|
if ($path == null || is_file($path)) return $path;
|
||||||
|
if (is_file("$path.html")) return "$path.html";
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
public function handle_request(TurtlePathInfo $path_info): void {
|
public function handle_request(TurtlePathInfo $path_info): void {
|
||||||
$referer = $_SERVER['HTTP_REFERER'] ?? '';
|
$referer = $_SERVER['HTTP_REFERER'] ?? '';
|
||||||
|
|
||||||
$filePath = $path_info->content . $this->url;
|
$filePath = $path_info->contentDir . $this->url;
|
||||||
|
if (strlen($this->url) == 0) $filePath = $path_info->homeFile;
|
||||||
|
|
||||||
if (strlen($this->url) == 0) {
|
$filePath = $this->_get_path($filePath, $path_info->filesDir);
|
||||||
$filePath = "{$path_info->content}START.html";
|
if (!($this->allow_ext_referer(pathinfo($filePath, PATHINFO_EXTENSION)))) {
|
||||||
|
$filePath = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------Image-Pages-------------------//
|
if ($filePath == null || !is_file($filePath)) {
|
||||||
else if (
|
|
||||||
!empty($referer) && $this->is_image_request()
|
|
||||||
) {
|
|
||||||
if (file_exists($filePath)) {
|
|
||||||
$this->send_image($filePath);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
$filePath = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------HTML-Pages-------------------//
|
|
||||||
|
|
||||||
if ($filePath === NULL || !file_exists($filePath)) {
|
|
||||||
$filePath = "{$path_info->content}NOT-FOUND.html";
|
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
|
$filePath = $this->_get_path($path_info->notFoundFile, $path_info->filesDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->send_custom_file($filePath);
|
$this->send_file($filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _parseUrlMark($urlParts) :object {
|
|
||||||
$res = (object) [];
|
|
||||||
if (count($urlParts) == 1) return $res;
|
|
||||||
foreach (explode('&', $urlParts[1]) as $part) {
|
|
||||||
$arr = explode('=', $part, 2);
|
|
||||||
$cnt = count($arr);
|
|
||||||
switch ($cnt) {
|
|
||||||
case 1:
|
|
||||||
$res->{$arr[0]} = 1;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
$res->{$arr[0]} = $arr[1];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
function isFileExtImage(string $fileExt) :bool {
|
function isFileExtImage(string $fileExt) :bool {
|
||||||
switch ($fileExt) {
|
switch ($fileExt) {
|
||||||
case 'png':
|
case 'png':
|
||||||
|
|||||||
Reference in new issue
Block a user