add some failsafes

This commit is contained in:
Bruno Rybársky 2023-06-09 22:06:13 +02:00
parent 40ab0e4624
commit 40be40db92
No known key found for this signature in database
GPG Key ID: DFE2C061EF985CD4
2 changed files with 18 additions and 1 deletions

@ -14,6 +14,9 @@ if (!empty($action)){
if ($action == "get"){ if ($action == "get"){
if ($_POST["password"] == $config["admin_pwd"]){ 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); $stranky = json_decode(file_get_contents("../data/pageindex.json"), true);
$out = "<table><tbody><tr><th>ID</th><th>Content ID</th><th>Nickname</th><th>Button</th></tr>"; $out = "<table><tbody><tr><th>ID</th><th>Content ID</th><th>Nickname</th><th>Button</th></tr>";
foreach($stranky as $idx => $arr) { foreach($stranky as $idx => $arr) {
@ -46,6 +49,9 @@ if (!empty($action)){
} }
if ($action == "getcontent"){ if ($action == "getcontent"){
if(!file_exists("../data/contents.json")){
file_put_contents("../data/contents.json", "{}");
}
if ($_POST["password"] == $config["admin_pwd"]){ if ($_POST["password"] == $config["admin_pwd"]){
$contents = json_decode(file_get_contents("../data/contents.json"), true); $contents = json_decode(file_get_contents("../data/contents.json"), true);
$out = "<table><tbody><tr><th>Content ID</th><th>Content</th><th>Button</th></tr>"; $out = "<table><tbody><tr><th>Content ID</th><th>Content</th><th>Button</th></tr>";
@ -77,6 +83,9 @@ if (!empty($action)){
} }
if ($action == "getlog"&& !empty($_POST["id"])){ if ($action == "getlog"&& !empty($_POST["id"])){
if(!file_exists("../data/logs.json")){
file_put_contents("../data/logs.json", "{}");
}
if ($_POST["password"] == $config["admin_pwd"]){ if ($_POST["password"] == $config["admin_pwd"]){
$logy = json_decode(file_get_contents("../data/logs.json"), true)[$_POST["id"]]; $logy = json_decode(file_get_contents("../data/logs.json"), true)[$_POST["id"]];
$out = "<table><tbody><tr><th>Action</th><th>Date and Time</th><th>Nickname</th><th>Link</th><th>IP</th></tr>"; $out = "<table><tbody><tr><th>Action</th><th>Date and Time</th><th>Nickname</th><th>Link</th><th>IP</th></tr>";

@ -10,6 +10,14 @@ if (!empty($idcko)){
file_put_contents("data/logs.json", "{}"); 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); $stranky = json_decode(file_get_contents("data/pageindex.json"), true);
$contents = json_decode(file_get_contents("data/contents.json"), true); $contents = json_decode(file_get_contents("data/contents.json"), true);
$logs = json_decode(file_get_contents("data/logs.json"), true); $logs = json_decode(file_get_contents("data/logs.json"), true);