Skip to content

Commit

Permalink
include API client class 1.1.25
Browse files Browse the repository at this point in the history
add support for list_country_codes()
  • Loading branch information
malle-pietje committed Mar 24, 2018
1 parent e44ca42 commit c6222d2
Show file tree
Hide file tree
Showing 23 changed files with 1,332 additions and 106 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ This tool is for browsing data that is exposed through Ubiquiti's UniFi Controll
It comes bundled with a **PHP class for access to the UniFi Controller API**, which supports [more API endpoints](https://github.com/Art-of-WiFi/UniFi-API-client#methods-and-functions-supported) than the UniFi API browser tool does.
If you plan to create your own PHP code levering the UniFi controller API, it is recommended to use the standalone version of the API client class which can be found here: https://github.com/Art-of-WiFi/UniFi-API-client
If you plan to create your own PHP code leveraging the UniFi controller API, it is recommended to use the standalone version of the API client class which can be found here: https://github.com/Art-of-WiFi/UniFi-API-client
You will find examples and detailed instructions there.
Please keep the following in mind:
- the API Browser tool doesn't support all available data collections/API endpoints, see the list below of those that are currently supported
- currently, versions 4.x.x and 5.x.x of the UniFi Controller software are supported (version 5.6.18 has been confirmed to work)
- currently, versions 4.x.x and 5.x.x of the UniFi Controller software are supported (version 5.7.20 has been confirmed to work)
- there is still work to be done to add/improve functionality and usability of this tool so suggestions/comments are welcome. Please use the github [issue](https://github.com/Art-of-WiFi/UniFi-API-browser/issues) list or the Ubiquiti Community forums (https://community.ubnt.com/t5/UniFi-Wireless/UniFi-API-browser-tool-released/m-p/1392651) to share your ideas/questions.
- please read the Security Notice below before installing this tool!
Expand Down Expand Up @@ -81,6 +81,7 @@ The UniFi API browser tool offers the following features:
- list current channels
- list DPI stats
- dynamic DNS configuration
- list country codes
- list Radius accounts (supported on controller version 5.5.19 and higher)
- Messages
- list events
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions config.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@
// bootstrap, cerulean, cosmo, cyborg, darkly, flatly, journal, lumen, paper
// readable, sandstone, simplex, slate, spacelab, superhero, united, yeti

$debug = false; // set to true (without quotes) to enable debug output to the browser and the PHP error log
?>
$debug = false; // set to true (without quotes) to enable debug output to the browser and the PHP error log
26 changes: 17 additions & 9 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
* - not all data collections/API endpoints are supported (yet), see the list of
* the currently supported data collections/API endpoints in the README.md file
* - this tool currently supports versions 4.x and 5.x of the UniFi Controller software
*
* VERSION: 1.0.26
*
* ------------------------------------------------------------------------------------
*
* Copyright (c) 2017, Art of WiFi
Expand All @@ -20,7 +17,7 @@
* with this package in the file LICENSE.md
*
*/
define('API_BROWSER_VERSION', '1.0.26');
define('API_BROWSER_VERSION', '1.0.27');
define('API_CLASS_VERSION', get_client_version());

/**
Expand All @@ -29,10 +26,13 @@
* - if not, stop and display an error message
*/
if (function_exists('curl_version')) {
$curl_info = curl_version();
$curl_version = $curl_info['version'];
$curl_info = curl_version();
$curl_version = $curl_info['version'];
$openssl_version = $curl_info['ssl_version'];
} else {
exit('The <b>PHP curl</b> module is not installed! Please correct this before you proceed!<br>');
$curl_version = 'unavailable';
$openssl_version = 'unavailable';
}

/**
Expand Down Expand Up @@ -491,6 +491,10 @@
$selection = 'list radius profiles';
$data = $unifidata->list_radius_profiles();
break;
case 'list_country_codes':
$selection = 'list country codes';
$data = $unifidata->list_country_codes();
break;
default:
break;
}
Expand Down Expand Up @@ -837,6 +841,8 @@ function get_client_version()
<li id="list_portconf"><a href="?action=list_portconf">list port configuration</a></li>
<li id="list_portforwarding"><a href="?action=list_portforwarding">list port forwarding rules</a></li>
<li id="list_dynamicdns"><a href="?action=list_dynamicdns">dynamic DNS configuration</a></li>
<li role="separator" class="divider"></li>
<li id="list_country_codes"><a href="?action=list_country_codes">list country codes</a></li>
<!-- Radius-related collections, only to be displayed when we have detected a capable controller version -->
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.5.19') >= 0) { ?>
<li role="separator" class="divider"></li>
Expand Down Expand Up @@ -1001,6 +1007,8 @@ function get_client_version()
<dd><span id="span_memory_used" class="label label-primary"></span></dd>
<dt>cURL version</dt>
<dd><span id="span_curl_version" class="label label-primary"></span></dd>
<dt>OpenSSL version</dt>
<dd><span id="span_openssl_version" class="label label-primary"></span></dd>
<dt>operating system</dt>
<dd><span id="span_os_version" class="label label-primary"></span></dd>
</dl>
Expand Down Expand Up @@ -1045,6 +1053,7 @@ function get_client_version()
var memory_limit = '<?php echo (ini_get('memory_limit')) ?>';
var memory_used = '<?php echo round(memory_get_peak_usage(false)/1024/1024, 2) . 'M' ?>';
var curl_version = '<?php echo $curl_version ?>';
var openssl_version = '<?php echo $openssl_version ?>';
var os_version = '<?php echo (php_uname('s') . ' ' . php_uname('r')) ?>';
var api_browser_version = '<?php echo API_BROWSER_VERSION ?>';
var api_class_version = '<?php echo API_CLASS_VERSION ?>';
Expand All @@ -1057,24 +1066,22 @@ function get_client_version()
*/
$('#alert_placeholder').html(alert_message);
$('#alert_placeholder').fadeIn(1000);

$('#span_site_id').html(site_id);
$('#span_site_name').html(site_name);
$('#span_output_format').html(output_format);
$('#span_selection').html(selection);
$('#span_objects_count').html(objects_count);

$('#span_elapsed_time').html('total elapsed time: ' + timing_total_time + ' seconds');

$('#timing_login_perc').attr('aria-valuenow', timing_login_perc);
$('#timing_login_perc').css('width', timing_login_perc + '%');
$('#timing_login_perc').attr('data-original-title', time_after_login + ' seconds');
$('#timing_login_perc').html('API login time');

$('#timing_load_perc').attr('aria-valuenow', timing_load_perc);
$('#timing_load_perc').css('width', timing_load_perc + '%');
$('#timing_load_perc').attr('data-original-title', time_for_load + ' seconds');
$('#timing_load_perc').html('data load time');

$('#timing_remain_perc').attr('aria-valuenow', timing_remain_perc);
$('#timing_remain_perc').css('width', timing_remain_perc + '%');
$('#timing_remain_perc').attr('data-original-title', 'PHP overhead: ' + timing_remain_perc + '%');
Expand All @@ -1087,6 +1094,7 @@ function get_client_version()
$('#span_controller_version').html(controller_version);
$('#span_php_version').html(php_version);
$('#span_curl_version').html(curl_version);
$('#span_openssl_version').html(openssl_version);
$('#span_os_version').html(os_version);
$('#span_memory_limit').html(memory_limit);
$('#span_memory_used').html(memory_used);
Expand Down
65 changes: 41 additions & 24 deletions vendor/art-of-wifi/unifi-api-client/README.md
Original file line number Diff line number Diff line change
@@ -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 our 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.

### 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.

[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=M7TVNVX3Z44VN)
This class can be installed using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects.

## 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()
- logout()
- adopt_device()
- archive_alarm()
- authorize_guest()
- block_sta()
- count_alarms()
Expand All @@ -26,6 +22,7 @@ The class currently supports the following functions/methods to get/post/put/del
- create_usergroup()
- create_voucher()
- create_wlan()
- delete_device()
- delete_network()
- delete_radius_account()
- delete_site()
Expand All @@ -36,9 +33,11 @@ The class currently supports the following functions/methods to get/post/put/del
- extend_guest_validity()
- led_override()
- list_admins()
- list_all_admins()
- list_alarms()
- list_aps() (deprecated but still available as alias)
- list_clients()
- list_country_codes()
- list_current_channels()
- list_dashboard()
- list_devices()
Expand Down Expand Up @@ -66,6 +65,7 @@ The class currently supports the following functions/methods to get/post/put/del
- list_wlan_groups()
- list_wlanconf()
- locate_ap()
- move_device()
- power_cycle_switch_port()
- reconnect_sta()
- rename_ap()
Expand All @@ -74,9 +74,18 @@ The class currently supports the following functions/methods to get/post/put/del
- set_ap_radiosettings()
- set_device_settings_base()
- set_guestlogin_settings()
- set_guestlogin_settings_base()
- set_locate_ap() (deprecated but still available as alias)
- set_networksettings_base()
- set_radius_account_base()
- set_site_connectivity()
- set_site_country()
- set_site_guest_access()
- set_site_locale()
- set_site_mgmt()
- set_site_name()
- set_site_ntp()
- set_site_snmp()
- set_sta_name()
- set_sta_note()
- set_usergroup()
Expand Down Expand Up @@ -111,24 +120,25 @@ The class currently supports the following functions/methods to get/post/put/del
- upgrade_device_external()

Internal functions, getters/setters:

- set_debug()
- set_site()
- get_debug()
- set_site()
- get_site()
- get_cookie() (renamed from getcookie())
- get_last_results_raw()
- 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

- 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 ##

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

Expand All @@ -138,6 +148,16 @@ Once composer is installed, simply execute this command from the shell in your p

```sh
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:
Expand Down Expand Up @@ -189,18 +209,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.

### 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.
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.
#### 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.

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:
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:

`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?

Expand All @@ -212,11 +229,11 @@ If you would like to contribute code (improvements), please open an issue and in

## 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
- 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

## 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.
2 changes: 1 addition & 1 deletion vendor/art-of-wifi/unifi-api-client/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ If you would like to share your own example file(s), please open an issue and in

## Important Disclaimer

Use these examples at your own risk!
Use these examples at your own risk!
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* PHP API usage example
*
* contributed by: @4oo4
* description: example script to check and upgrade device firmware (can be scheduled with systemd/cron)
* to the most current version
*/
require_once('vendor/autoload.php');
require_once('config.php');

/**
* site id of the AP to update
*/
$site_id = '<enter your site id here>';

/**
* device MAC address formatted with colons, e.g. 'de:ad:be:ef:01:23'
*/
$device_mac = '<enter MAC address of device to update>';

/**
* initialize the UniFi API connection class, log in to the controller
* (this example assumes you have already assigned the correct values in config.php to the variables used)
*/
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion, false);
$login = $unifi_connection->login();

/**
* Run the actual upgrade
*/
$results = $unifi_connection->upgrade_device($device_mac);

/**
* provide feedback in json format from $response given by upgrade_device();
*/
echo json_encode($results, JSON_PRETTY_PRINT);
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* PHP API usage example
*
* contributed by: Art of WiFi
* description: example basic PHP script to auth a guest device and attach a note to it
* description: example basic PHP script to auth a guest device and attach a note to it,
* this requires the device to be connected to the WLAN/LAN at moment of
* authorization
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
/**
* set to true (without quotes) to enable debug output to the browser and the PHP error log
*/
$debug = false;
$debug = false;
Loading

0 comments on commit c6222d2

Please sign in to comment.