Handle hostnames with upper-case letters
[webmin.git] / bind8 / conf_logging.cgi
1 #!/usr/local/bin/perl
2 # conf_logging.cgi
3 # Display global logging options
4
5 require './bind8-lib.pl';
6 $access{'defaults'} || &error($text{'logging_ecannot'});
7 &ui_print_header(undef, $text{'logging_title'}, "",
8                  undef, undef, undef, undef, &restart_links());
9 &ReadParse();
10 $conf = &get_config();
11 $logging = &find("logging", $conf);
12 $mems = $logging ? $logging->{'members'} : [ ];
13
14 # Start of tabs for channels and categories
15 @tabs = ( [ "chans", $text{'logging_chans'}, "conf_logging.cgi?mode=chans" ],
16           [ "cats", $text{'logging_cats'}, "conf_logging.cgi?mode=cats" ] );
17 print &ui_tabs_start(\@tabs, "mode", $in{'mode'} || "chans", 1);
18
19 print &ui_tabs_start_tab("mode", "chans");
20 print $text{'logging_chansdesc'},"<p>\n";
21
22 # Add default channels to table
23 @table = ( );
24 @defchans = ( { 'name' => 'default_syslog',
25                 'syslog' => 'daemon',
26                 'severity' => 'info' },
27               { 'name' => 'default_debug',
28                 'file' => 'named.run',
29                 'severity' => 'dynamic' },
30               { 'name' => 'default_stderr',
31                 'fd' => 'stderr',
32                 'severity' => 'info' },
33               { 'name' => 'null',
34                 'null' => 1 } );
35 foreach $c (@defchans) {
36         push(@table, [
37                 $c->{'name'},
38                 $c->{'syslog'} ? $c->{'syslog'} :
39                 $c->{'file'} ? $text{'logging_file'}.
40                                " <tt>".$c->{'file'}."</tt>" :
41                 $c->{'fd'} ? $text{'logging_fd'}." <tt>".$c->{'fd'}."</tt>" :
42                              $text{'logging_null'},
43                 $c->{'severity'} || "<i>$text{'logging_any'}</i>",
44                 "", "", "",
45                 ]);
46         }
47
48 # Add user-defined channels
49 # XXX
50 @chans = &find("channel", $mems);
51 @channames = ( (map { $_->{'value'} } @chans) ,
52                'default_syslog', 'default_debug', 'default_stderr', 'null' );
53 push(@chans, { });
54 for($i=0; $i<@chans; $i++) {
55         $cmems = $chans[$i]->{'members'};
56         $file = &find("file", $cmems);
57         $filestr = $file ? join(" ", @{$file->{'values'}}) : "";
58         $syslog = &find_value("syslog", $cmems);
59         $null = &find("null", $cmems);
60         $stderr = &find("stderr", $cmems);
61         my @cols;
62
63         # Channel name
64         push(@cols, &ui_textbox("cname_$i", $chans[$i]->{'value'}, 10));
65
66         # Log destination
67         my @dests;
68         $to = $file ? 0 : $syslog ? 1 : $stderr ? 3 : $null ? 2 : 0;
69         push(@dests, [ 0, $text{'logging_file'},
70                        &ui_filebox("file_$i", $file->{'value'}, 40) ]);
71         push(@dests, [ 1, $text{'logging_syslog'},
72                        &ui_select("syslog_$i", $syslog,
73                                   \@syslog_levels, 1, 0, $syslog ? 1 : 0) ]);
74         push(@dests, [ 3, $text{'logging_stderr'} ]);
75         push(@dests, [ 2, $text{'logging_null'} ]);
76         push(@cols, &ui_radio_table("to_$i", $to, \@dests));
77
78         # Severity
79         $sev = &find("severity", $cmems);
80         push(@cols, &ui_select("sev_$i", $sev->{'value'},
81                 [ [ "", "&nbsp;" ],
82                   map { [ $_, $_ eq 'debug' ? $text{'logging_debug'} :
83                               $_ eq 'dynamic' ? $text{'logging_dyn'} : $_ ] }
84                       @severities ],
85                 1, 0, 0, 0,
86                 "onChange='form.debug_$i.disabled = form.sev_$i.value != \"debug\"'"
87                 )." ".
88                 &ui_textbox("debug_$i", $sev->{'value'} eq 'debug' ?
89                                            $sev->{'values'}->[1] : "", 5,
90                             $sev->{'value'} ne "debug"));
91
92         # Log category, severity and time
93         push(@cols, &yes_no_default("print-category-$i",
94                         &find_value("print-category", $cmems)));
95         push(@cols, &yes_no_default("print-severity-$i",
96                         &find_value("print-severity", $cmems)));
97
98         push(@cols, &yes_no_default("print-time-$i",
99                         &find_value("print-time", $cmems)));
100
101         push(@table, \@cols);
102         }
103
104 # Output the channels table
105 print &ui_form_columns_table(
106         "save_logging.cgi",
107         [ [ undef, $text{'save'} ] ],
108         0,
109         undef,
110         [ [ 'mode', 'chans' ] ],
111         [ $text{'logging_cname'}, $text{'logging_to'}, $text{'logging_sev'},
112           $text{'logging_pcat2'}, $text{'logging_psev2'},
113           $text{'logging_ptime2'} ],
114         100,
115         \@table,
116         undef,
117         1);
118
119 print &ui_tabs_end_tab("mode", "chans");
120
121 # Start of categories tab
122 print &ui_tabs_start_tab("mode", "cats");
123 print $text{'logging_catsdesc'},"<p>\n";
124
125 # Build table of categories
126 @table = ( );
127 @cats = ( &find("category", $mems), { } );
128 for($i=0; $i<@cats; $i++) {
129         my %cchan;
130         foreach $c (@{$cats[$i]->{'members'}}) {
131                 $cchan{$c->{'name'}}++;
132                 }
133         push(@table, [
134                 &ui_select("cat_$i", $cats[$i]->{'value'},
135                            [ [ "", "&nbsp;" ], @cat_list ],
136                            1, 0, $cats[$i]->{'value'} ? 1 : 0),
137                 join(" ", map { &ui_checkbox("cchan_$i", $_, $_, $cchan{$_}) }
138                               @channames)
139                 ]);
140         }
141
142 # Show the table
143 print &ui_form_columns_table(
144         "save_logging.cgi",
145         [ [ undef, $text{'save'} ] ],
146         0,
147         undef,
148         [ [ 'mode', 'cats' ] ],
149         [ $text{'logging_cat'}, $text{'logging_cchans'} ],
150         100,
151         \@table,
152         undef,
153         1);
154
155 print &ui_tabs_end_tab("mode", "cats");
156 print &ui_tabs_end(1);
157
158 &ui_print_footer("", $text{'index_return'});
159
160 # yes_no_default(name, value)
161 sub yes_no_default
162 {
163 my ($n, $v) = @_;
164 return &ui_select($n, lc($v), [ [ '', $text{'default'} ],
165                                 [ 'yes', $text{'yes'} ],
166                                 [ 'no', $text{'no'} ] ]);
167 }
168