diff --git a/app/system/app_config.php b/app/system/app_config.php index 45e2ce42e6..66ddaf638e 100644 --- a/app/system/app_config.php +++ b/app/system/app_config.php @@ -161,5 +161,13 @@ $apps[$x]['default_settings'][$y]['default_setting_value'] = "#d4d4d4"; $apps[$x]['default_settings'][$y]['default_setting_enabled'] = "false"; $apps[$x]['default_settings'][$y]['default_setting_description'] = ""; + $y++; + $apps[$x]['default_settings'][$y]['default_setting_uuid'] = "93193159-0033-43a6-99d5-5dc652b38724"; + $apps[$x]['default_settings'][$y]['default_setting_category'] = "session"; + $apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "filesystem_retention_days"; + $apps[$x]['default_settings'][$y]['default_setting_name'] = "numeric"; + $apps[$x]['default_settings'][$y]['default_setting_value'] = "1"; + $apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true"; + $apps[$x]['default_settings'][$y]['default_setting_description'] = "Number of days to keep PHP session files on the server until the maintenance application deletes them"; ?> diff --git a/app/system/resources/classes/session.php b/app/system/resources/classes/session.php new file mode 100644 index 0000000000..985484e977 --- /dev/null +++ b/app/system/resources/classes/session.php @@ -0,0 +1,68 @@ + + * Portions created by the Initial Developer are Copyright (C) 2008-2024 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Mark J Crane + * Tim Fry + */ + +/** + * Description of session + * + * @author Tim Fry + */ +class session { + + /** + * Removes old php session files. Called by the maintenance application. + * @param settings $settings A settings object + * @return void + */ + public static function filesystem_maintenance(settings $settings): void { + $retention_days = $settings->get('session', 'filesystem_retention_days', ''); + if (!empty($retention_days) && is_numeric($retention_days)) { + //get the session location + if (session_status() === PHP_SESSION_ACTIVE) { + //session should not normally be running already in a service + $session_location = session_save_path(); + } else { + //session has to be started to get the path + session_start(); + $session_location = session_save_path(); + session_destroy(); + } + //loop through all files and check the modified time + $files = glob($session_location . '/sess_*'); + foreach ($files as $file) { + if (maintenance_service::days_since_modified($file) > $retention_days) { + //remove old file + if (unlink($file)) { + maintenance_service::log_write(self::class, "Removed old session file $file"); + } else { + maintenance_service::log_write(self::class, "Unable to remove old session file $file", null, maintenance_service::LOG_ERROR); + } + } + } + } + } +}