Skip to content

Commit

Permalink
API browser version 1.0.33
Browse files Browse the repository at this point in the history
included API client class version 1.1.36
changed layout of dropdowns and of tooltip
added support for new stat_ips_events() method, only supported with controllers 5.9.10 and higher
  • Loading branch information
malle-pietje committed Oct 24, 2018
1 parent 93cfc4b commit 7deca56
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 107 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
>**NOTICE**
>
>The repository has been transferred to this new GitHub organisation account, the project maintainer will remain the same and will continue to actively maintain it.
> If you have previously installed the API Browser tool using `git clone`, you may consider pointing the clone to the new repository URL. You can do this with the following command from within the directory of your clone:
> If you have previously installed the API browser tool using `git clone`, you may consider pointing the clone to the new repository URL. You can do this with the following command from within the directory of your clone:
>
>```bash
>$ git remote set-url origin https://github.com/Art-of-WiFi/UniFi-API-browser.git
Expand All @@ -19,7 +19,7 @@ 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
- 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.8.24 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
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.

26 changes: 22 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* with this package in the file LICENSE.md
*
*/
define('API_BROWSER_VERSION', '1.0.32');
define('API_BROWSER_VERSION', '1.0.33');
define('API_CLASS_VERSION', get_client_version());

/**
Expand Down Expand Up @@ -537,6 +537,10 @@
$selection = 'list auto backups';
$data = $unifidata->list_backups();
break;
case 'stat_ips_events':
$selection = 'list IPS/IDS events';
$data = $unifidata->stat_ips_events();
break;
default:
break;
}
Expand Down Expand Up @@ -730,6 +734,7 @@ function get_client_version()
</a>
<ul class="dropdown-menu scrollable-menu" id="controllerslist">
<li class="dropdown-header">Select a controller</li>
<li role="separator" class="divider"></li>
<?php
/**
* here we loop through the configured UniFi controllers
Expand Down Expand Up @@ -761,6 +766,7 @@ function get_client_version()
</a>
<ul class="dropdown-menu scrollable-menu" id="siteslist">
<li class="dropdown-header">Select a site</li>
<li role="separator" class="divider"></li>
<?php
/**
* here we loop through the available sites, after we've sorted the sites collection
Expand Down Expand Up @@ -788,14 +794,15 @@ function get_client_version()
</a>
<ul class="dropdown-menu scrollable-menu" id="outputselection">
<li class="dropdown-header">Select an output format</li>
<li id="json"><a href="?output_format=json">json (default)</a></li>
<li role="separator" class="divider"></li>
<li id="json"><a href="?output_format=json">JSON (default)</a></li>
<li role="separator" class="divider"></li>
<li id="php_array"><a href="?output_format=php_array">PHP array</a></li>
<li id="php_var_dump"><a href="?output_format=php_var_dump">PHP var_dump</a></li>
<li id="php_var_export"><a href="?output_format=php_var_export">PHP var_export</a></li>
<li role="separator" class="divider"></li>
<li class="dropdown-header">Nice but slow with large collections</li>
<li id="json_color"><a href="?output_format=json_color">json highlighted</a></li>
<li id="json_color"><a href="?output_format=json_color">JSON highlighted</a></li>
<li id="php_array_kint"><a href="?output_format=php_array_kint">PHP array using Kint</a></li>
</ul>
</li>
Expand All @@ -806,6 +813,7 @@ function get_client_version()
</a>
<ul class="dropdown-menu scrollable-menu">
<li class="dropdown-header">Select a data collection</li>
<li role="separator" class="divider"></li>
<li id="list_clients"><a href="?action=list_clients">list online clients</a></li>
<li id="list_guests"><a href="?action=list_guests">list guests</a></li>
<li id="list_users"><a href="?action=list_users">list users</a></li>
Expand All @@ -823,6 +831,7 @@ function get_client_version()
</a>
<ul class="dropdown-menu scrollable-menu">
<li class="dropdown-header">Select a data collection</li>
<li role="separator" class="divider"></li>
<li id="list_devices"><a href="?action=list_devices">list devices</a></li>
<li id="list_wlan_groups"><a href="?action=list_wlan_groups">list wlan groups</a></li>
<li id="list_rogueaps"><a href="?action=list_rogueaps">list rogue access points</a></li>
Expand All @@ -841,6 +850,7 @@ function get_client_version()
</a>
<ul class="dropdown-menu scrollable-menu">
<li class="dropdown-header">Select a data collection</li>
<li role="separator" class="divider"></li>
<li id="stat_5minutes_site"><a href="?action=stat_5minutes_site">5 minutes site stats</a></li>
<li id="stat_hourly_site"><a href="?action=stat_hourly_site">hourly site stats</a></li>
<li id="stat_daily_site"><a href="?action=stat_daily_site">daily site stats</a></li>
Expand Down Expand Up @@ -884,6 +894,7 @@ function get_client_version()
</a>
<ul class="dropdown-menu scrollable-menu">
<li class="dropdown-header">Select a data collection</li>
<li role="separator" class="divider"></li>
<li id="stat_voucher"><a href="?action=stat_voucher">stat vouchers</a></li>
<li id="stat_payment"><a href="?action=stat_payment">stat payments</a></li>
<li role="separator" class="divider"></li>
Expand All @@ -897,6 +908,7 @@ function get_client_version()
</a>
<ul class="dropdown-menu scrollable-menu">
<li class="dropdown-header">Select a data collection</li>
<li role="separator" class="divider"></li>
<li id="list_sites"><a href="?action=list_sites">list sites on this controller</a></li>
<li id="stat_sysinfo"><a href="?action=stat_sysinfo">sysinfo</a></li>
<li id="list_self"><a href="?action=list_self">self</a></li>
Expand Down Expand Up @@ -933,11 +945,16 @@ function get_client_version()
</a>
<ul class="dropdown-menu scrollable-menu">
<li class="dropdown-header">Select a data collection</li>
<li role="separator" class="divider"></li>
<li id="list_alarms"><a href="?action=list_alarms">list alarms</a></li>
<li id="count_alarms"><a href="?action=count_alarms">count all alarms</a></li>
<li id="count_active_alarms"><a href="?action=count_active_alarms">count active alarms</a></li>
<li role="separator" class="divider"></li>
<li id="list_events"><a href="?action=list_events">list events</a></li>
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.9.10') >= 0) { ?>
<li role="separator" class="divider"></li>
<li id="stat_ips_events"><a href="?action=stat_ips_events">list IPS/IDS events</a></li>
<?php } ?>
</ul>
</li>
<?php } ?>
Expand All @@ -951,7 +968,8 @@ function get_client_version()
<ul class="dropdown-menu scrollable-menu">
<li id="info" data-toggle="modal" data-target="#about_modal"><a href="#"><i class="fa fa-info-circle"></i> About UniFi API browser</a></li>
<li role="separator" class="divider"></li>
<li id="reset_session" data-toggle="tooltip" data-placement="top" data-original-title="In some cases this will fix login errors (e.g. empty sites list)">
<li id="reset_session" data-toggle="tooltip" data-container="body" data-placement="left"
data-original-title="In some cases this can fix login errors and/or an empty sites list">
<a href="?reset_session=true"><i class="fa fa-refresh"></i> Reset PHP session</a>
</li>
<li role="separator" class="divider"></li>
Expand Down
14 changes: 11 additions & 3 deletions vendor/art-of-wifi/unifi-api-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -83,6 +85,7 @@ The class currently supports the following functions/methods to get/post/put/del
- set_device_settings_base()
- set_guestlogin_settings()
- set_guestlogin_settings_base()
- set_ips_settings_base() (supported on controller version 5.9.10 and higher)
- set_locate_ap() (deprecated but still available as alias)
- set_networksettings_base()
- set_radius_account_base()
Expand Down Expand Up @@ -111,6 +114,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()
Expand All @@ -120,6 +126,8 @@ The class currently supports the following functions/methods to get/post/put/del
- stat_payment()
- stat_sessions()
- stat_sites()
- stat_speedtest_results()
- stat_ips_events() (supported on controller version 5.9.10 and higher)
- stat_sta_sessions_latest()
- stat_status()
- stat_sysinfo()
Expand Down Expand Up @@ -224,7 +232,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:

Expand All @@ -234,7 +242,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

Expand Down
26 changes: 10 additions & 16 deletions vendor/art-of-wifi/unifi-api-client/examples/block_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@
*/
require_once('config.php');

$debug=false;
$debug = false;
/**
* the MAC address(es) of the device(s) to block
* the MAC address(es) of the device(s) to block
*/
$macs_to_block = explode(',',$argv[1]);

/**
* The site to authorize the device with
*/
$site_id = 'MUST_DEFINE_THIS';
if ($site_id == "MUST_DEFINE_THIS")
{
if ($site_id == "MUST_DEFINE_THIS") {
print 'ERROR: set the site id in your script';
return;
}
Expand All @@ -48,8 +47,7 @@
$set_debug_mode = $unifi_connection->set_debug($debug);
$loginresults = $unifi_connection->login(); // always true regardless of site id

foreach ($macs_to_block as &$mac)
{
foreach ($macs_to_block as &$mac) {
// block_result is always true even if mac address does not exist :(
$block_result = $unifi_connection->block_sta($mac);

Expand All @@ -65,20 +63,16 @@

$getid_result = $unifi_connection->stat_client($mac);

if (property_exists($getid_result[0], "oui")) // this field(manufacturer) seems to exist on valid mac addresses
{
if (property_exists($getid_result[0], "name")) // this is the alias field if it has been defined
{
if (property_exists($getid_result[0], "oui")) {
// this field(manufacturer) seems to exist on valid mac addresses
if (property_exists($getid_result[0], "name")) {
// this is the alias field if it has been defined
$name = $getid_result[0]->name;
}
else
{
} else {
$name = $getid_result[0]->hostname;
}
print 'blocked ' . $name . PHP_EOL;
}
else
{
} else {
print 'ERROR: could not block ' . $mac . PHP_EOL;
print ' check mac address is valid and part of your network' . PHP_EOL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,18 @@
print "UniFi controller login failure, please check your credentials in config.php.\n";
} else {
$guestlist = $unifi_connection->list_guests();
// print "<pre>"; print_r ($guestlist); print "</pre>";
// loop thru all known guests
foreach ($guestlist as $guest) {
// print "<pre>"; print_r ($guest); print "</pre>";
print "<pre>" . $guest->_id . " (" . $guest->mac . "), valid until " . date (DATE_ATOM, $guest->end) . " (" . $guest->end . ")</pre>";
print "<pre>" . $guest->_id . " (" . $guest->mac . "), valid until " . date(DATE_ATOM, $guest->end) . " (" . $guest->end . ")</pre>";

// just a sample: only extend validity of guests which have end date after 2017-04-02
if ($guest->end > 1491166482) {
// extend clients five times = five days
if (!$unifi_connection->extend_guest_validity ($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
if (!$unifi_connection->extend_guest_validity ($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
if (!$unifi_connection->extend_guest_validity ($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
if (!$unifi_connection->extend_guest_validity ($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
if (!$unifi_connection->extend_guest_validity ($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n";
}
}

Expand Down
Loading

0 comments on commit 7deca56

Please sign in to comment.