mirror of
https://github.com/Art-of-WiFi/UniFi-API-client.git
synced 2024-11-21 17:49:59 +01:00
removed and added spaces, and changed brackets usage following PSR-2 guidelines
This commit is contained in:
parent
30f4230cfd
commit
7c6cd4eb85
@ -25,9 +25,9 @@ require_once('vendor/autoload.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]);
|
||||
|
||||
@ -35,8 +35,7 @@ $macs_to_block = explode(',',$argv[1]);
|
||||
* The site to authorize the device with
|
||||
*/
|
||||
$site_id = 'MUST_DEFINE_THIS';
|
||||
if ($site_id == "MUST_DEFINE_THIS")
|
||||
{
|
||||
if ($site_id == "MUST_DEFINE_THIS") {
|
||||
print 'ERROR: set the site id in your script';
|
||||
return;
|
||||
}
|
||||
@ -48,8 +47,7 @@ $unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $
|
||||
$set_debug_mode = $unifi_connection->set_debug($debug);
|
||||
$loginresults = $unifi_connection->login(); // always true regardless of site id
|
||||
|
||||
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 = $unifi_connection->block_sta($mac);
|
||||
|
||||
@ -65,20 +63,16 @@ foreach ($macs_to_block as &$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
|
||||
{
|
||||
if (property_exists($getid_result[0], "name")) // this is the alias field if it has been defined
|
||||
{
|
||||
if (property_exists($getid_result[0], "oui")) {
|
||||
// this field(manufacturer) seems to exist on valid mac addresses
|
||||
if (property_exists($getid_result[0], "name")) {
|
||||
// this is the alias field if it has been defined
|
||||
$name = $getid_result[0]->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$name = $getid_result[0]->hostname;
|
||||
}
|
||||
print 'blocked ' . $name . PHP_EOL;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
print 'ERROR: could not block ' . $mac . PHP_EOL;
|
||||
print ' check mac address is valid and part of your network' . PHP_EOL;
|
||||
}
|
||||
|
@ -29,20 +29,18 @@ if ($loginresults === 400) {
|
||||
print "UniFi controller login failure, please check your credentials in config.php.\n";
|
||||
} else {
|
||||
$guestlist = $unifi_connection->list_guests();
|
||||
// print "<pre>"; print_r ($guestlist); print "</pre>";
|
||||
// loop thru all known guests
|
||||
foreach ($guestlist as $guest) {
|
||||
// print "<pre>"; print_r ($guest); print "</pre>";
|
||||
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
|
||||
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";
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,14 +29,13 @@ $debug=false;
|
||||
/**
|
||||
* the MAC addresses of the device(s) to unblock
|
||||
*/
|
||||
$macs_to_unblock = explode(',',$argv[1]);
|
||||
$macs_to_unblock = explode(',', $argv[1]);
|
||||
|
||||
/**
|
||||
* The site to authorize the device with
|
||||
*/
|
||||
$site_id = 'MUST_DEFINE_THIS';
|
||||
if ($site_id == "MUST_DEFINE_THIS")
|
||||
{
|
||||
if ($site_id == "MUST_DEFINE_THIS") {
|
||||
print 'ERROR: set the site id in your script';
|
||||
return;
|
||||
}
|
||||
@ -48,10 +47,9 @@ $unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $
|
||||
$set_debug_mode = $unifi_connection->set_debug($debug);
|
||||
$loginresults = $unifi_connection->login(); // always true regardless of site id
|
||||
|
||||
foreach ($macs_to_unblock as &$mac)
|
||||
{
|
||||
foreach ($macs_to_unblock as &$mac) {
|
||||
// block_result is always true even if mac address does not exist :(
|
||||
$block_result = $unifi_connection->unblock_sta($mac);
|
||||
$block_result = $unifi_connection->unblock_sta($mac);
|
||||
|
||||
/**
|
||||
* NOTE:
|
||||
@ -63,22 +61,17 @@ foreach ($macs_to_unblock 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
|
||||
{
|
||||
if (property_exists($getid_result[0], "name"))
|
||||
{
|
||||
if (property_exists($getid_result[0], "oui")) {
|
||||
// this field(manufacturer) seems to exist on valid mac addresses
|
||||
if (property_exists($getid_result[0], "name")) {
|
||||
$name = $getid_result[0]->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$name = $getid_result[0]->hostname;
|
||||
}
|
||||
print 'unblocked ' . $name . PHP_EOL;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
print 'ERROR: could not unblock ' . $mac . PHP_EOL;
|
||||
print ' check mac address is valid and part of your network' . PHP_EOL;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ $data = $unifi_connection->list_devices($device_mac);
|
||||
$device_id = $data[0]->device_id;
|
||||
$update_device = $unifi_connection->set_device_settings_base($device_id, $new_ports_config);
|
||||
|
||||
if(!$update_device){
|
||||
if (!$update_device) {
|
||||
$error = $unifi_connection->get_last_results_raw();
|
||||
echo json_encode($error, JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
@ -58,13 +58,13 @@ $data = $unifi_connection->list_devices($ap_mac);
|
||||
$radio_table = $data[0]->radio_table;
|
||||
$device_id = $data[0]->device_id;
|
||||
|
||||
foreach($radio_table as $radio){
|
||||
if($radio->radio === 'ng'){
|
||||
foreach ($radio_table as $radio) {
|
||||
if ($radio->radio === 'ng') {
|
||||
$radio->tx_power_mode = $ng_tx_power_mode;
|
||||
$radio->channel = $ng_channel;
|
||||
}
|
||||
|
||||
if($radio->radio === 'na'){
|
||||
if ($radio->radio === 'na') {
|
||||
$radio->tx_power_mode = $na_tx_power_mode;
|
||||
$radio->channel = $na_channel;
|
||||
}
|
||||
@ -72,7 +72,7 @@ foreach($radio_table as $radio){
|
||||
|
||||
$update_device = $unifi_connection->set_device_settings_base($device_id, ['radio_table' => $radio_table]);
|
||||
|
||||
if(!$update_device){
|
||||
if (!$update_device) {
|
||||
$error = $unifi_connection->get_last_results_raw();
|
||||
echo json_encode($error, JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
@ -540,6 +540,7 @@ class Client
|
||||
if (!is_null($mac)) {
|
||||
$json['mac'] = strtolower($mac);
|
||||
}
|
||||
|
||||
$json = json_encode($json);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site . '/stat/report/5minutes.ap', 'json=' . $json);
|
||||
|
||||
@ -600,6 +601,7 @@ class Client
|
||||
if (!is_null($mac)) {
|
||||
$json['mac'] = strtolower($mac);
|
||||
}
|
||||
|
||||
$json = json_encode($json);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site . '/stat/report/daily.ap', 'json=' . $json);
|
||||
|
||||
@ -728,11 +730,11 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? ((time())*1000) : intval($end);
|
||||
$start = is_null($start) ? $end-(12*3600*1000) : intval($start);
|
||||
$end = is_null($end) ? ((time()) * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (12 * 3600 * 1000) : intval($start);
|
||||
$attribs = is_null($attribs) ? ['time', 'mem', 'cpu', 'loadavg_5'] : array_merge(['time'], $attribs);
|
||||
$json = json_encode(['attrs' => $attribs, 'start' => $start, 'end' => $end]);
|
||||
$response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/5minutes.gw', 'json='.$json);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site.'/stat/report/5minutes.gw', 'json=' . $json);
|
||||
|
||||
return $this->process_response($response);
|
||||
}
|
||||
@ -758,11 +760,11 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? ((time())*1000) : intval($end);
|
||||
$start = is_null($start) ? $end-(7*24*3600*1000) : intval($start);
|
||||
$end = is_null($end) ? ((time()) * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start);
|
||||
$attribs = is_null($attribs) ? ['time', 'mem', 'cpu', 'loadavg_5'] : array_merge(['time'], $attribs);
|
||||
$json = json_encode(['attrs' => $attribs, 'start' => $start, 'end' => $end]);
|
||||
$response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/hourly.gw', 'json='.$json);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site.'/stat/report/hourly.gw', 'json=' . $json);
|
||||
|
||||
return $this->process_response($response);
|
||||
}
|
||||
@ -788,11 +790,11 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? ((time()-(time() % 3600))*1000) : intval($end);
|
||||
$start = is_null($start) ? $end-(52*7*24*3600*1000) : intval($start);
|
||||
$end = is_null($end) ? ((time() - (time() % 3600)) * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (52 * 7 * 24 * 3600 * 1000) : intval($start);
|
||||
$attribs = is_null($attribs) ? ['time', 'mem', 'cpu', 'loadavg_5'] : array_merge(['time'], $attribs);
|
||||
$json = json_encode(['attrs' => $attribs, 'start' => $start, 'end' => $end]);
|
||||
$response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/daily.gw', 'json='.$json);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site.'/stat/report/daily.gw', 'json=' . $json);
|
||||
|
||||
return $this->process_response($response);
|
||||
}
|
||||
@ -2699,7 +2701,7 @@ class Client
|
||||
|
||||
$macs = array_map('strtolower', $macs);
|
||||
$payload = [
|
||||
'mac_filter_enabled' => (bool)$mac_filter_enabled,
|
||||
'mac_filter_enabled' => (bool) $mac_filter_enabled,
|
||||
'mac_filter_policy' => $mac_filter_policy,
|
||||
'mac_filter_list' => $macs
|
||||
];
|
||||
@ -3054,11 +3056,11 @@ class Client
|
||||
$account_details = [
|
||||
'name' => $name,
|
||||
'x_password' => $x_password,
|
||||
'tunnel_type' => (int)$tunnel_type,
|
||||
'tunnel_medium_type' => (int)$tunnel_medium_type
|
||||
'tunnel_type' => (int) $tunnel_type,
|
||||
'tunnel_medium_type' => (int) $tunnel_medium_type
|
||||
];
|
||||
if (isset($vlan)) {
|
||||
$account_details['vlan'] = (int)$vlan;
|
||||
$account_details['vlan'] = (int) $vlan;
|
||||
}
|
||||
|
||||
$json = json_encode($account_details);
|
||||
|
Loading…
Reference in New Issue
Block a user