Supporting add new logrotate config files to a directory

This commit is contained in:
Jamie Cameron
2013-04-21 12:59:13 -07:00
parent c0f848c522
commit 8a03fafe08
3 changed files with 12 additions and 4 deletions

View File

@@ -5,3 +5,5 @@ Added a button on the Edit Log File page for forcing the immediate rotation of j
Added a Module Config option for specifying a file to add new logrotate sections to.
---- Changes since 1.270 ----
Added checkboxes and a button for deleting multiple logs at once.
---- Changes since 1.620 ----
The module config option for the new file to add logrotate sections to can now be a directory, like /etc/logrotate.d

View File

@@ -349,11 +349,16 @@ local $out = &backquote_logged("$config{'logrotate'} -f $temp 2>&1");
return ($?, $out);
}
# get_add_file()
# get_add_file([filename])
# Returns the file to which new logrotate sections should be added
sub get_add_file
{
if ($config{'add_file'}) {
local ($filename) = @_;
if ($config{'add_file'} && -d $config{'add_file'} && $filename) {
# Adding to a new file in a directory
return "$config{'add_file'}/$filename.conf";
}
elsif ($config{'add_file'} && !-d $config{'add_file'}) {
# Make sure file is valid
local ($conf, $lnum, $files) = &get_config();
if (&indexof($config{'add_file'}, @$files) >= 0) {

View File

@@ -6,14 +6,16 @@ require './logrotate-lib.pl';
&ReadParse();
$parent = &get_config_parent();
$conf = $parent->{'members'};
@files = split(/\s+/, $in{'file'});
if ($in{'global'}) {
# Editing the global options
$log = $parent;
}
elsif ($in{'new'}) {
# Adding a new section
$cfilename = $files[0] =~ /\/([^\/]+)$/ ? $1 : undef;
$log = { 'members' => [ ],
'file' => &get_add_file() };
'file' => &get_add_file($cfilename) };
$logfile = $in{'file'};
}
else {
@@ -50,7 +52,6 @@ else {
&lock_file($log->{'file'});
&error_setup($text{'save_err'});
if (!$in{'global'}) {
@files = split(/\s+/, $in{'file'});
foreach $f (@files) {
$f =~ /^\/\S+$/ || &error($text{'save_efile'});
}