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 * see the config.template.php file for an example
*/ */
require_once('config.php'); require_once('config.php');
$debug = false; $debug = false;
/** /**
* the MAC address(es) of the device(s) to block * 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 * 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) { foreach ($macs_to_block as &$mac) {
// block_result is always true even if mac address does not exist :( // 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: * NOTE:
@ -61,7 +61,7 @@ foreach ($macs_to_block as &$mac) {
*/ */
sleep(1); sleep(1);
$getid_result = $unifi_connection->stat_client($mac); $getid_result = $unifi_connection->stat_client($mac);
if (property_exists($getid_result[0], "oui")) { if (property_exists($getid_result[0], "oui")) {
// this field(manufacturer) seems to exist on valid mac addresses // this field(manufacturer) seems to exist on valid mac addresses

View File

@ -33,10 +33,10 @@ $site_settings = $unifi_connection->list_settings();
$super_mgmt_settings = []; $super_mgmt_settings = [];
$super_mgmt_settings_id = ''; $super_mgmt_settings_id = '';
if(!empty($site_settings)) { if (!empty($site_settings)) {
foreach($site_settings as $section) { foreach($site_settings as $section) {
echo 'section key: ' . $section->key . PHP_EOL; echo 'section key: ' . $section->key . PHP_EOL;
if($section->key === 'super_mgmt') { if ($section->key === 'super_mgmt') {
$super_mgmt_settings = $section; $super_mgmt_settings = $section;
$super_mgmt_settings_id = $section->_id; $super_mgmt_settings_id = $section->_id;
} }

View File

@ -17,7 +17,9 @@ require_once('vendor/autoload.php');
*/ */
require_once('config.php'); require_once('config.php');
// must be adapted to your site! /**
* must be adapted to your site!
*/
$site_id = "default"; $site_id = "default";
$site_name = "*enter your site name*"; $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"; print "UniFi controller login failure, please check your credentials in config.php.\n";
} else { } else {
$guestlist = $unifi_connection->list_guests(); $guestlist = $unifi_connection->list_guests();
// loop thru all known guests
/**
* loop thru all known guests
*/
foreach ($guestlist as $guest) { foreach ($guestlist as $guest) {
print "<pre>" . $guest->_id . " (" . $guest->mac . "), valid until " . date(DATE_ATOM, $guest->end) . " (" . $guest->end . ")</pre>"; 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) { 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"; * 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)) {
if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n"; 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";
}
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 * see the config.template.php file for an example
*/ */
require_once('config.php'); require_once('config.php');
$debug = false;
$debug=false;
/** /**
* the MAC addresses of the device(s) to unblock * the MAC addresses of the device(s) to unblock
*/ */