Handle hostnames with upper-case letters
[webmin.git] / status / save_sched.cgi
1 #!/usr/local/bin/perl
2 # save_sched.cgi
3 # Save scheduled monitoring options
4
5 require './status-lib.pl';
6 $access{'sched'} || &error($text{'sched_ecannot'});
7 &ReadParse();
8 &error_setup($text{'sched_err'});
9
10 # Parse and save inputs
11 $in{'email_def'} || $in{'email'} =~ /\S/ || &error($text{'sched_eemail'});
12 $config{'sched_email'} = $in{'email_def'} ? '' : $in{'email'};
13 if ($config{'pager_cmd'}) {
14         $config{'sched_pager'} = $in{'pager_def'} ? '' : $in{'pager'};
15         }
16 if ($in{'sms_def'}) {
17         delete($config{'sched_carrier'});
18         delete($config{'sched_sms'});
19         }
20 else {
21         $config{'sched_carrier'} = $in{'carrier'};
22         ($carrier) = grep { $_->{'id'} eq $in{'carrier'} }
23                           &list_sms_carriers();
24         if ($carrier->{'alpha'}) {
25                 $in{'sms'} =~ /^\S+$/ || &error($text{'sched_esmsname'});
26                 }
27         else {
28                 $in{'sms'} =~ /^\d+$/ || &error($text{'sched_esmsnumber'});
29                 }
30         $config{'sched_sms'} = $in{'sms'};
31         }
32 if ($in{'from_def'}) {
33         delete($config{'sched_from'});
34         }
35 else {
36         $in{'from'} =~ /^\S+$/ || &error($text{'sched_efrom'});
37         $config{'sched_from'} = $in{'from'};
38         }
39 if ($in{'smtp_def'}) {
40         if (!$in{'from_def'}) {
41                 &foreign_require("mailboxes");
42                 $err = &mailboxes::test_mail_system();
43                 $err && &error(&text('sched_eemailserver', $err));
44                 }
45         delete($config{'sched_smtp'});
46         }
47 else {
48         if (!$in{'from_def'}) {
49                 &to_ipaddress($in{'smtp'}) || &to_ip6address($in{'smtp'}) ||
50                         &error($text{'sched_esmtp'});
51                 }
52         $config{'sched_smtp'} = $in{'smtp'};
53         }
54 $config{'sched_mode'} = $in{'mode'};
55 $in{'int'} =~ /^\d+$/ || &error($text{'sched_eint'});
56 $config{'sched_int'} = $in{'int'};
57 $config{'sched_period'} = $in{'period'};
58 $in{'offset'} =~ /^\d+$/ || &error($text{'sched_eoffset'});
59 $config{'sched_offset'} = $in{'offset'};
60 $config{'sched_warn'} = $in{'warn'};
61 $config{'sched_single'} = $in{'single'};
62 @hours = split(/\0/, $in{'hours'});
63 @hours || &error($text{'sched_ehours'});
64 $config{'sched_hours'} = @hours == 24 ? '' : join(" ", @hours);
65 @days = split(/\0/, $in{'days'});
66 @days || &error($text{'sched_edays'});
67 $config{'sched_days'} = @days == 7 ? '' : join(" ", @days);
68 &lock_file("$module_config_directory/config");
69 &save_module_config();
70 &unlock_file("$module_config_directory/config");
71
72 # Setup or remove the cron job
73 &setup_cron_job();
74
75 &webmin_log("sched");
76 &redirect("");
77
78