Skip to content

Commit

Permalink
added support for list_known_rogueaps()
Browse files Browse the repository at this point in the history
  • Loading branch information
malle-pietje committed Oct 18, 2017
1 parent 535bd7b commit 48f807f
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 61 deletions.
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* the currently supported data collections/API endpoints in the README.md file
* - this tool currently supports versions 4.x and 5.x of the UniFi Controller software
*
* VERSION: 1.0.25
* VERSION: 1.0.26
*
* ------------------------------------------------------------------------------------
*
Expand All @@ -20,11 +20,11 @@
* with this package in the file LICENSE.md
*
*/
define('API_BROWSER_VERSION', '1.0.25');
define('API_BROWSER_VERSION', '1.0.26');
define('API_CLASS_VERSION', get_client_version());

/**
* check whether the PHP curl module is available
* check whether the required PHP curl module is available
* - if yes, collect cURL version details for the info modal
* - if not, stop and display an error message
*/
Expand Down Expand Up @@ -383,6 +383,10 @@
$selection = 'list rogue access points';
$data = $unifidata->list_rogueaps();
break;
case 'list_known_rogueaps':
$selection = 'list known rogue access points';
$data = $unifidata->list_known_rogueaps();
break;
case 'list_events':
$selection = 'list events';
$data = $unifidata->list_events();
Expand Down Expand Up @@ -757,6 +761,7 @@ function get_client_version()
<li id="list_devices"><a href="?action=list_devices">list devices</a></li>
<li id="list_wlan_groups"><a href="?action=list_wlan_groups">list wlan groups</a></li>
<li id="list_rogueaps"><a href="?action=list_rogueaps">list rogue access points</a></li>
<li id="list_known_rogueaps"><a href="?action=list_known_rogueaps">list known rogue access points</a></li>
<!-- all sites stats, only to be displayed when we have detected a capable controller version -->
<?php if ($detected_controller_version != 'undetected' && version_compare($detected_controller_version, '5.5.0') >= 0) { ?>
<li role="separator" class="divider"></li>
Expand Down
6 changes: 5 additions & 1 deletion vendor/art-of-wifi/unifi-api-client/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## UniFi controller API client class

A PHP class which provides access to Ubiquiti's **UniFi Controller API**. Versions 4.x.x and 5.x.x of the UniFi Controller software are supported (version 5.6.18 has been confirmed to work). It's a standalone version of the class which is used in the API browser tool [here](https://github.com/Art-of-WiFi/UniFi-API-browser).
A PHP class which provides access to Ubiquiti's **UniFi Controller API**. Versions 4.x.x and 5.x.x of the UniFi Controller software are supported (version 5.6.18 has been confirmed to work). It's a standalone version of the class which is used in our API browser tool [here](https://github.com/Art-of-WiFi/UniFi-API-browser).

This class can now also be installed using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects.

Expand Down Expand Up @@ -49,6 +49,7 @@ The class currently supports the following functions/methods to get/post/put/del
- list_guests()
- list_health()
- list_hotspotop()
- list_known_rogueaps()
- list_networkconf()
- list_portconf()
- list_portforward_stats()
Expand All @@ -65,11 +66,13 @@ The class currently supports the following functions/methods to get/post/put/del
- list_wlan_groups()
- list_wlanconf()
- locate_ap()
- power_cycle_switch_port()
- reconnect_sta()
- rename_ap()
- restart_ap()
- revoke_voucher()
- set_ap_radiosettings()
- set_device_settings_base()
- set_guestlogin_settings()
- set_locate_ap() (deprecated but still available as alias)
- set_networksettings_base()
Expand Down Expand Up @@ -98,6 +101,7 @@ The class currently supports the following functions/methods to get/post/put/del
- stat_sessions()
- stat_sites()
- stat_sta_sessions_latest()
- stat_status()
- stat_sysinfo()
- stat_voucher()
- unauthorize_guest()
Expand Down
136 changes: 90 additions & 46 deletions vendor/art-of-wifi/unifi-api-client/src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,9 @@ public function list_tags()
}

/**
* List rogue access points
* ------------------------
* returns an array of known rogue access point objects
* List rogue/neighboring access points
* ------------------------------------
* returns an array of rogue/neighboring access point objects
* optional parameter <within> = hours to go back to list discovered "rogue" access points (default = 24 hours)
*/
public function list_rogueaps($within = 24)
Expand All @@ -795,6 +795,18 @@ public function list_rogueaps($within = 24)
return $this->process_response($response);
}

/**
* List known rogue access points
* ------------------------------
* returns an array of known rogue access point objects
*/
public function list_known_rogueaps()
{
if (!$this->is_loggedin) return false;
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/rogueknown');
return $this->process_response($response);
}

/**
* List sites
* ----------
Expand Down Expand Up @@ -888,6 +900,17 @@ public function stat_sysinfo()
return $this->process_response($response);
}

/**
* List controller status
* ----------------------
* returns an array containing general controller status info
*/
public function stat_status()
{
$response = $this->exec_curl('/status');
return $this->process_response($response);
}

/**
* List self
* ---------
Expand Down Expand Up @@ -1177,14 +1200,10 @@ public function led_override($device_id, $override_mode)
{
if (!$this->is_loggedin) return false;
$this->request_type = 'PUT';
$override_mode_options = ['off', 'on', 'default'];
if (in_array($override_mode, $override_mode_options)) {
$json = json_encode(['led_override' => $override_mode]);
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/device/'.trim($device_id), $json);
return $this->process_response_boolean($response);
}

return false;
if (!in_array($override_mode, ['off', 'on', 'default'])) return false;
$json = json_encode(['led_override' => $override_mode]);
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/device/'.trim($device_id), $json);
return $this->process_response_boolean($response);
}

/**
Expand Down Expand Up @@ -1253,14 +1272,10 @@ public function set_ap_radiosettings($ap_id, $radio, $channel, $ht, $tx_power_mo
*/
public function set_ap_wlangroup($wlantype_id, $device_id, $wlangroup_id) {
if (!$this->is_loggedin) return false;
$wlantype_id_options = ['ng', 'na'];
if (in_array($wlantype_id, $wlantype_id_options)) {
$json = json_encode(['wlan_overrides' => [],'wlangroup_id_'.$wlantype_id => $wlangroup_id]);
$response = $this->exec_curl('/api/s/'.$this->site.'/upd/device/'.trim($device_id),'json='.$json);
return $this->process_response_boolean($response);
}

return false;
if (in_array($wlantype_id, ['ng', 'na'])) return false;
$json = json_encode(['wlan_overrides' => [],'wlangroup_id_'.$wlantype_id => $wlangroup_id]);
$response = $this->exec_curl('/api/s/'.$this->site.'/upd/device/'.trim($device_id),'json='.$json);
return $this->process_response_boolean($response);
}

/**
Expand Down Expand Up @@ -1532,16 +1547,12 @@ public function delete_wlan($wlan_id)
*/
public function set_wlan_mac_filter($wlan_id, $mac_filter_policy, $mac_filter_enabled, array $macs)
{
$mac_filter_policy_options = ['allow', 'deny'];
if (in_array($mac_filter_policy, $mac_filter_policy_options)) {
$payload = new \stdClass();
$payload->mac_filter_enabled = (bool)$mac_filter_enabled;
$payload->mac_filter_policy = $mac_filter_policy;
$payload->mac_filter_list = $macs;
return $this->set_wlansettings_base($wlan_id, $payload);
}

return false;
if (in_array($mac_filter_policy, ['allow', 'deny'])) return false;
$payload = new \stdClass();
$payload->mac_filter_enabled = (bool)$mac_filter_enabled;
$payload->mac_filter_policy = $mac_filter_policy;
$payload->mac_filter_list = $macs;
return $this->set_wlansettings_base($wlan_id, $payload);
}

/**
Expand Down Expand Up @@ -1625,6 +1636,25 @@ public function upgrade_device_external($firmware_url, $device_mac)
return $this->process_response_boolean($response);
}

/**
* Power-cycle the PoE output of a switch port
* -------------------------------------------
* return true on success
* required parameter <switch_mac> = string; main MAC address of the switch
* required parameter <port_idx> = integer; port number/index of the port to be affected
*
* NOTES:
* - only applies to switches and their PoE ports...
*/
public function power_cycle_switch_port($switch_mac, $port_idx)
{
if (!$this->is_loggedin) return false;
$json = ['mac' => $switch_mac, 'port_idx' => intval($port_idx), 'cmd' => 'power-cycle'];
$json = json_encode($json);
$response = $this->exec_curl('/api/s/'.$this->site.'/cmd/devmgr', 'json='.$json);
return $this->process_response_boolean($response);
}

/**
* Trigger an RF scan by an AP
* ---------------------------
Expand Down Expand Up @@ -1653,6 +1683,23 @@ public function spectrum_scan_state($ap_mac)
return $this->process_response($response);
}

/**
* Update device settings, base (using REST)
* -----------------------------------------
* return true on success
* required parameter <device_id> = 24 char string; _id of the device which can be found with the list_devices() function
* required parameter <device_settings> = stdClass object or associative array containing the configuration to apply to the device, must be a
* (partial) object/array structured in the same manner as is returned by list_devices() for the device.
*/
public function set_device_settings_base($device_id, $device_settings)
{
if (!$this->is_loggedin) return false;
$this->request_type = 'PUT';
$json = json_encode($device_settings);
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/device/'.trim($device_id), 'json='.$json);
return $this->process_response_boolean($response);
}

/**
* List Radius profiles (using REST)
* --------------------------------------
Expand Down Expand Up @@ -1727,23 +1774,20 @@ public function list_radius_accounts()
public function create_radius_account($name, $x_password, $tunnel_type, $tunnel_medium_type, $vlan = null)
{
if (!$this->is_loggedin) return false;
$tunnel_type_options = [1,2,3,4,5,6,7,8,9,10,11,12,13];
$tunnel_medium_type_options = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
if (in_array($tunnel_type, $tunnel_type_options) && in_array($tunnel_medium_type, $tunnel_medium_type_options)) {
$this->request_type = 'POST';
$account_details = [
'name' => $name,
'x_password' => $x_password,
'tunnel_type' => (int) $tunnel_type,
'tunnel_medium_type' => (int) $tunnel_medium_type
];
if (isset($vlan)) $account_details['vlan'] = (int) $vlan;
$json = json_encode($account_details);
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/account', 'json='.$json);
return $this->process_response($response);
}

return false;
$tunnel_types = [1,2,3,4,5,6,7,8,9,10,11,12,13];
$tunnel_medium_types = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
if (!in_array($tunnel_type, $tunnel_types) || !in_array($tunnel_medium_type, $tunnel_medium_types)) return false;
$this->request_type = 'POST';
$account_details = [
'name' => $name,
'x_password' => $x_password,
'tunnel_type' => (int) $tunnel_type,
'tunnel_medium_type' => (int) $tunnel_medium_type
];
if (isset($vlan)) $account_details['vlan'] = (int) $vlan;
$json = json_encode($account_details);
$response = $this->exec_curl('/api/s/'.$this->site.'/rest/account', 'json='.$json);
return $this->process_response($response);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@
},
{
"name": "art-of-wifi/unifi-api-client",
"version": "v1.1.18",
"version_normalized": "1.1.18.0",
"version": "1.1.20",
"version_normalized": "1.1.20.0",
"source": {
"type": "git",
"url": "https://github.com/Art-of-WiFi/UniFi-API-client.git",
"reference": "746a29fbcffe19dcc7241d8a3a6e6d16a037f44d"
"reference": "141b0ff55f2919d1c30cae0e75a7f30d6e2b9f26"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Art-of-WiFi/UniFi-API-client/zipball/746a29fbcffe19dcc7241d8a3a6e6d16a037f44d",
"reference": "746a29fbcffe19dcc7241d8a3a6e6d16a037f44d",
"url": "https://api.github.com/repos/Art-of-WiFi/UniFi-API-client/zipball/141b0ff55f2919d1c30cae0e75a7f30d6e2b9f26",
"reference": "141b0ff55f2919d1c30cae0e75a7f30d6e2b9f26",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.4.0"
},
"time": "2017-10-12 15:21:50",
"time": "2017-10-18 06:35:11",
"type": "library",
"installation-source": "dist",
"autoload": {
Expand Down

0 comments on commit 48f807f

Please sign in to comment.