Skip to content

Commit 2240949

Browse files
committed
API Browser version 1.0.6, API client class version 1.0.9
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
1 parent 0ac83f7 commit 2240949

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

index.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Ubiquiti Community forums for this:
1515
* https://community.ubnt.com/t5/UniFi-Wireless/UniFi-API-browser-tool-released/m-p/1392651
1616
*
17-
* VERSION: 1.0.5
17+
* VERSION: 1.0.6
1818
*
1919
* ------------------------------------------------------------------------------------
2020
*
@@ -25,7 +25,7 @@
2525
*
2626
*/
2727

28-
define('API_BROWSER_VERSION', '1.0.5');
28+
define('API_BROWSER_VERSION', '1.0.6');
2929

3030
/**
3131
* to use the PHP $_SESSION array for temporary storage of variables, session_start() is required
@@ -617,7 +617,7 @@ function sites_sort($a, $b)
617617
<li id="stat_hourly_site"><a href="?action=stat_hourly_site">hourly site stats</a></li>
618618
<li id="stat_daily_site"><a href="?action=stat_daily_site">daily site stats</a></li>
619619
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.2.9') >= 0) { ?>
620-
<li id="list_dashboard"><a href="?action=stat_sites">all sites stats</a></li>
620+
<li id="stat_sites"><a href="?action=stat_sites">all sites stats</a></li>
621621
<?php } ?>
622622
<li role="separator" class="divider"></li>
623623
<li id="stat_hourly_aps"><a href="?action=stat_hourly_aps">hourly access point stats</a></li>
@@ -790,11 +790,6 @@ function sites_sort($a, $b)
790790
<dd><span class="label label-primary"><?php if (isset($_SESSION['controller'])) { echo $detected_controller_version; } ?></span></dd>
791791
</dl>
792792
<hr>
793-
<dl class="dl-horizontal col-sm-offset-1">
794-
<dt>cookie timeout setting</dt>
795-
<dd><span class="label label-primary"><?php echo $cookietimeout ?> seconds</span></dd>
796-
</dl>
797-
<hr>
798793
<dl class="dl-horizontal col-sm-offset-1">
799794
<dt>PHP version</dt>
800795
<dd><span class="label label-primary"><?php echo (phpversion()) ?></span></dd>

phpapi/class.unifi.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* and the API as published by Ubiquiti:
1010
* https://www.ubnt.com/downloads/unifi/5.2.9/unifi_sh_api
1111
*
12-
* VERSION: 1.0.8
12+
* VERSION: 1.0.9
1313
*
1414
* NOTES:
1515
* - this Class will only work with UniFi Controller versions 4.x and higher. There are no checks to prevent
@@ -27,7 +27,7 @@
2727
*
2828
*/
2929

30-
define('API_CLASS_VERSION', '1.0.8');
30+
define('API_CLASS_VERSION', '1.0.9');
3131

3232
class unifiapi {
3333
public $user = '';
@@ -921,27 +921,26 @@ public function list_hotspotop() {
921921
/**
922922
* Create voucher(s)
923923
* -----------------
924-
* returns an array of vouchers codes (NOTE: without the "-" in the middle) by calling the stat_voucher method
924+
* returns an array of voucher codes (NOTE: without the "-" in the middle) by calling the stat_voucher method
925925
* required parameter <minutes> = minutes the voucher is valid after activation
926-
* required parameter <number_of_vouchers_to_create>
926+
* optional parameter <number_of_vouchers_to_create> = number of vouchers to create, default value is 1
927+
* optional parameter <quota> = single-use or multi-use vouchers, string value '0' is for multi-use, '1' is for single-use
927928
* optional parameter <note> = note text to add to voucher when printing
928929
* optional parameter <up> = upload speed limit in kbps
929930
* optional parameter <down> = download speed limit in kbps
930931
* optional parameter <MBytes> = data transfer limit in MB
931932
*/
932-
public function create_voucher($minutes, $number_of_vouchers_to_create = 1, $note = NULL, $up = NULL, $down = NULL, $MBytes = NULL) {
933+
public function create_voucher($minutes, $number_of_vouchers_to_create = 1, $quota = '0', $note = NULL, $up = NULL, $down = NULL, $MBytes = NULL) {
933934
if (!$this->is_loggedin) return FALSE;
934935
$return = array();
935-
$json = array('cmd' => 'create-voucher', 'expire' => $minutes, 'n' => $number_of_vouchers_to_create);
936-
936+
$json = array('cmd' => 'create-voucher', 'expire' => $minutes, 'n' => $number_of_vouchers_to_create, 'quota' => $quota);
937937
/**
938938
* if we have received values for note/up/down/MBytes we append them to the payload array to be submitted
939939
*/
940940
if (isset($note)) $json['note'] = trim($note);
941941
if (isset($up)) $json['up'] = $up;
942942
if (isset($down)) $json['down'] = $down;
943943
if (isset($MBytes)) $json['bytes'] = $MBytes;
944-
945944
$json = json_encode($json);
946945
$content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/cmd/hotspot','json='.$json));
947946
if ($content_decoded->meta->rc == 'ok') {
@@ -955,6 +954,25 @@ public function create_voucher($minutes, $number_of_vouchers_to_create = 1, $not
955954
return $return;
956955
}
957956

957+
/**
958+
* Revoke voucher
959+
* --------------
960+
* return TRUE on success
961+
* required parameter <voucher_id> = _id of the voucher to revoke
962+
*/
963+
public function revoke_voucher($voucher_id) {
964+
if (!$this->is_loggedin) return FALSE;
965+
$return = FALSE;
966+
$json = json_encode(array('_id' => $voucher_id, 'cmd' => 'delete-voucher'));
967+
$content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/cmd/hotspot','json='.$json));
968+
if (isset($content_decoded->meta->rc)) {
969+
if ($content_decoded->meta->rc == 'ok') {
970+
$return = TRUE;
971+
}
972+
}
973+
return $return;
974+
}
975+
958976
/**
959977
* List port forwarding stats
960978
* --------------------------

0 commit comments

Comments
 (0)