diff --git a/GIT-MGMT.sh b/GIT-MGMT.sh new file mode 100644 index 0000000..cf46dde --- /dev/null +++ b/GIT-MGMT.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +while true; do + +echo "" +echo "=============================" +echo " Git Management Script" +echo "=============================" +echo "" +echo "1) Geänderte Dateien anzeigen" +echo "2) Einzelne Dateien zum Commit auswählen" +echo "3) Alles stagen" +echo "4) Commit & Push" +echo "5) Alte Stände anzeigen" +echo "6) Aktueller Branch" +echo "7) Änderungen" +echo "99) Programm beenden" +echo "" + +read -p "Auswahl: " auswahl + +case $auswahl in + + 1) + echo "Geänderte Dateien:" + git status -s + ;; + + 2) + echo "Geänderte Dateien:" + git status -s + echo "" + read -p "Welche Datei soll gestaged werden? (Pfad eingeben): " file + git add "$file" + echo ">> Datei '$file' wurde gestaged." + ;; + + 3) + echo ">> Alle Dateien werden gestaged..." + git add -A + ;; + + 4) + read -p "Commit Nachricht: " commitmsg + git commit -m "$commitmsg" + echo ">> Pushen..." + git push + ;; + + 5) + echo ">> Alte Commits:" + git log --oneline --graph --decorate --all + ;; + 6) + echo "Aktueller Branch" + git branch + ;; + 7) + echo "Änderungen" + git status + ;; + + 99) + echo "Beendet." + exit 0 + ;; + + *) + echo "Ungültige Auswahl!" + ;; +esac +done + diff --git a/PUBLIC.code-workspace b/PUBLIC.code-workspace new file mode 100644 index 0000000..81f970f --- /dev/null +++ b/PUBLIC.code-workspace @@ -0,0 +1,46 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "workbench.colorTheme": "Default Dark Modern", + "workbench.colorCustomizations": { + "activityBar.background": "#ff000075", + "activityBar.foreground": "#000000", + "breadcrumb.foreground": "#FFFFFF", + }, + "editor.renderWhitespace": "all", + "editor.smoothScrolling": true, + "editor.fontSize": 14, + "editor.formatOnSave": true, + "editor.minimap.enabled": true, + "editor.minimap.scale": 2, + "editor.minimap.side": "right", + "editor.minimap.maxColumn": 100, + "editor.minimap.renderCharacters": true, + "editor.minimap.showSlider": "always", + "files.autoSave": "off", + "files.autoSaveDelay": 3000, + "window.title": "BACKEND", + "workbench.editor.wrapTabs": true, + }, + "extensions": { + "recommendations": [ + "oderwat.indent-rainbow", + "pranaygp.vscode-css-peek", + "wayou.vscode-todo-highlight", + "mrmlnc.vscode-mustache", + "fabiospampinato.vscode-highlight", + "junstyle.php-cs-fixer", + "mtea.gettext-editor", + "neilbrayfield.php-docblocker", + "bmewburn.vscode-intelephense-client", + "mohamed-ali.html-css-class-completion", + "rifi2k.format-html-in-php", + "mrorz.language-gettext", + "voldemortensen.rainbow-tags", + ] + } +} \ No newline at end of file diff --git a/WEBROOT/config.php b/WEBROOT/config.php new file mode 100644 index 0000000..d7b59a1 --- /dev/null +++ b/WEBROOT/config.php @@ -0,0 +1,8 @@ + ['name' => 'Service 1', 'active' => false], + 'request_logs' => ['name' => 'Request Logs', 'active' => true], + 'request_chart' => ['name' => 'Request Statics', 'active' => true], + 'services_control' => ['name' => 'Services Control', 'active' => true], +]; +?> \ No newline at end of file diff --git a/WEBROOT/controller/CookieController.php b/WEBROOT/controller/CookieController.php new file mode 100644 index 0000000..d95870d --- /dev/null +++ b/WEBROOT/controller/CookieController.php @@ -0,0 +1,39 @@ +SetCookie("USER", "7", 60); + */ + +/** + * Cookie auslesen: + * $cookieValue = $cookieManager->readCookieValueCookie("USER"); + * echo $cookieValue; + */ + +/** + * Cookie loeschen: + * $cookieManager->DeleteCookie("USER"); + */ \ No newline at end of file diff --git a/WEBROOT/controller/DataController.php b/WEBROOT/controller/DataController.php new file mode 100644 index 0000000..f0eacd8 --- /dev/null +++ b/WEBROOT/controller/DataController.php @@ -0,0 +1,188 @@ +host_info; + } + + public function getServerName(): string { + $Servername = $_SERVER['SERVER_NAME'] ?? 'Unbekannt'; + + if (in_array($Servername, ['Unbekannt', '0.0.0.0', '127.0.0.1'])) { + return "Lokal"; + } else { + return $Servername; + } + } + + public function getServerIP(): string { + $ServerIP = $_SERVER['SERVER_ADDR'] ?? 'Unbekannt'; + + if (in_array($ServerIP, ['Unbekannt', '0.0.0.0', '127.0.0.1'])) { + return "Lokal"; + } else { + return $ServerIP; + } + } + + public function getClientIP(): string { + $xff = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? null; + + if ($xff) { + $ips = array_map('trim', explode(',', $xff)); + $clientIp = $ips[0]; + return $clientIp; + } else { + return $_SERVER['REMOTE_ADDR']; + } + } + + public function getRequestTime(): string { + date_default_timezone_set('Europe/Berlin'); + $timestamp = $_SERVER['REQUEST_TIME'] ?? time(); + return date('Y-m-d H:i:s', $timestamp); + } + + function getGeoIP($ClientIP) { + $whitelist = (new getSpecificData())->getWhitelistedIPs(); + + if (in_array($ClientIP, $whitelist)) { + return "Lokal"; + } else { + $response = file_get_contents("http://ip-api.com/json/{$ClientIP}?fields=country,countryCode"); + $data = json_decode($response); + return $data->country; + } + } + + function getWhitelistedIPs() { + include_once 'DatabaseController.php'; + $data = DatabaseShow( + "Whitelisted", + "`IP-ADDRESSE`" + ); + + $results = []; + foreach ($data as $row) { + $results[] =$row['IP-ADDRESSE']; + } + return $results; + } + + function getServerNode($ServerIP) { + $nodes = [ + 'node1' => '172.30.0.11', + 'node2' => '172.30.0.12', + 'node3' => '172.30.0.13', + 'node4' => '172.30.0.14', + 'Lokal' => 'Lokal', + ]; + + foreach ($nodes as $node => $ip) { + if ($ServerIP == $ip) { + return $node; + break; + } + } + } + + function getClientStatus($ClientIP) { + if (in_array($ClientIP, $this->getWhitelistedIPs())) { + return "Trusted"; + } + return "Untrusted"; + } + + function test() { + return "TEST"; + } + + public function getAllData(): array { + return [ + 'Document-Root' => $this->getDocumentRoot(), + 'CurrentDir' => $this->getCurrentDir(), + 'Referer' => $this->getReferer(), + 'Request URL' => $this->getRequestURL(), + 'Server-Port' => $this->getServerPort(), + 'Server-IP' => $this->getServerIP(), + 'Server-Name' => $this->getServerName(), + 'Server-Node' => $this->getServerNode($this->getServerIP()), + 'Client-IP' => $this->getClientIP(), + 'Client-Port' => $this->getClientPort(), + 'Client-Land' => $this->getGeoIP($this->getClientIP()), + 'Client-User-Agent' => $this->getUserAgent(), + 'Client-Cookie' => $this->getCookie('USER'), + 'Client-Server-Cookie' => $this->getCookie('SESSSRV'), + 'Client-Session-ID' => $this->getSessionID(), + 'Query' => $this->getQuery(), + 'Request-Method' => $this->getRequestMethod(), + 'Request-Time' => $this->getRequestTime(), + 'Database' => $this->getDatabase(), + 'Whitelisted Status' => $this->getClientStatus($this->getClientIP()), + 'Whitelisted IPs' => $this->getWhitelistedIPs(), + ]; + } + + public function ShowAllData(): void { + $SpecificData = (new getSpecificData())->getAllData(); + + echo "
";
+ foreach ($SpecificData as $key => $value) {
+ if (is_array($value)) {
+ $value = implode(', ', $value);
+ }
+ printf("%-22s : %s\n", $key, $value);
+ }
+ echo "";
+ }
+}
\ No newline at end of file
diff --git a/WEBROOT/controller/DatabaseConnect.php b/WEBROOT/controller/DatabaseConnect.php
new file mode 100644
index 0000000..d1c4b41
--- /dev/null
+++ b/WEBROOT/controller/DatabaseConnect.php
@@ -0,0 +1,42 @@
+ [
+ 'hostaddr' => '10.233.1.29',
+ 'username' => 'worker',
+ 'password' => 'bBHofurUJWKzPE8Z',
+ 'database' => 'DEV',
+ ],
+ 'vpn' => [
+ 'hostaddr' => '100.123.136.86',
+ 'username' => 'worker',
+ 'password' => 'bBHofurUJWKzPE8Z',
+ 'database' => 'DEV',
+ ],
+ 'live' => [
+ 'hostaddr' => '10.233.1.244',
+ 'username' => 'worker',
+ 'password' => 'bBHofurUJWKzPE8Z',
+ 'database' => 'DEV',
+ ]
+ ];
+
+ $enviroment = 'vpn';
+
+ $conn = new mysqli(
+ $servers[$enviroment]['hostaddr'],
+ $servers[$enviroment]['username'],
+ $servers[$enviroment]['password'],
+ $servers[$enviroment]['database'],
+ );
+
+ if ($conn->connect_error) {
+ throw new Exception('Connection Error: ' . $conn->connect_error);
+ }
+
+ $conn->set_charset("utf8mb4");
+ return $conn;
+}
+
+?>
\ No newline at end of file
diff --git a/WEBROOT/controller/DatabaseController.php b/WEBROOT/controller/DatabaseController.php
new file mode 100644
index 0000000..1095905
--- /dev/null
+++ b/WEBROOT/controller/DatabaseController.php
@@ -0,0 +1,177 @@
+prepare($sql);
+
+ if (!$stmt) {
+ die("Fehler beim Prepare: " . $conn->error);
+ }
+
+ if (!$stmt->execute($values)) {
+ die("Fehler beim Execute: " . $stmt->error);
+ }
+
+ $result = $stmt->get_result();
+ return $result->fetch_all(MYSQLI_ASSOC);
+}
+
+
+function DatabaseInsert($table, $columns, ...$values) {
+ include_once 'DatabaseConnect.php';
+ $conn = db_connect();
+
+ $placeholders = rtrim(str_repeat("?,", count($values)), ",");
+ $sql = "INSERT INTO `$table` ($columns) VALUES ($placeholders)";
+ $stmt = $conn->prepare($sql);
+
+ if (!$stmt) {
+ die("Fehler beim Prepare: " . $conn->error);
+ }
+
+ if (!$stmt->execute($values)) {
+ die("Fehler beim Execute: " . $stmt->error);
+ }
+
+ return true;
+}
+
+function DatabaseDelete($table, $where, ...$values) {
+ include_once 'DatabaseConnect.php';
+ $conn = db_connect();
+
+ $sql = "DELETE FROM `$table` WHERE $where";
+ $stmt = $conn->prepare($sql);
+
+ if (!$stmt) {
+ die("Fehler beim Prepare: " . $conn->error);
+ }
+
+ if (!$stmt->execute($values)) {
+ die("Fehler beim Execute: " . $stmt->error);
+ }
+
+ return true;
+}
+
+function DatabaseUpdate($table, $set, $where, ...$values) {
+ include_once 'DatabaseConnect.php';
+ $conn = db_connect();
+
+ $sql = "UPDATE `$table` SET $set WHERE $where";
+ $stmt = $conn->prepare($sql);
+
+ if (!$stmt) {
+ die("Fehler beim Prepare: " . $conn->error);
+ }
+
+ if (!$stmt->execute($values)) {
+ die("Fehler beim Execute: " . $stmt->error);
+ }
+
+ return true;
+}
+
+function DatabaseShowWithFK($table, $fkMap = [], $columns = "*", $where = "", ...$values) {
+ include_once 'DatabaseConnect.php';
+ $conn = db_connect();
+
+ $select = is_array($columns) ? implode(", ", $columns) : $columns;
+
+ $sql = "SELECT $select FROM `$table`";
+ if (!empty($where)) {
+ $sql .= " WHERE $where";
+ }
+
+ $stmt = $conn->prepare($sql);
+ if (!$stmt) die("Fehler beim Prepare: " . $conn->error);
+
+ if (!$stmt->execute($values)) die("Fehler beim Execute: " . $stmt->error);
+
+ $result = $stmt->get_result();
+ if (!$result) die("Fehler beim get_result: " . $stmt->error);
+
+ $columnsResult = [];
+ while ($fieldinfo = $result->fetch_field()) {
+ $columnsResult[] = $fieldinfo->name;
+ }
+
+ $rows = $result->fetch_all(MYSQLI_ASSOC);
+
+ foreach ($rows as &$row) {
+ foreach ($fkMap as $fkColumn => $fkInfo) {
+ if (isset($row[$fkColumn]) && $row[$fkColumn] !== null) {
+ $fkStmt = $conn->prepare(
+ "SELECT {$fkInfo['value']} FROM `{$fkInfo['table']}` WHERE {$fkInfo['key']} = ?"
+ );
+ if (!$fkStmt) die("Fehler beim Prepare FK: " . $conn->error);
+
+ $fkStmt->bind_param("i", $row[$fkColumn]);
+ $fkStmt->execute();
+ $fkResult = $fkStmt->get_result();
+ $fkRow = $fkResult->fetch_assoc();
+
+ $row[$fkColumn] = $fkRow ? $fkRow[$fkInfo['value']] : null;
+ }
+ }
+ }
+
+ return [
+ "rows" => $rows
+ ];
+}
+
+$Berufsschulberichte = [
+ "FACH_S1" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+ "LEHRER_S1" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
+ "RAUM_S1" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
+
+ "FACH_S2" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+ "LEHRER_S2" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
+ "RAUM_S2" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
+
+ "FACH_S3" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+ "LEHRER_S3" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
+ "RAUM_S3" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
+
+ "FACH_S4" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+ "LEHRER_S4" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
+ "RAUM_S4" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
+
+ "FACH_S5" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+ "LEHRER_S5" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
+ "RAUM_S5" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
+
+ "FACH_S6" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+ "LEHRER_S6" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
+ "RAUM_S6" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
+
+ "FACH_S7" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+ "LEHRER_S7" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
+ "RAUM_S7" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
+
+ "FACH_S8" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+ "LEHRER_S8" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
+ "RAUM_S8" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
+];
+
+$Stundenplan = [
+ "MO" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+ "DI" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+ "MI" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+ "DO" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+ "FR" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
+];
+
+$Berechtigungen = [
+ "BENUTZER_ID" => ["table" => "Benutzer", "key" => "ID", "value" => "ID"],
+ "BERECHTIGUNGEN_ID" => ["table" => "Berechtigungen", "key" => "ID", "value" => "ID"]
+];
\ No newline at end of file
diff --git a/WEBROOT/controller/LogController.php b/WEBROOT/controller/LogController.php
new file mode 100644
index 0000000..dbeed92
--- /dev/null
+++ b/WEBROOT/controller/LogController.php
@@ -0,0 +1,80 @@
+getClientIP();
+ $UserAgent = (new getSpecificData())->getUserAgent();
+ $RequestURL = (new getSpecificData())->getRequestURL();
+ $USERCOOKIE = (new getSpecificData())->getCookie("USER");
+ $SessionID = (new getSpecificData())->getSessionID();
+ $REQUESTTIME = (new getSpecificData())->getRequestTime();
+ $QUERY = (new getSpecificData())->getQuery();
+ $LAND = (new getSpecificData())->getGeoIP($ClientIP);
+ $Whitelisted = (new getSpecificData())->getWhitelistedIPs();
+ $node = (new getSpecificData())->getServerNode((new getSpecificData())->getServerIP());
+
+ if (in_array($ClientIP, $Whitelisted)) {
+ return;
+ }
+
+ $db_conn = db_connect();
+
+ $stmt = $db_conn->prepare("SELECT * FROM logs WHERE
+ `CLIENT_IP` LIKE ? and
+ `REQUEST_URL` = ? and
+ `REQUEST_URL` <> '/favicon.ico'
+ ");
+
+ $stmt->bind_param("ss", $ClientIP, $RequestURL);
+ $stmt->execute();
+ $stmt->store_result();
+
+ if ($RequestURL !== '/favicon.ico') {
+ if ($stmt->num_rows > 0) { //wenn mindestens eine zeile vorhanden ist für die client ip dann führe updates durch, wenn nicht mache neue zeile
+ $updateCounter = $db_conn->prepare("
+ UPDATE logs
+ SET COUNTER = COUNTER + 1
+ WHERE `CLIENT_IP` = ?
+ AND `REQUEST_URL` = ?
+ ");
+ $updateCounter->bind_param("ss", $ClientIP, $RequestURL);
+ $updateCounter->execute();
+
+ $updateLastRequest = $db_conn->prepare("
+ UPDATE logs
+ SET `LAST_REQUEST` = ?
+ WHERE `CLIENT_IP` = ?
+ AND `REQUEST_URL` = ?
+ ");
+ $updateLastRequest->bind_param("sss", $REQUESTTIME, $ClientIP, $RequestURL);
+ $updateLastRequest->execute();
+
+ $updateCookieValue = $db_conn->prepare("
+ UPDATE logs
+ SET `USER_COOKIE_VALUE` = ?
+ WHERE `CLIENT_IP` = ?
+ AND `REQUEST_URL` = ?
+ ");
+ $updateCookieValue->bind_param("sss", $USERCOOKIE, $ClientIP, $RequestURL);
+ $updateCookieValue->execute();
+ } else {
+ DatabaseInsert(
+ "logs",
+ "CLIENT_IP, LAND, SERVER_IP, USER_AGENT, REQUEST_URL, USER_COOKIE_VALUE, USER_SESSION_VALUE, FIRST_REQUEST, QUERY",
+ $ClientIP,
+ $LAND,
+ $node,
+ $UserAgent,
+ $RequestURL,
+ $USERCOOKIE,
+ $SessionID,
+ $REQUESTTIME,
+ $QUERY
+ );
+ }
+ }
+}
\ No newline at end of file
diff --git a/WEBROOT/controller/RoutesController.php b/WEBROOT/controller/RoutesController.php
new file mode 100644
index 0000000..6eb0aee
--- /dev/null
+++ b/WEBROOT/controller/RoutesController.php
@@ -0,0 +1,31 @@
+
+