Implement changes in to the session class (#7042)

This commit is contained in:
frytimo 2024-07-09 15:50:01 -03:00 committed by GitHub
parent d68c1a08d8
commit d7f05621c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 76 additions and 0 deletions

View File

@ -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";
?>

View File

@ -0,0 +1,68 @@
<?php
/*
* FusionPBX
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FusionPBX
*
* The Initial Developer of the Original Code is
* Mark J Crane <markjcrane@fusionpbx.com>
* Portions created by the Initial Developer are Copyright (C) 2008-2024
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark J Crane <markjcrane@fusionpbx.com>
* Tim Fry <tim@fusionpbx.com>
*/
/**
* Description of session
*
* @author Tim Fry <tim@fusionpbx.com>
*/
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);
}
}
}
}
}
}