Handle hostnames with upper-case letters
[webmin.git] / fetchmail / edit_cron.cgi
1 #!/usr/local/bin/perl
2 # edit_cron.cgi
3 # Show fetchmail cron configuration
4
5 require './fetchmail-lib.pl';
6 &foreign_require("cron", "cron-lib.pl");
7 $can_cron || &error($text{'cron_ecannot2'});
8 &ui_print_header(undef, $text{'cron_title'}, "");
9
10 print "$text{'cron_desc'}<p>\n";
11
12 # Get the cron job
13 @jobs = &cron::list_cron_jobs();
14 ($job) = grep { $_->{'user'} eq $cron_user &&
15                 $_->{'command'} =~ /^$cron_cmd/ } @jobs;
16
17 print &ui_form_start("save_cron.cgi");
18 print &ui_table_start($text{'cron_header'}, "width=100%", 2);
19
20 if ($job) {
21         if ($job->{'command'} =~ /--mail\s+(\S+)/) {
22                 $mail = `echo $1`;
23                 }
24         elsif ($job->{'command'} =~ /--file\s+(\S+)/) {
25                 $file = `echo $1`;
26                 }
27         elsif ($job->{'command'} =~ /--output/) {
28                 $output = 1;
29                 }
30         elsif ($job->{'command'} =~ /--owner/) {
31                 $owner = 1;
32                 }
33         if ($job->{'command'} =~ /--user\s+(\S+)/) {
34                 $user = $1;
35                 }
36         if ($job->{'command'} =~ /--errors/) {
37                 $errors = 1;
38                 }
39         }
40
41 print &ui_table_row($text{'cron_output'},
42                    &ui_radio("output", $owner ? 4 : $output ? 3 : $mail ? 2 : $file ? 1 : 0,
43                              [ [ 0, $text{'cron_throw'}."<br>" ],
44                                [ 3, $text{'cron_cron'}."<br>" ],
45                                [ 1, &text('cron_file',
46                                 &ui_textbox("file", $file, 30))."<br>" ],
47                                [ 2, &text('cron_mail',
48                                 &ui_textbox("mail", $mail, 30))."<br>" ],
49                                $fetchmail_config ? ( ) :
50                                  ( [ 4, $text{'cron_owner'}."<br>" ] ) ]));
51
52 print &ui_table_row($text{'cron_errors'},
53                     &ui_radio("errors", $errors ? 1 : 0,
54                               [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
55
56 if ($cron_user eq "root" && $fetchmail_config) {
57         print &ui_table_row($text{'cron_user'},
58                             &ui_user_textbox("user", $user || "root"));
59         }
60
61 print &ui_table_row($text{'cron_enabled'},
62                     &ui_radio("enabled", $job ? 1 : 0,
63                               [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
64
65 $job ||= { 'special' => 'hourly' };
66 print &ui_table_row(undef,
67         "<table>".
68         &capture_function_output(\&cron::show_times_input, $job).
69         "</table>");
70
71 print &ui_table_end();
72 print &ui_form_end([ [ undef, $text{'save'} ] ]);
73
74 &ui_print_footer("", $text{'index_return'});
75
76