Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14f4d58b02 | ||
|
|
77972aab55 | ||
|
|
9629cc909d | ||
|
|
f6201ec21c | ||
|
|
dcf7d2059c | ||
|
|
7a5e2b5bbb | ||
|
|
1db9040ea8 | ||
|
|
cab0c1a35d | ||
|
|
2b5ed31759 | ||
|
|
a13ff36409 | ||
|
|
c4bc1243eb | ||
|
|
c25f4d1937 | ||
|
|
e3e70cce72 | ||
|
|
449baa70a3 | ||
|
|
2dc5136eba | ||
|
|
e1f3cd6e73 | ||
|
|
141b0ff55f | ||
|
|
e6ffb2e5de |
59
README.md
59
README.md
@@ -1,21 +1,17 @@
|
|||||||
## UniFi controller API client class
|
## 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.6.18 has been confirmed to work). It's a standalone version of the class which is used in the API browser tool [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.6.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 now also 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 using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects.
|
||||||
|
|
||||||
### Donations
|
|
||||||
|
|
||||||
If you'd like to support further development of this PHP API client class, please use the PayPal donate button below. All donations go to the project maintainer.
|
|
||||||
|
|
||||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=M7TVNVX3Z44VN)
|
|
||||||
|
|
||||||
## Methods and functions supported
|
## Methods and functions supported
|
||||||
|
|
||||||
The class currently supports the following functions/methods to get/post/put/delete data through the UniFi controller API:
|
The class currently supports the following functions/methods to get/post/put/delete data through the UniFi Controller API:
|
||||||
|
|
||||||
- login()
|
- login()
|
||||||
- logout()
|
- logout()
|
||||||
- adopt_device()
|
- adopt_device()
|
||||||
|
- archive_alarm()
|
||||||
- authorize_guest()
|
- authorize_guest()
|
||||||
- block_sta()
|
- block_sta()
|
||||||
- count_alarms()
|
- count_alarms()
|
||||||
@@ -26,6 +22,7 @@ The class currently supports the following functions/methods to get/post/put/del
|
|||||||
- create_usergroup()
|
- create_usergroup()
|
||||||
- create_voucher()
|
- create_voucher()
|
||||||
- create_wlan()
|
- create_wlan()
|
||||||
|
- delete_device()
|
||||||
- delete_network()
|
- delete_network()
|
||||||
- delete_radius_account()
|
- delete_radius_account()
|
||||||
- delete_site()
|
- delete_site()
|
||||||
@@ -36,6 +33,7 @@ The class currently supports the following functions/methods to get/post/put/del
|
|||||||
- extend_guest_validity()
|
- extend_guest_validity()
|
||||||
- led_override()
|
- led_override()
|
||||||
- list_admins()
|
- list_admins()
|
||||||
|
- list_all_admins()
|
||||||
- list_alarms()
|
- list_alarms()
|
||||||
- list_aps() (deprecated but still available as alias)
|
- list_aps() (deprecated but still available as alias)
|
||||||
- list_clients()
|
- list_clients()
|
||||||
@@ -49,6 +47,7 @@ The class currently supports the following functions/methods to get/post/put/del
|
|||||||
- list_guests()
|
- list_guests()
|
||||||
- list_health()
|
- list_health()
|
||||||
- list_hotspotop()
|
- list_hotspotop()
|
||||||
|
- list_known_rogueaps()
|
||||||
- list_networkconf()
|
- list_networkconf()
|
||||||
- list_portconf()
|
- list_portconf()
|
||||||
- list_portforward_stats()
|
- list_portforward_stats()
|
||||||
@@ -65,11 +64,14 @@ The class currently supports the following functions/methods to get/post/put/del
|
|||||||
- list_wlan_groups()
|
- list_wlan_groups()
|
||||||
- list_wlanconf()
|
- list_wlanconf()
|
||||||
- locate_ap()
|
- locate_ap()
|
||||||
|
- move_device()
|
||||||
|
- power_cycle_switch_port()
|
||||||
- reconnect_sta()
|
- reconnect_sta()
|
||||||
- rename_ap()
|
- rename_ap()
|
||||||
- restart_ap()
|
- restart_ap()
|
||||||
- revoke_voucher()
|
- revoke_voucher()
|
||||||
- set_ap_radiosettings()
|
- set_ap_radiosettings()
|
||||||
|
- set_device_settings_base()
|
||||||
- set_guestlogin_settings()
|
- set_guestlogin_settings()
|
||||||
- set_locate_ap() (deprecated but still available as alias)
|
- set_locate_ap() (deprecated but still available as alias)
|
||||||
- set_networksettings_base()
|
- set_networksettings_base()
|
||||||
@@ -98,6 +100,7 @@ The class currently supports the following functions/methods to get/post/put/del
|
|||||||
- stat_sessions()
|
- stat_sessions()
|
||||||
- stat_sites()
|
- stat_sites()
|
||||||
- stat_sta_sessions_latest()
|
- stat_sta_sessions_latest()
|
||||||
|
- stat_status()
|
||||||
- stat_sysinfo()
|
- stat_sysinfo()
|
||||||
- stat_voucher()
|
- stat_voucher()
|
||||||
- unauthorize_guest()
|
- unauthorize_guest()
|
||||||
@@ -107,24 +110,25 @@ The class currently supports the following functions/methods to get/post/put/del
|
|||||||
- upgrade_device_external()
|
- upgrade_device_external()
|
||||||
|
|
||||||
Internal functions, getters/setters:
|
Internal functions, getters/setters:
|
||||||
|
|
||||||
- set_debug()
|
- set_debug()
|
||||||
- set_site()
|
- get_debug()
|
||||||
- set_site()
|
- set_site()
|
||||||
- get_site()
|
- get_site()
|
||||||
- get_cookie() (renamed from getcookie())
|
- get_cookie() (renamed from getcookie())
|
||||||
- get_last_results_raw()
|
- get_last_results_raw()
|
||||||
- get_last_error_message()
|
- get_last_error_message()
|
||||||
|
|
||||||
Please refer to the source code for more details on each function/method and their parameters.
|
Please refer to the source code for more details on the functions/methods and their parameters.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- a web server with PHP and cURL modules installed (tested on apache2 with PHP Version 5.6.1 and cURL 7.42.1)
|
- a web server with PHP and cURL modules installed (tested on apache2 with PHP Version 5.6.1 and cURL 7.42.1)
|
||||||
- network connectivity between this web server and the server and port (normally TCP port 8443) where the UniFi controller is running
|
- network connectivity between this web server and the server and port (normally TCP port 8443) where the UniFi Controller is running
|
||||||
|
|
||||||
## Installation ##
|
## Installation ##
|
||||||
|
|
||||||
You can use **Composer**, **Git** or simply **Download the Release** to install the API client class.
|
You can use [Composer](#composer), [Git](#git) or simply [Download the Release](#download-the-release) to install the API client class.
|
||||||
|
|
||||||
### Composer
|
### Composer
|
||||||
|
|
||||||
@@ -134,6 +138,16 @@ Once composer is installed, simply execute this command from the shell in your p
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
composer require art-of-wifi/unifi-api-client
|
composer require art-of-wifi/unifi-api-client
|
||||||
|
```
|
||||||
|
|
||||||
|
Or you can manually add the package to your composer.json file:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"art-of-wifi/unifi-api-client": "^1.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, be sure to include the autoloader in your code:
|
Finally, be sure to include the autoloader in your code:
|
||||||
@@ -185,18 +199,15 @@ $results = $unifi_connection->list_alarms(); // returns a PHP array con
|
|||||||
|
|
||||||
Please refer to the `examples/` directory for some more detailed examples which you can use as a starting point for your own PHP code.
|
Please refer to the `examples/` directory for some more detailed examples which you can use as a starting point for your own PHP code.
|
||||||
|
|
||||||
### IMPORTANT NOTES:
|
#### IMPORTANT NOTES:
|
||||||
|
|
||||||
In the example above, the last parameter (`true`) that is passed to the constructor, enables validation of the controller's SSL certificate which is otherwise **disabled** by default.
|
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.
|
||||||
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:
|
||||||
|
|
||||||
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:
|
`https://<controller IP address or FQDN>:8443/manage/site/jl3z2shm/dashboard`
|
||||||
|
|
||||||
`https://<controller IP address or FQDN>:8443/manage/site/jl3z2shm/dashboard`
|
In this case, `jl3z2shm` is the value required for $site_id.
|
||||||
|
|
||||||
In this case, `jl3z2shm` is the value required for $site_id.
|
|
||||||
|
|
||||||
## Need help or have suggestions?
|
## Need help or have suggestions?
|
||||||
|
|
||||||
@@ -208,11 +219,11 @@ If you would like to contribute code (improvements), please open an issue and in
|
|||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
This class is largely based on the work done by the following developers:
|
This class is based on the work done by the following developers:
|
||||||
- domwo: http://community.ubnt.com/t5/UniFi-Wireless/little-php-class-for-unifi-api/m-p/603051
|
- domwo: http://community.ubnt.com/t5/UniFi-Wireless/little-php-class-for-unifi-api/m-p/603051
|
||||||
- fbagnol: https://github.com/fbagnol/class.unifi.php
|
- fbagnol: https://github.com/fbagnol/class.unifi.php
|
||||||
- and the API as published by Ubiquiti: https://dl.ubnt.com/unifi/5.6.18-8261dc5066/unifi_sh_api
|
- and the API as published by Ubiquiti: https://dl.ubnt.com/unifi/5.6.18-8261dc5066/unifi_sh_api
|
||||||
|
|
||||||
## Important Disclaimer
|
## Important Disclaimer
|
||||||
|
|
||||||
Many of the functions in this API client class are not officially supported by UBNT and as such, may not be supported in future versions of the UniFi controller API.
|
Many of the functions in this API client class are not officially supported by UBNT and as such, may not be supported in future versions of the UniFi Controller API.
|
||||||
|
|||||||
40
examples/create_site.php
Executable file
40
examples/create_site.php
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHP API usage example
|
||||||
|
*
|
||||||
|
* contributed by: Art of WiFi
|
||||||
|
* description: example basic PHP script to create a new site, returns true upon success
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* using the composer autoloader
|
||||||
|
*/
|
||||||
|
require_once('vendor/autoload.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* include the config file (place your credentials etc. there if not already present)
|
||||||
|
* see the config.template.php file for an example
|
||||||
|
*/
|
||||||
|
require_once('config.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the site to use to log in to the controller
|
||||||
|
*/
|
||||||
|
$site_id = '<short site name of a site the credentials used have access to>';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* description of the new site
|
||||||
|
*/
|
||||||
|
$description = 'new site';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize the UniFi API connection class and log in to the controller and do our thing
|
||||||
|
*/
|
||||||
|
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
|
||||||
|
$loginresults = $unifi_connection->login();
|
||||||
|
$results = $unifi_connection->create_site($description);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provide feedback in json format
|
||||||
|
*/
|
||||||
|
echo json_encode($results, JSON_PRETTY_PRINT);
|
||||||
41
examples/delete_site.php
Executable file
41
examples/delete_site.php
Executable file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHP API usage example
|
||||||
|
*
|
||||||
|
* contributed by: Art of WiFi
|
||||||
|
* description: example basic PHP script to delete a site, returns true upon success
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* using the composer autoloader
|
||||||
|
*/
|
||||||
|
require_once('vendor/autoload.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* include the config file (place your credentials etc. there if not already present)
|
||||||
|
* see the config.template.php file for an example
|
||||||
|
*/
|
||||||
|
require_once('config.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the site to use to log in to the controller
|
||||||
|
*/
|
||||||
|
$site_id = '<short site name of a site the credentials used have access to>';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the site to delete, must not be the same site as referenced by $site_id
|
||||||
|
*/
|
||||||
|
$site_to_delete = '<_id value of the site>';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize the UniFi API connection class and log in to the controller and do our thing
|
||||||
|
*/
|
||||||
|
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
|
||||||
|
$loginresults = $unifi_connection->login();
|
||||||
|
$results = $unifi_connection->delete_site($site_to_delete);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provide feedback in json format
|
||||||
|
*/
|
||||||
|
echo json_encode($results, JSON_PRETTY_PRINT);
|
||||||
50
examples/disable_device.php
Executable file
50
examples/disable_device.php
Executable file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHP API usage example
|
||||||
|
*
|
||||||
|
* contributed by: Art of WiFi
|
||||||
|
* description: example basic PHP script to disable/enable a device, returns true upon success
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* using the composer autoloader
|
||||||
|
*/
|
||||||
|
require_once('vendor/autoload.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* include the config file (place your credentials etc. there if not already present)
|
||||||
|
* see the config.template.php file for an example
|
||||||
|
*/
|
||||||
|
require_once('config.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the 24 character id of the device to disable/enable
|
||||||
|
*/
|
||||||
|
$device_id = '<enter the id of your device here>';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the site to which the device belongs
|
||||||
|
*/
|
||||||
|
$site_id = '<enter your site id here>';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize the UniFi API connection class and log in to the controller
|
||||||
|
*/
|
||||||
|
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
|
||||||
|
$set_debug_mode = $unifi_connection->set_debug($debug);
|
||||||
|
$loginresults = $unifi_connection->login();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* then we disable the device
|
||||||
|
*/
|
||||||
|
$disable_result = $unifi_connection->disable_ap($device_id, true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* or we enable the device, uncomment as neccesary (then also comment the previous call)
|
||||||
|
*/
|
||||||
|
//$disable_result = $unifi_connection->disable_ap($device_id, false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provide feedback in json format
|
||||||
|
*/
|
||||||
|
echo json_encode($disable_result, JSON_PRETTY_PRINT);
|
||||||
83
examples/update_wlan_settings_5.5.X.php
Executable file
83
examples/update_wlan_settings_5.5.X.php
Executable file
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHP API usage example
|
||||||
|
*
|
||||||
|
* contributed by: Art of WiFi
|
||||||
|
* description: example basic PHP script to update WLAN settings when using a controller version 5.5.X or higher
|
||||||
|
* where set_ap_radiosettings() throws an error
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* using the composer autoloader
|
||||||
|
*/
|
||||||
|
require_once('vendor/autoload.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* include the config file (place your credentials etc. there if not already present)
|
||||||
|
* see the config.template.php file for an example
|
||||||
|
*/
|
||||||
|
require_once('config.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the site to use to log in to the controller
|
||||||
|
*/
|
||||||
|
$site_id = '<short site name of a site the credentials used have access to>';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the MAC address of the access point to modify
|
||||||
|
*/
|
||||||
|
$ap_mac = '<enter MAC address>';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* power level for 2.4GHz
|
||||||
|
*/
|
||||||
|
$ng_tx_power_mode = 'low';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* channel for 2.4GHz
|
||||||
|
*/
|
||||||
|
$ng_channel = 6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* power level for 5GHz
|
||||||
|
*/
|
||||||
|
$na_tx_power_mode = 'medium';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* channel for 5GHz
|
||||||
|
*/
|
||||||
|
$na_channel = 44;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize the UniFi API connection class and log in to the controller and do our thing
|
||||||
|
*/
|
||||||
|
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion, false);
|
||||||
|
$set_debug_mode = $unifi_connection->set_debug(false);
|
||||||
|
$loginresults = $unifi_connection->login();
|
||||||
|
$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'){
|
||||||
|
$radio->tx_power_mode = $ng_tx_power_mode;
|
||||||
|
$radio->channel = $ng_channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($radio->radio === 'na'){
|
||||||
|
$radio->tx_power_mode = $na_tx_power_mode;
|
||||||
|
$radio->channel = $na_channel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$update_device = $unifi_connection->set_device_settings_base($device_id, ['radio_table' => $radio_table]);
|
||||||
|
|
||||||
|
if(!$update_device){
|
||||||
|
$error = $unifi_connection->get_last_results_raw();
|
||||||
|
echo json_encode($error, JSON_PRETTY_PRINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provide feedback in json format
|
||||||
|
*/
|
||||||
|
echo json_encode($update_device, JSON_PRETTY_PRINT);
|
||||||
264
src/Client.php
264
src/Client.php
@@ -24,11 +24,11 @@ class Client
|
|||||||
/**
|
/**
|
||||||
* private properties
|
* private properties
|
||||||
*/
|
*/
|
||||||
private $baseurl = 'https://127.0.0.1:8443';
|
protected $baseurl = 'https://127.0.0.1:8443';
|
||||||
private $site = 'default';
|
protected $site = 'default';
|
||||||
private $version = '5.4.16';
|
protected $version = '5.4.16';
|
||||||
private $debug = false;
|
protected $debug = false;
|
||||||
private $is_loggedin = false;
|
protected $is_loggedin = false;
|
||||||
private $cookies = '';
|
private $cookies = '';
|
||||||
private $request_type = 'POST';
|
private $request_type = 'POST';
|
||||||
private $connect_timeout = 10;
|
private $connect_timeout = 10;
|
||||||
@@ -46,9 +46,9 @@ class Client
|
|||||||
* optional parameter <baseurl> = string; base URL of the UniFi controller, must include "https://" prefix and port suffix (:8443)
|
* optional parameter <baseurl> = string; base URL of the UniFi controller, must include "https://" prefix and port suffix (:8443)
|
||||||
* optional parameter <site> = string; short site name to access, defaults to "default"
|
* optional parameter <site> = string; short site name to access, defaults to "default"
|
||||||
* optional parameter <version> = string; the version number of the controller, defaults to "5.4.16"
|
* optional parameter <version> = string; the version number of the controller, defaults to "5.4.16"
|
||||||
* optional parameter <ssl_verify> = boolean; whether to validate the controller's SSL certificate or not, true is recommended for
|
* optional parameter <ssl_verify> = boolean; whether to validate the controller's SSL certificate or not, a value of true is
|
||||||
* production environments to prevent potential MitM attacks, default is to not validate the
|
* recommended for production environments to prevent potential MitM attacks, default (false) is to
|
||||||
* controller certificate
|
* not validate the controller certificate
|
||||||
*/
|
*/
|
||||||
function __construct($user, $password, $baseurl = '', $site = '', $version = '', $ssl_verify = false)
|
function __construct($user, $password, $baseurl = '', $site = '', $version = '', $ssl_verify = false)
|
||||||
{
|
{
|
||||||
@@ -178,8 +178,8 @@ class Client
|
|||||||
*/
|
*/
|
||||||
public function set_site($site)
|
public function set_site($site)
|
||||||
{
|
{
|
||||||
|
$this->check_site($site);
|
||||||
$this->site = trim($site);
|
$this->site = trim($site);
|
||||||
$this->check_site($this->site);
|
|
||||||
return $this->site;
|
return $this->site;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,6 +210,16 @@ class Client
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get debug mode
|
||||||
|
* --------------
|
||||||
|
* get the value of private property debug, returns the current boolean value for debug
|
||||||
|
*/
|
||||||
|
public function get_debug()
|
||||||
|
{
|
||||||
|
return $this->debug;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get last raw results
|
* Get last raw results
|
||||||
* --------------------
|
* --------------------
|
||||||
@@ -242,6 +252,12 @@ class Client
|
|||||||
* Get Cookie from UniFi Controller
|
* Get Cookie from UniFi Controller
|
||||||
* --------------------------------
|
* --------------------------------
|
||||||
* returns the UniFi controller cookie
|
* returns the UniFi controller cookie
|
||||||
|
*
|
||||||
|
* NOTES:
|
||||||
|
* - when the results from this method are stored in $_SESSION['unificookie'], the class will initially not
|
||||||
|
* log in to the controller when a subsequent request is made using a new instance. This speeds up the
|
||||||
|
* overall request considerably. If that subsequent request fails (e.g. cookies have expired), a new login
|
||||||
|
* is executed automatically and the value of $_SESSION['unificookie'] is updated.
|
||||||
*/
|
*/
|
||||||
public function get_cookie()
|
public function get_cookie()
|
||||||
{
|
{
|
||||||
@@ -467,7 +483,7 @@ class Client
|
|||||||
$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);
|
$start = is_null($start) ? $end-(12*3600*1000) : intval($start);
|
||||||
$json = ['attrs' => ['bytes', 'num_sta', 'time'], 'start' => $start, 'end' => $end];
|
$json = ['attrs' => ['bytes', 'num_sta', 'time'], 'start' => $start, 'end' => $end];
|
||||||
if (!is_null($mac)) $json['mac'] = $mac;
|
if (!is_null($mac)) $json['mac'] = strtolower($mac);
|
||||||
$json = json_encode($json);
|
$json = json_encode($json);
|
||||||
$response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/5minutes.ap', 'json='.$json);
|
$response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/5minutes.ap', 'json='.$json);
|
||||||
return $this->process_response($response);
|
return $this->process_response($response);
|
||||||
@@ -491,7 +507,7 @@ class Client
|
|||||||
$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);
|
$start = is_null($start) ? $end-(7*24*3600*1000) : intval($start);
|
||||||
$json = ['attrs' => ['bytes', 'num_sta', 'time'], 'start' => $start, 'end' => $end];
|
$json = ['attrs' => ['bytes', 'num_sta', 'time'], 'start' => $start, 'end' => $end];
|
||||||
if (!is_null($mac)) $json['mac'] = $mac;
|
if (!is_null($mac)) $json['mac'] = strtolower($mac);
|
||||||
$json = json_encode($json);
|
$json = json_encode($json);
|
||||||
$response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/hourly.ap', 'json='.$json);
|
$response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/hourly.ap', 'json='.$json);
|
||||||
return $this->process_response($response);
|
return $this->process_response($response);
|
||||||
@@ -515,7 +531,7 @@ class Client
|
|||||||
$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);
|
$start = is_null($start) ? $end-(7*24*3600*1000) : intval($start);
|
||||||
$json = ['attrs' => ['bytes', 'num_sta', 'time'], 'start' => $start, 'end' => $end];
|
$json = ['attrs' => ['bytes', 'num_sta', 'time'], 'start' => $start, 'end' => $end];
|
||||||
if (!is_null($mac)) $json['mac'] = $mac;
|
if (!is_null($mac)) $json['mac'] = strtolower($mac);
|
||||||
$json = json_encode($json);
|
$json = json_encode($json);
|
||||||
$response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/daily.ap', 'json='.$json);
|
$response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/daily.ap', 'json='.$json);
|
||||||
return $this->process_response($response);
|
return $this->process_response($response);
|
||||||
@@ -528,17 +544,19 @@ class Client
|
|||||||
* optional parameter <start> = Unix timestamp in seconds
|
* optional parameter <start> = Unix timestamp in seconds
|
||||||
* optional parameter <end> = Unix timestamp in seconds
|
* optional parameter <end> = Unix timestamp in seconds
|
||||||
* optional parameter <mac> = client MAC address to return sessions for (can only be used when start and end are also provided)
|
* optional parameter <mac> = client MAC address to return sessions for (can only be used when start and end are also provided)
|
||||||
|
* optional parameter <type> = client type to return sessions for, can be 'all', 'guest' or 'user'; default value is 'all'
|
||||||
*
|
*
|
||||||
* NOTES:
|
* NOTES:
|
||||||
* - defaults to the past 7*24 hours
|
* - defaults to the past 7*24 hours
|
||||||
*/
|
*/
|
||||||
public function stat_sessions($start = null, $end = null, $mac = null)
|
public function stat_sessions($start = null, $end = null, $mac = null, $type = 'all')
|
||||||
{
|
{
|
||||||
if (!$this->is_loggedin) return false;
|
if (!$this->is_loggedin) return false;
|
||||||
|
if (!in_array($type, ['all', 'guest', 'user'])) return false;
|
||||||
$end = is_null($end) ? time() : intval($end);
|
$end = is_null($end) ? time() : intval($end);
|
||||||
$start = is_null($start) ? $end-(7*24*3600) : intval($start);
|
$start = is_null($start) ? $end-(7*24*3600) : intval($start);
|
||||||
$json = ['type'=> 'all', 'start' => $start, 'end' => $end];
|
$json = ['type'=> $type, 'start' => $start, 'end' => $end];
|
||||||
if (!is_null($mac)) $json['mac'] = $mac;
|
if (!is_null($mac)) $json['mac'] = strtolower($mac);
|
||||||
$json = json_encode($json);
|
$json = json_encode($json);
|
||||||
$response = $this->exec_curl('/api/s/'.$this->site.'/stat/session', 'json='.$json);
|
$response = $this->exec_curl('/api/s/'.$this->site.'/stat/session', 'json='.$json);
|
||||||
return $this->process_response($response);
|
return $this->process_response($response);
|
||||||
@@ -782,9 +800,9 @@ class Client
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List rogue access points
|
* List rogue/neighboring access points
|
||||||
* ------------------------
|
* ------------------------------------
|
||||||
* returns an array of known rogue access point objects
|
* returns an array of rogue/neighboring access point objects
|
||||||
* optional parameter <within> = hours to go back to list discovered "rogue" access points (default = 24 hours)
|
* optional parameter <within> = hours to go back to list discovered "rogue" access points (default = 24 hours)
|
||||||
*/
|
*/
|
||||||
public function list_rogueaps($within = 24)
|
public function list_rogueaps($within = 24)
|
||||||
@@ -795,6 +813,18 @@ class Client
|
|||||||
return $this->process_response($response);
|
return $this->process_response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List known rogue access points
|
||||||
|
* ------------------------------
|
||||||
|
* returns an array of known rogue access point objects
|
||||||
|
*/
|
||||||
|
public function list_known_rogueaps()
|
||||||
|
{
|
||||||
|
if (!$this->is_loggedin) return false;
|
||||||
|
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/rogueknown');
|
||||||
|
return $this->process_response($response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List sites
|
* List sites
|
||||||
* ----------
|
* ----------
|
||||||
@@ -864,6 +894,18 @@ class Client
|
|||||||
return $this->process_response($response);
|
return $this->process_response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all admins
|
||||||
|
* ---------------
|
||||||
|
* returns an array containing administrator objects for all sites
|
||||||
|
*/
|
||||||
|
public function list_all_admins()
|
||||||
|
{
|
||||||
|
if (!$this->is_loggedin) return false;
|
||||||
|
$response = $this->exec_curl('/api/stat/admin');
|
||||||
|
return $this->process_response($response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List wlan_groups
|
* List wlan_groups
|
||||||
* ----------------
|
* ----------------
|
||||||
@@ -877,7 +919,7 @@ class Client
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List sysinfo
|
* Show sysinfo
|
||||||
* ------------
|
* ------------
|
||||||
* returns an array of known sysinfo data
|
* returns an array of known sysinfo data
|
||||||
*/
|
*/
|
||||||
@@ -888,6 +930,20 @@ class Client
|
|||||||
return $this->process_response($response);
|
return $this->process_response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get controller status
|
||||||
|
* ---------------------
|
||||||
|
* returns true upon success (controller is online)
|
||||||
|
*
|
||||||
|
* NOTES: in order to get useful results (e.g. controller version) you can call get_last_results_raw()
|
||||||
|
* immediately after this method
|
||||||
|
*/
|
||||||
|
public function stat_status()
|
||||||
|
{
|
||||||
|
$response = $this->exec_curl('/status');
|
||||||
|
return $this->process_response_boolean($response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List self
|
* List self
|
||||||
* ---------
|
* ---------
|
||||||
@@ -1177,14 +1233,10 @@ class Client
|
|||||||
{
|
{
|
||||||
if (!$this->is_loggedin) return false;
|
if (!$this->is_loggedin) return false;
|
||||||
$this->request_type = 'PUT';
|
$this->request_type = 'PUT';
|
||||||
$override_mode_options = ['off', 'on', 'default'];
|
if (!in_array($override_mode, ['off', 'on', 'default'])) return false;
|
||||||
if (in_array($override_mode, $override_mode_options)) {
|
$json = json_encode(['led_override' => $override_mode]);
|
||||||
$json = json_encode(['led_override' => $override_mode]);
|
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/device/'.trim($device_id), $json);
|
||||||
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/device/'.trim($device_id), $json);
|
return $this->process_response_boolean($response);
|
||||||
return $this->process_response_boolean($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1231,6 +1283,9 @@ class Client
|
|||||||
* required parameter <ht>(default=20)
|
* required parameter <ht>(default=20)
|
||||||
* required parameter <tx_power_mode>
|
* required parameter <tx_power_mode>
|
||||||
* required parameter <tx_power>(default=0)
|
* required parameter <tx_power>(default=0)
|
||||||
|
*
|
||||||
|
* NOTES:
|
||||||
|
* - only supported on pre-5.X.X controller versions
|
||||||
*/
|
*/
|
||||||
public function set_ap_radiosettings($ap_id, $radio, $channel, $ht, $tx_power_mode, $tx_power)
|
public function set_ap_radiosettings($ap_id, $radio, $channel, $ht, $tx_power_mode, $tx_power)
|
||||||
{
|
{
|
||||||
@@ -1253,14 +1308,10 @@ class Client
|
|||||||
*/
|
*/
|
||||||
public function set_ap_wlangroup($wlantype_id, $device_id, $wlangroup_id) {
|
public function set_ap_wlangroup($wlantype_id, $device_id, $wlangroup_id) {
|
||||||
if (!$this->is_loggedin) return false;
|
if (!$this->is_loggedin) return false;
|
||||||
$wlantype_id_options = ['ng', 'na'];
|
if (!in_array($wlantype_id, ['ng', 'na'])) return false;
|
||||||
if (in_array($wlantype_id, $wlantype_id_options)) {
|
$json = json_encode(['wlan_overrides' => [],'wlangroup_id_'.$wlantype_id => $wlangroup_id]);
|
||||||
$json = json_encode(['wlan_overrides' => [],'wlangroup_id_'.$wlantype_id => $wlangroup_id]);
|
$response = $this->exec_curl('/api/s/'.$this->site.'/upd/device/'.trim($device_id),'json='.$json);
|
||||||
$response = $this->exec_curl('/api/s/'.$this->site.'/upd/device/'.trim($device_id),'json='.$json);
|
return $this->process_response_boolean($response);
|
||||||
return $this->process_response_boolean($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1320,6 +1371,35 @@ class Client
|
|||||||
return $this->process_response_boolean($response);
|
return $this->process_response_boolean($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move a device to another site
|
||||||
|
* -----------------------------
|
||||||
|
* return true on success
|
||||||
|
* required parameter <mac> = string; MAC address of the device to move
|
||||||
|
* required parameter <site_id> = 24 char string; _id of the site to move the device to
|
||||||
|
*/
|
||||||
|
public function move_device($mac, $site_id)
|
||||||
|
{
|
||||||
|
if (!$this->is_loggedin) return false;
|
||||||
|
$json = json_encode(['site' => $site_id, 'mac' => $mac, 'cmd' => 'move-device']);
|
||||||
|
$response = $this->exec_curl('/api/s/'.$this->site.'/cmd/sitemgr', 'json='.$json);
|
||||||
|
return $this->process_response_boolean($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a device from the current site
|
||||||
|
* -------------------------------------
|
||||||
|
* return true on success
|
||||||
|
* required parameter <mac> = string; MAC address of the device to delete
|
||||||
|
*/
|
||||||
|
public function delete_device($mac)
|
||||||
|
{
|
||||||
|
if (!$this->is_loggedin) return false;
|
||||||
|
$json = json_encode(['mac' => $mac, 'cmd' => 'delete-device']);
|
||||||
|
$response = $this->exec_curl('/api/s/'.$this->site.'/cmd/sitemgr', 'json='.$json);
|
||||||
|
return $this->process_response_boolean($response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List network settings (using REST)
|
* List network settings (using REST)
|
||||||
* ----------------------------------
|
* ----------------------------------
|
||||||
@@ -1345,7 +1425,7 @@ class Client
|
|||||||
if (!$this->is_loggedin) return false;
|
if (!$this->is_loggedin) return false;
|
||||||
$this->request_type = 'POST';
|
$this->request_type = 'POST';
|
||||||
$json = json_encode($network_settings);
|
$json = json_encode($network_settings);
|
||||||
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/networkconf/', 'json='.$json);
|
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/networkconf', 'json='.$json);
|
||||||
return $this->process_response($response);
|
return $this->process_response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1484,7 +1564,7 @@ class Client
|
|||||||
*/
|
*/
|
||||||
public function set_wlansettings($wlan_id, $x_passphrase, $name = null)
|
public function set_wlansettings($wlan_id, $x_passphrase, $name = null)
|
||||||
{
|
{
|
||||||
$payload = new \stdClass();
|
$payload = (object)[];
|
||||||
if (!is_null($x_passphrase)) $payload->x_passphrase = trim($x_passphrase);
|
if (!is_null($x_passphrase)) $payload->x_passphrase = trim($x_passphrase);
|
||||||
if (!is_null($name)) $payload->name = trim($name);
|
if (!is_null($name)) $payload->name = trim($name);
|
||||||
return $this->set_wlansettings_base($wlan_id, $payload);
|
return $this->set_wlansettings_base($wlan_id, $payload);
|
||||||
@@ -1499,7 +1579,7 @@ class Client
|
|||||||
*/
|
*/
|
||||||
public function disable_wlan($wlan_id, $disable)
|
public function disable_wlan($wlan_id, $disable)
|
||||||
{
|
{
|
||||||
$payload = new \stdClass();
|
$payload = (object)[];
|
||||||
$action = ($disable) ? false : true;
|
$action = ($disable) ? false : true;
|
||||||
$payload->enabled = (bool)$action;
|
$payload->enabled = (bool)$action;
|
||||||
return $this->set_wlansettings_base($wlan_id, $payload);
|
return $this->set_wlansettings_base($wlan_id, $payload);
|
||||||
@@ -1526,22 +1606,18 @@ class Client
|
|||||||
* required parameter <wlan_id>
|
* required parameter <wlan_id>
|
||||||
* required parameter <mac_filter_policy> = string, "allow" or "deny"; default MAC policy to apply
|
* required parameter <mac_filter_policy> = string, "allow" or "deny"; default MAC policy to apply
|
||||||
* required parameter <mac_filter_enabled> = boolean; true enables the policy, false disables it
|
* required parameter <mac_filter_enabled> = boolean; true enables the policy, false disables it
|
||||||
* required parameter <macs> = array; must contain MAC strings to be placed in the MAC filter list,
|
* required parameter <macs> = array; must contain valid MAC strings to be placed in the MAC filter list,
|
||||||
* replacing existing values. Existing MAC filter list can be obtained
|
* replacing existing values. Existing MAC filter list can be obtained
|
||||||
* through list_wlanconf().
|
* through list_wlanconf().
|
||||||
*/
|
*/
|
||||||
public function set_wlan_mac_filter($wlan_id, $mac_filter_policy, $mac_filter_enabled, array $macs)
|
public function set_wlan_mac_filter($wlan_id, $mac_filter_policy, $mac_filter_enabled, array $macs)
|
||||||
{
|
{
|
||||||
$mac_filter_policy_options = ['allow', 'deny'];
|
if (!in_array($mac_filter_policy, ['allow', 'deny'])) return false;
|
||||||
if (in_array($mac_filter_policy, $mac_filter_policy_options)) {
|
$payload = (object)[];
|
||||||
$payload = new \stdClass();
|
$payload->mac_filter_enabled = (bool)$mac_filter_enabled;
|
||||||
$payload->mac_filter_enabled = (bool)$mac_filter_enabled;
|
$payload->mac_filter_policy = $mac_filter_policy;
|
||||||
$payload->mac_filter_policy = $mac_filter_policy;
|
$payload->mac_filter_list = $macs;
|
||||||
$payload->mac_filter_list = $macs;
|
return $this->set_wlansettings_base($wlan_id, $payload);
|
||||||
return $this->set_wlansettings_base($wlan_id, $payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1587,6 +1663,23 @@ class Client
|
|||||||
return $this->process_response($response);
|
return $this->process_response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Archive alarms(s)
|
||||||
|
* -----------------
|
||||||
|
* return true on success
|
||||||
|
* optional parameter <alarm_id> = 24 char string; _id of the alarm to archive which can be found with the list_alarms() function,
|
||||||
|
* if not provided, *all* un-archived alarms for the current site will be archived!
|
||||||
|
*/
|
||||||
|
public function archive_alarm($alarm_id = null)
|
||||||
|
{
|
||||||
|
if (!$this->is_loggedin) return false;
|
||||||
|
$this->request_type = 'POST';
|
||||||
|
$json = json_encode(['cmd' => 'archive-all-alarms']);
|
||||||
|
if (!is_null($alarm_id)) $json = json_encode(['_id' => $alarm_id, 'cmd' => 'archive-alarm']);
|
||||||
|
$response = $this->exec_curl('/api/s/'.$this->site.'/cmd/evtmgr', 'json='.$json);
|
||||||
|
return $this->process_response_boolean($response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upgrade a device to the latest firmware
|
* Upgrade a device to the latest firmware
|
||||||
* ---------------------------------------
|
* ---------------------------------------
|
||||||
@@ -1625,6 +1718,25 @@ class Client
|
|||||||
return $this->process_response_boolean($response);
|
return $this->process_response_boolean($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Power-cycle the PoE output of a switch port
|
||||||
|
* -------------------------------------------
|
||||||
|
* return true on success
|
||||||
|
* required parameter <switch_mac> = string; main MAC address of the switch
|
||||||
|
* required parameter <port_idx> = integer; port number/index of the port to be affected
|
||||||
|
*
|
||||||
|
* NOTES:
|
||||||
|
* - only applies to switches and their PoE ports...
|
||||||
|
*/
|
||||||
|
public function power_cycle_switch_port($switch_mac, $port_idx)
|
||||||
|
{
|
||||||
|
if (!$this->is_loggedin) return false;
|
||||||
|
$json = ['mac' => $switch_mac, 'port_idx' => intval($port_idx), 'cmd' => 'power-cycle'];
|
||||||
|
$json = json_encode($json);
|
||||||
|
$response = $this->exec_curl('/api/s/'.$this->site.'/cmd/devmgr', 'json='.$json);
|
||||||
|
return $this->process_response_boolean($response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger an RF scan by an AP
|
* Trigger an RF scan by an AP
|
||||||
* ---------------------------
|
* ---------------------------
|
||||||
@@ -1653,6 +1765,23 @@ class Client
|
|||||||
return $this->process_response($response);
|
return $this->process_response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update device settings, base (using REST)
|
||||||
|
* -----------------------------------------
|
||||||
|
* return true on success
|
||||||
|
* required parameter <device_id> = 24 char string; _id of the device which can be found with the list_devices() function
|
||||||
|
* required parameter <device_settings> = stdClass object or associative array containing the configuration to apply to the device, must be a
|
||||||
|
* (partial) object/array structured in the same manner as is returned by list_devices() for the device.
|
||||||
|
*/
|
||||||
|
public function set_device_settings_base($device_id, $device_settings)
|
||||||
|
{
|
||||||
|
if (!$this->is_loggedin) return false;
|
||||||
|
$this->request_type = 'PUT';
|
||||||
|
$json = json_encode($device_settings);
|
||||||
|
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/device/'.trim($device_id), 'json='.$json);
|
||||||
|
return $this->process_response_boolean($response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List Radius profiles (using REST)
|
* List Radius profiles (using REST)
|
||||||
* --------------------------------------
|
* --------------------------------------
|
||||||
@@ -1727,23 +1856,20 @@ class Client
|
|||||||
public function create_radius_account($name, $x_password, $tunnel_type, $tunnel_medium_type, $vlan = null)
|
public function create_radius_account($name, $x_password, $tunnel_type, $tunnel_medium_type, $vlan = null)
|
||||||
{
|
{
|
||||||
if (!$this->is_loggedin) return false;
|
if (!$this->is_loggedin) return false;
|
||||||
$tunnel_type_options = [1,2,3,4,5,6,7,8,9,10,11,12,13];
|
$tunnel_types = [1,2,3,4,5,6,7,8,9,10,11,12,13];
|
||||||
$tunnel_medium_type_options = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
|
$tunnel_medium_types = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
|
||||||
if (in_array($tunnel_type, $tunnel_type_options) && in_array($tunnel_medium_type, $tunnel_medium_type_options)) {
|
if (!in_array($tunnel_type, $tunnel_types) || !in_array($tunnel_medium_type, $tunnel_medium_types)) return false;
|
||||||
$this->request_type = 'POST';
|
$this->request_type = 'POST';
|
||||||
$account_details = [
|
$account_details = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'x_password' => $x_password,
|
'x_password' => $x_password,
|
||||||
'tunnel_type' => (int) $tunnel_type,
|
'tunnel_type' => (int) $tunnel_type,
|
||||||
'tunnel_medium_type' => (int) $tunnel_medium_type
|
'tunnel_medium_type' => (int) $tunnel_medium_type
|
||||||
];
|
];
|
||||||
if (isset($vlan)) $account_details['vlan'] = (int) $vlan;
|
if (isset($vlan)) $account_details['vlan'] = (int) $vlan;
|
||||||
$json = json_encode($account_details);
|
$json = json_encode($account_details);
|
||||||
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/account', 'json='.$json);
|
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/account', 'json='.$json);
|
||||||
return $this->process_response($response);
|
return $this->process_response($response);
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1877,7 +2003,7 @@ class Client
|
|||||||
/**
|
/**
|
||||||
* Process regular responses where output is the content of the data array
|
* Process regular responses where output is the content of the data array
|
||||||
*/
|
*/
|
||||||
private function process_response($response_json)
|
protected function process_response($response_json)
|
||||||
{
|
{
|
||||||
$response = json_decode($response_json);
|
$response = json_decode($response_json);
|
||||||
$this->catch_json_last_error();
|
$this->catch_json_last_error();
|
||||||
@@ -1903,7 +2029,7 @@ class Client
|
|||||||
/**
|
/**
|
||||||
* Process responses where output should be boolean (true/false)
|
* Process responses where output should be boolean (true/false)
|
||||||
*/
|
*/
|
||||||
private function process_response_boolean($response_json)
|
protected function process_response_boolean($response_json)
|
||||||
{
|
{
|
||||||
$response = json_decode($response_json);
|
$response = json_decode($response_json);
|
||||||
$this->catch_json_last_error();
|
$this->catch_json_last_error();
|
||||||
@@ -2027,7 +2153,7 @@ class Client
|
|||||||
/**
|
/**
|
||||||
* Execute the cURL request
|
* Execute the cURL request
|
||||||
*/
|
*/
|
||||||
private function exec_curl($path, $data = '')
|
protected function exec_curl($path, $data = '')
|
||||||
{
|
{
|
||||||
$url = $this->baseurl.$path;
|
$url = $this->baseurl.$path;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user