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
+32
-1
No files matched your search
Regular → Executable
+28
-1
@@ -4,10 +4,37 @@ class gbAPI {
|
|||||||
public $authRequired;
|
public $authRequired;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
define("APP_PATH", __DIR__ . "/..");
|
define("APP_PATH", __DIR__ . "/../");
|
||||||
|
|
||||||
if ($this->authRequited) {
|
if ($this->authRequited) {
|
||||||
$this->checkAuth();
|
$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
@@ -1,3 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// Load Main Libary
|
// Load Main Libary
|
||||||
require "../api.php";
|
require "../api.php";
|
||||||
|
|
||||||
|
bin2hex(random_bytes(32))
|
||||||
Regular → Executable
File mode changed.
Regular → Executable
File mode changed.
@@ -3,3 +3,5 @@
|
|||||||
foreach($_SERVER as $key => $value) {
|
foreach($_SERVER as $key => $value) {
|
||||||
echo $key . " === " . $value . "<br>";
|
echo $key . " === " . $value . "<br>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//echo $_SERVER["HTTP_X_API_KEY"];
|
||||||
Reference in new issue
Block a user