Skip to content

Commit

Permalink
API Browser version 1.0.16, API client class version 1.1.5
Browse files Browse the repository at this point in the history
- API client class: changed class name to UnifiApi
- API client class: general code cleanup and improvements
- API client class: enhanced method/function list_events()
- API client class: added method/function list_devices() to replace
list_aps() which is still available as alias
- API browser tool: general code cleanup
- examples: general code cleanup, added config file template
  • Loading branch information
malle-pietje committed May 29, 2017
1 parent a6bbb29 commit 86d9c1d
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 151 deletions.
4 changes: 2 additions & 2 deletions examples/ap_scanning_state.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* NOTE:
* this example will only work out of the box with a single controller config file!
*/
require_once('config-local.php');
require_once('../config.php');

/**
* site id and MAC address of AP to query
Expand All @@ -25,7 +25,7 @@
* spectrum_scan_state()
*/
require_once('phpapi/class.unifi.php');
$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$unifidata = new UnifiApi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$loginresults = $unifidata->login();
$data = $unifidata->spectrum_scan_state($ap_mac);

Expand Down
2 changes: 1 addition & 1 deletion examples/auth_guest_basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* load the Unifi API connection class and log in to the controller
*/
require_once('../phpapi/class.unifi.php');
$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$unifidata = new UnifiApi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$set_debug_mode = $unifidata->set_debug($debug);
$loginresults = $unifidata->login();

Expand Down
2 changes: 1 addition & 1 deletion examples/auth_guest_with_note.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* load the Unifi API connection class and log in to the controller
*/
require_once('../phpapi/class.unifi.php');
$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$unifidata = new UnifiApi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$set_debug_mode = $unifidata->set_debug($debug);
$loginresults = $unifidata->login();

Expand Down
23 changes: 23 additions & 0 deletions examples/config.template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Copyright (c) 2016, Slooffmaster
*
* This file is subject to the MIT license that is bundled
* with this package in the file LICENSE.md
*
*/

/**
* Single controller configuration
* ===============================
* Update this section with your UniFi controller details and credentials
*/
$controlleruser = ''; // the user name for access to the UniFi Controller
$controllerpassword = ''; // the password for access to the UniFi Controller
$controllerurl = ''; // full url to the UniFi Controller, eg. 'https://22.22.11.11:8443'
$controllerversion = ''; // the version of the Controller software, eg. '4.6.6' (must be at least 4.0.0)

/**
* set to true (without quotes) to enable debug output to the browser and the PHP error log
*/
$debug = false;
2 changes: 1 addition & 1 deletion examples/create_voucher.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* load the Unifi API connection class and log in to the controller
*/
require_once('../phpapi/class.unifi.php');
$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$unifidata = new UnifiApi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$set_debug_mode = $unifidata->set_debug($debug);
$loginresults = $unifidata->login();

Expand Down
8 changes: 4 additions & 4 deletions examples/extend_guest_auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
* description: example of how to extend validity of guest authorizations
*/

require_once ("../phpapi/class.unifi.php");
require_once ("../config.php");
require_once("../phpapi/class.unifi.php");
require_once("../config.php");

// must be adapted to your site!
$site_id = "default";
$site_id = "default";
$site_name = "*enter your site name*";

