panicbutton.php3 3.97 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1 2
<?php
#
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 B. Stoller's avatar
Leigh B. Stoller committed
23 24 25 26 27 28
#
include("defs.php3");

#
# Only known and logged in users.
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
32

33 34 35
# This will not return if its a sajax request.
include("showlogfile_sup.php3");

Leigh B. Stoller's avatar
Leigh B. Stoller committed
36
#
37 38 39 40
# Verify page arguments.
#
$reqargs = RequiredPageArguments("experiment", PAGEARG_EXPERIMENT);
$optargs = OptionalPageArguments("canceled",   PAGEARG_BOOLEAN,
Leigh B Stoller's avatar
Leigh B Stoller committed
41 42 43
				 "confirmed",  PAGEARG_BOOLEAN,
				 "level",      PAGEARG_INTEGER,
				 "clear",      PAGEARG_BOOLEAN);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
44

45 46 47 48
# Need these below.
$pid = $experiment->pid();
$eid = $experiment->eid();
$unix_gid = $experiment->UnixGID();
49 50
$project  = $experiment->Project();
$unix_pid = $project->unix_gid();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
51 52

# Canceled operation redirects back to showexp page. See below.
53 54
if (isset($canceled) && $canceled) {
    header("Location: " . CreateURL("showexp", $experiment));
Leigh B. Stoller's avatar
Leigh B. Stoller committed
55 56 57 58 59 60 61 62 63 64 65
    return;
}

#
# Standard Testbed Header, after checking for cancel above.
#
PAGEHEADER("Press the Panic Button!");

#
# Verify permissions.
#
66
if (!$experiment->AccessCheck($this_user, $TB_EXPT_MODIFY)) {
Leigh B Stoller's avatar
Leigh B Stoller committed
67 68 69 70 71 72 73 74 75 76 77 78 79
    USERERROR("You do not have permission to press/clear the panic button.", 1);
}

if (isset($level)) {
    if ($level < 1 || $level > 2) {
	USERERROR("Improper level argument", 1);
    }
}
else {
    $level = 1;
}
if (!isset($clear)) {
    $clear = 0;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
80 81
}

82 83
echo $experiment->PageHeader();
echo "<br>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
84 85 86 87 88 89 90
    
#
# 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 redirect the
# browser back up a level.
#
91 92
if (!isset($confirmed)) {
    echo "<center><h3><br>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
93
          Are you <b>REALLY</b>
Leigh B Stoller's avatar
Leigh B Stoller committed
94 95
          sure you want to " . ($clear ? "clear" : "press") .
	  " the panic button for Experiment '$eid?'
96 97 98
          </h3>\n";

    $experiment->Show(1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
99

100
    $url = CreateURL("panicbutton", $experiment);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
101
    
102
    echo "<form action='$url' method=post>";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
103 104
    echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
105 106 107 108
    echo "<b><input type=hidden name=level value=$level></b>\n";
    if ($clear) {
	echo "<b><input type=hidden name=clear value=$clear></b>\n";
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
109 110 111 112 113 114 115 116 117 118
    echo "</form>\n";
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

#
# We run a wrapper script that does all the work.
#
Leigh B Stoller's avatar
Leigh B Stoller committed
119 120 121 122 123 124
if ($clear) {
    $opt = "-r";
}
else {
    $opt = "-l $level";
}
125
$retval = SUEXEC($uid, "$unix_pid,$unix_gid", "webpanic -w $opt $pid $eid",
Leigh B. Stoller's avatar
Leigh B. Stoller committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
		 SUEXEC_ACTION_IGNORE);

#
# Fatal Error. Report to the user, even though there is not much he can
# do with the error. Also reports to tbops.
# 
if ($retval < 0) {
    SUEXECERROR(SUEXEC_ACTION_DIE);
    #
    # Never returns ...
    #
    die("");
}

#
# Exit status >0 means the operation could not proceed.
# Exit status =0 means the experiment is terminating in the background.
#
if ($retval) {
    echo "<h3>Panic Button failure</h3>";
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";
}
else {
Leigh B Stoller's avatar
Leigh B Stoller committed
149
    if ($clear) {
150
	echo "<h3>Clearing the panic button!</h3>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
151 152
    }
    else {
153
	echo "<h3>Pressing the panic button!</h3>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
154
    }
155
    STARTLOG($experiment);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
156 157 158 159 160 161 162
}

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>