Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a566ad18a | ||
|
|
1714e9587c | ||
|
|
cd92192cb8 | ||
|
|
7c6cd4eb85 |
14
README.md
14
README.md
@@ -2,7 +2,7 @@
|
||||
|
||||
A PHP class which provides access to Ubiquiti's **UniFi Controller API**, versions 4.X.X and 5.X.X of the UniFi Controller software are supported (version 5.8.24 has been confirmed to work). It's a standalone version of the class which is used in our API browser tool which can be found [here](https://github.com/Art-of-WiFi/UniFi-API-browser).
|
||||
|
||||
This class can be installed using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects.
|
||||
This class can be installed manually or using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects.
|
||||
|
||||
## Methods and functions supported
|
||||
|
||||
@@ -32,6 +32,7 @@ The class currently supports the following functions/methods to get/post/put/del
|
||||
- delete_usergroup()
|
||||
- delete_wlan()
|
||||
- disable_ap()
|
||||
- edit_client_fixedip()
|
||||
- edit_firewallgroup()
|
||||
- edit_usergroup()
|
||||
- extend_guest_validity()
|
||||
@@ -43,6 +44,7 @@ The class currently supports the following functions/methods to get/post/put/del
|
||||
- list_all_admins()
|
||||
- list_alarms()
|
||||
- list_aps() (deprecated but still available as alias)
|
||||
- list_backups()
|
||||
- list_clients()
|
||||
- list_country_codes()
|
||||
- list_current_channels()
|
||||
@@ -83,6 +85,7 @@ The class currently supports the following functions/methods to get/post/put/del
|
||||
- set_device_settings_base()
|
||||
- set_guestlogin_settings()
|
||||
- set_guestlogin_settings_base()
|
||||
- set_ips_settings_base() (supported on controller version 5.9.10 and higher)
|
||||
- set_locate_ap() (deprecated but still available as alias)
|
||||
- set_networksettings_base()
|
||||
- set_radius_account_base()
|
||||
@@ -111,6 +114,9 @@ The class currently supports the following functions/methods to get/post/put/del
|
||||
- stat_5minutes_aps() (supported on controller version 5.5.X and higher)
|
||||
- stat_hourly_aps()
|
||||
- stat_daily_aps()
|
||||
- stat_5minutes_gateway() (supported on controller version 5.7.X and higher)
|
||||
- stat_hourly_gateway() (supported on controller version 5.7.X and higher)
|
||||
- stat_daily_gateway() (supported on controller version 5.7.X and higher)
|
||||
- stat_5minutes_site() (supported on controller version 5.5.X and higher)
|
||||
- stat_hourly_site()
|
||||
- stat_daily_site()
|
||||
@@ -120,6 +126,8 @@ The class currently supports the following functions/methods to get/post/put/del
|
||||
- stat_payment()
|
||||
- stat_sessions()
|
||||
- stat_sites()
|
||||
- stat_speedtest_results()
|
||||
- stat_ips_events() (supported on controller version 5.9.10 and higher)
|
||||
- stat_sta_sessions_latest()
|
||||
- stat_status()
|
||||
- stat_sysinfo()
|
||||
@@ -224,7 +232,7 @@ Please refer to the `examples/` directory for some more detailed examples which
|
||||
|
||||
#### IMPORTANT NOTES:
|
||||
|
||||
1. The last parameter (`true`) that is passed to the constructor, enables validation of the controller's SSL certificate which is otherwise **disabled** by default. It is highly recommended to enable this feature in production environments where you have a valid SSL cert installed on the UniFi Controller, and which is associated with the FQDN of the server as used in the `controller_url` parameter. This option was added with API client version 1.1.16.
|
||||
1. The last optional parameter that is passed to the constructor in the above example (`true`), enables validation of the controller's SSL certificate which is otherwise **disabled** by default. It is highly recommended to enable this feature in production environments where you have a valid SSL cert installed on the UniFi Controller, and which is associated with the FQDN of the server as used in the `controller_url` parameter. This option was added with API client version 1.1.16.
|
||||
|
||||
2. In the example above, `$site_id` is the 8 character short site "name" which is visible in the URL when managing the site in the UniFi Controller:
|
||||
|
||||
@@ -234,7 +242,7 @@ Please refer to the `examples/` directory for some more detailed examples which
|
||||
|
||||
## Need help or have suggestions?
|
||||
|
||||
There is still work to be done to add functionality and improve the usability of this class, so all suggestions/comments are welcome. Please use the github [issue](https://github.com/Art-of-WiFi/UniFi-API-client/issues) list or the Ubiquiti Community forums (https://community.ubnt.com/t5/UniFi-Wireless/PHP-class-to-access-the-UniFi-controller-API-updates-and/td-p/1512870) to share your ideas/questions.
|
||||
There is still work to be done to add functionality and further improve the usability of this class, so all suggestions/comments are welcome. Please use the GitHub [issue list](https://github.com/Art-of-WiFi/UniFi-API-client/issues) or the Ubiquiti Community forums (https://community.ubnt.com/t5/UniFi-Wireless/PHP-class-to-access-the-UniFi-controller-API-updates-and/td-p/1512870) to share your suggestions and questions.
|
||||
|
||||
## Contribute
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
134
src/Client.php
134
src/Client.php
@@ -25,6 +25,8 @@ class Client
|
||||
* private properties
|
||||
*/
|
||||
protected $baseurl = 'https://127.0.0.1:8443';
|
||||
protected $user = '';
|
||||
protected $password = '';
|
||||
protected $site = 'default';
|
||||
protected $version = '5.6.39';
|
||||
protected $debug = false;
|
||||
@@ -50,7 +52,7 @@ class Client
|
||||
* recommended for production environments to prevent potential MitM attacks, default value (false)
|
||||
* is to not validate the controller certificate
|
||||
*/
|
||||
function __construct($user, $password, $baseurl = '', $site = '', $version = '', $ssl_verify = false)
|
||||
public function __construct($user, $password, $baseurl = '', $site = '', $version = '', $ssl_verify = false)
|
||||
{
|
||||
if (!extension_loaded('curl')) {
|
||||
trigger_error('The PHP curl extension is not loaded. Please correct this before proceeding!');
|
||||
@@ -81,7 +83,7 @@ class Client
|
||||
$this->update_unificookie();
|
||||
}
|
||||
|
||||
function __destruct()
|
||||
public function __destruct()
|
||||
{
|
||||
/**
|
||||
* if user has $_SESSION['unificookie'] set, do not logout here
|
||||
@@ -212,15 +214,15 @@ class Client
|
||||
/**
|
||||
* if we have received values for up/down/MBytes/ap_mac we append them to the payload array to be submitted
|
||||
*/
|
||||
if (isset($up)) {
|
||||
if (!empty($up)) {
|
||||
$json['up'] = intval($up);
|
||||
}
|
||||
|
||||
if (isset($down)) {
|
||||
if (!empty($down)) {
|
||||
$json['down'] = intval($down);
|
||||
}
|
||||
|
||||
if (isset($MBytes)) {
|
||||
if (!empty($MBytes)) {
|
||||
$json['bytes'] = intval($MBytes);
|
||||
}
|
||||
|
||||
@@ -426,7 +428,7 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? ((time()) * 1000) : intval($end);
|
||||
$end = is_null($end) ? (time() * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (12 * 3600 * 1000) : intval($start);
|
||||
$attributes = [
|
||||
'bytes',
|
||||
@@ -461,7 +463,7 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? ((time()) * 1000) : intval($end);
|
||||
$end = is_null($end) ? (time() * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start);
|
||||
$attributes = [
|
||||
'bytes',
|
||||
@@ -534,12 +536,13 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? ((time()) * 1000) : intval($end);
|
||||
$end = is_null($end) ? (time() * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (12 * 3600 * 1000) : intval($start);
|
||||
$json = ['attrs' => ['bytes', 'num_sta', 'time'], 'start' => $start, 'end' => $end];
|
||||
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);
|
||||
|
||||
@@ -564,7 +567,7 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? ((time()) * 1000) : intval($end);
|
||||
$end = is_null($end) ? (time() * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start);
|
||||
$json = ['attrs' => ['bytes', 'num_sta', 'time'], 'start' => $start, 'end' => $end];
|
||||
if (!is_null($mac)) {
|
||||
@@ -594,12 +597,13 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? ((time()) * 1000) : intval($end);
|
||||
$end = is_null($end) ? (time() * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start);
|
||||
$json = ['attrs' => ['bytes', 'num_sta', 'time'], 'start' => $start, 'end' => $end];
|
||||
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);
|
||||
|
||||
@@ -630,7 +634,7 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? ((time()) * 1000) : intval($end);
|
||||
$end = is_null($end) ? (time() * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (12 * 3600 * 1000) : intval($start);
|
||||
$attribs = is_null($attribs) ? ['time', 'rx_bytes', 'tx_bytes'] : array_merge(['time'], $attribs);
|
||||
$json = ['attrs' => $attribs, 'start' => $start, 'end' => $end, 'mac' => strtolower($mac)];
|
||||
@@ -662,7 +666,7 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? ((time()) * 1000) : intval($end);
|
||||
$end = is_null($end) ? (time() * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start);
|
||||
$attribs = is_null($attribs) ? ['time', 'rx_bytes', 'tx_bytes'] : array_merge(['time'], $attribs);
|
||||
$json = ['attrs' => $attribs, 'start' => $start, 'end' => $end, 'mac' => strtolower($mac)];
|
||||
@@ -694,7 +698,7 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? ((time()) * 1000) : intval($end);
|
||||
$end = is_null($end) ? (time() * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start);
|
||||
$attribs = is_null($attribs) ? ['time', 'rx_bytes', 'tx_bytes'] : array_merge(['time'], $attribs);
|
||||
$json = ['attrs' => $attribs, 'start' => $start, 'end' => $end, 'mac' => strtolower($mac)];
|
||||
@@ -728,11 +732,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 +762,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 +792,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);
|
||||
}
|
||||
@@ -814,7 +818,7 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? ((time()) * 1000) : intval($end);
|
||||
$end = is_null($end) ? (time() * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (24 * 3600 * 1000) : intval($start);
|
||||
$json = ['attrs' => ['xput_download', 'xput_upload', 'latency', 'time'], 'start' => $start, 'end' => $end];
|
||||
$json = json_encode($json);
|
||||
@@ -823,6 +827,35 @@ class Client
|
||||
return $this->process_response($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to fetch IPS/IDS event
|
||||
* ----------------------------------
|
||||
* returns an array of IPS/IDS event objects
|
||||
* optional parameter <start> = Unix timestamp in milliseconds
|
||||
* optional parameter <end> = Unix timestamp in milliseconds
|
||||
* optional parameter <limit> = Maximum number of events to return, defaults to 10000
|
||||
*
|
||||
* NOTES:
|
||||
* - defaults to the past 24 hours
|
||||
* - requires a USG
|
||||
* - supported in UniFi controller versions 5.9.X and higher
|
||||
*/
|
||||
public function stat_ips_events($start = null, $end = null, $limit = null)
|
||||
{
|
||||
if (!$this->is_loggedin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$end = is_null($end) ? (time() * 1000) : intval($end);
|
||||
$start = is_null($start) ? $end - (24 * 3600 * 1000) : intval($start);
|
||||
$limit = is_null($limit) ? 10000 : intval($limit);
|
||||
$json = ['start' => $start, 'end' => $end, '_limit' => $limit];
|
||||
$json = json_encode($json);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site . '/stat/ips/event', 'json=' . $json);
|
||||
|
||||
return $this->process_response($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all login sessions
|
||||
* -----------------------
|
||||
@@ -1064,12 +1097,12 @@ class Client
|
||||
}
|
||||
|
||||
$this->request_type = 'POST';
|
||||
$json = json_encode([
|
||||
$json = json_encode([
|
||||
'name' => $group_name,
|
||||
'qos_rate_max_down' => intval($group_dn),
|
||||
'qos_rate_max_up' => intval($group_up)
|
||||
]);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/usergroup', $json);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/usergroup', $json);
|
||||
|
||||
return $this->process_response($response);
|
||||
}
|
||||
@@ -1091,7 +1124,7 @@ class Client
|
||||
}
|
||||
|
||||
$this->request_type = 'PUT';
|
||||
$json = json_encode([
|
||||
$json = json_encode([
|
||||
'_id' => $group_id,
|
||||
'name' => $group_name,
|
||||
'qos_rate_max_down' => intval($group_dn),
|
||||
@@ -1099,7 +1132,7 @@ class Client
|
||||
'site_id' => $site_id
|
||||
]);
|
||||
|
||||
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/usergroup/' . trim($group_id), $json);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/usergroup/' . trim($group_id), $json);
|
||||
|
||||
return $this->process_response($response);
|
||||
}
|
||||
@@ -1158,12 +1191,12 @@ class Client
|
||||
}
|
||||
|
||||
$this->request_type = 'POST';
|
||||
$json = json_encode([
|
||||
$json = json_encode([
|
||||
'name' => $group_name,
|
||||
'group_type' => $group_type,
|
||||
'group_members' => $group_members
|
||||
]);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/firewallgroup', $json);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/firewallgroup', $json);
|
||||
|
||||
return $this->process_response($response);
|
||||
}
|
||||
@@ -1193,14 +1226,14 @@ class Client
|
||||
}
|
||||
|
||||
$this->request_type = 'PUT';
|
||||
$json = json_encode([
|
||||
$json = json_encode([
|
||||
'_id' => $group_id,
|
||||
'name' => $group_name,
|
||||
'group_type' => $group_type,
|
||||
'group_members' => $group_members,
|
||||
'site_id' => $site_id
|
||||
]);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/firewallgroup/' . trim($group_id),
|
||||
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/firewallgroup/' . trim($group_id),
|
||||
$json);
|
||||
|
||||
return $this->process_response($response);
|
||||
@@ -1905,15 +1938,15 @@ class Client
|
||||
$json['note'] = trim($note);
|
||||
}
|
||||
|
||||
if (isset($up)) {
|
||||
if (!empty($up)) {
|
||||
$json['up'] = intval($up);
|
||||
}
|
||||
|
||||
if (isset($down)) {
|
||||
if (!empty($down)) {
|
||||
$json['down'] = intval($down);
|
||||
}
|
||||
|
||||
if (isset($MBytes)) {
|
||||
if (!empty($MBytes)) {
|
||||
$json['bytes'] = intval($MBytes);
|
||||
}
|
||||
|
||||
@@ -2270,7 +2303,7 @@ class Client
|
||||
return false;
|
||||
}
|
||||
|
||||
$json = json_encode([
|
||||
$json = json_encode([
|
||||
'radio_table' => [
|
||||
'radio' => $radio,
|
||||
'channel' => $channel,
|
||||
@@ -2340,7 +2373,7 @@ class Client
|
||||
if (!$this->is_loggedin) {
|
||||
return false;
|
||||
}
|
||||
$json = [
|
||||
$json = [
|
||||
'portal_enabled' => $portal_enabled,
|
||||
'portal_customized' => $portal_customized,
|
||||
'redirect_enabled' => $redirect_enabled,
|
||||
@@ -2361,7 +2394,7 @@ class Client
|
||||
* ------------------------------------------
|
||||
* return true on success
|
||||
* required parameter <network_settings> = stdClass object or associative array containing the configuration to apply to the guestlogin, must be a (partial)
|
||||
* object/array structured in the same manner as is returned by list_settings() for the guest_access.
|
||||
* object/array structured in the same manner as is returned by list_settings() for the "guest_access" section.
|
||||
*/
|
||||
public function set_guestlogin_settings_base($guestlogin_settings)
|
||||
{
|
||||
@@ -2375,6 +2408,25 @@ class Client
|
||||
return $this->process_response_boolean($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update IPS/IDS settings, base
|
||||
* ------------------------------------------
|
||||
* return true on success
|
||||
* required parameter <ips_settings> = stdClass object or associative array containing the IPS/IDS settings to apply, must be a (partial)
|
||||
* object/array structured in the same manner as is returned by list_settings() for the "ips" section.
|
||||
*/
|
||||
public function set_ips_settings_base($ips_settings)
|
||||
{
|
||||
if (!$this->is_loggedin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$json = json_encode($ips_settings, JSON_UNESCAPED_SLASHES);
|
||||
$response = $this->exec_curl('/api/s/' . $this->site . '/set/setting/ips', 'json=' . $json);
|
||||
|
||||
return $this->process_response_boolean($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename access point
|
||||
* -------------------
|
||||
@@ -2699,7 +2751,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 +3106,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);
|
||||
|
||||
Reference in New Issue
Block a user