From ce0777bb332feb33feba64a97bd7a77cf9e5f049 Mon Sep 17 00:00:00 2001 From: hacker_marc Date: Sat, 10 Oct 2026 21:26:38 +0200 Subject: [PATCH] Update file permissions and enhance error handling in API responses --- .env | 0 api/api.php | 16 ++++++++++++++-- api/settings/appname.php | 14 ++++++++++---- api/template/get.php | 0 database.db | Bin 24576 -> 24576 bytes public/admin/index.php | 0 public/html_loader.php | 4 ++++ public/templates/templates.json | 0 8 files changed, 28 insertions(+), 6 deletions(-) mode change 100644 => 100755 .env mode change 100644 => 100755 api/template/get.php mode change 100644 => 100755 public/admin/index.php mode change 100644 => 100755 public/templates/templates.json diff --git a/.env b/.env old mode 100644 new mode 100755 diff --git a/api/api.php b/api/api.php index a38bb6f..916aa96 100755 --- a/api/api.php +++ b/api/api.php @@ -220,10 +220,18 @@ class gbAPI { if (!is_file($db_path)) { $api->answer(500, [ "error" => "database_not_found", - "error_display" => "The Database was not found." + "error_text" => "The Database was not found." ], true); } + if (!is_writeable($db_path)) { + $this->answer(500, [ + "error" => "database_not_writeable", + "error_text" => "The Database is not writeable." + ]); + return; + } + $db = new PDO("sqlite:" . $db_path); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } @@ -243,6 +251,10 @@ class gbAPI { $value = $this->dbCommand($command, true, true, [":name" => $key]); - return $value[0]["value"]; + if (isset($value[0]["value"])) { + return $value[0]["value"]; + }else{ + return; + } } } diff --git a/api/settings/appname.php b/api/settings/appname.php index a9d279f..0ef8973 100755 --- a/api/settings/appname.php +++ b/api/settings/appname.php @@ -12,7 +12,13 @@ $api = new gbAPI(false, $internal); // Get App Name $result = $api->getSetting("application_name"); - -$api->answer(200, [ - "application_name" => $result -]); \ No newline at end of file +if ($result !== NULL) { + $api->answer(200, [ + "application_name" => $result + ]); +}else{ + $api->answer(500, [ + "error" => "empty_query", + "error_text" => "Database query returned nothing." + ]); +} \ No newline at end of file diff --git a/api/template/get.php b/api/template/get.php old mode 100644 new mode 100755 diff --git a/database.db b/database.db index 4870db2a1abc84f1b150d641576221e7b0500ff2..c98c864d4d24516e34c41e9d27f5d97e39d41a39 100644 GIT binary patch delta 106 zcmZoTz}Rqrae_1>_e2?IR&EBpsb@B(EYRm-=D*9p|Be3z|J}`k3g`K`IhmOyIaBjW ziYkjIzp$5KV+6^AAY%h>99>mZTP!fUuE)k(sWc0T3w|T38ubSQ(ft3J?GQ D(d-_Q delta 55 zcmZoTz}Rqrae_1>=R_H2R!#=Js=|#a3-mdd_+K#af8&3#Sy15)|Ku0;GE58tK=yO~ Li4%ku1qc8D?q?DA diff --git a/public/admin/index.php b/public/admin/index.php old mode 100644 new mode 100755 diff --git a/public/html_loader.php b/public/html_loader.php index a719383..fa475a1 100755 --- a/public/html_loader.php +++ b/public/html_loader.php @@ -93,6 +93,10 @@ class HTMLLoader { if ($showAppName) { $call = new APICall("settings/appname.php"); $response = $call->response; + if (isset($response["error"])) { + $this->showError("Failed to get Application Name: API Returned an error: " . $response["error_text"]); + } + $app_name = $response["data"]["application_name"]; $html = str_replace("%appname%", $app_name, $html); diff --git a/public/templates/templates.json b/public/templates/templates.json old mode 100644 new mode 100755