boot.php3 4.27 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
24
include("defs.php3");
25
include_once("node_defs.php");
26 27 28 29 30 31 32 33

#
# No PAGEHEADER since we spit out a Location header later. See below.
# 

#
# Only known and logged in users can do this.
#
34 35 36
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
37 38

#
39
# Verify page arguments.
40
#
41 42 43 44 45 46
$optargs = OptionalPageArguments("experiment", PAGEARG_EXPERIMENT,
				 "node", PAGEARG_NODE,
				 "canceled", PAGEARG_BOOLEAN,
				 "confirmed", PAGEARG_BOOLEAN);

if (isset($experiment)) {
47 48
    if (! ($isadmin ||
	   $experiment->AccessCheck($this_user, $TB_EXPT_MODIFY))) {
49 50
	USERERROR("You do not have permission to reboot nodes in this ".
		  "experiment", 1);
51
    }
52 53
    $pid = $experiment->pid();
    $eid = $experiment->eid();
54
}
55
elseif (isset($node)) {
56 57
    if (! ($isadmin ||
	   $node->AccessCheck($this_user, $TB_NODEACCESS_REBOOT))) {
58
        USERERROR("You do not have permission to reboot this node", 1);
59
    }
60
    $node_id = $node->node_id();
61 62 63 64 65 66 67 68 69 70 71
}
else {
    USERERROR("Must specify a node or an experiment!", 1);
}

#
# We run this twice. The first time we are checking for a confirmation
# by putting up a form. The next time through the confirmation will be
# set. Or, the user can hit the cancel button, in which case we should
# probably redirect the browser back up a level.
#
72
if (isset($canceled) && $canceled) {
73 74 75 76 77 78 79 80 81 82
    PAGEHEADER("Reboot Nodes");
	
    echo "<center><h3><br>
          Operation canceled!
          </h3></center>\n";
    
    PAGEFOOTER();
    return;
}

83
if (!isset($confirmed)) {
84 85
    PAGEHEADER("Reboot Nodes");

86
    if (isset($node)) {
87 88 89 90 91
	echo "<center><h2><br>
              Are you <b>REALLY</b>
                sure you want to reboot node '$node_id?'
              </h2>\n";
	
92
	$node->Show(SHOWNODE_SHORT);
93 94
    }
    else {
95
	echo $experiment->PageHeader();
96 97

	echo "<center><font size=+2><br>
98
              Are you <b>REALLY</b>
99
                sure you want to reboot all nodes?
100
              </font>\n";
101

102
	$experiment->Show(1);
103 104
    }

105
    $url = CreateURL("boot", ((isset($node) ? $node : $experiment)));
106
    
107
    echo "<form action='$url' target=_blank method=post>";
108 109 110 111 112 113 114 115 116
    echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
    echo "</form>\n";
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

117
if (isset($node)) {
118 119
    $message = "$node_id was rebooted via the web interface by $uid\n";
    $subject = "Node Reboot: $node_id";
120 121
}
else {
122 123 124
    $message = "Nodes in $pid/$eid were rebooted via the web interface ".
	       "by $uid\n";
    $subject = "Nodes Rebooted: $pid/$eid";
125 126 127
}

#
128 129
# A cleanup function to keep the child from becoming a zombie, since
# the script is terminated, but the children are left to roam.
130
#
131 132 133 134 135 136 137 138 139 140 141 142 143
$fp = 0;

function SPEWCLEANUP()
{
    global $fp;

    if (connection_aborted() && $fp) {
	pclose($fp);
    }
    exit();
}
register_shutdown_function("SPEWCLEANUP");
ignore_user_abort(1);
144

145
if (isset($node)) {
146
    $fp = popen("$TBSUEXEC_PATH $uid nobody webnode_reboot -w $node_id",
147
		"r");
148 149
}
else {
150
    $fp = popen("$TBSUEXEC_PATH $uid nobody webnode_reboot -w -e $pid,$eid",
151 152 153 154
		"r");
}
if (! $fp) {
    USERERROR("Reboot failed!", 1);
155 156
}

157 158 159 160 161 162
header("Content-Type: text/plain");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
flush();

163
echo date("D M d G:i:s T");
164
echo "\n";
165 166 167 168 169
while (!feof($fp)) {
    $string = fgets($fp, 1024);
    echo "$string";
    flush();
}
170
echo date("D M d G:i:s T");
171
echo "\n";
172 173
pclose($fp);
$fp = 0;
174 175

?>