Compare commits

...

5 Commits

Author SHA1 Message Date
malle-pietje
5389f3a486 API client class v1.1.37
updated both READMEs
added cmd_stat() function, can currently only be used to reset DPI counters for the current site
added optional group_id parameter to list_firewallgroups() which allows you to select a single firewall group, thanks to @VWT-Dan for the suggestion
2018-11-05 12:18:10 +01:00
malle-pietje
2a566ad18a API client class v1.1.36
added methods stat_ips_events(), set_ips_settings_base(), supported with controllers 5.9.10 and higher
thanks go to @leonardogyn for providing access to a controller and test network for test/validation purposes
2018-10-24 09:54:43 +02:00
malle-pietje
1714e9587c general code cleanup
added spaces throughout Client.php following PSR-2 guidelines that were skipped with the previous commit
added visibility to constructor and destructor methods following PSR-2 recommendations
declare user and password properties and visibility following PSR-2 recommendations
updated README to add recently added functions/methods
minor general changes to the README
2018-10-20 14:29:08 +02:00
malle-pietje
cd92192cb8 API client class v1.1.34
- added spaces throughout Client.php following PSR-2 guidelines
- changed checks to prevent 0 (zero) values from being submitted to the API for routes where this can have negative side effects
2018-10-10 10:14:00 +02:00
malle-pietje
7c6cd4eb85 removed and added spaces, and changed brackets usage following PSR-2 guidelines 2018-10-02 13:16:48 +02:00
8 changed files with 191 additions and 95 deletions

View File

@@ -1,8 +1,8 @@
## UniFi Controller API client class
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).
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.9.29 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()
@@ -131,6 +139,7 @@ The class currently supports the following functions/methods to get/post/put/del
- upgrade_device_external()
- start_rolling_upgrade()
- cancel_rolling_upgrade()
- cmd_stat()
Internal functions, getters/setters:
@@ -224,7 +233,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 +243,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

View File

@@ -9,6 +9,17 @@ Then update the contents of your new config.php with your controller details and
Also make sure to update the path for the composer autoloader file (`vendor/autoload.php`) or the file containing the Class itself (`src/Client.php`) in your `require_once()` statement as required.
#### Executing scripts from the CLI
Most of the included example scripts can be run from the CLI or shell as follows after the necessary credentials and parameters have been added or updated:
```sh
$ php list_site_health.php
```
NOTE: this does require the `php-cli` module to be installed
### Contribute
If you would like to share your own example file(s), please open an issue and include your code there or else create a pull request.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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);
}
@@ -1125,15 +1158,16 @@ class Client
/**
* List firewall groups (using REST)
* ----------------------------------
* returns an array containing the current firewall groups on success
* returns an array containing the current firewall groups or the selected firewall group on success
* optional parameter <group_id> = id of the single firewall group to list
*/
public function list_firewallgroups()
public function list_firewallgroups($group_id = null)
{
if (!$this->is_loggedin) {
return false;
}
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/firewallgroup');
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/firewallgroup/' . trim($group_id));
return $this->process_response($response);
}
@@ -1158,12 +1192,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 +1227,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);
@@ -1224,6 +1258,22 @@ class Client
return $this->process_response_boolean($response);
}
/**
* List firewall rules (using REST)
* ----------------------------------
* returns an array containing the current firewall rules on success
*/
public function list_firewallrules()
{
if (!$this->is_loggedin) {
return false;
}
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/firewallrule');
return $this->process_response($response);
}
/**
* List health metrics
* -------------------
@@ -1905,15 +1955,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 +2320,7 @@ class Client
return false;
}
$json = json_encode([
$json = json_encode([
'radio_table' => [
'radio' => $radio,
'channel' => $channel,
@@ -2340,7 +2390,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 +2411,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 +2425,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 +2768,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
];
@@ -2721,7 +2790,7 @@ class Client
return false;
}
$json = [
$json = [
'_sort' => '-time',
'within' => intval($historyhours),
'type' => null,
@@ -3054,11 +3123,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);
@@ -3113,6 +3182,28 @@ class Client
return $this->process_response_boolean($response);
}
/**
* Execute specific command
* ------------------------
* return true on success
* required parameter <command> = string; command to execute, known valid values
* 'reset-dpi': reset all DPI counters for the current site
*
* NOTE:
* the provided <command> parameter isn't validated so make sure you're using a correct value
*/
public function cmd_stat($command)
{
if (!$this->is_loggedin) {
return false;
}
$json = json_encode(['cmd' => trim($command)]);
$response = $this->exec_curl('/api/s/' . $this->site . '/cmd/stat', 'json=' . $json);
return $this->process_response_boolean($response);
}
/****************************************************************
* "Aliases" for deprecated functions from here, to support
* backward compatibility: