Skip to content

Commit

Permalink
added several new data collections and some minor code tweaks
Browse files Browse the repository at this point in the history
- added the following new data collections:
list network configuration
self
and for hotspots:
stat vouchers
stat payments
list hotspot operators
- added debug option to config.template.php file
- updated README to reflect new data collections
  • Loading branch information
malle-pietje committed Jan 2, 2016
1 parent 1b3ee16 commit f58af0a
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 96 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ The Unifi API browser tool offers the following features:
- hourly access point stats
- daily site stats
- health metrics
- Hotspot
- stat vouchers
- stat payments
- list hotspot operators
- Configuration
- list sites on this controller
- list site settings
- sysinfo
- self
- wlan config
- list VoIP extension
- list network configuration
- list port configurations
- list port forwarding rules
- dynamic DNS configuration
Expand Down Expand Up @@ -78,14 +84,14 @@ git clone https://github.com/malle-pietje/Unifi-API-browser.git

Alternatively you may choose to download the zip file and unzip it in your directory of choice, then follow the configuration steps below.

### Updates
When you have installed the tool using the `git clone` command you can install updates by going into the directory where the tools has been installed, and by running the `git pull` command from there.

### Configuration
- credentials for access to the Unifi Controller API need to be configured in the file named `config.template.php` which should be copied/renamed to `config.php` before using the Unifi API browser tool
- please see the `config.template.php` file for further instructions
- after following these steps, you can open the tool in your browser (assuming you installed it in the root folder of your web server as suggested above) by going to this url: `http://serverip/Unifi-API-browser/`

### Updates
If you have installed the tool using the `git clone` command, you can install updates by going into the directory where the tool has been installed, and running the `git pull` command from there.

### Security notice
The use of this tool is **not secured in any way**! Make sure to prevent unauthorised access to it, preventing exposure of details and credentials such as user names and passwords for access to the Unifi controller!

Expand Down
1 change: 1 addition & 0 deletions config.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
$controllerversion = ''; // the version of the Controller software, eg. '4.6.6' (must be at least 4.0.0)
$cookietimeout = '3600'; // time of inactivity in seconds, after which the PHP session cookie will be refreshed
// this means the site and data collection will need to be selected again
$debug = false; // set to true (without quotes) to enable debug output to the browser and PHP error log
?>
128 changes: 85 additions & 43 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
$objectscount = '';
$alertmessage = '';
$cookietimeout = '1800';
$debug = false;

/*
load the settings file
Expand Down Expand Up @@ -81,38 +82,12 @@
/*
process the GET variables and store them in the $_SESSION array,
if a GET variable is not set, get the value from $_SESSION (if available)
- siteid
Only process these after siteid is set:
- action
- outputformat
- theme
- siteid
*/
if (isset($_GET['action'])) {
$action = $_GET['action'];
$_SESSION['action'] = $action;
} else {
if (isset($_SESSION['action'])) {
$action = $_SESSION['action'];
}
}

if (isset($_GET['outputformat'])) {
$outputformat = $_GET['outputformat'];
$_SESSION['outputformat'] = $outputformat;
} else {
if (isset($_SESSION['outputformat'])) {
$outputformat = $_SESSION['outputformat'];
}
}

if (isset($_GET['theme'])) {
$theme = $_GET['theme'];
$_SESSION['theme'] = $theme;
} else {
if (isset($_SESSION['theme'])) {
$theme = $_SESSION['theme'];
}
}

if (isset($_GET['siteid'])) {
$siteid = $_GET['siteid'];
$_SESSION['siteid'] = $siteid;
Expand All @@ -122,6 +97,33 @@
if (isset($_SESSION['siteid'])) {
$siteid = $_SESSION['siteid'];
$sitename = $_SESSION['sitename'];

if (isset($_GET['action'])) {
$action = $_GET['action'];
$_SESSION['action'] = $action;
} else {
if (isset($_SESSION['action'])) {
$action = $_SESSION['action'];
}
}

if (isset($_GET['outputformat'])) {
$outputformat = $_GET['outputformat'];
$_SESSION['outputformat'] = $outputformat;
} else {
if (isset($_SESSION['outputformat'])) {
$outputformat = $_SESSION['outputformat'];
}
}

if (isset($_GET['theme'])) {
$theme = $_GET['theme'];
$_SESSION['theme'] = $theme;
} else {
if (isset($_SESSION['theme'])) {
$theme = $_SESSION['theme'];
}
}
}
}

Expand All @@ -130,12 +132,10 @@
placed here so they can be overwritten by more "severe" error messages later down
*/
if ($action === '') {
$alertmessage = '<div class="alert alert-info" role="alert">Please select a data collection from one of the <b>menus</b>'
. ' above.</div>';
$alertmessage = '<div class="alert alert-info" role="alert">Please select a data collection.</div>';
}
if ($siteid === '') {
$alertmessage = '<div class="alert alert-info" role="alert">Please select a site from the <b>Select site menu</b> above.'
. '</div>';
$alertmessage = '<div class="alert alert-info" role="alert">Please select a site from the menu above.</div>';
}

/*
Expand All @@ -144,8 +144,9 @@
*/
require('phpapi/class.unifi.php');

$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $siteid, $controllerversion);
$loginresults = $unifidata->login();
$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $siteid, $controllerversion);
$unifidata->debug = $debug;
$loginresults = $unifidata->login();

