summaryrefslogtreecommitdiff
path: root/Private/SessionManager.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-06-06 17:10:14 +0200
committerMinteck <contact@minteck.org>2022-06-06 17:10:14 +0200
commit10b1ace835d908d32f99874facf8811534087d5b (patch)
treeecf068e4ac40f7470ca2b5ac6bd13bd8fbe13ba9 /Private/SessionManager.php
downloadbits-server-10b1ace835d908d32f99874facf8811534087d5b.tar.gz
bits-server-10b1ace835d908d32f99874facf8811534087d5b.tar.bz2
bits-server-10b1ace835d908d32f99874facf8811534087d5b.zip
Initial commit
Diffstat (limited to 'Private/SessionManager.php')
-rw-r--r--Private/SessionManager.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/Private/SessionManager.php b/Private/SessionManager.php
new file mode 100644
index 0000000..bb6c721
--- /dev/null
+++ b/Private/SessionManager.php
@@ -0,0 +1,33 @@
+<?php
+
+if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/Data")) mkdir($_SERVER['DOCUMENT_ROOT'] . "/Data");
+if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/Data/Transactions.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/Data/Transactions.json", "[]");
+if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/Data/Users.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/Data/Users.json", "{}");
+
+global $SessionManagerAllowDisallowed;
+
+if (isset($_COOKIE['BITS_SESSION_TOKEN'])) {
+ if (str_contains($_COOKIE['BITS_SESSION_TOKEN'], ".") || str_contains($_COOKIE['BITS_SESSION_TOKEN'], "/")) {
+ header("Location: /Authentication/Start");
+ die();
+ }
+
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/Private/SessionTokens/" . str_replace(".", "", str_replace("/", "", $_COOKIE['BITS_SESSION_TOKEN'])))) {
+ $_PROFILE = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/SessionTokens/" . str_replace(".", "", str_replace("/", "", $_COOKIE['BITS_SESSION_TOKEN']))), true);
+
+ if (!in_array($_PROFILE["id"], json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/AllowedUsers.json"), true)) && !$SessionManagerAllowDisallowed) {
+ header("Location: /Authentication/Disallowed");
+ die();
+ } else {
+ $users = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Users.json"), true);
+ $users[$_PROFILE["id"]] = $_PROFILE["name"];
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Users.json", json_encode($users));
+ }
+ } else {
+ header("Location: /Authentication/Start");
+ die();
+ }
+} else {
+ header("Location: /Authentication/Start");
+ die();
+} \ No newline at end of file