Handle hostnames with upper-case letters
[webmin.git] / bind8 / save_logging.cgi
1 #!/usr/local/bin/perl
2 # save_logging.cgi
3 # Save global logging options
4
5 require './bind8-lib.pl';
6 $access{'defaults'} || &error($text{'logging_ecannot'});
7 &error_setup($text{'files_err'});
8 &ReadParse();
9
10 &lock_file(&make_chroot($config{'named_conf'}));
11 $conf = &get_config();
12 $logging = &find("logging", $conf);
13
14 if ($in{'mode'} eq 'cats') {
15         # Save categories
16         for($i=0; defined($cat = $in{"cat_$i"}); $i++) {
17                 next if (!$cat);
18                 @cchan = split(/\0/, $in{"cchan_$i"});
19                 push(@category, { 'name' => 'category',
20                                   'values' => [ $cat ],
21                                   'type' => 1,
22                                   'members' =>
23                                         [ map { { 'name' => $_ } } @cchan ] });
24                 }
25         @channel = &find("channel", $logging->{'members'}) if ($logging);
26         }
27 else {
28         # Save channels
29         for($i=0; defined($cname = $in{"cname_$i"}); $i++) {
30                 next if (!$cname);
31                 $cname =~ /^\S+$/ || &error(&text('logging_ename', $cname));
32                 local @mems;
33                 if ($in{"to_$i"} == 0) {
34                         $in{"file_$i"} || &error($text{'logging_efile'});
35                         $in{"file_$i"} =~ /^\// ||
36                                 &error($text{'logging_efile2'});
37                         local @fvals = ( $in{"file_$i"} );
38                         if ($in{"vmode_$i"} == 1) {
39                                 push(@fvals, 'versions', 'unlimited');
40                                 }
41                         elsif ($in{"vmode_$i"} == 2) {
42                                 $in{"ver_$i"} =~ /^\d+$/ ||
43                                         &error(&text('logging_ever', $in{"ver_$i"}));
44                                 push(@fvals, 'versions', $in{"ver_$i"});
45                                 }
46                         if ($in{"smode_$i"}) {
47                                 $in{"size_$i"} =~ /^\d+[kmg]*$/i ||
48                                         &error(&text('logging_esize', $in{"size_$i"}));
49                                 push(@fvals, 'size', $in{"size_$i"});
50                                 }
51                         push(@mems, { 'name' => 'file',
52                                       'values' => \@fvals });
53                         }
54                 elsif ($in{"to_$i"} == 1) {
55                         push(@mems, { 'name' => 'syslog',
56                                       'values' => [ $in{"syslog_$i"} ] });
57                         }
58                 else {
59                         push(@mems, { 'name' => 'null' });
60                         }
61                 if ($in{"sev_$i"} eq 'debug') {
62                         push(@mems, { 'name' => 'severity',
63                                       'values' => [ 'debug', $in{"debug_$i"} ] });
64                         }
65                 elsif ($in{"sev_$i"}) {
66                         push(@mems, { 'name' => 'severity',
67                                       'values' => [ $in{"sev_$i"} ] });
68                         }
69                 foreach $p ('print-category', 'print-severity', 'print-time') {
70                         push(@mems, { 'name' => $p,
71                                       'values' => [ $in{"$p-$i"} ] }) if ($in{"$p-$i"});
72                         }
73                 push(@channel, { 'name' => 'channel',
74                                  'values' => [ $cname ],
75                                  'type' => 1,
76                                  'members' => \@mems } );
77                 }
78         @category = &find("category", $logging->{'members'}) if ($logging);
79         }
80
81 # Write out the logging section, creating if needed
82 if ($logging) {
83         &save_directive($logging, 'channel', \@channel, 1);
84         &save_directive($logging, 'category', [ ], 1);
85         &save_directive($logging, 'category', [ reverse(@category) ], 1);
86         }
87 else {
88         $logging = { 'name' => 'logging',
89                      'type' => 1,
90                      'members' => [ @channel, @category ] };
91         &save_directive(&get_config_parent(), 'logging', [ $logging ], 0);
92         }
93 &flush_file_lines();
94 &unlock_file(&make_chroot($config{'named_conf'}));
95 &webmin_log("logging", undef, undef, \%in);
96 &redirect("");
97