if($loginresults === 400) {
$alertmessage = '<div class="alert alert-danger" role="alert">HTTP response status: 400'
Expand Down Expand Up @@ -250,7 +251,7 @@
$data = $unifidata->list_alarms();
break;
case 'list_wlanconf':
$selection = 'wlan config';
$selection = 'list wlan config';
$data = $unifidata->list_wlanconf();
break;
case 'list_health':
Expand All @@ -273,6 +274,10 @@
$selection = 'list port configuration';
$data = $unifidata->list_portconf();
break;
case 'list_networkconf':
$selection = 'list network configuration';
$data = $unifidata->list_networkconf();
break;
case 'list_dynamicdns':
$selection = 'dynamic dns configuration';
$data = $unifidata->list_dynamicdns();
Expand All @@ -281,6 +286,22 @@
$selection = 'list port forwarding rules';
$data = $unifidata->list_portforwarding();
break;
case 'stat_voucher':
$selection = 'list hotspot vouchers';
$data = $unifidata->stat_voucher();
break;
case 'stat_payment':
$selection = 'list hotspot payments';
$data = $unifidata->stat_payment();
break;
case 'list_hotspotop':
$selection = 'list hotspot operators';
$data = $unifidata->list_hotspotop();
break;
case 'list_self':
$selection = 'self';
$data = $unifidata->list_self();
break;
default:
break;
}
Expand Down Expand Up @@ -363,7 +384,7 @@ function to print the output
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<!-- Latest compiled and minified Bootstrap, Font-awesome and Highlight CSS loaded from CDN -->
<link rel="stylesheet" href="<?php echo $cssurl ?>">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/styles/default.min.css">
<style>
body {
Expand All @@ -385,10 +406,11 @@ function to print the output
<ul class="nav navbar-nav navbar-left">
<li id="site-menu" class="dropdown">
<a id="site-menu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Select site
Sites
<span class="caret"></span>
</a>
<ul class="dropdown-menu" id="siteslist">
<li class="dropdown-header">Select a site</li>
<?php
foreach ($sites as $site) {
echo '<li id="' . $site->name . '"><a href="?siteid=' . $site->name . '&sitename=' . $site->desc . '">' . $site->desc . '</a></li>' . "\n";
Expand Down Expand Up @@ -455,6 +477,18 @@ function to print the output
<li id="list_health"><a href="?action=list_health">site health metrics</a></li>
</ul>
</li>
<li id="hotspot-menu" class="dropdown">
<a id="msg-menu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Hotspot
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<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>
<li id="list_hotspotop"><a href="?action=list_hotspotop">list hotspot operators</a></li>
</ul>
</li>
<li id="config-menu" class="dropdown">
<a id="config-menu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Configuration
Expand All @@ -463,13 +497,15 @@ function to print the output
<ul class="dropdown-menu">
<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>
<li role="separator" class="divider"></li>
<li id="list_settings"><a href="?action=list_settings">site settings</a></li>
<li id="list_settings"><a href="?action=list_settings">list site settings</a></li>
<li role="separator" class="divider"></li>
<li id="list_wlanconf"><a href="?action=list_wlanconf">wireless configuration</a></li>
<li id="list_wlanconf"><a href="?action=list_wlanconf">list wlan configuration</a></li>
<li role="separator" class="divider"></li>
<li id="list_extension"><a href="?action=list_extension">list VoIP extensions</a></li>
<li role="separator" class="divider"></li>
<li id="list_networkconf"><a href="?action=list_networkconf">list network configuration</a></li>
<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>
Expand Down Expand Up @@ -534,8 +570,9 @@ function to print the output
<?php } ?>
output: <span class="label label-primary"><?php echo $outputformat ?></span>
<?php if ($objectscount) { ?>
# of objects: <span class="badge"><?php echo $objectscount ?></span></div>
# of objects: <span class="badge"><?php echo $objectscount ?></span>
<?php } ?>
</div>
<div class="panel-body">
<!-- present the timing results using an HTML5 progress bar -->
total elapsed time: <?php echo $timetotal ?> seconds<br>
Expand Down Expand Up @@ -576,20 +613,25 @@ function to print the output
</div>
<hr>
<dl class="dl-horizontal col-sm-offset-1">
<dt>Controller user</dt>
<dt>controller user</dt>
<dd><span class="label label-primary"><?php echo $controlleruser ?></span></dd>
<dt>Controller url</dt>
<dt>controller url</dt>
<dd><span class="label label-primary"><?php echo $controllerurl ?></span></dd>
<dt>version detected</dt>
<dd><span class="label label-primary"><?php echo $detected_controller_version ?></span></dd>
</dl>
<hr>
<dl class="dl-horizontal col-sm-offset-1">
<dt>cookie timeout setting</dt>
<dd><span class="label label-primary"><?php echo $cookietimeout ?> seconds</span></dd>
</dl>
<hr>
<dl class="dl-horizontal col-sm-offset-1">
<dt>PHP version</dt>
<dd><span class="label label-primary"><?php echo (phpversion()) ?></span></dd>
<dt>cURL version</dt>
<dd><span class="label label-primary"><?php echo $curl_version ?></span></dd>
<dt>Operating System</dt>
<dt>operating system</dt>
<dd><span class="label label-primary"><?php echo (php_uname('s') . ' ' . php_uname('r')) ?></span></dd>
</dl>
<hr>
Expand Down
Loading

0 comments on commit f58af0a

Please sign in to comment.