Enhance gbAPI with configuration loading, token generation, and response formatting; update file permissions for API and template files
This commit is contained in:
1 parent
06a4f9a6c0
commit
2ac799d0a4
5 files changed
+34
-3
No files matched your search
Regular → Executable
+28
-1
@@ -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
+3
-1
@@ -1,3 +1,5 @@
|
||||
<?php
|
||||
// Load Main Libary
|
||||
require "../api.php";
|
||||
require "../api.php";
|
||||
|
||||
bin2hex(random_bytes(32))
|
||||
Reference in new issue
Block a user