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