clean up of example code based on feedback from scrutinizer-ci.com

This commit is contained in:
malle-pietje 2019-10-15 14:27:28 +02:00
parent b3521d8c1d
commit 17bfe0087c
4 changed files with 39 additions and 16 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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";
}
}
}

View File

@ -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
*/