Compare commits

...

1 Commits

Author SHA1 Message Date
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
2 changed files with 16 additions and 8 deletions

View File

@@ -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()
@@ -111,6 +113,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 +125,7 @@ The class currently supports the following functions/methods to get/post/put/del
- stat_payment()
- stat_sessions()
- stat_sites()
- stat_speedtest_results()
- stat_sta_sessions_latest()
- stat_status()
- stat_sysinfo()
@@ -224,7 +230,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 +240,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

@@ -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
@@ -734,7 +736,7 @@ class Client
$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);
}
@@ -764,7 +766,7 @@ class Client
$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);
}
@@ -794,7 +796,7 @@ class Client
$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);
}