Enhance gbAPI with configuration loading, token generation, and response formatting; update file permissions for API and template files

This commit is contained in:
admin committed 2026-10-03 22:03:11 +02:00
1 parent 06a4f9a6c0
commit 2ac799d0a4
5 files changed
+32 -1

No files matched your search

Regular → Executable
+28 -1
View File
@@ -4,10 +4,37 @@ class gbAPI {
public $authRequired;
function __construct() {
define("APP_PATH", __DIR__ . "/..");
define("APP_PATH", __DIR__ . "/../");
if ($this->authRequited) {
$this->checkAuth();
}
}
function getConfig() {
return parse_ini_file(APP_PATH . ".env");
}
function generateToken() {
$config = $this->getConfig();
// Generate Token
$token = bin2hex(random_bytes(32));
$secret = $config["COOKIE_SIGNATURE"];
return hash_hmac('sha256', $token, SECRET, true);
}
function checkAuth() {
if (isset($_SERVER))
}
function answer($status, $data) {
http_response_code($status);
$data = json_encode($data);
$json = '{"status":' . $status . ',"data":' $data . '}';
die($json);
}
}
Regular → Executable
+2
View File
@@ -1,3 +1,5 @@
<?php
// Load Main Libary
require "../api.php";
bin2hex(random_bytes(32))
View File
File mode changed.
Regular → Executable
View File
File mode changed.
+2
View File
@@ -3,3 +3,5 @@
foreach($_SERVER as $key => $value) {
echo $key . " === " . $value . "<br>";
}
//echo $_SERVER["HTTP_X_API_KEY"];