system: move syslog reset function to system include #6830

This commit is contained in:
Franco Fichtner 2024-02-28 12:22:56 +01:00
parent 359954ddbb
commit 5247ab3f3a
3 changed files with 18 additions and 17 deletions

View File

@ -471,6 +471,7 @@ function core_configure()
'dns_reload' => ['system_resolver_configure'],
'firmware_reload' => ['system_firmware_configure'],
'route_reload' => ['core_routing_batch:2'],
'syslog_reset' => ['system_syslog_reset'],
'user_changed' => ['core_user_changed_groups:2'],
];
}

View File

@ -812,6 +812,22 @@ function system_syslog_stop()
mwexecf('/usr/sbin/service syslog-ng stop');
}
function system_syslog_reset($verbose = false)
{
$it = new RecursiveDirectoryIterator('/var/log');
foreach (new RecursiveIteratorIterator($it) as $file) {
if ($file->isFile() && strpos($file->getFilename(), '.log') > -1) {
if (strpos($file->getFilename(), 'flowd') === false) {
@unlink((string)$file);
}
}
}
system_syslog_start($verbose);
plugins_configure('dhcp', $verbose);
}
/*
* get_memory()
* returns an array listing the amount of

View File

@ -34,22 +34,6 @@ require_once("interfaces.inc");
require_once("filter.inc");
require_once("system.inc");
function clear_all_log_files()
{
$it = new RecursiveDirectoryIterator('/var/log');
foreach(new RecursiveIteratorIterator($it) as $file) {
if ($file->isFile() && strpos($file->getFilename(), '.log') > -1) {
if (strpos($file->getFilename(), 'flowd') === false) {
@unlink((string)$file);
}
}
}
system_syslog_start();
plugins_configure('dhcp');
}
function is_valid_syslog_server($target) {
return (is_ipaddr($target)
|| is_ipaddrwithport($target)
@ -70,7 +54,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig['disablelocallogging'] = isset($config['syslog']['disablelocallogging']);
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!empty($_POST['action']) && $_POST['action'] == "resetlogs") {
clear_all_log_files();
system_syslog_reset();
$pconfig = $_POST;
$savemsg = gettext("The log files have been reset.");
} else {