From 40be40db926f6a305a1d989a9dd5af35e22dcf4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Fri, 9 Jun 2023 22:06:13 +0200 Subject: [PATCH] add some failsafes --- admin/api.php | 9 +++++++++ index.php | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/admin/api.php b/admin/api.php index 6d66327..9bbb386 100644 --- a/admin/api.php +++ b/admin/api.php @@ -14,6 +14,9 @@ if (!empty($action)){ if ($action == "get"){ if ($_POST["password"] == $config["admin_pwd"]){ + if(!file_exists("../data/pageindex.json")){ + file_put_contents("../data/pageindex.json", "{}"); + } $stranky = json_decode(file_get_contents("../data/pageindex.json"), true); $out = ""; foreach($stranky as $idx => $arr) { @@ -46,6 +49,9 @@ if (!empty($action)){ } if ($action == "getcontent"){ + if(!file_exists("../data/contents.json")){ + file_put_contents("../data/contents.json", "{}"); + } if ($_POST["password"] == $config["admin_pwd"]){ $contents = json_decode(file_get_contents("../data/contents.json"), true); $out = "
IDContent IDNicknameButton
"; @@ -77,6 +83,9 @@ if (!empty($action)){ } if ($action == "getlog"&& !empty($_POST["id"])){ + if(!file_exists("../data/logs.json")){ + file_put_contents("../data/logs.json", "{}"); + } if ($_POST["password"] == $config["admin_pwd"]){ $logy = json_decode(file_get_contents("../data/logs.json"), true)[$_POST["id"]]; $out = "
Content IDContentButton
"; diff --git a/index.php b/index.php index 3d77fca..ded7785 100644 --- a/index.php +++ b/index.php @@ -10,6 +10,14 @@ if (!empty($idcko)){ file_put_contents("data/logs.json", "{}"); } + if(!file_exists("data/pageindex.json")){ + file_put_contents("data/pageindex.json", "{}"); + } + + if(!file_exists("data/contents.json")){ + file_put_contents("data/contents.json", "{}"); + } + $stranky = json_decode(file_get_contents("data/pageindex.json"), true); $contents = json_decode(file_get_contents("data/contents.json"), true); $logs = json_decode(file_get_contents("data/logs.json"), true); @@ -20,7 +28,7 @@ if (!empty($idcko)){ if(array_key_exists($idcko, $stranky)){ $entry = $stranky[$idcko]; - + if (!array_key_exists($entry["contentid"], $contents)){ die("Faulty link"); }
ActionDate and TimeNicknameLinkIP