diff --git a/README.md b/README.md index 1311f9c..97032df 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## 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 manually or using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects. @@ -139,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: diff --git a/examples/README.md b/examples/README.md index 53d0ea4..a79468b 100755 --- a/examples/README.md +++ b/examples/README.md @@ -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. diff --git a/src/Client.php b/src/Client.php index 1173b1f..9e7229d 100755 --- a/src/Client.php +++ b/src/Client.php @@ -1158,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 = 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); } @@ -1257,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 * ------------------- @@ -2773,7 +2790,7 @@ class Client return false; } - $json = [ + $json = [ '_sort' => '-time', 'within' => intval($historyhours), 'type' => null, @@ -3165,6 +3182,28 @@ class Client return $this->process_response_boolean($response); } + /** + * Execute specific command + * ------------------------ + * return true on success + * required parameter = string; command to execute, known valid values + * 'reset-dpi': reset all DPI counters for the current site + * + * NOTE: + * the provided 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: