-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added support for UniFi OS-based controllers - included the version 1.1.47 of the PHP API client class
- Loading branch information
1 parent
4aceffc
commit 55843a5
Showing
15 changed files
with
638 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -325,7 +325,8 @@ function fetchDebugDetails() { | |
} | ||
} | ||
}); | ||
}} | ||
} | ||
} | ||
|
||
/** | ||
* function to fetch a collection | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
vendor/art-of-wifi/unifi-api-client/examples/list_connected_users.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* PHP API usage example | ||
* | ||
* contributed by: @gahujipo | ||
* description: example to pull connected users and their details from the UniFi controller and output the results | ||
* in JSON format | ||
*/ | ||
/** | ||
* using the composer autoloader | ||
*/ | ||
require_once('vendor/autoload.php'); | ||
|
||
/** | ||
* include the config file (place your credentials etc there if not already present) | ||
* see the config.template.php file for an example | ||
*/ | ||
require_once('config.php'); | ||
|
||
/** | ||
* the short name of the site which you wish to query | ||
*/ | ||
$site_id = '<enter your site id here>'; | ||
|
||
/** | ||
* initialize the UniFi API connection class and log in to the controller and pull the requested data | ||
*/ | ||
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); | ||
$set_debug_mode = $unifi_connection->set_debug($debug); | ||
$loginresults = $unifi_connection->login(); | ||
$clients_array = $unifi_connection->list_clients(); | ||
|
||
/** | ||
* output the results in JSON format | ||
*/ | ||
header('Content-Type: application/json; charset=utf-8'); | ||
echo json_encode($clients_array); |
45 changes: 45 additions & 0 deletions
45
vendor/art-of-wifi/unifi-api-client/examples/reconnect_client.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* PHP API usage example | ||
* | ||
* contributed by: Art of WiFi | ||
* description: example basic PHP script to force a client device to reconnect | ||
*/ | ||
|
||
/** | ||
* using the composer autoloader | ||
*/ | ||
require_once('vendor/autoload.php'); | ||
|
||
/** | ||
* include the config file (place your credentials etc. there if not already present) | ||
* see the config.template.php file for an example | ||
*/ | ||
require_once('config.php'); | ||
|
||
/** | ||
* the MAC address to reconnect | ||
*/ | ||
$mac_to_reconnect = '<MAC address>'; | ||
|
||
/** | ||
* site where the above MAC address is connected | ||
*/ | ||
$site_id = '<enter your site id here>'; | ||
|
||
/** | ||
* initialize the UniFi API connection class and log in to the controller | ||
*/ | ||
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); | ||
$set_debug_mode = $unifi_connection->set_debug($debug); | ||
$loginresults = $unifi_connection->login(); | ||
|
||
/** | ||
* then we force the device to reconnect | ||
*/ | ||
$reconnect_result = $unifi_connection->reconnect_sta($mac_to_reconnect); | ||
|
||
/** | ||
* provide feedback in json format | ||
*/ | ||
echo json_encode($reconnect_result, JSON_PRETTY_PRINT); |
94 changes: 94 additions & 0 deletions
94
vendor/art-of-wifi/unifi-api-client/examples/update_switch_poe-mode.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* PHP API usage example to turn the PoE of the selected switch ports to "off" or "auto" | ||
* | ||
* contributed by: @Kaltt | ||
* description: A use case for this script is to turn off the PoE of the port where a camera is connected in order to turn off the camera | ||
* | ||
* usage: If the file is called via a web URL, it should be called like: update_switch_poe-mode.php?poe_mode=off | ||
* If the file is called via the command line, it should be called like: php update_switch_poe-mode.php off | ||
* The values can be "off" or "auto" | ||
*/ | ||
|
||
/** | ||
* using the composer autoloader | ||
*/ | ||
require_once('vendor/autoload.php'); | ||
|
||
/** | ||
* include the config file (place your credentials etc. there if not already present) | ||
* see the config.template.php file for an example | ||
*/ | ||
require_once('config.php'); | ||
|
||
/** | ||
* the site to use to log in to the controller | ||
*/ | ||
$site_id = '<short site name of a site the credentials used have access to>'; | ||
|
||
/** | ||
* the MAC address of the AC-IW device to re-configure | ||
*/ | ||
$device_mac = '<enter MAC address>'; | ||
|
||
/** | ||
* $lanports is an array that defines which ports should be changed | ||
*/ | ||
$lanports = [6]; | ||
|
||
/** | ||
* This is the function that reads out the current port configuration and changes the value for the poe_mode for the ports defined in $lanports | ||
*/ | ||
function update_ports($running_config, $ports, $poe_mode){ | ||
/** | ||
* Update already non-default ports | ||
*/ | ||
$running_config_count = count($running_config); | ||
for($i = 0; $i < $running_config_count; $i++){ | ||
if(in_array($running_config[$i]->port_idx, $ports)){ | ||
$running_config[$i]->poe_mode = $poe_mode; | ||
unset($ports[array_search($running_config[$i]->port_idx, $ports)]); | ||
} | ||
} | ||
|
||
$add_conf = []; | ||
foreach($ports as $port){ | ||
$add_conf[] = [ | ||
'port_idx' => $port, | ||
'poe_mode' => $poe_mode | ||
]; | ||
} | ||
|
||
return array_merge($running_config, $add_conf); | ||
} | ||
|
||
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion, false); | ||
$set_debug_mode = $unifi_connection->set_debug(false); | ||
$loginresults = $unifi_connection->login(); | ||
$data = $unifi_connection->list_devices($device_mac); | ||
$device_id = $data[0]->device_id; | ||
$current_conf = $data[0]->port_overrides; | ||
|
||
/** | ||
* This reads in the values provided via URL or in the command line, if nothing is set than it will poe_mode will be set to "auto" | ||
*/ | ||
if (isset($_GET['poe_mode'])) { | ||
$poe_mode = $_GET['poe_mode']; | ||
} elseif (isset($argv[1])) { | ||
$poe_mode = $argv[1]; | ||
} else { | ||
$poe_mode = 'auto'; | ||
} | ||
|
||
$new_ports_config = [ | ||
'port_overrides' => update_ports($current_conf, $lanports, $poe_mode) | ||
]; | ||
|
||
$update_device = $unifi_connection->set_device_settings_base($device_id, $new_ports_config); | ||
|
||
if (!$update_device) { | ||
$error = $unifi_connection->get_last_results_raw(); | ||
echo json_encode($error, JSON_PRETTY_PRINT); | ||
} | ||
|
||
echo json_encode($update_device, JSON_PRETTY_PRINT); |
Oops, something went wrong.