Handle hostnames with upper-case letters
[webmin.git] / init / mass_start_stop.cgi
1 #!/usr/local/bin/perl
2 # mass_start_stop.cgi
3 # Start or stop multiple actions at once
4
5 require './init-lib.pl';
6 &ReadParse();
7 @sel = split(/\0/, $in{'idx'});
8 @sel || &error($text{'mass_enone2'});
9
10 $start = 1 if ($in{'start'} || $in{'addboot_start'});
11 $stop = 1 if ($in{'stop'} || $in{'delboot_stop'});
12 $restart = 1 if ($in{'restart'});
13 $enable = 1 if ($in{'addboot'} || $in{'addboot_start'});
14 $disable = 1 if ($in{'delboot'} || $in{'delboot_stop'});
15
16 &ui_print_unbuffered_header(undef, $start || $enable ? $text{'mass_start'} :
17                                    $restart ? $text{'mass_restart'} :
18                                               $text{'mass_stop'}, "");
19
20 # In case the action was Webmin
21 $SIG{'TERM'} = 'IGNORE';
22
23 if ($start || $stop || $restart) {
24         # Starting or stopping a bunch of actions
25         &foreign_require("proc", "proc-lib.pl");
26         $access{'bootup'} || &error($text{'ss_ecannot'});
27
28         # build list of normal and broken actions
29         ($initrl) = &get_inittab_runlevel();
30         @iacts = &list_actions();
31         foreach $a (@iacts) {
32                 @ac = split(/\s+/, $a);
33                 push(@acts, $ac[0]);
34                 local $order = "9" x $config{'order_digits'};
35                 if ($ac[0] =~ /^\//) {
36                         push(@actsf, $ac[0]);
37                         }
38                 else {
39                         push(@actsf, "$config{'init_dir'}/$ac[0]");
40                         local @lvls = &action_levels(
41                                 $start || $restart ? 'S' : 'K', $ac[0]);
42                         foreach $lon (@lvls) {
43                                 local ($l, $o, $n) = split(/\s+/, $lon);
44                                 if ($l eq $initrl) {
45                                         $order = $o;
46                                         last;
47                                         }
48                                 }
49                         }
50                 push(@orders, $order);
51                 }
52
53         if ($start || $restart) {
54                 @sel = sort { $orders[$a] <=> $orders[$b] } @sel;
55                 }
56         else {
57                 @sel = sort { $orders[$b] <=> $orders[$a] } @sel;
58                 }
59         foreach $idx (@sel) {
60                 local $cmd = "$actsf[$idx] ".($start ? "start" :
61                                               $restart ? "restart" :
62                                                          "stop");
63                 print &text('ss_exec', "<tt>$cmd</tt>"),"<p>\n";
64                 print "<pre>";
65                 &foreign_call("proc", "safe_process_exec_logged", $cmd, 0, 0, STDOUT, undef, 1);
66                 print "</pre>\n";
67                 push(@selacts, $acts[$idx]);
68                 }
69         &webmin_log($start ? 'massstart' :
70                     $restart ? 'massrestart' : 'massstop', 'action',
71                     join(" ", @selacts));
72         }
73
74 if ($enable || $disable) {
75         # Enabling or disabling a bunch of actions
76         $access{'bootup'} == 1 || &error($text{'edit_ecannot'});
77         @iacts = &list_actions();
78         foreach $a (@iacts) {
79                 @ac = split(/\s+/, $a);
80                 push(@acts, $ac[0]);
81                 }
82         @toboot = map { $acts[$_] } @sel;
83         foreach $b (@toboot) {
84                 if ($b =~ /^\//) {
85                         &error(&text('mass_ebroken', $ac[0]));
86                         }
87                 }
88         if ($enable) {
89                 # Enable them all
90                 foreach $b (@toboot) {
91                         print &text('mass_enable', "<tt>$b</tt>"),"<p>\n";
92                         &enable_at_boot($b);
93                         }
94                 }
95         else {
96                 # Disable them all
97                 foreach $b (@toboot) {
98                         print &text('mass_disable', "<tt>$b</tt>"),"<p>\n";
99                         &disable_at_boot($b);
100                         }
101                 }
102         &webmin_log($enable ? 'massenable' : 'massdisable', 'action',
103                     join(" ", @toboot));
104         }
105
106 &ui_print_footer("", $text{'index_return'});
107