webmin/bind8/save_logging.cgi

106 lines
3.0 KiB
Plaintext
Raw Permalink Normal View History

2007-04-12 20:24:50 +00:00
#!/usr/local/bin/perl
# save_logging.cgi
# Save global logging options
2016-06-02 19:30:01 -07:00
use strict;
use warnings;
no warnings 'redefine';
no warnings 'uninitialized';
2016-06-02 19:30:01 -07:00
our (%access, %text, %in, %config);
2007-04-12 20:24:50 +00:00
require './bind8-lib.pl';
$access{'defaults'} || &error($text{'logging_ecannot'});
&error_setup($text{'files_err'});
&ReadParse();
&lock_file(&make_chroot($config{'named_conf'}));
2016-06-02 19:30:01 -07:00
my $conf = &get_config();
my $logging = &find("logging", $conf);
my (@category, @channel);
2007-04-12 20:24:50 +00:00
2008-08-30 22:28:50 +00:00
if ($in{'mode'} eq 'cats') {
# Save categories
2016-06-02 19:30:01 -07:00
my $cat;
for(my $i=0; defined($cat = $in{"cat_$i"}); $i++) {
2008-08-30 22:28:50 +00:00
next if (!$cat);
2016-06-02 19:30:01 -07:00
my @cchan = split(/\0/, $in{"cchan_$i"});
2008-08-30 22:28:50 +00:00
push(@category, { 'name' => 'category',
'values' => [ $cat ],
'type' => 1,
'members' =>
[ map { { 'name' => $_ } } @cchan ] });
}
2008-08-31 05:29:21 +00:00
@channel = &find("channel", $logging->{'members'}) if ($logging);
2007-04-12 20:24:50 +00:00
}
2008-08-30 22:28:50 +00:00
else {
# Save channels
2016-06-02 19:30:01 -07:00
my $cname;
for(my $i=0; defined($cname = $in{"cname_$i"}); $i++) {
2008-08-30 22:28:50 +00:00
next if (!$cname);
$cname =~ /^\S+$/ || &error(&text('logging_ename', $cname));
2016-06-02 19:30:01 -07:00
my @mems;
2008-08-30 22:28:50 +00:00
if ($in{"to_$i"} == 0) {
$in{"file_$i"} || &error($text{'logging_efile'});
2010-10-17 14:32:41 -07:00
$in{"file_$i"} =~ /^\// ||
&error($text{'logging_efile2'});
2016-06-02 19:30:01 -07:00
my @fvals = ( $in{"file_$i"} );
2008-08-30 22:28:50 +00:00
if ($in{"vmode_$i"} == 1) {
push(@fvals, 'versions', 'unlimited');
}
elsif ($in{"vmode_$i"} == 2) {
$in{"ver_$i"} =~ /^\d+$/ ||
&error(&text('logging_ever', $in{"ver_$i"}));
push(@fvals, 'versions', $in{"ver_$i"});
}
if ($in{"smode_$i"}) {
$in{"size_$i"} =~ /^\d+[kmg]*$/i ||
&error(&text('logging_esize', $in{"size_$i"}));
push(@fvals, 'size', $in{"size_$i"});
}
push(@mems, { 'name' => 'file',
'values' => \@fvals });
2007-04-12 20:24:50 +00:00
}
2008-08-30 22:28:50 +00:00
elsif ($in{"to_$i"} == 1) {
push(@mems, { 'name' => 'syslog',
'values' => [ $in{"syslog_$i"} ] });
2007-04-12 20:24:50 +00:00
}
2008-08-30 22:28:50 +00:00
else {
push(@mems, { 'name' => 'null' });
2007-04-12 20:24:50 +00:00
}
2008-08-30 22:28:50 +00:00
if ($in{"sev_$i"} eq 'debug') {
push(@mems, { 'name' => 'severity',
'values' => [ 'debug', $in{"debug_$i"} ] });
}
elsif ($in{"sev_$i"}) {
push(@mems, { 'name' => 'severity',
'values' => [ $in{"sev_$i"} ] });
}
2016-06-02 19:30:01 -07:00
foreach my $p ('print-category', 'print-severity', 'print-time') {
2008-08-30 22:28:50 +00:00
push(@mems, { 'name' => $p,
'values' => [ $in{"$p-$i"} ] }) if ($in{"$p-$i"});
}
push(@channel, { 'name' => 'channel',
'values' => [ $cname ],
'type' => 1,
'members' => \@mems } );
2007-04-12 20:24:50 +00:00
}
2008-08-31 05:29:21 +00:00
@category = &find("category", $logging->{'members'}) if ($logging);
2007-04-12 20:24:50 +00:00
}
2008-08-30 22:28:50 +00:00
# Write out the logging section, creating if needed
2007-04-12 20:24:50 +00:00
if ($logging) {
&save_directive($logging, 'channel', \@channel, 1);
&save_directive($logging, 'category', [ ], 1);
&save_directive($logging, 'category', [ reverse(@category) ], 1);
}
else {
$logging = { 'name' => 'logging',
'type' => 1,
'members' => [ @channel, @category ] };
&save_directive(&get_config_parent(), 'logging', [ $logging ], 0);
}
&flush_file_lines();
&unlock_file(&make_chroot($config{'named_conf'}));
&webmin_log("logging", undef, undef, \%in);
&redirect("");