diff --git a/config.template.php b/config.template.php index 09d2a91..8940ba3 100644 --- a/config.template.php +++ b/config.template.php @@ -29,5 +29,8 @@ $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 +$theme = 'bootstrap'; // your default theme of choice, pick one from the list below + // bootstrap/cerulean/cosmo/cyborg/darkly/flatly/journal/lumen/paper/ + // readable/sandstone/simplex/slate/spacelab/superhero/united/yeti $debug = false; // set to true (without quotes) to enable debug output to the browser and PHP error log ?> \ No newline at end of file diff --git a/index.php b/index.php index 82d3741..e08c290 100644 --- a/index.php +++ b/index.php @@ -50,6 +50,7 @@ /* load the settings file +- allows override of several of the previously declared variables - if the config.php file is unreadable or does not exist, an alert is displayed on the page */ if(!is_readable('config.php')) { @@ -97,7 +98,7 @@ if (isset($_SESSION['siteid'])) { $siteid = $_SESSION['siteid']; $sitename = $_SESSION['sitename']; - + if (isset($_GET['action'])) { $action = $_GET['action']; $_SESSION['action'] = $action; @@ -106,7 +107,7 @@ $action = $_SESSION['action']; } } - + if (isset($_GET['outputformat'])) { $outputformat = $_GET['outputformat']; $_SESSION['outputformat'] = $outputformat; @@ -115,7 +116,7 @@ $outputformat = $_SESSION['outputformat']; } } - + if (isset($_GET['theme'])) { $theme = $_GET['theme']; $_SESSION['theme'] = $theme; @@ -295,7 +296,7 @@ case 'list_portforward_stats': $selection = 'list port forwarding stats'; $data = $unifidata->list_portforward_stats(); - break; + break; case 'stat_voucher': $selection = 'list hotspot vouchers'; $data = $unifidata->stat_voucher(); diff --git a/phpapi/class.unifi.php b/phpapi/class.unifi.php index b5ce71a..bb6104f 100644 --- a/phpapi/class.unifi.php +++ b/phpapi/class.unifi.php @@ -8,9 +8,13 @@ and the API as published by Ubiquiti: https://dl.ubnt.com/unifi/4.7.6/unifi_sh_api -NOTE: this Class will only work with Unifi Controller versions 4.x. There are no checks to prevent you from - trying to use it with a pre-4.x version controller. - +NOTE: +this Class will only work with Unifi Controller versions 4.x. There are no checks to prevent you from +trying to use it with a pre-4.x version controller. + +IMPORTANT CHANGES: +- function "list_vouchers" has been removed and has been replaced by "stat_voucher" + ------------------------------------------------------------------------------------ The MIT License (MIT) @@ -37,13 +41,11 @@ */ class unifiapi { - public $user = ''; public $password = ''; public $site = 'default'; public $baseurl = 'https://127.0.0.1:8443'; public $version = '4.8.6'; - public $is_loggedin = false; private $cookies = '/tmp/unify_browser'; public $debug = false; @@ -129,14 +131,27 @@ public function logout() { /* Authorize a MAC address parameter - parameter + parameter = minutes (from now) until authorization expires + optional parameter = upload speed limit in kbps + optional parameter = download speed limit in kbps + optional parameter = data transfer limit in MB + optional parameter = AP MAC address to which client is connected, should result in faster authorization return true on success */ - public function authorize_guest($mac,$minutes) { + public function authorize_guest($mac, $minutes, $up = NULL, $down = NULL, $MBytes = NULL, $ap_mac = NULL) { if (!$this->is_loggedin) return false; $mac = strtolower($mac); $return = false; - $json = json_encode(array('cmd' => 'authorize-guest', 'mac' => $mac, 'minutes' => $minutes)); + $authorize_array = array('cmd' => 'authorize-guest', 'mac' => $mac, 'minutes' => $minutes); + + /* + if we have received values for up/down/MBytes we append them to the payload array to be submitted + */ + if (isset($up)) $authorize_array['up'] = $up; + if (isset($down)) $authorize_array['down'] = $down; + if (isset($MBytes)) $authorize_array['bytes'] = $MBytes; + if (isset($ap_mac)) $authorize_array['ap_mac'] = $ap_mac; + $json = json_encode($authorize_array); $content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/cmd/stamgr','json='.$json)); if (isset($content_decoded->meta->rc)) { if ($content_decoded->meta->rc == 'ok') { @@ -276,8 +291,8 @@ public function stat_hourly_site($start = NULL, $end = NULL) { /* hourly stats method for all access points - parameter - parameter + optional parameter + optional parameter NOTE: defaults to the past 7*24 hours, but unifi controller does not keep these stats longer than 5 hours (controller v 4.6.6) */ @@ -302,8 +317,8 @@ public function stat_hourly_aps($start = NULL, $end = NULL) { /* show all login sessions - parameter - parameter + optional parameter + optional parameter NOTE: default start value is 7 days ago */ public function stat_sessions($start = NULL, $end = NULL) { @@ -327,8 +342,8 @@ public function stat_sessions($start = NULL, $end = NULL) { /* show all authorizations - parameter - parameter + optional parameter + optional parameter NOTE: defaults to the past 7*24 hours */ public function stat_auths($start = NULL, $end = NULL) { @@ -352,7 +367,7 @@ public function stat_auths($start = NULL, $end = NULL) { /* get details of all clients ever connected to the site - parameter + optional parameter NOTE: "within" only allows to select clients that were online in that period. Stats per client are totals, irrespective of "within" value defaults to 1 year of history @@ -625,12 +640,17 @@ public function list_networkconf() { /* stat vouchers - returns an array of hotspot vouchers + optional parameter + returns an array of hotspot voucher objects */ - public function stat_voucher() { + public function stat_voucher($create_time = NULL) { if (!$this->is_loggedin) return false; $return = array(); - $content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/stat/voucher')); + $json = json_encode(array()); + if (trim($create_time) != NULL) { + $json=json_encode(array('create_time' => $create_time)); + } + $content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/stat/voucher','json='.$json)); if (isset($content_decoded->meta->rc)) { if ($content_decoded->meta->rc == 'ok') { if (is_array($content_decoded->data)) { @@ -1029,7 +1049,6 @@ public function list_wlanconf() { return $return; } - /* list alarms returns an array of known alarms @@ -1051,57 +1070,29 @@ public function list_alarms() { return $return; } - /* - list vouchers - parameter - returns an array of voucher objects - */ - public function get_vouchers($create_time='') { - if (!$this->is_loggedin) return false; - $return = array(); - $json = json_encode(array()); - if (trim($create_time) != '') { - $json=json_encode(array('create_time' => $create_time)); - } - $content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/stat/voucher','json='.$json)); - if (isset($content_decoded->meta->rc)) { - if ($content_decoded->meta->rc == 'ok') { - if (is_array($content_decoded->data)) { - foreach ($content_decoded->data as $voucher) { - $return[]= $voucher; - } - } - } - } - return $return; - } - /* create voucher(s) - parameter + parameter = minutes the voucher is valid after activation parameter - parameter - parameter - parameter - parameter - returns an array of vouchers codes (Note: without the "-" in the middle) + optional parameter = note text to add to voucher when printing + optional parameter = upload speed limit in kbps + optional parameter = download speed limit in kbps + optional parameter = data transfer limit in MB + returns an array of vouchers codes (NOTE: without the "-" in the middle) */ - public function create_voucher($minutes,$number_of_vouchers_to_create=1,$note='',$up=0,$down=0,$Mbytes=0) { + public function create_voucher($minutes, $number_of_vouchers_to_create = 1, $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); - if (trim($note) != '') { - $json += array('note'=>$note); - } - if ($up > 0) { - $json += array('up'=>$up); - } - if ($down > 0) { - $json += array('down'=>$down); - } - if ($Mbytes > 0) { - $json += array('bytes'=>$Mbytes); - } + + /* + if we have received values for note/up/down/MBytes we append them to the payload array to be submitted + */ + if (isset($note)) $json += array('note' => trim($note)); + if (isset($up)) $json += array('up' => $up); + if (isset($down)) $json += array('down' => $down); + if (isset($MBytes)) $json += array('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') {