forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshutdown.cgi
executable file
·67 lines (57 loc) · 1.81 KB
/
shutdown.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
#!/usr/local/bin/perl
# Shut down the servers, after asking for confirmation
require './cluster-shutdown-lib.pl';
&ReadParse();
$pfx = $in{'shut'} ? 'shut' : 'reboot';
$access{$pfx} || &error($text{$pfx.'_ecannot'});
@ids = split(/\0/, $in{'id'});
@ids || &error($text{$pfx.'_enone'});
@servers = &servers::list_servers();
# Setup error handler for down hosts
sub inst_error
{
$inst_error_msg = join("", @_);
}
&remote_error_setup(\&inst_error);
if ($in{'confirm'}) {
# Do it!
&ui_print_unbuffered_header(undef, $text{$pfx.'_title'}, "");
foreach $id (@ids) {
($server) = grep { $_->{'id'} eq $id } @servers;
next if (!$server);
print &text($pfx.'_doing', $server->{'host'}),"<br>\n";
$inst_error_msg = undef;
$iconfig = &remote_foreign_config($server->{'host'}, "init");
if ($inst_error_msg) {
print &text('shut_failed', $inst_error_msg),"<p>\n";
next;
}
&remote_foreign_require($server->{'host'}, "init",
"init-lib.pl");
$cmd = $pfx eq 'shut' ? $iconfig->{'shutdown_command'}
: $iconfig->{'reboot_command'};
$out = &remote_eval($server->{'host'}, "init",
"system('$cmd')");
print &text('shut_done'),"<p>\n";
}
&ui_print_footer("", $text{'index_return'});
}
else {
# Ask first
&ui_print_header(undef, $text{$pfx.'_title'}, "");
print &ui_form_start("shutdown.cgi", "post");
foreach $id (@ids) {
print &ui_hidden("id", $id);
($server) = grep { $_->{'id'} eq $id } @servers;
push(@names, $server->{'host'});
}
print &ui_hidden($pfx, 1);
print "<center>\n";
print "<b>",&text($pfx.'_rusure', scalar(@ids)),"</b> <p>\n";
print &ui_submit($text{'shut_ok'}, "confirm"),"<p>\n";
print "<b>",$text{'shut_sel'},"\n",
join(" ", map { "<tt>$_</tt>" } @names),"</b><p>\n";
print "</center>\n";
print &ui_form_end();
&ui_print_footer("", $text{'index_return'});
}