Handle hostnames with upper-case letters
[webmin.git] / init / mass_upstarts.cgi
1 #!/usr/local/bin/perl
2 # Start or stop a bunch of upstart services
3
4 require './init-lib.pl';
5 &ReadParse();
6 @sel = split(/\0/, $in{'d'});
7 @sel || &error($text{'mass_enone'});
8
9 $start = 1 if ($in{'start'} || $in{'addboot_start'});
10 $stop = 1 if ($in{'stop'} || $in{'delboot_stop'});
11 $restart = 1 if ($in{'restart'} || $in{'delboot_restart'});
12 $enable = 1 if ($in{'addboot'} || $in{'addboot_start'});
13 $disable = 1 if ($in{'delboot'} || $in{'delboot_stop'});
14
15 &ui_print_unbuffered_header(undef, $start || $enable ? $text{'mass_ustart'}
16                                           : $text{'mass_ustop'}, "");
17
18 if ($start || $stop || $restart) {
19         # Starting or stopping a bunch of services
20         $access{'bootup'} || &error($text{'ss_ecannot'});
21         foreach $s (@sel) {
22                 if ($start) {
23                         print &text('mass_ustarting', "<tt>$s</tt>"),"<p>\n";
24                         ($ok, $out) = &start_upstart_service($s);
25                         }
26                 elsif ($stop) {
27                         print &text('mass_ustopping', "<tt>$s</tt>"),"<p>\n";
28                         ($ok, $out) = &stop_upstart_service($s);
29                         }
30                 elsif ($restart) {
31                         print &text('mass_urestarting', "<tt>$s</tt>"),"<p>\n";
32                         ($ok, $out) = &restart_upstart_service($s);
33                         }
34                 print "<pre>$out</pre>";
35                 if (!$ok) {
36                         print $text{'mass_failed'},"<p>\n";
37                         }
38                 else {
39                         print $text{'mass_ok'},"<p>\n";
40                         }
41                 }
42         &webmin_log($start ? 'massstart' : $stop ? 'massstop' : 'massrestart',
43                     'upstart', join(" ", @sel));
44         }
45
46 if ($enable || $disable) {
47         # Enable or disable at boot
48         $access{'bootup'} == 1 || &error($text{'edit_ecannot'});
49         foreach $b (@sel) {
50                 if ($enable) {
51                         print &text('mass_uenable', "<tt>$b</tt>"),"<p>\n";
52                         &enable_at_boot($b);
53                         }
54                 else {
55                         print &text('mass_udisable', "<tt>$b</tt>"),"<p>\n";
56                         &disable_at_boot($b);
57                         }
58                 }
59         &webmin_log($enable ? 'massenable' : 'massdisable', 'upstart',
60                     join(" ", @sel));
61         }
62
63 if ($in{'return'}) {
64         &ui_print_footer("edit_upstart.cgi?name=".&urlize($in{'return'}),
65                          $text{'upstart_return'});
66         }
67 else {
68         &ui_print_footer("", $text{'index_return'});
69         }