2017-09-05 11:48:35 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHP API usage example
|
|
|
|
*
|
|
|
|
* contributed by: mtotone
|
2021-01-21 10:59:27 +01:00
|
|
|
* description: example of how to extend validity of guest authorizations
|
2017-09-05 11:48:35 +02:00
|
|
|
*/
|
|
|
|
|
2017-09-05 13:04:11 +02:00
|
|
|
/**
|
|
|
|
* using the composer autoloader
|
|
|
|
*/
|
2021-01-21 10:59:27 +01:00
|
|
|
require_once 'vendor/autoload.php';
|
2017-09-05 13:04:11 +02:00
|
|
|
|
2017-09-05 11:48:35 +02:00
|
|
|
/**
|
|
|
|
* include the config file (place your credentials etc. there if not already present)
|
|
|
|
* see the config.template.php file for an example
|
|
|
|
*/
|
2021-01-21 10:59:27 +01:00
|
|
|
require_once 'config.php';
|
2017-09-05 11:48:35 +02:00
|
|
|
|
2019-10-15 14:27:28 +02:00
|
|
|
/**
|
|
|
|
* must be adapted to your site!
|
|
|
|
*/
|
2017-09-05 11:48:35 +02:00
|
|
|
$site_id = "default";
|
|
|
|
$site_name = "*enter your site name*";
|
|
|
|
|
2023-12-18 11:11:27 +01:00
|
|
|
$unifi_connection = new UniFi_API\Client(
|
|
|
|
$controlleruser,
|
|
|
|
$controllerpassword,
|
|
|
|
$controllerurl,
|
|
|
|
$site_id,
|
|
|
|
$controllerversion
|
|
|
|
);
|
|
|
|
|
|
|
|
$set_debug_mode = $unifi_connection->set_debug($debug);
|
|
|
|
$loginresults = $unifi_connection->login();
|
2017-09-05 11:48:35 +02:00
|
|
|
|
|
|
|
if ($loginresults === 400) {
|
2018-03-24 10:46:42 +01:00
|
|
|
print "UniFi controller login failure, please check your credentials in config.php.\n";
|
2017-09-05 11:48:35 +02:00
|
|
|
} else {
|
2018-03-24 10:46:42 +01:00
|
|
|
$guestlist = $unifi_connection->list_guests();
|
2019-10-15 14:27:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* loop thru all known guests
|
|
|
|
*/
|
2018-03-24 10:46:42 +01:00
|
|
|
foreach ($guestlist as $guest) {
|
2023-12-18 11:11:27 +01:00
|
|
|
print "<pre>" . $guest->_id . " (" . $guest->mac . "), valid until " .
|
|
|
|
date(DATE_ATOM, $guest->end) . " (" . $guest->end . ")</pre>";
|
2017-09-05 11:48:35 +02:00
|
|
|
|
2019-10-15 14:27:28 +02:00
|
|
|
/**
|
|
|
|
* just a sample: only extend validity of guests which have end date after 2017-04-02
|
|
|
|
*/
|
2018-03-24 10:46:42 +01:00
|
|
|
if ($guest->end > 1491166482) {
|
2019-10-15 14:27:28 +02:00
|
|
|
/**
|
|
|
|
* 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)) {
|
2019-10-15 14:41:16 +02:00
|
|
|
print "Extend failed for guest with id " . $guest->_id . "\n";
|
2019-10-15 14:27:28 +02:00
|
|
|
}
|
2018-03-24 10:46:42 +01:00
|
|
|
}
|
|
|
|
}
|
2017-09-05 11:48:35 +02:00
|
|
|
|
2018-03-24 10:46:42 +01:00
|
|
|
$logout_results = $unifi_connection->logout();
|
2017-09-05 11:48:35 +02:00
|
|
|
}
|