Handle hostnames with upper-case letters
[webmin.git] / fetchmail / save_cron.cgi
1 #!/usr/local/bin/perl
2 # save_cron.cgi
3 # Create, update or delete a cron job for fetchmail
4
5 require './fetchmail-lib.pl';
6 &foreign_require("cron", "cron-lib.pl");
7 $can_cron || &error($text{'cron_ecannot2'});
8 &error_setup($text{'cron_err'});
9 &ReadParse();
10
11 @jobs = &cron::list_cron_jobs();
12 ($job) = grep { $_->{'user'} eq $cron_user &&
13                 $_->{'command'} =~ /^$cron_cmd/ } @jobs;
14            
15 # Validate inputs
16 $cmd = $cron_cmd;
17 if ($in{'output'} == 0) {
18         $cmd .= " --null";
19         }
20 elsif ($in{'output'} == 1) {
21         $in{'file'} =~ /^\/.+$/ || &error($text{'cron_efile'});
22         $cmd .= " --file ".quotemeta($in{'file'});
23         }
24 elsif ($in{'output'} == 2) {
25         $in{'mail'} =~ /^\S+$/ || &error($text{'cron_efile'});
26         $cmd .= " --mail ".quotemeta($in{'mail'});
27         }
28 elsif ($in{'output'} == 3) {
29         $cmd .= " --output";
30         }
31 elsif ($in{'output'} == 4) {
32         $cmd .= " --owner";
33         }
34 if ($in{'errors'}) {
35         $cmd .= " --errors";
36         }
37 if ($cron_user eq "root" && $fetchmail_config) {
38         defined(getpwnam($in{'user'})) || &error($text{'cron_euser'});
39         $cmd .= " --user $in{'user'}";
40         }
41
42 if ($job && $in{'enabled'}) {
43         # Update cron job
44         $job->{'command'} = $cmd;
45         &cron::parse_times_input($job, \%in);
46         &lock_file(&cron::cron_file($job));
47         &cron::change_cron_job($job);
48         $what = "update";
49         }
50 elsif (!$job && $in{'enabled'}) {
51         # Create job
52         $job = { 'user' => $cron_user,
53                  'command' => $cmd,
54                  'active' => 1 };
55         &cron::parse_times_input($job, \%in);
56         &lock_file($cron_cmd);
57         &lock_file(&cron::cron_file($job));
58         &cron::create_cron_job($job);
59         $what = "create";
60         }
61 elsif ($job && !$in{'enabled'}) {
62         # Delete job
63         &lock_file(&cron::cron_file($job));
64         &cron::delete_cron_job($job);
65         $what = "delete";
66         }
67 &cron::create_wrapper($cron_cmd, $module_name, "check.pl");
68 &unlock_all_files();
69 &webmin_log($what, "cron");
70 &redirect("");
71
72