Permalink
Browse files

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
  • Loading branch information...
malle-pietje committed Nov 5, 2018
1 parent 2a566ad commit 5389f3a486c7b598fd87c1e36b6b639e239138dd
Showing with 56 additions and 5 deletions.
  1. +2 −1 README.md
  2. +11 −0 examples/README.md
  3. +43 −4 src/Client.php
@@ -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:

@@ -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.
@@ -1158,15 +1158,16 @@ public function delete_usergroup($group_id)
/**
* 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);
}
@@ -1257,6 +1258,22 @@ public function delete_firewallgroup($group_id)
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 @@ public function list_events($historyhours = 720, $start = 0, $limit = 3000)
return false;
}
$json = [
$json = [
'_sort' => '-time',
'within' => intval($historyhours),
'type' => null,
@@ -3165,6 +3182,28 @@ public function delete_radius_account($account_id)
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:

0 comments on commit 5389f3a

Please sign in to comment.