mirror of
https://github.com/Art-of-WiFi/UniFi-API-client.git
synced 2024-11-22 02:00:21 +01:00
clean up of example code based on feedback from scrutinizer-ci.com
This commit is contained in:
parent
b3521d8c1d
commit
17bfe0087c
@ -24,12 +24,12 @@ require_once('vendor/autoload.php');
|
||||
* see the config.template.php file for an example
|
||||
*/
|
||||
require_once('config.php');
|
||||
|
||||
$debug = false;
|
||||
|
||||
/**
|
||||
* the MAC address(es) of the device(s) to block
|
||||
*/
|
||||
$macs_to_block = explode(',',$argv[1]);
|
||||
$macs_to_block = explode(',', $argv[1]);
|
||||
|
||||
/**
|
||||
* The site to authorize the device with
|
||||
@ -49,7 +49,7 @@ $loginresults = $unifi_connection->login(); // always true regardless of sit
|
||||
|
||||
foreach ($macs_to_block as &$mac) {
|
||||
// block_result is always true even if mac address does not exist :(
|
||||
$block_result = $unifi_connection->block_sta($mac);
|
||||
$block_result = $unifi_connection->block_sta($mac);
|
||||
|
||||
/**
|
||||
* NOTE:
|
||||
@ -61,7 +61,7 @@ foreach ($macs_to_block as &$mac) {
|
||||
*/
|
||||
sleep(1);
|
||||
|
||||
$getid_result = $unifi_connection->stat_client($mac);
|
||||
$getid_result = $unifi_connection->stat_client($mac);
|
||||
|
||||
if (property_exists($getid_result[0], "oui")) {
|
||||
// this field(manufacturer) seems to exist on valid mac addresses
|
||||
|
@ -33,10 +33,10 @@ $site_settings = $unifi_connection->list_settings();
|
||||
$super_mgmt_settings = [];
|
||||
$super_mgmt_settings_id = '';
|
||||
|
||||
if(!empty($site_settings)) {
|
||||
if (!empty($site_settings)) {
|
||||
foreach($site_settings as $section) {
|
||||
echo 'section key: ' . $section->key . PHP_EOL;
|
||||
if($section->key === 'super_mgmt') {
|
||||
if ($section->key === 'super_mgmt') {
|
||||
$super_mgmt_settings = $section;
|
||||
$super_mgmt_settings_id = $section->_id;
|
||||
}
|
||||
|
@ -17,7 +17,9 @@ require_once('vendor/autoload.php');
|
||||
*/
|
||||
require_once('config.php');
|
||||
|
||||
// must be adapted to your site!
|
||||
/**
|
||||
* must be adapted to your site!
|
||||
*/
|
||||
$site_id = "default";
|
||||
$site_name = "*enter your site name*";
|
||||
|
||||
@ -29,18 +31,39 @@ if ($loginresults === 400) {
|
||||
print "UniFi controller login failure, please check your credentials in config.php.\n";
|
||||
} else {
|
||||
$guestlist = $unifi_connection->list_guests();
|
||||
// loop thru all known guests
|
||||
|
||||
/**
|
||||
* loop thru all known guests
|
||||
*/
|
||||
foreach ($guestlist as $guest) {
|
||||
print "<pre>" . $guest->_id . " (" . $guest->mac . "), valid until " . date(DATE_ATOM, $guest->end) . " (" . $guest->end . ")</pre>";
|
||||
|
||||
// just a sample: only extend validity of guests which have end date after 2017-04-02
|
||||
/**
|
||||
* just a sample: only extend validity of guests which have end date after 2017-04-02
|
||||
*/
|
||||
if ($guest->end > 1491166482) {
|
||||
// extend clients five times = five days
|
||||
if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
|
||||
if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
|
||||
if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
|
||||
if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
|
||||
if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
|
||||
/**
|
||||
* extend clients five times = five days
|
||||
*/
|
||||
if (!$unifi_connection->extend_guest_validity($guest->_id)) {
|
||||
print "Extend failed for guest with id " . $guest->_id . "\n";
|
||||
}
|
||||
|
||||
if (!$unifi_connection->extend_guest_validity($guest->_id)) {
|
||||
print "Extend failed for guest with id " . $guest->_id . "\n";
|
||||
}
|
||||
|
||||
if (!$unifi_connection->extend_guest_validity($guest->_id)) {
|
||||
print "Extend failed for guest with id " . $guest->_id . "\n";
|
||||
}
|
||||
|
||||
if (!$unifi_connection->extend_guest_validity($guest->_id)) {
|
||||
print "Extend failed for guest with id " . $guest->_id . "\n";
|
||||
}
|
||||
|
||||
if (!$unifi_connection->extend_guest_validity($guest->_id)) {
|
||||
{print "Extend failed for guest with id " . $guest->_id . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@ require_once('vendor/autoload.php');
|
||||
* see the config.template.php file for an example
|
||||
*/
|
||||
require_once('config.php');
|
||||
$debug = false;
|
||||
|
||||
$debug=false;
|
||||
/**
|
||||
* the MAC addresses of the device(s) to unblock
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user