Handle hostnames with upper-case letters
[webmin.git] / cron / edit_cron.cgi
1 #!/usr/local/bin/perl
2 # edit_cron.cgi
3 # Edit an existing or new cron job
4
5 require './cron-lib.pl';
6 &ReadParse();
7 @jobs = &list_cron_jobs();
8
9 if (!$in{'new'}) {
10         $job = $jobs[$in{'idx'}];
11         &can_edit_user(\%access, $job->{'user'}) ||
12                 &error($text{'edit_ecannot'});
13         &ui_print_header(undef, $text{'edit_title'}, "");
14         }
15 else {
16         &ui_print_header(undef, $text{'create_title'}, "");
17         if (defined($in{'clone'})) {
18                 # Default to clone source
19                 $clone = $jobs[$in{'clone'}];
20                 $job = { %$clone };
21                 }
22         elsif ($config{'vixie_cron'}) {
23                 # Default to hourly, using @ format
24                 $job = { 'special' => 'hourly',
25                          'active' => 1 };
26                 }
27         else {
28                 # Default to hourly, using standard notation
29                 $job = { 'mins' => '0',
30                          'hours' => '*',
31                          'days' => '*',
32                          'months' => '*',
33                          'weekdays' => '*',
34                          'active' => 1 };
35                 }
36         }
37
38 print &ui_form_start("save_cron.cgi");
39 print &ui_hidden("new", $in{'new'});
40 print &ui_hidden("idx", $in{'idx'});
41 print &ui_table_start($text{'edit_details'}, "width=100%", 2);
42
43 if (&supports_users()) {
44         # Allow selection of user
45         if ($access{'mode'} == 1) {
46                 $usel = &ui_select("user", $job->{'user'},
47                                    [ split(/\s+/, $access{'users'}) ]);
48                 }
49         elsif ($access{'mode'} == 3) {
50                 $usel = "<tt>$remote_user</tt>";
51                 print &ui_hidden("user", $remote_user);
52                 }
53         else {
54                 $usel = &ui_user_textbox("user", $job->{'user'});
55                 }
56         print &ui_table_row($text{'edit_user'}, $usel);
57         }
58
59 # Is job active?
60 print &ui_table_row($text{'edit_active'},
61         &ui_yesno_radio("active", $job->{'active'} ? 1 : 0));
62
63 &convert_comment($job);
64 $rpd = &is_run_parts($job->{'command'});
65 if ($rpd) {
66         # run-parts command.. just show scripts that will be run
67         print &ui_table_row($text{'edit_commands'},
68                 "<tt>".join("<br>",&expand_run_parts($rpd))."</tt>");
69         print &ui_hidden("cmd", $job->{'command'});
70         }
71 elsif (!$access{'command'}) {
72         # Just show command, which cannot be edited
73         print &ui_table_row($text{'edit_commands'},
74                 "<tt>".&html_escape($job->{'command'})."</tt>");
75         }
76 else {
77         # Normal cron job.. can edit command
78         &convert_range($job);
79         $rangeable = 1;
80         ($command, $input) = &extract_input($job->{'command'});
81         @lines = split(/%/, $input);
82         print &ui_table_row($text{'edit_command'},
83                 &ui_textbox("cmd", $command, 60));
84
85         if ($config{'cron_input'}) {
86                 print &ui_table_row($text{'edit_input'},
87                         &ui_textarea("input", join("\n" , @lines), 3, 50));
88                 }
89         }
90
91 # Show comment
92 print &ui_table_row($text{'edit_comment'},
93         &ui_textbox("comment", $job->{'comment'}, 60));
94
95 print &ui_table_end();
96
97 # Show times and days to run
98 print &ui_table_start($text{'edit_when'}, "width=100%", 2);
99 print &ui_table_row(undef, "<table border width=100%>".
100                            &capture_function_output(\&show_times_input, $job).
101                            "</table>", 2);
102 print &ui_table_end();
103
104 if ($rangeable) {
105         # Show date range to run
106         print &ui_table_start($text{'edit_range'}, "width=100%", 2);
107         print &ui_table_row(undef,
108                 &capture_function_output(\&show_range_input, $job), 2);
109         print &ui_table_end();
110         }
111
112 if (!$in{'new'}) {
113         print "<table><tr>\n";
114
115         # Save button
116         print "<td>",&ui_submit($text{'save'}),"</td>\n";
117         print "<td>",&ui_submit($text{'edit_saverun'}, 'saverun'),"</td>\n";
118         print &ui_form_end();
119
120         # Run button
121         if (!$rpd) {
122                 print &ui_form_start("exec_cron.cgi");
123                 print &ui_hidden("idx", $in{'idx'});
124                 print "<td>",&ui_submit($text{'edit_run'}),"</td>\n";
125                 print &ui_form_end();
126                 }
127
128         # Clone button
129         print &ui_form_start("edit_cron.cgi");
130         print &ui_hidden("clone", $in{'idx'});
131         print &ui_hidden("new", 1);
132         print "<td>",&ui_submit($text{'edit_clone'}),"</td>\n";
133         print &ui_form_end();
134
135         # Delete button
136         if ($access{'delete'}) {
137                 print &ui_form_start("delete_cron.cgi");
138                 print &ui_hidden("idx", $in{'idx'});
139                 print "<td>",&ui_submit($text{'delete'}),"</td>\n";
140                 print &ui_form_end();
141                 }
142         print "</tr></table>\n";
143         }
144 else {
145         print &ui_form_end([ [ undef, $text{'create'} ] ]);
146         }
147
148 &ui_print_footer("", $text{'index_return'});
149