boot.php3 3.78 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2 3 4 5 6
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
include("defs.php3");
include("showstuff.php3");

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

#
# Only known and logged in users can do this.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

#
# Check to make sure a valid nodeid, *or* a valid experiment.
#
if (isset($pid) && strcmp($pid, "") &&
    isset($eid) && strcmp($eid, "")) {
    if (! TBValidExperiment($pid, $eid)) {
	USERERROR("$pid/$eid is not a valid experiment!", 1);
    }

    if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_MODIFY)) {
	USERERROR("You do not have permission to reboot nodes in ".
		  "experiment $exp_eid!", 1);
    }
    $nodemode = 0;
}
elseif (isset($node_id) && strcmp($node_id, "")) {
    if (! TBValidNodeName($node_id)) {
	USERERROR("$node_id is not a valid node name!", 1);
    }

    if (! TBNodeAccessCheck($uid, $node_id, $TB_NODEACCESS_REBOOT)) {
        USERERROR("You do not have permission to reboot $node_id!", 1);
    }
    $nodemode = 1;
}
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.
#
if ($canceled) {
    PAGEHEADER("Reboot Nodes");
	
    echo "<center><h3><br>
          Operation canceled!
          </h3></center>\n";
    
    PAGEFOOTER();
    return;
}

if (!$confirmed) {
    PAGEHEADER("Reboot Nodes");

    if ($nodemode) {
	echo "<center><h2><br>
              Are you <b>REALLY</b>
                sure you want to reboot node '$node_id?'
              </h2>\n";
	
	SHOWNODE($node_id);
    }
    else {
	echo "<center><h2><br>
              Are you <b>REALLY</b>
                sure you want to reboot all nodes in experiment $pid/$eid?
              </h2>\n";

	SHOWEXP($pid, $eid);
    }

    
    echo "<form action=boot.php3 target=_blank method=post>";
    if ($nodemode) {
	echo "<input type=hidden name=node_id value=$node_id>\n";
    }
    else {
	echo "<input type=hidden name=pid value=$pid>\n";
	echo "<input type=hidden name=eid value=$eid>\n";
    }
    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;
}

#
105
# For the audit message.
106
#
107
TBUserInfo($uid, $uid_name, $uid_email);
108 109

if ($nodemode) {
110 111
    $message = "$node_id was rebooted via the web interface by $uid\n";
    $subject = "Node Reboot: $node_id";
112 113
}
else {
114 115 116
    $message = "Nodes in $pid/$eid were rebooted via the web interface ".
	       "by $uid\n";
    $subject = "Nodes Rebooted: $pid/$eid";
117 118 119
}

#
120 121
# A cleanup function to keep the child from becoming a zombie, since
# the script is terminated, but the children are left to roam.
122
#
123 124 125 126 127 128 129 130 131 132 133 134 135
$fp = 0;

function SPEWCLEANUP()
{
    global $fp;

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

if ($nodemode) {
138 139
    $fp = popen("$TBSUEXEC_PATH $uid nobody webnodereboot -w $node_id",
		"r");
140 141
}
else {
142 143 144 145 146
    $fp = popen("$TBSUEXEC_PATH $uid nobody webnodereboot -w -e $pid,$eid",
		"r");
}
if (! $fp) {
    USERERROR("Reboot failed!", 1);
147 148 149 150 151 152 153
}

TBMAIL($TBMAIL_AUDIT,
       $subject, $message,
       "From: $uid_name <$uid_email>\n".
       "Errors-To: $TBMAIL_WWW");

154 155 156 157 158 159 160 161 162 163 164 165 166
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();

while (!feof($fp)) {
    $string = fgets($fp, 1024);
    echo "$string";
    flush();
}
pclose($fp);
$fp = 0;
167 168

?>