Skip to content

Commit

Permalink
added cookie timeout function
Browse files Browse the repository at this point in the history
added a timeout function to clear the PHP SESSION cookie after a defined
period of inactivity. Update your config file with this variable if you
are upgrading from an earlier version.
  • Loading branch information
malle-pietje committed Dec 24, 2015
1 parent 7f76295 commit 071625b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
5 changes: 3 additions & 2 deletions config.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
$controllerpassword = ''; // the password for access to the Unifi Controller
$controllerurl = ''; // full url to the Unifi Controller, eg. 'https://22.22.11.11:8443'
$controllerversion = ''; // the version of the Controller software, eg. '4.6.6' (must be at least 4.0.0)

?>
$cookietimeout = '3600'; // time of inactivity in seconds, after which the PHP session cookie will be refreshed
// this means the site and data collection will need to be selected again
?>
39 changes: 27 additions & 12 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
$time_start = microtime(true);

/*
assign variables required later on together with their default values
assign variables which are required later on together with their default values
*/
$action = '';
$siteid = '';
Expand All @@ -45,6 +45,30 @@
$data = '';
$objectscount = '';
$alertmessage = '';
$cookietimeout = '1800';

/*
load the settings file
- if the config.php file is unreadable or does not exist, an alert is displayed on the page
*/
if(!is_readable('config.php')) {
$alertmessage = '<div class="alert alert-danger" role="alert">The file config.php is not readable or does not exist.'
. '<br>If you have not yet done so, please copy/rename the config.template.php file to config.php and modify the contents as required.</div>';
}

include('config.php');

/*
determine whether we have reached the cookie timeout, if so, refresh the PHP session
*/
if (isset($_SESSION['last_activity']) && (time() - $_SESSION['last_activity'] > $cookietimeout)) {
/*
last activity was longer than "$cookietimeout" seconds ago
*/
session_unset();
session_destroy();
}
$_SESSION['last_activity'] = time(); // update last activity time stamp

/*
collect cURL version details for the info modal
Expand Down Expand Up @@ -111,19 +135,10 @@
}

/*
load the unifi api connection class as well as the settings files
and log in to the controller
- if the config.php file is unreadable or does not exist, an alert is displayed on the page
- if an error occurs with the login process an alert is displayed on the page
load the Unifi API connection class and log in to the controller
- if an error occurs during the login process, an alert is displayed on the page
*/
require('phpapi/class.unifi.php');
if(!is_readable('config.php')) {
$alertmessage = '<div class="alert alert-danger" role="alert">The file config.php is not readable or does not exist.'
. '<br>If you have not yet done so, please copy/rename the config.template.php file to config.php and modify the contents as required.</div>';
}

include('config.php');

$unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $siteid, $controllerversion);
$loginresults = $unifidata->login();
if($loginresults === 400) {
Expand Down

0 comments on commit 071625b

Please sign in to comment.