Handle hostnames with upper-case letters
[webmin.git] / syslog / edit_log.cgi
1 #!/usr/local/bin/perl
2 # edit_log.cgi
3 # Display a form for editing or creating a new log destination
4
5 require './syslog-lib.pl';
6 &ReadParse();
7 $access{'noedit'} && &error($text{'edit_ecannot'});
8 $access{'syslog'} || &error($text{'edit_ecannot'});
9 $conf = &get_config();
10 if ($in{'new'}) {
11         &ui_print_header(undef, $text{'create_title'}, "");
12         $log = { 'active' => '1',
13                  'sync' => 1,
14                  'file' => -d '/var/log' ? '/var/log/' :
15                            -d '/var/adm' ? '/var/adm/' : undef };
16         }
17 else {
18         &ui_print_header(undef, $text{'edit_title'}, "");
19         $log = $conf->[$in{'idx'}];
20         &can_edit_log($log) || &error($text{'edit_ecannot2'});
21         }
22
23 # Log destination section
24 print &ui_form_start("save_log.cgi");
25 print &ui_hidden("new", $in{'new'});
26 print &ui_hidden("idx", $in{'idx'});
27 print &ui_table_start($text{'edit_header1'}, "width=100%", 2);
28
29 # Log destination, starting with file
30 @dopts = ( [ 0, $text{'edit_file'},
31              &ui_textbox("file", $log->{'file'}, 40)." ".
32              &file_chooser_button("file")." ".
33              ($config{'sync'} ? "<br>".&ui_checkbox("sync", 1,
34                                 $text{'edit_sync'}, $log->{'sync'}) : "") ]);
35
36 # Named pipe
37 if ($config{'pipe'} == 1) {
38         push(@dopts, [ 1, $text{'edit_pipe'},
39                        &ui_textbox("pipe", $log->{'pipe'}, 40)." ".
40                        &file_chooser_button("pipe") ]);
41         }
42 elsif ($config{'pipe'} == 2) {
43         push(@dopts, [ 1, $text{'edit_pipe2'},
44                        &ui_textbox("pipe", $log->{'pipe'}, 40) ]);
45         }
46
47 # Socket file
48 if ($config{'socket'}) {
49         push(@dopts, [ 5, $text{'edit_socket'},
50                        &ui_textbox("socket", $log->{'socket'}, 40)." ".
51                        &file_chooser_button("socket") ]);
52         }
53
54 # Send to users
55 push(@dopts, [ 3, $text{'edit_users'},
56                &ui_textbox("users", join(" ", @{$log->{'users'}}), 40)." ".
57                &user_chooser_button("users", 1) ]);
58
59 # All users
60 push(@dopts, [ 4, $text{'edit_allusers'} ]);
61
62 # Remote host
63 push(@dopts, [ 2, $text{'edit_host'},
64                &ui_textbox("host", $log->{'host'}, 30) ]);
65
66 print &ui_table_row($text{'edit_logto'},
67         &ui_radio_table("mode", $log->{'file'} ? 0 :
68                                 $log->{'pipe'} ? 1 :
69                                 $log->{'socket'} ? 5 :
70                                 $log->{'host'} ? 2 :
71                                 $log->{'users'} ? 3 :
72                                 $log->{'all'} ? 4 : -1, \@dopts));
73
74 # Log active?
75 print &ui_table_row($text{'edit_active'},
76         &ui_yesno_radio("active", $log->{'active'}));
77
78 if ($config{'tags'}) {
79         # Tag name
80         print &ui_table_row($text{'edit_tag'},
81             &ui_select("tag", $log->{'section'}->{'tag'},
82                 [ map { [ $_->{'index'},
83                           $_->{'tag'} eq '*' ? $text{'all'} : $_->{'tag'} ] }
84                       grep { $_->{'tag'} } @$conf ]));
85         }
86
87 print &ui_table_end();
88
89 # Log selection section
90 print &ui_table_start($text{'edit_header2'}, "width=100%", 2);
91
92 @facil = split(/\s+/, $config{'facilities'});
93 $table = &ui_columns_start([ $text{'edit_facil'}, $text{'edit_pri'} ], 100);
94 $i = 0;
95 foreach $s (@{$log->{'sel'}}, ".none") {
96         ($f, $p) = split(/\./, $s);
97         $p =~ s/warn$/warning/;
98         $p =~ s/panic$/emerg/;
99         $p =~ s/error$/err/;
100
101         # Facility column
102         local $facil;
103         $facil .= &ui_radio("fmode_$i", $f =~ /,/ ? 1 : 0,
104            [ [ 0, &ui_select("facil_$i", $f =~ /,/ ? undef : $f,
105                      [ [ undef, '&nbsp;' ],
106                        [ '*', $text{'edit_all'} ],
107                        @facil ], 1, 0, 1) ],
108              [ 1, $text{'edit_many'}." ".
109                   &ui_textbox("facils_$i",
110                         $f =~ /,/ ? join(" ", split(/,/, $f)) : '', 25) ] ]);
111
112         # Priorities range selector
113         if ($config{'pri_dir'} == 1) {
114                 # Linux style
115                 $psel = &ui_select("pdir_$i",
116                     $p eq '*' || $p eq 'none' ? '' :
117                       $p =~ /^=/ ? '=' :
118                       $p =~ /^![^=]/ ? '!' :
119                       $p =~ /^!=/ ? '!=' : '',
120                     [ [ '', $text{'edit_pdir0'} ],
121                       [ '=', $text{'edit_pdir1'} ],
122                       [ '!', $text{'edit_pdir2'} ],
123                       [ '!=', $text{'edit_pdir3'} ] ]);
124                 $p =~ s/^[!=]*//;
125                 }
126         elsif ($config{'pri_dir'} == 2) {
127                 # FreeBSD style
128                 local $pfx = $p =~ /^([<=>]+)/ ? $1 : undef;
129                 $psel = &ui_select("pdir_$i",
130                     $p eq '*' || $p eq 'none' ||
131                       $pfx eq '>=' || $pfx eq '=>' || !$pfx ? '' :
132                     $pfx eq '<=' || $pfx eq '=<' ? '<=' :
133                     $pfx eq '<>' || $pfx eq '><' ? '<>' : $pfx,
134                     [ [ '', '&gt;=' ],
135                       [ '>', '&gt;' ],
136                       [ '<=', '&lt;=' ],
137                       [ '<', '&lt;' ],
138                       [ '<>', '&lt;&gt;' ] ], 1, 0, 1);
139                 $p =~ s/^[<=>]*//;
140                 }
141         else {
142                 # No range selection allowed
143                 $psel = $text{'edit_pdir0'};
144                 }
145
146         # Priorities column
147         local $pri;
148         local $pmode = $p eq 'none' ? 0 : $p eq '*' ? 1 : 2;
149         $pri .= &ui_radio("pmode_$i", $pmode,
150            [ [ 0, $text{'edit_none'} ],
151              $config{'pri_all'} ? ( [ 1, $text{'edit_all'} ] ) : ( ),
152              [ 2, $psel ] ]);
153
154         # Priority menu
155         local $selpri;
156         foreach $pr (&list_priorities()) {
157                 $selpri = $pr if ($p =~ /$pr/);
158                 }
159         $pri .= &ui_select("pri_$i", $selpri,
160            [ $p eq '*' || $p eq 'none' ? ( '' ) : ( ),
161              &list_priorities() ], 1, 0, 1);
162
163         $table .= &ui_columns_row([ $facil, $pri ]);
164         $i++;
165         }
166 $table .= &ui_columns_end();
167 print &ui_table_row(undef, $table, 2);
168 print &ui_table_end();
169
170 @buts = ( [ undef, $text{'save'} ] );
171 if (!$in{'new'}) {
172         if ($log->{'file'} && -f $log->{'file'}) {
173                 push(@buts, [ 'view', $text{'edit_view'} ]);
174                 }
175         push(@buts, [ 'delete', $text{'delete'} ]);
176         }
177 print &ui_form_end(\@buts);
178
179 &ui_print_footer("", $text{'index_return'});
180