-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- include PHP API client class version 1.1.30 - support site names which contain URL-unfriendly characters such as single and double quotes
- Loading branch information
1 parent
c6222d2
commit 2b34c23
Showing
9 changed files
with
507 additions
and
35 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
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
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
90 changes: 90 additions & 0 deletions
90
vendor/art-of-wifi/unifi-api-client/examples/block_list.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,90 @@ | ||
<?php | ||
/** | ||
* PHP API usage example | ||
* | ||
* contributed by: @malcolmcif, based on another Art of WiFi example | ||
* description: basic PHP script to block a list of mac addresses passed in via command line, | ||
* output is to console in non json format | ||
* | ||
* usage: | ||
* php block_list.php <list of comma seperated mac addresses> | ||
* | ||
* example: | ||
* php block_list.php 09:09:09:09:09:09,10:10:10:10:10:10 | ||
* | ||
*/ | ||
|
||
/** | ||
* 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'); | ||
|
||
$debug=false; | ||
/** | ||
* the MAC address(es) of the device(s) to block | ||
*/ | ||
$macs_to_block = explode(',',$argv[1]); | ||
|
||
/** | ||
* The site to authorize the device with | ||
*/ | ||
$site_id = 'MUST_DEFINE_THIS'; | ||
if ($site_id == "MUST_DEFINE_THIS") | ||
{ | ||
print 'ERROR: set the site id in your script'; | ||
return; | ||
} | ||
|
||
/** | ||
* 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(); // always true regardless of site id | ||
|
||
foreach ($macs_to_block as &$mac) | ||
{ | ||
// block_result is always true even if mac address does not exist :( | ||
$block_result = $unifi_connection->block_sta($mac); | ||
|
||
/** | ||
* NOTE: | ||
* during testing I had some strange behavior where clients were not reconnecting to the network correctly, | ||
* they appeared unblocked and received a valid IP address but could not actually get any data. | ||
* the clients did not come to life until I disabled the SSID and then re enabled it. | ||
* I guessed maybe these commands were occurring too quickly for the controller so I have slowed them down; | ||
* since introducing the sleep I have not seen the above behavior so it might be fixed | ||
*/ | ||
sleep(1); | ||
|
||
$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")) // this is the alias field if it has been defined | ||
{ | ||
$name = $getid_result[0]->name; | ||
} | ||
else | ||
{ | ||
$name = $getid_result[0]->hostname; | ||
} | ||
print 'blocked ' . $name . PHP_EOL; | ||
} | ||
else | ||
{ | ||
print 'ERROR: could not block ' . $mac . PHP_EOL; | ||
print ' check mac address is valid and part of your network' . PHP_EOL; | ||
} | ||
} | ||
|
||
/** | ||
* No json formatted data | ||
*/ | ||
//echo json_encode($block_result, JSON_PRETTY_PRINT); |
51 changes: 51 additions & 0 deletions
51
vendor/art-of-wifi/unifi-api-client/examples/list_user_stats.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,51 @@ | ||
<?php | ||
/** | ||
* PHP API usage example | ||
* | ||
* contributed by: Art of WiFi | ||
* description: example basic PHP script to pull stats for s epcific user/client device from the UniFi controller and output 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 site to use | ||
*/ | ||
$site_id = '<enter your site id here>'; | ||
|
||
/** | ||
* MAC address of client to fetch stats for | ||
*/ | ||
$mac = '<MAC address>'; | ||
|
||
/** | ||
* array of attributes to collect | ||
* valid attributes: | ||
* rx_bytes, tx_bytes, signal, rx_rate, tx_rate, rx_retries, tx_retries, rx_packets, tx_packets | ||
*/ | ||
//$attribs = ['rx_bytes', 'tx_bytes', 'signal', 'rx_rate', 'tx_rate', 'rx_retries', 'tx_retries', 'rx_packets', 'tx_packets']; | ||
$attribs = ['rx_bytes', 'tx_bytes']; | ||
|
||
/** | ||
* initialize the UniFi API connection class and log in to the controller and do our thing | ||
*/ | ||
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion, true); | ||
$set_debug_mode = $unifi_connection->set_debug(false); | ||
$loginresults = $unifi_connection->login(); | ||
//$data = $unifi_connection->stat_5minutes_user($mac, null, null, $attribs); | ||
//$data = $unifi_connection->stat_hourly_user($mac, null, null, $attribs); | ||
$data = $unifi_connection->stat_daily_user($mac, null, null, $attribs); | ||
|
||
/** | ||
* provide feedback in json format | ||
*/ | ||
echo json_encode($data, JSON_PRETTY_PRINT); |
90 changes: 90 additions & 0 deletions
90
vendor/art-of-wifi/unifi-api-client/examples/unblock_list.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,90 @@ | ||
<?php | ||
/** | ||
* PHP API usage example | ||
* | ||
* contributed by: @malcolmcif, based on another Art of WiFi example | ||
* description: basic PHP script to unblock a list of mac addresses passed in via command line, | ||
* output is to console in non json format | ||
* | ||
* usage: | ||
* php unblock_list.php <list of comma seperated mac addresses> | ||
* | ||
* example: | ||
* php unblock_list.php 09:09:09:09:09:09,10:10:10:10:10:10 | ||
* | ||
*/ | ||
|
||
/** | ||
* 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'); | ||
|
||
$debug=false; | ||
/** | ||
* the MAC addresses of the device(s) to unblock | ||
*/ | ||
$macs_to_unblock = explode(',',$argv[1]); | ||
|
||
/** | ||
* The site to authorize the device with | ||
*/ | ||
$site_id = 'MUST_DEFINE_THIS'; | ||
if ($site_id == "MUST_DEFINE_THIS") | ||
{ | ||
print 'ERROR: set the site id in your script'; | ||
return; | ||
} | ||
|
||
/** | ||
* 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(); // always true regardless of site id | ||
|
||
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); | ||
|
||
/** | ||
* NOTE: | ||
* during testing I had some strange behavior where clients were not reconnecting to the network correctly, | ||
* they appeared unblocked and received a valid IP address but could not actually get any data. | ||
* the clients did not come to life until I disabled the SSID and then re enabled it. | ||
* I guessed maybe these commands were occurring too quickly for the controller so I have slowed them down; | ||
* since introducing the sleep I have not seen the above behavior so it might be fixed | ||
*/ | ||
sleep(1); | ||
|
||
$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")) | ||
{ | ||
$name = $getid_result[0]->name; | ||
} | ||
else | ||
{ | ||
$name = $getid_result[0]->hostname; | ||
} | ||
print 'unblocked ' . $name . PHP_EOL; | ||
} | ||
else | ||
{ | ||
print 'ERROR: could not unblock ' . $mac . PHP_EOL; | ||
print ' check mac address is valid and part of your network' . PHP_EOL; | ||
} | ||
} | ||
|
||
/** | ||
* provide feedback in json format | ||
*/ | ||
//echo json_encode($block_result, JSON_PRETTY_PRINT); |
Oops, something went wrong.