Commit a14eb49d authored by Michael Seevogel's avatar Michael Seevogel

WiP log file retention for webserver logs

parent 0b3b1f66
......@@ -1986,6 +1986,7 @@ CREATE TABLE `web_domain` (
`http_port` int(11) unsigned NOT NULL DEFAULT '80',
`https_port` int(11) unsigned NOT NULL DEFAULT '443',
`folder_directive_snippets` text,
`log_retention` int(11) NOT NULL DEFAULT '30',
PRIMARY KEY (`domain_id`),
UNIQUE KEY `serverdomain` ( `server_id` , `ip_address`, `domain` )
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
......
......@@ -917,7 +917,19 @@ if($_SESSION["s"]["user"]["typ"] == 'admin'
'value' => '',
'width' => '3',
'maxlength' => '6'
)
),
'log_retention' => array (
'datatype' => 'INTEGER',
'formtype' => 'TEXT',
'validators' => array ( 0 => array ( 'type' => 'REGEX',
'regex' => '/^([0-9]{1,5})$/',
'errmsg'=> 'log_retention_error_regex'),
),
'default' => '30',
'value' => '',
'width' => '4',
'maxlength' => '6'
)
//#################################
// ENDE Datatable fields
//#################################
......
......@@ -133,4 +133,6 @@ $wb['http_port_txt'] = 'HTTP Port';
$wb['https_port_txt'] = 'HTTPS Port';
$wb['http_port_error_regex'] = 'HTTP Port invalid.';
$wb['https_port_error_regex'] = 'HTTPS Port invalid.';
$wb['log_retention_txt'] = 'Log-Datei Aufbewahrungszeit';
$wb['log_retention_error_regex'] = 'Nur Nummern von 0-9999 zulässig.'
?>
......@@ -148,4 +148,6 @@ $wb['https_port_txt'] = 'HTTPS Port';
$wb['http_port_error_regex'] = 'HTTP Port invalid.';
$wb['https_port_error_regex'] = 'HTTPS Port invalid.';
$wb['enable_pagespeed_txt'] = 'Enable PageSpeed';
$wb['log_retention_txt'] = 'Log-Datei Aufbewahrungszeit';
$wb['log_retention_error_regex'] = 'Nur Nummern von 0-9999 zulässig.'
?>
......@@ -35,6 +35,10 @@
</div>
<input name="system_group" id="system_group" value="{tmpl_var name='system_group'}" type="hidden" />
</div>
<div class="form-group">
<label for="log_retention" class="col-sm-3 control-label">{tmpl_var name='log_retention_txt'}</label>
<div class="col-sm-9"><input name="log_retention" id="log_retention" value="{tmpl_var name='log_retention'}" type="text" class="form-control" /></div>
</div>
<div class="form-group apache">
<label for="allow_override" class="col-sm-3 control-label">{tmpl_var name='allow_override_txt'}</label>
<div class="col-sm-9"><input type="text" name="allow_override" id="allow_override" value="{tmpl_var name='allow_override'}" class="form-control" /></div></div>
......
......@@ -60,7 +60,7 @@ class cronjob_logfiles extends cronjob {
// Manage and compress web logfiles and create traffic statistics
//######################################################################################################
$sql = "SELECT domain_id, domain, type, document_root, web_folder, parent_domain_id FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain' or type = 'vhostalias') AND server_id = ?";
$sql = "SELECT domain_id, domain, type, document_root, web_folder, parent_domain_id, log_retention FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain' or type = 'vhostalias') AND server_id = ?";
$records = $app->db->queryAllRecords($sql, $conf['server_id']);
foreach($records as $rec) {
......@@ -76,6 +76,8 @@ class cronjob_logfiles extends cronjob {
unset($tmp);
}
$log_retention = $rec['log_retention'];
$logfile = $rec['document_root'].'/' . $log_folder . '/'.$yesterday.'-access.log';
$total_bytes = 0;
......@@ -142,21 +144,25 @@ class cronjob_logfiles extends cronjob {
exec("cat /dev/null > $logfile");
}
// delete logfiles after 30 days
$month_ago = date('Ymd', time() - 86400 * 30);
// delete logfiles after x days (default 30)
if($log_retention > 0) {
$month_ago = date('Ymd', time() - 86400 * $log_retention);
$logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/'.$month_ago.'-access.log.gz');
if(@is_file($logfile)) {
unlink($logfile);
}
}
//* Delete older Log files, in case that we missed them before due to serverdowntimes.
$datepart = date('Ym', time() - 86400 * 31 * 2);
if($log_retention > 0) {
$datepart = date('Ym', time() - 86400 * $log_retention+1 * 2);
$logfile = escapeshellcmd($rec['document_root']).'/' . $log_folder . '/'.$datepart.'*-access.log.gz';
exec('rm -f '.$logfile);
$logfile = escapeshellcmd($rec['document_root']).'/' . $log_folder . '/'.$datepart.'*-access.log';
exec('rm -f '.$logfile);
}
}
//* Delete old logfiles in /var/log/ispconfig/httpd/ that were created by vlogger for the hostname of the server
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment