Skip to content

Commit

Permalink
API Browser version 1.0.6, API client class version 1.0.9
Browse files Browse the repository at this point in the history
API Browser: cosmetic bug fixes
API client class: updated the create_voucher() function/method to allow
for creation of multi-use or single-use vouchers
API client class: added the revoke_voucher() function/method
  • Loading branch information
malle-pietje committed Nov 9, 2016
1 parent 0ac83f7 commit 2240949
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
11 changes: 3 additions & 8 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Ubiquiti Community forums for this:
* https://community.ubnt.com/t5/UniFi-Wireless/UniFi-API-browser-tool-released/m-p/1392651
*
* VERSION: 1.0.5
* VERSION: 1.0.6
*
* ------------------------------------------------------------------------------------
*
Expand All @@ -25,7 +25,7 @@
*
*/

define('API_BROWSER_VERSION', '1.0.5');
define('API_BROWSER_VERSION', '1.0.6');

/**
* to use the PHP $_SESSION array for temporary storage of variables, session_start() is required
Expand Down Expand Up @@ -617,7 +617,7 @@ function sites_sort($a, $b)
<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>
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.2.9') >= 0) { ?>
<li id="list_dashboard"><a href="?action=stat_sites">all sites stats</a></li>
<li id="stat_sites"><a href="?action=stat_sites">all sites stats</a></li>
<?php } ?>
<li role="separator" class="divider"></li>
<li id="stat_hourly_aps"><a href="?action=stat_hourly_aps">hourly access point stats</a></li>
Expand Down Expand Up @@ -790,11 +790,6 @@ function sites_sort($a, $b)
<dd><span class="label label-primary"><?php if (isset($_SESSION['controller'])) { 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>
Expand Down
34 changes: 26 additions & 8 deletions phpapi/class.unifi.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* and the API as published by Ubiquiti:
* https://www.ubnt.com/downloads/unifi/5.2.9/unifi_sh_api
*
* VERSION: 1.0.8
* VERSION: 1.0.9
*
* NOTES:
* - this Class will only work with UniFi Controller versions 4.x and higher. There are no checks to prevent
Expand All @@ -27,7 +27,7 @@
*
*/

define('API_CLASS_VERSION', '1.0.8');
define('API_CLASS_VERSION', '1.0.9');

class unifiapi {
public $user = '';
Expand Down Expand Up @@ -921,27 +921,26 @@ public function list_hotspotop() {
/**
* Create voucher(s)
* -----------------
* returns an array of vouchers codes (NOTE: without the "-" in the middle) by calling the stat_voucher method
* returns an array of voucher codes (NOTE: without the "-" in the middle) by calling the stat_voucher method
* required parameter <minutes> = minutes the voucher is valid after activation
* required parameter <number_of_vouchers_to_create>
* optional parameter <number_of_vouchers_to_create> = number of vouchers to create, default value is 1
* optional parameter <quota> = single-use or multi-use vouchers, string value '0' is for multi-use, '1' is for single-use
* optional parameter <note> = note text to add to voucher when printing
* optional parameter <up> = upload speed limit in kbps
* optional parameter <down> = download speed limit in kbps
* optional parameter <MBytes> = data transfer limit in MB
*/
public function create_voucher($minutes, $number_of_vouchers_to_create = 1, $note = NULL, $up = NULL, $down = NULL, $MBytes = NULL) {
public function create_voucher($minutes, $number_of_vouchers_to_create = 1, $quota = '0', $note = NULL, $up = NULL, $down = NULL, $MBytes = NULL) {
if (!$this->is_loggedin) return FALSE;
$return = array();
$json = array('cmd' => 'create-voucher', 'expire' => $minutes, 'n' => $number_of_vouchers_to_create);

$json = array('cmd' => 'create-voucher', 'expire' => $minutes, 'n' => $number_of_vouchers_to_create, 'quota' => $quota);
/**
* if we have received values for note/up/down/MBytes we append them to the payload array to be submitted
*/
if (isset($note)) $json['note'] = trim($note);
if (isset($up)) $json['up'] = $up;
if (isset($down)) $json['down'] = $down;
if (isset($MBytes)) $json['bytes'] = $MBytes;

$json = json_encode($json);
$content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/cmd/hotspot','json='.$json));
if ($content_decoded->meta->rc == 'ok') {
Expand All @@ -955,6 +954,25 @@ public function create_voucher($minutes, $number_of_vouchers_to_create = 1, $not
return $return;
}

/**
* Revoke voucher
* --------------
* return TRUE on success
* required parameter <voucher_id> = _id of the voucher to revoke
*/
public function revoke_voucher($voucher_id) {
if (!$this->is_loggedin) return FALSE;
$return = FALSE;
$json = json_encode(array('_id' => $voucher_id, 'cmd' => 'delete-voucher'));
$content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/cmd/hotspot','json='.$json));
if (isset($content_decoded->meta->rc)) {
if ($content_decoded->meta->rc == 'ok') {
$return = TRUE;
}
}
return $return;
}

/**
* List port forwarding stats
* --------------------------
Expand Down

0 comments on commit 2240949

Please sign in to comment.