Handle hostnames with upper-case letters
[webmin.git] / logrotate / edit_log.cgi
1 #!/usr/local/bin/perl
2 # edit_log.cgi
3 # Show a form for creating or editing a log
4
5 require './logrotate-lib.pl';
6 &ReadParse();
7 $conf = &get_config();
8 if ($in{'global'}) {
9         &ui_print_header(undef, $text{'global_title'}, "", "global");
10         $lconf = $conf;
11         }
12 elsif ($in{'new'}) {
13         &ui_print_header(undef, $text{'edit_title2'}, "", "create");
14         }
15 else {
16         &ui_print_header(undef, $text{'edit_title1'}, "", "edit");
17         $log = $conf->[$in{'idx'}];
18         $lconf = $log->{'members'};
19         }
20
21 print &ui_form_start("save_log.cgi", "post");
22 print &ui_hidden("new", $in{'new'}),"\n";
23 print &ui_hidden("idx", $in{'idx'}),"\n";
24 print &ui_hidden("global", $in{'global'}),"\n";
25
26 if (!$in{'global'}) {
27         print &ui_table_start($text{'edit_header'}, "width=100%", 2);
28         print &ui_table_row($text{'edit_file'},
29                             &ui_textarea("file",
30                                 join("\n", @{$log->{'name'}}), 3, 60)." ".
31                             &file_chooser_button("file"));
32         }
33 else {
34         print &ui_table_start($text{'global_header'}, "width=100%", 2);
35         }
36
37 $period = &get_period($lconf);
38 $defperiod = &get_period($conf) if (!$in{'global'});
39 $dptext = $text{"period_".$defperiod} || $text{'period_never'};
40 print &ui_table_row($text{'edit_sched'},
41                     &ui_select("sched", $period,
42                                 [ [ '', &deftext($dptext)  ],
43                                   [ 'daily', $text{'period_daily'} ],
44                                   [ 'weekly', $text{'period_weekly'} ],
45                                   [ 'monthly', $text{'period_monthly'} ] ]));
46
47 $size = &find_value("size", $lconf);
48 print &ui_table_row($text{'edit_size'},
49                     &ui_opt_textbox("size", $size, 10,
50                                     &deftext(&find_default("size") ||
51                                              $text{'period_never'})).
52                     " ".$text{'period_bytes'});
53
54 print &ui_table_hr();
55
56 $rotate = &find_value("rotate", $lconf);
57 print &ui_table_row($text{'edit_rotate'},
58                     &ui_opt_textbox("rotate", $rotate, 5,
59                                     &deftext(&find_default("rotate"))));
60
61 &yesno_option("compress", "nocompress", $lconf);
62 &yesno_option("delaycompress", "nodelaycompress", $lconf);
63 &yesno_option("copytruncate", "nocopytruncate", $lconf);
64 &yesno_option("ifempty", "notifempty", $lconf);
65 &yesno_option("missingok", "nomissingok", $lconf);
66
67 print &ui_table_hr();
68
69 $create = &find_value("create", $lconf);
70 $nocreate = &find("nocreate", $lconf);
71 ($mode, $user, $group) = split(/\s+/, $create);
72 $dcr = &find_default("create");
73 @crinputs = ( "createmode", "createuser", "creategroup" );
74 print &ui_table_row($text{'edit_create'},
75     &ui_radio("create", defined($create) ? 2 : $nocreate ? 1 : 0,
76               [ [ 2, &text('edit_createas',
77                    &ui_textbox("createmode", $mode, 4, !defined($create)),
78                    &ui_user_textbox("createuser", $user, 0,
79                                     !defined($create)),
80                    &ui_group_textbox("creategroup", $group, 0,
81                                      !defined($create)))."<br>",
82                    &js_disable_inputs([ ], \@crinputs, "onClick") ],
83                 [ 1, $text{'edit_createno'}."<br>",
84                   &js_disable_inputs(\@crinputs, [ ], "onClick") ],
85                 [ 0, &deftext($dcr ne '' ? $dcr :
86                       defined($dcr) ? $text{'edit_createsame'} :
87                                 $text{'edit_createno'}),
88                   &js_disable_inputs(\@crinputs, [ ], "onClick") ] ]));
89
90 $olddir = &find_value("olddir", $lconf);
91 $noolddir = &find("noolddir", $lconf);
92 print &ui_table_row($text{'edit_olddir'},
93     &ui_radio("olddir", $olddir ? 2 : $noolddir ? 1 : 0,
94               [ [ 2, $text{'edit_olddirto'}." ".
95                      &ui_textbox("olddirto", $olddir, 30, !$olddir)." ".
96                      &file_chooser_button("olddirto", 1)."<br>",
97                   &js_disable_inputs([ ], [ "olddirto" ], "onClick") ],
98                 [ 1, $text{'edit_olddirsame'}."<br>",
99                   &js_disable_inputs([ "olddirto" ], [ ], "onClick") ],
100                 [ 0, &deftext(&find_default("olddir") ||
101                               $text{'edit_olddirsame'}),
102                   &js_disable_inputs([ "olddirto" ], [ ], "onClick") ] ]));
103
104 $ext = &find_value("extension", $lconf);
105 print &ui_table_row($text{'edit_ext'},
106     &ui_opt_textbox("ext", $ext, 10,
107                     &deftext(&find_default("ext"))));
108
109 print &ui_table_hr();
110
111 $mail = &find_value("mail", $lconf);
112 $nomail = &find("nomail", $lconf);
113 $mmode = $mail ? 2 : $nomail ? 1 : 0;
114 print &ui_table_row($text{'edit_mail'},
115             &ui_radio("mail", $mmode,
116                       [ [ 2, $text{'edit_mailto'}." ".
117                              &ui_textbox("mailto", $mail, 30, $mmode != 2).
118                              "<br>",
119                              &js_disable_inputs([ ], [ "mailto" ], "onClick") ],
120                         [ 1, $text{'edit_mailno'}."<br>",
121                           &js_disable_inputs([ "mailto" ], [ ], "onClick") ],
122                         [ 0, &deftext(&find_default("mail") ||
123                                       $text{'edit_mailno'}),
124                           &js_disable_inputs([ "mailto" ], [ ], "onClick") ] ]));
125
126 $mailfirst = &find("mailfirst", $lconf);
127 $maillast = &find("maillast", $lconf);
128 print &ui_table_row($text{'edit_mailfl'},
129                     &ui_radio("mailfirst", $mailfirst ? 2 : $maillast ? 1 : 0,
130                               [ [ 2, $text{'edit_mailfirst'}."<br>" ],
131                                 [ 1, $text{'edit_maillast'}."<br>" ],
132                                 [ 0, &deftext(defined(
133                                         &find_default("mailfirst")) ?
134                                                 $text{'edit_mailfirst'} :
135                                                 $text{'edit_maillast'}) ] ]));
136
137 if (&get_logrotate_version() < 3.6) {
138         $errors = &find_value("errors", $lconf);
139         print &ui_table_row($text{'edit_errors'},
140                             &ui_opt_textbox("errors", $errors, 30,
141                                     &deftext(&find_default("errors") ||
142                                              $text{'edit_errorsno'})."<br>",
143                                     $text{'edit_errorsto'}));
144         }
145
146 print &ui_table_hr();
147
148 $pre = &find_value("prerotate", $lconf);
149 print &ui_table_row($text{'edit_pre'},
150                     &ui_textarea("pre", $pre, 3, 60));
151
152 $post = &find_value("postrotate", $lconf);
153 print &ui_table_row($text{'edit_post'},
154                     &ui_textarea("post", $post, 3, 60));
155
156 if (&get_logrotate_version() >= 3.4) {
157         &yesno_option("sharedscripts", "nosharedscripts", $lconf);
158         }
159
160 print &ui_table_end();
161 if ($in{'global'}) {
162         print &ui_form_end([ [ 'save', $text{'save'} ] ], "100%");
163         }
164 elsif ($in{'new'}) {
165         print &ui_form_end([ [ 'create', $text{'create'} ] ], "100%");
166         }
167 else {
168         print &ui_form_end([ [ 'save', $text{'save'} ],
169                              [ 'now', $text{'edit_now'} ],
170                              [ 'delete', $text{'delete'} ] ], "100%");
171         }
172
173 &ui_print_footer("", $text{'index_return'});
174
175 # yesno_option(name1, name2, &conf)
176 sub yesno_option
177 {
178 local $y = &find($_[0], $_[2]);
179 local $n = &find($_[1], $_[2]);
180 local $yd = &find_default($_[0]);
181 local $nd = &find_default($_[1]);
182 print &ui_table_row($text{'edit_'.$_[0]},
183                     &ui_radio($_[0], $y ? 2 : $n ? 1 : 0,
184                               [ [ 2, $text{'yes'} ],
185                                 [ 1, $text{'no'} ],
186                                 [ 0, &deftext(defined($yd) ? $text{'yes'} : $text{'no'}) ] ]), 1);
187 }
188
189 # find_default(name, [global])
190 sub find_default
191 {
192 if ($in{'global'} || $_[1]) {
193         # Return global hard-coded default
194         return $global_default{$_[0]};
195         }
196 else {
197         # Look at global first
198         local $rv = &find_value($_[0], $conf);
199         return $rv if (defined($rv));
200         return &find_default($_[0], 1);
201         }
202 }
203
204 sub deftext
205 {
206 return $_[0] ? &text('edit_default', $_[0]) : $text{'default'};
207 }