diff options
author | Minteck <contact@minteck.org> | 2022-06-06 17:10:14 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-06-06 17:10:14 +0200 |
commit | 10b1ace835d908d32f99874facf8811534087d5b (patch) | |
tree | ecf068e4ac40f7470ca2b5ac6bd13bd8fbe13ba9 /Private/SessionChecker.php | |
download | bits-server-10b1ace835d908d32f99874facf8811534087d5b.tar.gz bits-server-10b1ace835d908d32f99874facf8811534087d5b.tar.bz2 bits-server-10b1ace835d908d32f99874facf8811534087d5b.zip |
Initial commit
Diffstat (limited to 'Private/SessionChecker.php')
-rw-r--r-- | Private/SessionChecker.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Private/SessionChecker.php b/Private/SessionChecker.php new file mode 100644 index 0000000..194c398 --- /dev/null +++ b/Private/SessionChecker.php @@ -0,0 +1,25 @@ +<?php + +global $SessionManagerAllowDisallowed; + +if (isset($_COOKIE['BITS_SESSION_TOKEN'])) { + if (str_contains($_COOKIE['BITS_SESSION_TOKEN'], ".") || str_contains($_COOKIE['BITS_SESSION_TOKEN'], "/")) { + header("Content-Type: application/json"); die("{\n \"status\": 1\n}"); + } + + 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("Content-Type: application/json"); die("{\n \"status\": 1\n}"); + } 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("Content-Type: application/json"); die("{\n \"status\": 1\n}"); + } +} else { + header("Content-Type: application/json"); die("{\n \"status\": 1\n}"); +}
\ No newline at end of file |