$unifidata = new unifiapi ($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$unifidata = new UnifiApi ($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$set_debug_mode = $unifidata->set_debug($debug);
$loginresults = $unifidata->login();

Expand Down
2 changes: 1 addition & 1 deletion examples/list_alarms.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* load the Unifi API connection class and log in to the controller and do our thing
*/
require_once('../phpapi/class.unifi.php');
$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$unifidata = new UnifiApi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$set_debug_mode = $unifidata->set_debug($debug);
$loginresults = $unifidata->login();
$data = $unifidata->list_alarms();
Expand Down
2 changes: 1 addition & 1 deletion examples/list_ap_connected_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* load the Unifi API connection class and log in to the controller and pull the requested data
*/
require_once('../phpapi/class.unifi.php');
$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$unifidata = new UnifiApi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$set_debug_mode = $unifidata->set_debug($debug);
$loginresults = $unifidata->login();
$aps_array = $unifidata->list_aps();
Expand Down
2 changes: 1 addition & 1 deletion examples/list_site_health.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
require_once('../phpapi/class.unifi.php');

$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$unifidata = new UnifiApi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$set_debug_mode = $unifidata->set_debug($debug);
$loginresults = $unifidata->login();
$result = $unifidata->list_health();
Expand Down
2 changes: 1 addition & 1 deletion examples/list_social_auth_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* load the Unifi API connection class and log in to the controller and do our thing
*/
require_once('../phpapi/class.unifi.php');
$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$unifidata = new UnifiApi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$set_debug_mode = $unifidata->set_debug($debug);
$loginresults = $unifidata->login();
$data = $unifidata->stat_payment();
Expand Down
6 changes: 3 additions & 3 deletions examples/toggle_led.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* NOTE:
* this example will only work out of the box with a single controller config file!
*/
require_once('../config-local.php');
require_once('../config.php');

/**
* site id to use
Expand All @@ -29,9 +29,9 @@
* load the Unifi API connection class and log in to the controller to do our thing
*/
require_once('../phpapi/class.unifi.php');
$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); // initialize the class instance
$unifidata = new UnifiApi($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); // initialize the class instance
$set_debug_mode = $unifidata->set_debug($debug);
$loginresults = $unifidata->login(); // log into the controller
$loginresults = $unifidata->login();

/**
* using the "old" deprecated methods/functions
Expand Down
24 changes: 12 additions & 12 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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.15
* VERSION: 1.0.16
*
* ------------------------------------------------------------------------------------
*
Expand All @@ -20,7 +20,7 @@
* with this package in the file LICENSE.md
*
*/
define('API_BROWSER_VERSION', '1.0.15');
define('API_BROWSER_VERSION', '1.0.16');

/**
* in order to use the PHP $_SESSION array for temporary storage of variables, session_start() is required
Expand All @@ -32,7 +32,7 @@
* - this function can be useful when login errors occur, mostly after upgrades or incorrect credential changes
*/
if (isset($_GET['reset_session']) && $_GET['reset_session'] == true) {
$_SESSION = array();
$_SESSION = [];
session_unset();
session_destroy();
session_start();
Expand Down Expand Up @@ -137,13 +137,13 @@
* if the user has configured a single controller, we push it's details
* to the $_SESSION and $controller arrays
*/
$_SESSION['controller'] = array(
$_SESSION['controller'] = [
'user' => $controlleruser,
'password' => $controllerpassword,
'url' => $controllerurl,
'name' => 'Controller',
'version' => $controllerversion
);
];
$controller = $_SESSION['controller'];
}
}
Expand Down Expand Up @@ -224,7 +224,7 @@
* create a new instance of the API client class and log in to the UniFi controller
* - if an error occurs during the login process, an alert is displayed on the page
*/
$unifidata = new unifiapi($controller['user'], $controller['password'], $controller['url'], $site_id, $controller['version']);
$unifidata = new UnifiApi($controller['user'], $controller['password'], $controller['url'], $site_id, $controller['version']);
$set_debug_mode = $unifidata->set_debug(trim($debug));
$loginresults = $unifidata->login();

Expand Down Expand Up @@ -317,7 +317,7 @@
break;
case 'list_devices':
$selection = 'list devices';
$data = $unifidata->list_aps();
$data = $unifidata->list_devices();
break;
case 'list_wlan_groups':
$selection = 'list wlan groups';
Expand Down Expand Up @@ -497,9 +497,9 @@ function print_output($output_format, $data)
/**
* function to sort the sites collection alpabetically by description
*/
function sites_sort($a, $b)
function sites_sort($site_a, $site_b)
{
return strcmp($a->desc, $b->desc);
return strcmp($site_a->desc, $site_b->desc);
}
?>
<!DOCTYPE html>
Expand Down Expand Up @@ -928,9 +928,9 @@ function sites_sort($a, $b)
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 ?>';
var controller_user = '<?php if (isset($_SESSION['controller'])) { echo $controller['user']; } ?>';
var controller_url = '<?php if (isset($_SESSION['controller'])) { echo $controller['url']; } ?>';
var controller_version = '<?php if (isset($_SESSION['controller'])) { echo $detected_controller_version; } ?>';
var controller_user = '<?php if (isset($_SESSION['controller'])) echo $controller['user'] ?>';
var controller_url = '<?php if (isset($_SESSION['controller'])) echo $controller['url'] ?>';
var controller_version = '<?php if (isset($_SESSION['controller'])) echo $detected_controller_version ?>';

/**
* update dynamic elements in the DOM using some of the above variables
Expand Down
Loading

0 comments on commit 86d9c1d

Please sign in to comment.