diff --git a/_api/guests.php b/_api/guests.php new file mode 100644 index 0000000..5cfe909 --- /dev/null +++ b/_api/guests.php @@ -0,0 +1,12 @@ +login(); +$clients = []; +foreach ($unifi_connection->list_clients() as $client) { + $client = get_object_vars($client); + if( $client['is_guest'] ) $clients[] = $client; +} +print(json_encode($clients)); diff --git a/submit.php b/_api/submit.php similarity index 97% rename from submit.php rename to _api/submit.php index 9464912..de15d74 100644 --- a/submit.php +++ b/_api/submit.php @@ -1,44 +1,44 @@ - "Invalid mac address", 'success' => FALSE], JSON_PRETTY_PRINT)); - return; -} - -$unifi_connection = new UniFi_API\Client($_ENV['hotspot_user'], $_ENV['hotspot_password'], $_ENV['unifi_url'], $_ENV['unifi_site'], $_ENV['unifi_version'], FALSE); -$login = $unifi_connection->login(); -$vouchers = $unifi_connection->stat_voucher(); - -if (isset($code)) { - foreach ($vouchers as $voucher) { - $voucher = get_object_vars($voucher); - if ($voucher['code'] == $code) { - $max_up = NULL; - $max_down = NULL; - $usage_quota = NULL; - if (isset($voucher['qos_rate_max_up'])) $max_up = $voucher['qos_rate_max_up']; - if (isset($voucher['qos_rate_max_down'])) $max_down = $voucher['qos_rate_max_down']; - if (isset($voucher['qos_usage_quota'])) $usage_quota = $voucher['qos_usage_quota']; - - $authorized = $unifi_connection->authorize_guest($mac, $voucher['duration'], $max_up, $max_down, $usage_quota, $ap_mac); - $unifi_connection->revoke_voucher($voucher['_id']); - header('Status: 202'); - print(json_encode(['success' => TRUE], JSON_PRETTY_PRINT)); - return; - } - } -} - -header('Status: 400'); -print(json_encode(['success' => FALSE, 'error' => 'Voucher code not found'], JSON_PRETTY_PRINT)); -return; + "Invalid mac address", 'success' => FALSE], JSON_PRETTY_PRINT)); + return; +} + +$unifi_connection = new UniFi_API\Client($_ENV['hotspot_user'], $_ENV['hotspot_password'], $_ENV['unifi_url'], $_ENV['unifi_site'], $_ENV['unifi_version'], FALSE); +$login = $unifi_connection->login(); +$vouchers = $unifi_connection->stat_voucher(); + +if (isset($code)) { + foreach ($vouchers as $voucher) { + $voucher = get_object_vars($voucher); + if ($voucher['code'] == $code) { + $max_up = NULL; + $max_down = NULL; + $usage_quota = NULL; + if (isset($voucher['qos_rate_max_up'])) $max_up = $voucher['qos_rate_max_up']; + if (isset($voucher['qos_rate_max_down'])) $max_down = $voucher['qos_rate_max_down']; + if (isset($voucher['qos_usage_quota'])) $usage_quota = $voucher['qos_usage_quota']; + + $authorized = $unifi_connection->authorize_guest($mac, $voucher['duration'], $max_up, $max_down, $usage_quota, $ap_mac); + $unifi_connection->revoke_voucher($voucher['_id']); + header('Status: 202'); + print(json_encode(['success' => TRUE], JSON_PRETTY_PRINT)); + return; + } + } +} + +header('Status: 400'); +print(json_encode(['success' => FALSE, 'error' => 'Voucher code not found'], JSON_PRETTY_PRINT)); +return; diff --git a/_layouts/default.html b/_layouts/default.html index 4acef1d..fd36e5c 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -9,18 +9,18 @@ - +