Files
cacti/include/session.php
T
netniV 89f0a06216 Resolving issue #2304 and #2311
This commit corrects a previous unseen issue where the PHP environment at command line level is being populated with environment variables normally only seen when called from a web server.

issue#2304: Installation progress stays at 0%
issue#2311: Unable to update PHP location during installation due to incorrect CLI environment

The new check uses the php_sapi_name() function to verify that we are indeed at 'cli' level.  All other values returned by php_sapi_name are considered non-cli including 'cli-server' which is for client/server scenarios.

Most checks have now been replaced by a single defintion ('CACTI_CLI') to define whether in CLI mode.  If a script is only to be called from CLI it must either defined 'CACTI_CLI_ONLY' or include include/cli_check.php instead of include/global.php.
2019-01-15 13:57:50 +00:00

52 lines
1.4 KiB
PHP

<?php
/*
* Have Cacti use the database for PHP session storage.
* This allows for easier distrubution of Web UI.
*/
// Don't run from the database if using the command line
if (php_sapi_name() == 'cli') {
return;
}
function cacti_session_open() {
// Cacti database is already active
return true;
}
function cacti_session_close() {
// Cacti database is not closed by sessions
return true;
}
function cacti_session_read($id) {
db_execute_prepared('UPDATE IGNORE sessions SET access = ? WHERE id = ?', array(time(), $id));
$session = db_fetch_cell_prepared('SELECT data FROM sessions WHERE id = ?', array($id));
// work with PHP 7.1
if (empty($session)) {
$session = '';
}
return $session;
}
function cacti_session_write($id, $data) {
$access = time();
return db_execute_prepared('REPLACE INTO sessions VALUES (?, ?, ?, ?)', array($id, $_SERVER['REMOTE_ADDR'], $access, $data));
}
function cacti_session_destroy($id) {
return db_execute_prepared('DELETE FROM sessions WHERE id = ?', array($id));
}
function cacti_session_clean($max) {
$old = time() - $max;
return db_execute_prepared('DELETE FROM sessions WHERE access < ?', array($old));
}
// register database session handling
session_set_save_handler('cacti_session_open', 'cacti_session_close', 'cacti_session_read', 'cacti_session_write', 'cacti_session_destroy', 'cacti_session_clean');
register_shutdown_function('session_write_close');