diff --git a/admin/index.php b/admin/index.php index e33a401..456a056 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,8 +1,16 @@ getSessionData("login") == null) && ($fs->getSessionData("login") != "true-as-hell")) { + header("Location: login.php"); + die(); } ?> diff --git a/admin/insert-jinxxy.php b/admin/insert-jinxxy.php index 87fc751..745cdba 100644 --- a/admin/insert-jinxxy.php +++ b/admin/insert-jinxxy.php @@ -1,8 +1,16 @@ getSessionData("login") == null) && ($fs->getSessionData("login") != "true-as-hell")) { + header("Location: login.php"); + die(); } $furatalog = new mysqli("localhost", "furatalog_admin_usr", "NR6tLk7c56bPT5[]", "furatalog"); diff --git a/admin/insert-species.php b/admin/insert-species.php index 57e0bff..1dc821a 100644 --- a/admin/insert-species.php +++ b/admin/insert-species.php @@ -1,9 +1,17 @@ getSessionData("login") == null) && ($fs->getSessionData("login") != "true-as-hell")) { + header("Location: login.php"); + die(); } $_POST["nsfw"] = isset($_POST["nsfw"]) ? "1" : "0"; diff --git a/admin/insert.php b/admin/insert.php index 59e6cf2..f2001d9 100644 --- a/admin/insert.php +++ b/admin/insert.php @@ -1,9 +1,17 @@ getSessionData("login") == null) && ($fs->getSessionData("login") != "true-as-hell")) { + header("Location: login.php"); + die(); } if (isset($_GET["url"])) { diff --git a/admin/login.php b/admin/login.php index bf24056..9ec131a 100644 --- a/admin/login.php +++ b/admin/login.php @@ -1,5 +1,6 @@ setSessionData("login", "true-as-hell"); + //$redirect = isset($_SESSION["ref"]) ? $_SESSION["ref"] : "index"; + $redirect = !($fs->getSessionData("ref") == null) ? $fs->getSessionData("ref") : "index"; + //unset($_SESSION["ref"]); + $fs->unsetSessionData("ref"); header("Location: " . $redirect . ".php"); die(); } } -if (isset($_SESSION["login"]) && $_SESSION["login"] == "true-as-hell") { +/*if (isset($_SESSION["login"]) && $_SESSION["login"] == "true-as-hell") { header("Location: index.php"); die(); +}*/ + +if (($fs->getSessionData("login") == null) && ($fs->getSessionData("login") == "true-as-hell")) { + header("Location: login.php"); + die(); } ?> diff --git a/admin/logout.php b/admin/logout.php index 88c6841..27f07d7 100644 --- a/admin/logout.php +++ b/admin/logout.php @@ -1,6 +1,12 @@ destroy(); + header("Location: login.php"); die(); ?> \ No newline at end of file diff --git a/admin/redirectFromJinxxy.php b/admin/redirectFromJinxxy.php index f0f622f..e62597f 100644 --- a/admin/redirectFromJinxxy.php +++ b/admin/redirectFromJinxxy.php @@ -1,6 +1,6 @@ getSessionData("tmpdata") == null) ) { + $_POST["data"] = $fs->getSessionData("tmpdata"); + $fs->unsetSessionData("tmpdata"); +} + +if (($fs->getSessionData("login") == null) && ($fs->getSessionData("login") != "true-as-hell")) { + $fs->setSessionData("tmpdata", $_POST["data"]); + header("Location: login.php"); + die(); } $creator_name; diff --git a/data/script/furatalog.sessions.php b/data/script/furatalog.sessions.php new file mode 100644 index 0000000..88caf72 --- /dev/null +++ b/data/script/furatalog.sessions.php @@ -0,0 +1,115 @@ +setSessionData("nsfw", true); +//$fs->getSessionData("nsfw"); + +class furatalogSessions { + public $cookieKey = ""; + public $dataObj; + private mysqli $db; + private $cookie_duration = 30 * 24 * 60 * 60; + + public function __construct() { + $this->dataObj = (object) array(); + $this->connectDb(); + $this->getCookieKey(); + } + + public function setSessionData($varName, $content) { + $this->dataObj->{$varName} = $content; + $this->saveToDb(); + $this->saveCookie(); + } + + public function getSessionData($varName) { + try { + return $this->dataObj->{$varName}; + } catch (Exception $e) { + return null; + } + } + + public function unsetSessionData($varName) { + unset($this->dataObj->{$varName}); + } + + public function destroy() { + $this->deleteData($this->cookieKey); + $this->deleteCookie(); + } + + private function saveToDb() { + $jsonDataToSave = json_encode($this->dataObj, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE); + + $tmpresult = $this->db->query("SELECT cookieKey FROM `sessions` WHERE cookieKey=\"" . $randomString . "\""); + if (!($tmpresult->num_rows > 0)) { + $this->db->query("INSERT INTO `sessions`(`cookieKey`, `lastused`, `data`) VALUES ('" . $this->cookieKey . "', now(),'" . $jsonDataToSave . "')"); + } else { + $this->db->query("UPDATE `sessions` SET lastused=now(), data='" . $jsonDataToSave . "' WHERE cookieKey=\"" . $this->cookieKey . "\";"); + } + } + + private function saveCookie() { + setcookie("_cookieKey", $this->cookieKey, $this->cookie_duration); + } + + private function connectDb() { + $this->db = new mysqli("localhost", "furatalog_admin_usr", "NR6tLk7c56bPT5[]", "furatalog"); + } + + private function getCookieKey() { + $this->cookieKey = isset($_COOKIE["_cookieKey"]) ? $_COOKIE["_cookieKey"] : ""; + + if ($this->cookieKey == "") { + $this->cookieKey = generateKey(); + } + } + + private function getData() { + $tmpresult = $this->db->query("SELECT id, cookieKey, UNIX_TIMESTAMP(lastused) as lastused, data FROM sessions WHERE cookieKey=\"" . $this->cookieKey . "\""); + if ($tmpresult->num_rows > 0) { + $fetchedData = $tmpresult->fetch_assoc(); + + if ($fetchedData["lastused"] < strtotime('-30 days')) { + $this->deleteData($fetchedData["cookieKey"]); + $this->deleteCookie(); + $this->getCookieKey(); + } else { + $this->dataObj = json_decode($fetchedData["data"]); + } + } + } + + private function deleteCookie() { + setcookie("_cookieKey", "", time()-3600); + } + + private function deleteData($cookieKey) { + if ($cookieKey != "" && $cookieKey != null) { + $tmpresult = $this->db->query("DELETE FROM sessions WHERE cookieKey=\"" . $cookieKey . "\""); + } + } + + private function generateKey() { + $isNotInDB = false; + + do { + $length = 20; + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[random_int(0, $charactersLength - 1)]; + } + + $tmpresult = $this->db->query("SELECT cookieKey FROM `sessions` WHERE cookieKey=\"" . $randomString . "\""); + if (!($tmpresult->num_rows > 0)) { + $isNotInDB = true; + } + } while (!$isNotInDB); + + return $randomString; + } +} \ No newline at end of file