inital commit

This commit is contained in:
2023-07-09 02:03:41 +02:00
commit 069a211528
9 changed files with 301 additions and 0 deletions

57
public/auth.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
//Load Post data in to variables
$accesCode = htmlspecialchars(trim($_POST['accesCode']));
$clientMac = htmlspecialchars(trim($_POST['clientMac']));
$apMac = htmlspecialchars(trim($_POST['apMac']));
//Check if request is (Prevent direct acces)
if ($_SERVER['REQUEST_METHOD'] !== 'POST' ) {
http_response_code(405);
return;
}
//Check if all neded data is present (Prevent direct acces)
if ( empty($accesCode) || empty($clientMac) || empty($apMac)) {
http_response_code(400);
return;
}
//Dummy sleep for testing loader
//sleep(5);
//LoadConfig
require_once __DIR__ . '/../config.php';
//Check acces code
if ($accesCode == 'ABC') {
$downloadSpeed = 5000;
$uploadSpeed = 5000;
}elseif ($accesCode == '123') {
$downloadSpeed = null;
$uploadSpeed = null;
}else{
echo 'Incorrect accesCode';
http_response_code(403);
return;
}
//load the class using the composer autoloader
require_once __DIR__ . '/../vendor/autoload.php';
//Initialize the UniFi API connection class and log in
$unifi_connection = new UniFi_API\Client(controllerUser, controllerPassword, controllerUrl, siteId, controllerVersion, controllerValidateSSL);
$login = $unifi_connection->login();
// authorize_guest Params: DeviceMac ExpireTime(Minutes) UploadSpeedLimit DownloadSpeedLimit DataCap ApMac
//Send AuthRequest
$auth_result = $unifi_connection->authorize_guest($clientMac, '2000', $uploadSpeed, $downloadSpeed, null, $apMac);
//Check if unsucsessfull
if ($auth_result == false) {
http_response_code(500);
}
//provide feedback in json format
//error_log (json_encode($auth_result, JSON_PRETTY_PRINT));