endexp.php3 4.35 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5 6
# All rights reserved.
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
7
include("defs.php3");
8
include("showstuff.php3");
9

Leigh B. Stoller's avatar
Leigh B. Stoller committed
10 11 12
#
# Only known and logged in users can end experiments.
#
13
$uid = GETLOGIN();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
14
LOGGEDINORDIE($uid);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
15

Leigh B. Stoller's avatar
Leigh B. Stoller committed
16 17 18
#
# Must provide the EID!
# 
Leigh B. Stoller's avatar
Leigh B. Stoller committed
19 20 21 22 23 24 25
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
  USERERROR("The project ID was not provided!", 1);
}

if (!isset($eid) ||
    strcmp($eid, "") == 0) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
26 27 28
  USERERROR("The experiment ID was not provided!", 1);
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
29 30
$exp_eid = $eid;
$exp_pid = $pid;
31

32 33 34 35 36 37
# Canceled operation redirects back to showexp page. See below.
if ($canceled) {
    header("Location: showexp.php3?pid=$pid&eid=$eid");
    return;
}

38
#
39
# Standard Testbed Header, after checking for cancel above.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
40
#
41 42 43 44 45 46 47 48 49
PAGEHEADER("Terminate a Testbed Experiment");

#
# Check to make sure thats this is a valid PID/EID, while getting the
# experiment GID.
#
if (! TBExptGroup($exp_pid, $exp_eid, $exp_gid)) {
    USERERROR("The experiment $exp_eid is not a valid experiment ".
	      "in project $exp_pid.", 1);
50
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
51

52 53 54 55 56 57
$query_result =
    DBQueryFatal("select lockdown FROM experiments WHERE ".
		 "eid='$exp_eid' and pid='$exp_pid'");
$row       = mysql_fetch_array($query_result);
$lockdown  = $row["lockdown"];

58
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
59
# Verify permissions.
60
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
61 62
if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_DESTROY)) {
    USERERROR("You do not have permission to end experiment $exp_eid!", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
63 64
}

65 66 67 68
echo "<font size=+2>Experiment <b>".
     "<a href='showproject.php3?pid=$exp_pid'>$exp_pid</a>/".
     "<a href='showexp.php3?pid=$exp_pid&eid=$exp_eid'>$exp_eid</a>".
     "</b></font>\n";
69 70 71 72 73 74 75

# A locked down experiment means just that!
if ($lockdown) {
    echo "<br><br>\n";
    USERERROR("Cannot proceed; the experiment is locked down!", 1);
}
   
76 77 78
#
# 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
79 80
# set. Or, the user can hit the cancel button, in which case redirect the
# browser back up a level.
81 82
#
if (!$confirmed) {
83
    echo "<center><br><font size=+2>
84 85
          Are you <b>REALLY</b>
          sure you want to terminate Experiment '$exp_eid?'
86 87 88
          </font>\n";
    echo "<br>(This will <b>completely</b> destroy all trace of the
           experiment)<br><br>\n";
89 90

    SHOWEXP($exp_pid, $exp_eid, 1);
91
    
Leigh B. Stoller's avatar
Leigh B. Stoller committed
92
    echo "<form action='endexp.php3?pid=$exp_pid&eid=$exp_eid' method=post>";
93 94 95 96 97 98 99 100 101 102
    echo "<input type=hidden name=exp_pideid value=\"$exp_pideid\">\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;
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
103
#
104
# We need the unix gid for the project for running the scripts below.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
105
# Note usage of default group in project.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
106
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
107
TBGroupUnixInfo($exp_pid, $exp_gid, $unix_gid, $unix_name);
108 109

#
110 111 112 113 114
# We run a wrapper script that does all the work of terminating the
# experiment. 
#
#   tbstopit <pid> <eid>
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
115
echo "<center><br>";
116 117
echo "<h2>Starting experiment termination. Please wait a moment ...
      </h2></center>";
118 119

flush();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
120 121

#
122
# Run the backend script.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
123
#
124
$retval = SUEXEC($uid, "$exp_pid,$unix_gid", "webendexp $exp_pid $exp_eid",
125
		 SUEXEC_ACTION_IGNORE);
126

127 128 129 130
#
# Fatal Error. Report to the user, even though there is not much he can
# do with the error. Also reports to tbops.
# 
131
if ($retval < 0) {
132 133 134 135
    SUEXECERROR(SUEXEC_ACTION_DIE);
    #
    # Never returns ...
    #
Leigh B. Stoller's avatar
Leigh B. Stoller committed
136 137 138
    die("");
}

139
#
140 141
# Exit status >0 means the operation could not proceed.
# Exit status =0 means the experiment is terminating in the background.
142
#
143
echo "<br>\n";
144
if ($retval) {
145 146
    echo "<h3>Experiment termination could not proceed</h3>";
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";
147 148
}
else {
149
    echo "<h3>Your experiment is terminating!</h3><br>
150 151
          You will be notified via email when the experiment has been torn
	  down, and you can reuse the experiment name.
152 153
          This typically takes less than two minutes, depending on the
          number of nodes in the experiment.
154 155
          If you do not receive email notification within a reasonable amount
          of time, please contact $TBMAILADDR.\n";
156 157 158 159 160 161

    echo "<br><br>
          If you are the morbid type, you can watch the experiment die in
          <a target=_blank href=spewlogfile.php3?pid=$exp_pid&eid=$exp_eid>
          realtime</a>.\n";
    
162
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
163

164 165 166 167
#
# Standard Testbed Footer
# 
PAGEFOOTER();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
168
?>