implement changes in to the event_guard class (#7045)
Co-authored-by: Tim Fry <tim@fusionpbx.com>
This commit is contained in:
@@ -178,6 +178,14 @@
|
|||||||
$apps[$x]['default_settings'][$y]['default_setting_value'] = "3600";
|
$apps[$x]['default_settings'][$y]['default_setting_value'] = "3600";
|
||||||
$apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true";
|
$apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true";
|
||||||
$apps[$x]['default_settings'][$y]['default_setting_description'] = "Login blocked for many failures in a given time.";
|
$apps[$x]['default_settings'][$y]['default_setting_description'] = "Login blocked for many failures in a given time.";
|
||||||
|
$y++;
|
||||||
|
$apps[$x]['default_settings'][$y]['default_setting_uuid'] = "56416cfe-c018-48db-8362-e90bc3fbaa4f";
|
||||||
|
$apps[$x]['default_settings'][$y]['default_setting_category'] = "users";
|
||||||
|
$apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "database_retention_days";
|
||||||
|
$apps[$x]['default_settings'][$y]['default_setting_name'] = "numeric";
|
||||||
|
$apps[$x]['default_settings'][$y]['default_setting_value'] = "180";
|
||||||
|
$apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true";
|
||||||
|
$apps[$x]['default_settings'][$y]['default_setting_description'] = "Number of days to retain the user logs in the database for the maintenance app.";
|
||||||
|
|
||||||
//schema details
|
//schema details
|
||||||
$y=0;
|
$y=0;
|
||||||
|
|||||||
@@ -287,6 +287,33 @@ if (!class_exists('users')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove old user log entries. Called the maintenance service application.
|
||||||
|
* @param settings $settings
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function database_maintenance(settings $settings): void {
|
||||||
|
$database = $settings->database();
|
||||||
|
$domains = maintenance_service::get_domains($database);
|
||||||
|
foreach ($domains as $domain_uuid => $domain_name) {
|
||||||
|
$domain_settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid]);
|
||||||
|
$retention_days = $domain_settings->get('users', 'database_retention_days', '');
|
||||||
|
if (!empty($retention_days) && is_numeric($retention_days)) {
|
||||||
|
$sql = "delete from v_user_logs where timestamp < NOW() - INTERVAL '$retention_days days'";
|
||||||
|
$sql.= " and domain_uuid = '$domain_uuid'";
|
||||||
|
$database->execute($sql);
|
||||||
|
$code = $database->message['code'] ?? 0;
|
||||||
|
if ($code == 200) {
|
||||||
|
maintenance_service::log_write(self::class, "Removed database entries older than $retention_days", $domain_uuid);
|
||||||
|
} else {
|
||||||
|
$message = $database->message['message'] ?? "An unknown error has occurred";
|
||||||
|
maintenance_service::log_write(self::class, "Unable to remove old database records. Error message: $message ($code)", $domain_uuid, maintenance_service::LOG_ERROR);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
maintenance_service::log_write(self::class, "Database retention days not set or not numeric", $domain_uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user