diff --git a/README.md b/README.md index 2687c2d..398162d 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ >**NOTICE** > >The repository has been transferred to this new GitHub organisation account, the project maintainer will remain the same and will continue to actively maintain it. -> If you have previously installed the API Browser tool using `git clone`, you may consider pointing the clone to the new repository URL. You can do this with the following command from within the directory of your clone: +> If you have previously installed the API browser tool using `git clone`, you may consider pointing the clone to the new repository URL. You can do this with the following command from within the directory of your clone: > >```bash >$ git remote set-url origin https://github.com/Art-of-WiFi/UniFi-API-browser.git @@ -19,7 +19,7 @@ You will find examples and detailed instructions there. Please keep the following in mind: -- the API Browser tool doesn't support all available data collections/API endpoints, see the list below of those that are currently supported +- the API browser tool doesn't support all available data collections/API endpoints, see the list below of those that are currently supported - currently, versions 4.x.x and 5.x.x of the UniFi Controller software are supported (version 5.8.24 has been confirmed to work) - there is still work to be done to add/improve functionality and usability of this tool so suggestions/comments are welcome. Please use the github [issue](https://github.com/Art-of-WiFi/UniFi-API-browser/issues) list or the Ubiquiti Community forums (https://community.ubnt.com/t5/UniFi-Wireless/UniFi-API-browser-tool-released/m-p/1392651) to share your ideas/questions. - please read the Security Notice below before installing this tool! diff --git a/composer.lock b/composer.lock index 310308c..8182a18 100644 --- a/composer.lock +++ b/composer.lock @@ -9,16 +9,16 @@ "packages": [ { "name": "art-of-wifi/unifi-api-client", - "version": "v1.1.33", + "version": "v1.1.36", "source": { "type": "git", "url": "https://github.com/Art-of-WiFi/UniFi-API-client.git", - "reference": "30f4230cfd21926e5b3026c7a06373b37873b20f" + "reference": "2a566ad18ae47363fa69b83b71f0ce62ad6e0c16" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Art-of-WiFi/UniFi-API-client/zipball/30f4230cfd21926e5b3026c7a06373b37873b20f", - "reference": "30f4230cfd21926e5b3026c7a06373b37873b20f", + "url": "https://api.github.com/repos/Art-of-WiFi/UniFi-API-client/zipball/2a566ad18ae47363fa69b83b71f0ce62ad6e0c16", + "reference": "2a566ad18ae47363fa69b83b71f0ce62ad6e0c16", "shasum": "" }, "require": { @@ -52,7 +52,7 @@ "ubiquiti", "unifi" ], - "time": "2018-10-02 10:10:46" + "time": "2018-10-24 07:54:43" }, { "name": "kint-php/kint", diff --git a/index.php b/index.php index 338eea5..5027299 100755 --- a/index.php +++ b/index.php @@ -17,7 +17,7 @@ * with this package in the file LICENSE.md * */ -define('API_BROWSER_VERSION', '1.0.32'); +define('API_BROWSER_VERSION', '1.0.33'); define('API_CLASS_VERSION', get_client_version()); /** @@ -537,6 +537,10 @@ $selection = 'list auto backups'; $data = $unifidata->list_backups(); break; + case 'stat_ips_events': + $selection = 'list IPS/IDS events'; + $data = $unifidata->stat_ips_events(); + break; default: break; } @@ -730,6 +734,7 @@ function get_client_version()
"; print_r ($guestlist); print ""; // loop thru all known guests foreach ($guestlist as $guest) { - // print "
"; print_r ($guest); print ""; - print "
" . $guest->_id . " (" . $guest->mac . "), valid until " . date (DATE_ATOM, $guest->end) . " (" . $guest->end . ")"; + print "
" . $guest->_id . " (" . $guest->mac . "), valid until " . date(DATE_ATOM, $guest->end) . " (" . $guest->end . ")"; // just a sample: only extend validity of guests which have end date after 2017-04-02 if ($guest->end > 1491166482) { // extend clients five times = five days - if (!$unifi_connection->extend_guest_validity ($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n"; - if (!$unifi_connection->extend_guest_validity ($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n"; - if (!$unifi_connection->extend_guest_validity ($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n"; - if (!$unifi_connection->extend_guest_validity ($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n"; - if (!$unifi_connection->extend_guest_validity ($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n"; + if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n"; + if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n"; + if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n"; + if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n"; + if (!$unifi_connection->extend_guest_validity($guest->_id)) print "Extend failed for guest with id " . $guest->_id . "\n"; } } diff --git a/vendor/art-of-wifi/unifi-api-client/examples/unblock_list.php b/vendor/art-of-wifi/unifi-api-client/examples/unblock_list.php index 042259f..0b04a0e 100755 --- a/vendor/art-of-wifi/unifi-api-client/examples/unblock_list.php +++ b/vendor/art-of-wifi/unifi-api-client/examples/unblock_list.php @@ -29,14 +29,13 @@ /** * the MAC addresses of the device(s) to unblock */ -$macs_to_unblock = explode(',',$argv[1]); +$macs_to_unblock = explode(',', $argv[1]); /** * The site to authorize the device with */ $site_id = 'MUST_DEFINE_THIS'; -if ($site_id == "MUST_DEFINE_THIS") -{ +if ($site_id == "MUST_DEFINE_THIS") { print 'ERROR: set the site id in your script'; return; } @@ -48,10 +47,9 @@ $set_debug_mode = $unifi_connection->set_debug($debug); $loginresults = $unifi_connection->login(); // always true regardless of site id -foreach ($macs_to_unblock as &$mac) -{ +foreach ($macs_to_unblock as &$mac) { // block_result is always true even if mac address does not exist :( - $block_result = $unifi_connection->unblock_sta($mac); + $block_result = $unifi_connection->unblock_sta($mac); /** * NOTE: @@ -63,22 +61,17 @@ */ sleep(1); - $getid_result = $unifi_connection->stat_client($mac); + $getid_result = $unifi_connection->stat_client($mac); - if (property_exists($getid_result[0], "oui")) // this field(manufacturer) seems to exist on valid mac addresses - { - if (property_exists($getid_result[0], "name")) - { + if (property_exists($getid_result[0], "oui")) { + // this field(manufacturer) seems to exist on valid mac addresses + if (property_exists($getid_result[0], "name")) { $name = $getid_result[0]->name; - } - else - { + } else { $name = $getid_result[0]->hostname; } print 'unblocked ' . $name . PHP_EOL; - } - else - { + } else { print 'ERROR: could not unblock ' . $mac . PHP_EOL; print ' check mac address is valid and part of your network' . PHP_EOL; } diff --git a/vendor/art-of-wifi/unifi-api-client/examples/update_ac-iw_ports.php b/vendor/art-of-wifi/unifi-api-client/examples/update_ac-iw_ports.php index 391fd5c..ec6f8c8 100755 --- a/vendor/art-of-wifi/unifi-api-client/examples/update_ac-iw_ports.php +++ b/vendor/art-of-wifi/unifi-api-client/examples/update_ac-iw_ports.php @@ -67,7 +67,7 @@ $device_id = $data[0]->device_id; $update_device = $unifi_connection->set_device_settings_base($device_id, $new_ports_config); -if(!$update_device){ +if (!$update_device) { $error = $unifi_connection->get_last_results_raw(); echo json_encode($error, JSON_PRETTY_PRINT); } diff --git a/vendor/art-of-wifi/unifi-api-client/examples/update_device_wlan_settings_5.5.X.php b/vendor/art-of-wifi/unifi-api-client/examples/update_device_wlan_settings_5.5.X.php index 847a363..cd594de 100755 --- a/vendor/art-of-wifi/unifi-api-client/examples/update_device_wlan_settings_5.5.X.php +++ b/vendor/art-of-wifi/unifi-api-client/examples/update_device_wlan_settings_5.5.X.php @@ -58,13 +58,13 @@ $radio_table = $data[0]->radio_table; $device_id = $data[0]->device_id; -foreach($radio_table as $radio){ - if($radio->radio === 'ng'){ +foreach ($radio_table as $radio) { + if ($radio->radio === 'ng') { $radio->tx_power_mode = $ng_tx_power_mode; $radio->channel = $ng_channel; } - if($radio->radio === 'na'){ + if ($radio->radio === 'na') { $radio->tx_power_mode = $na_tx_power_mode; $radio->channel = $na_channel; } @@ -72,7 +72,7 @@ $update_device = $unifi_connection->set_device_settings_base($device_id, ['radio_table' => $radio_table]); -if(!$update_device){ +if (!$update_device) { $error = $unifi_connection->get_last_results_raw(); echo json_encode($error, JSON_PRETTY_PRINT); } diff --git a/vendor/art-of-wifi/unifi-api-client/src/Client.php b/vendor/art-of-wifi/unifi-api-client/src/Client.php index 7ba8efd..1173b1f 100755 --- a/vendor/art-of-wifi/unifi-api-client/src/Client.php +++ b/vendor/art-of-wifi/unifi-api-client/src/Client.php @@ -25,6 +25,8 @@ class Client * private properties */ protected $baseurl = 'https://127.0.0.1:8443'; + protected $user = ''; + protected $password = ''; protected $site = 'default'; protected $version = '5.6.39'; protected $debug = false; @@ -50,7 +52,7 @@ class Client * recommended for production environments to prevent potential MitM attacks, default value (false) * is to not validate the controller certificate */ - function __construct($user, $password, $baseurl = '', $site = '', $version = '', $ssl_verify = false) + public function __construct($user, $password, $baseurl = '', $site = '', $version = '', $ssl_verify = false) { if (!extension_loaded('curl')) { trigger_error('The PHP curl extension is not loaded. Please correct this before proceeding!'); @@ -81,7 +83,7 @@ function __construct($user, $password, $baseurl = '', $site = '', $version = '', $this->update_unificookie(); } - function __destruct() + public function __destruct() { /** * if user has $_SESSION['unificookie'] set, do not logout here @@ -212,15 +214,15 @@ public function authorize_guest($mac, $minutes, $up = null, $down = null, $MByte /** * if we have received values for up/down/MBytes/ap_mac we append them to the payload array to be submitted */ - if (isset($up)) { + if (!empty($up)) { $json['up'] = intval($up); } - if (isset($down)) { + if (!empty($down)) { $json['down'] = intval($down); } - if (isset($MBytes)) { + if (!empty($MBytes)) { $json['bytes'] = intval($MBytes); } @@ -426,7 +428,7 @@ public function stat_5minutes_site($start = null, $end = null) return false; } - $end = is_null($end) ? ((time()) * 1000) : intval($end); + $end = is_null($end) ? (time() * 1000) : intval($end); $start = is_null($start) ? $end - (12 * 3600 * 1000) : intval($start); $attributes = [ 'bytes', @@ -461,7 +463,7 @@ public function stat_hourly_site($start = null, $end = null) return false; } - $end = is_null($end) ? ((time()) * 1000) : intval($end); + $end = is_null($end) ? (time() * 1000) : intval($end); $start = is_null($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start); $attributes = [ 'bytes', @@ -534,12 +536,13 @@ public function stat_5minutes_aps($start = null, $end = null, $mac = null) return false; } - $end = is_null($end) ? ((time()) * 1000) : intval($end); + $end = is_null($end) ? (time() * 1000) : intval($end); $start = is_null($start) ? $end - (12 * 3600 * 1000) : intval($start); $json = ['attrs' => ['bytes', 'num_sta', 'time'], 'start' => $start, 'end' => $end]; if (!is_null($mac)) { $json['mac'] = strtolower($mac); } + $json = json_encode($json); $response = $this->exec_curl('/api/s/' . $this->site . '/stat/report/5minutes.ap', 'json=' . $json); @@ -564,7 +567,7 @@ public function stat_hourly_aps($start = null, $end = null, $mac = null) return false; } - $end = is_null($end) ? ((time()) * 1000) : intval($end); + $end = is_null($end) ? (time() * 1000) : intval($end); $start = is_null($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start); $json = ['attrs' => ['bytes', 'num_sta', 'time'], 'start' => $start, 'end' => $end]; if (!is_null($mac)) { @@ -594,12 +597,13 @@ public function stat_daily_aps($start = null, $end = null, $mac = null) return false; } - $end = is_null($end) ? ((time()) * 1000) : intval($end); + $end = is_null($end) ? (time() * 1000) : intval($end); $start = is_null($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start); $json = ['attrs' => ['bytes', 'num_sta', 'time'], 'start' => $start, 'end' => $end]; if (!is_null($mac)) { $json['mac'] = strtolower($mac); } + $json = json_encode($json); $response = $this->exec_curl('/api/s/' . $this->site . '/stat/report/daily.ap', 'json=' . $json); @@ -630,7 +634,7 @@ public function stat_5minutes_user($mac, $start = null, $end = null, $attribs = return false; } - $end = is_null($end) ? ((time()) * 1000) : intval($end); + $end = is_null($end) ? (time() * 1000) : intval($end); $start = is_null($start) ? $end - (12 * 3600 * 1000) : intval($start); $attribs = is_null($attribs) ? ['time', 'rx_bytes', 'tx_bytes'] : array_merge(['time'], $attribs); $json = ['attrs' => $attribs, 'start' => $start, 'end' => $end, 'mac' => strtolower($mac)]; @@ -662,7 +666,7 @@ public function stat_hourly_user($mac, $start = null, $end = null, $attribs = nu return false; } - $end = is_null($end) ? ((time()) * 1000) : intval($end); + $end = is_null($end) ? (time() * 1000) : intval($end); $start = is_null($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start); $attribs = is_null($attribs) ? ['time', 'rx_bytes', 'tx_bytes'] : array_merge(['time'], $attribs); $json = ['attrs' => $attribs, 'start' => $start, 'end' => $end, 'mac' => strtolower($mac)]; @@ -694,7 +698,7 @@ public function stat_daily_user($mac, $start = null, $end = null, $attribs = nul return false; } - $end = is_null($end) ? ((time()) * 1000) : intval($end); + $end = is_null($end) ? (time() * 1000) : intval($end); $start = is_null($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start); $attribs = is_null($attribs) ? ['time', 'rx_bytes', 'tx_bytes'] : array_merge(['time'], $attribs); $json = ['attrs' => $attribs, 'start' => $start, 'end' => $end, 'mac' => strtolower($mac)]; @@ -728,11 +732,11 @@ public function stat_5minutes_gateway($start = null, $end = null, $attribs = nul return false; } - $end = is_null($end) ? ((time())*1000) : intval($end); - $start = is_null($start) ? $end-(12*3600*1000) : intval($start); + $end = is_null($end) ? (time() * 1000) : intval($end); + $start = is_null($start) ? $end - (12 * 3600 * 1000) : intval($start); $attribs = is_null($attribs) ? ['time', 'mem', 'cpu', 'loadavg_5'] : array_merge(['time'], $attribs); $json = json_encode(['attrs' => $attribs, 'start' => $start, 'end' => $end]); - $response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/5minutes.gw', 'json='.$json); + $response = $this->exec_curl('/api/s/' . $this->site . '/stat/report/5minutes.gw', 'json=' . $json); return $this->process_response($response); } @@ -758,11 +762,11 @@ public function stat_hourly_gateway($start = null, $end = null, $attribs = null) return false; } - $end = is_null($end) ? ((time())*1000) : intval($end); - $start = is_null($start) ? $end-(7*24*3600*1000) : intval($start); + $end = is_null($end) ? (time() * 1000) : intval($end); + $start = is_null($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start); $attribs = is_null($attribs) ? ['time', 'mem', 'cpu', 'loadavg_5'] : array_merge(['time'], $attribs); $json = json_encode(['attrs' => $attribs, 'start' => $start, 'end' => $end]); - $response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/hourly.gw', 'json='.$json); + $response = $this->exec_curl('/api/s/' . $this->site . '/stat/report/hourly.gw', 'json=' . $json); return $this->process_response($response); } @@ -788,11 +792,11 @@ public function stat_daily_gateway($start = null, $end = null, $attribs = null) return false; } - $end = is_null($end) ? ((time()-(time() % 3600))*1000) : intval($end); - $start = is_null($start) ? $end-(52*7*24*3600*1000) : intval($start); + $end = is_null($end) ? ((time() - (time() % 3600)) * 1000) : intval($end); + $start = is_null($start) ? $end - (52 * 7 * 24 * 3600 * 1000) : intval($start); $attribs = is_null($attribs) ? ['time', 'mem', 'cpu', 'loadavg_5'] : array_merge(['time'], $attribs); $json = json_encode(['attrs' => $attribs, 'start' => $start, 'end' => $end]); - $response = $this->exec_curl('/api/s/'.$this->site.'/stat/report/daily.gw', 'json='.$json); + $response = $this->exec_curl('/api/s/' . $this->site . '/stat/report/daily.gw', 'json=' . $json); return $this->process_response($response); } @@ -814,7 +818,7 @@ public function stat_speedtest_results($start = null, $end = null) return false; } - $end = is_null($end) ? ((time()) * 1000) : intval($end); + $end = is_null($end) ? (time() * 1000) : intval($end); $start = is_null($start) ? $end - (24 * 3600 * 1000) : intval($start); $json = ['attrs' => ['xput_download', 'xput_upload', 'latency', 'time'], 'start' => $start, 'end' => $end]; $json = json_encode($json); @@ -823,6 +827,35 @@ public function stat_speedtest_results($start = null, $end = null) return $this->process_response($response); } + /** + * Method to fetch IPS/IDS event + * ---------------------------------- + * returns an array of IPS/IDS event objects + * optional parameter