showexp.php3 8 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-2003 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");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
9

10
11
12
13
14
#
# Standard Testbed Header
#
PAGEHEADER("Show Experiment Information");

15
16
17
#
# Only known and logged in users can end experiments.
#
18
$uid = GETLOGIN();
19
LOGGEDINORDIE($uid);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
20
21

#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
22
# Verify page arguments.
23
# 
Leigh B. Stoller's avatar
Leigh B. Stoller committed
24
25
26
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
    USERERROR("You must provide a Project ID.", 1);
27
28
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
29
30
31
32
33
34
if (!isset($eid) ||
    strcmp($eid, "") == 0) {
    USERERROR("You must provide an Experiment ID.", 1);
}
$exp_eid = $eid;
$exp_pid = $pid;
35

Leigh B. Stoller's avatar
Leigh B. Stoller committed
36
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
37
# Check to make sure this is a valid PID/EID tuple.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
38
#
39
if (! TBValidExperiment($exp_pid, $exp_eid)) {
40
41
  USERERROR("The experiment $exp_eid is not a valid experiment ".
            "in project $exp_pid.", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
42
43
}

44
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
45
# Verify Permission.
46
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
47
48
if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_READINFO)) {
    USERERROR("You do not have permission to view experiment $exp_eid!", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
49
50
}

51
$expindex = TBExptIndex($exp_pid, $exp_eid);
52
$expstate = TBExptState($exp_pid, $exp_eid);
Chad Barb's avatar
   
Chad Barb committed
53

Chad Barb's avatar
   
Chad Barb committed
54
echo "<font size=+2>Experiment <b>".
Chad Barb's avatar
   
Chad Barb committed
55
     "<a href='showproject.php3?pid=$pid'>$pid</a>/".
56
     "<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a></b></font>\n";
Chad Barb's avatar
   
Chad Barb committed
57
echo "<br /><br />\n";
58
SUBPAGESTART();
Chad Barb's avatar
   
Chad Barb committed
59

60
SUBMENUSTART("Experiment Options");
61

62
if ($expstate) {
63
    if (TBExptLogFile($exp_pid, $exp_eid)) {
64
65
66
67
	WRITESUBMENUBUTTON("View Activation Logfile",
			   "spewlogfile.php3?pid=$exp_pid&eid=$exp_eid");
    }
      
68
    if (strcmp($expstate, $TB_EXPTSTATE_ACTIVE) == 0) {
Jay Lepreau's avatar
Jay Lepreau committed
69
	WRITESUBMENUBUTTON("Visualization, NS File, Mapping",
70
71
72
			   "shownsfile.php3?pid=$exp_pid&eid=$exp_eid");
    }
    elseif (strcmp($expstate, $TB_EXPTSTATE_SWAPPED) == 0) {
Jay Lepreau's avatar
Jay Lepreau committed
73
	WRITESUBMENUBUTTON("Visualization and NS File",
74
75
76
			   "shownsfile.php3?pid=$exp_pid&eid=$exp_eid");
    }
    else {
77
	WRITESUBMENUBUTTON("Visualization and NS File",
78
79
			   "shownsfile.php3?pid=$exp_pid&eid=$exp_eid");
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
80
81
    WRITESUBMENUBUTTON("Download NS File",
		       "spitnsdata.php3?pid=$exp_pid&eid=$exp_eid");
82
83

    # Swap option.
84
    if (strcmp($expstate, $TB_EXPTSTATE_SWAPPED) == 0) {
85
	WRITESUBMENUBUTTON("Swap this Experiment In",
86
		      "swapexp.php3?inout=in&pid=$exp_pid&eid=$exp_eid");
87
88
    }
    elseif (strcmp($expstate, $TB_EXPTSTATE_ACTIVE) == 0) {
89
	WRITESUBMENUBUTTON("Swap this Experiment Out",
90
		      "swapexp.php3?inout=out&pid=$exp_pid&eid=$exp_eid");
91

92
	WRITESUBMENUBUTTON("Modify Traffic Shaping",
93
			   "delaycontrol.php3?pid=$exp_pid&eid=$exp_eid");
Chad Barb's avatar
   
Chad Barb committed
94
    }
95
96
}

97
WRITESUBMENUBUTTON("Terminate this Experiment",
98
99
		   "endexp.php3?pid=$exp_pid&eid=$exp_eid");

100
$editflip = ($edit ? 0 : 1);
101
WRITESUBMENUBUTTON("Edit Experiment Meta-Data",
102
		   "showexp.php3?pid=$exp_pid&eid=$exp_eid&edit=$editflip");
103

104
105
106
107
108
109
110
111
#
# Admin and project/experiment leader get this option.
#
if (TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_UPDATEACCOUNTS)) {
    WRITESUBMENUBUTTON("Update Mounts/Accounts",
		       "updateaccounts.php3?pid=$exp_pid&eid=$exp_eid");
}

112
113
# Reboot option
if (TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_MODIFY)) {
114
    WRITESUBMENUBUTTON("Reboot All Nodes",
115
		       "boot.php3?pid=$exp_pid&eid=$exp_eid");
Chad Barb's avatar
   
Chad Barb committed
116
117
118
    WRITESUBMENUBUTTON("Modify this Experiment",
		       "modifyexp.php3?pid=$exp_pid&eid=$exp_eid");

119
120
}

121
122
123
124
# History
WRITESUBMENUBUTTON("Show History",
		   "showstats.php3?showby=expt&which=$expindex");

125
if (ISADMIN($uid)) {
Chad Barb's avatar
   
Chad Barb committed
126
    if (strcmp($expstate, $TB_EXPTSTATE_ACTIVE) == 0) {		
127
	SUBMENUSECTION("Beta-Test Options");
Chad Barb's avatar
   
Chad Barb committed
128
129
130
131
	WRITESUBMENUBUTTON("Restart this Experiment",
			   "swapexp.php3?inout=restart&pid=$exp_pid".
			   "&eid=$exp_eid");

132
133
134
135
136
137
138
139
140
	SUBMENUSECTION("Admin Options");
	
	WRITESUBMENUBUTTON("Send a Swap Request",
			   "request_swapexp.php3?".
			   "&pid=$exp_pid&eid=$exp_eid");
	
	WRITESUBMENUBUTTON("Force Swap Out (Idle-Swap)",
			   "swapexp.php3?inout=out&force=1".
			   "&pid=$exp_pid&eid=$exp_eid");
Chad Barb's avatar
Chad Barb committed
141
	
142
143
144
145
	SUBMENUSECTIONEND();
    }
}
    
Chad Barb's avatar
   
Chad Barb committed
146
147
SUBMENUEND_2A();

148
149
150
151
echo "<br>
      <a href='shownsfile.php3?pid=$exp_pid&eid=$exp_eid'>
         <img width=160 height=160 border=1 alt='experiment vis'
              src='top2image.php3?pid=$pid&eid=$eid&thumb=160'></a>\n";
Chad Barb's avatar
   
Chad Barb committed
152
153

SUBMENUEND_2B();
154

155
156
# if we got a submission of changes, update the db now...
if ($submit) {
157
158
    # Find out our limit
    $idlethresh = TBGetSiteVar("idle/threshold");
159
160
161
    $exp_name = addslashes(str_replace('"',"",$exp_name));
    $noswap = addslashes(str_replace('"',"",$noswap));
    $noidleswap = addslashes(str_replace('"',"",$noidleswap));
162
    $mail=0;
163
164
165
166
167
168
169
170
171
    $strs = array();
    $errors = array();
    if (isset($exp_name)) {
	if ($exp_name!="") {
	    $strs[] = "expt_name=\"$exp_name\"";
	} else {
	    $errors['Expt. Name'] = "Missing/Blank Field";
	}
    }
172
    if (isset($noswap)) {
173
	$strs[] = "noswap_reason=\"$noswap\"";
174
	$mail=1;
175
    }
176
    if (isset($noidleswap)) {
177
	$strs[].= "noidleswap_reason=\"$noidleswap\"";
178
	$mail=1;
179
    }
180
181
182
183
184
185
186
    if (isset($idleswap)) {
	if ($idleswap>0 && $idleswap <= $idlethresh && $idleswap !="") {
	    $strs[] = "idleswap_timeout=\"".(60*$idleswap)."\"";
	    $mail=1;
	} else {
	    $errors['Idle-Swap'] ="Time must be non-zero and <= $idlethresh";
	}
187
    }
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
    if (isset($autoswap)) {
	if ($autoswap>=0 && $autoswap !="") {
	    $strs[] = "autoswap_timeout=\"".(60*$autoswap)."\"";
	    $mail=1;
	} else {
	    $errors['Max Duration'] = "Time must be non-zero";
	}
    }
    if (count($strs)>0) {
	$str = implode(",",$strs);
	DBQueryWarn("update experiments set $str ".
		    "where pid='$pid' and eid='$eid'");
    }
    if ($errors) {
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
              <tr>
                 <th align=center colspan=2>
                   <font size=+1 color=red>
                      &nbsp;Oops, please fix the following errors!&nbsp;
                   </font>
                 </td>
              </tr>\n";

	while (list ($name, $message) = each ($errors)) {
	    echo "<tr>
                     <td align=right>
                       <font color=red>$name:&nbsp;</font></td>
                     <td align=left>
                       <font color=red>$message</font></td>
                  </tr>\n";
	}
	echo "</table><br>\n";
	# Jump back into edit mode
	$edit=1;
223
    }
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
    if ($mail) {
	$q = DBQueryFatal("select * from experiments ".
			  "where pid='$pid' and eid='$eid'");
	$r = mysql_fetch_array($q);
	$s = ($r[swappable] ? "Yes" : "No");
	$sr= $r[noswap_reason];
	$i = ($r[idleswap] ? "Yes" : "No");
	$it= $r[idleswap_timeout] / 60.0;
	$ir= $r[noidleswap_reason];
	$a = ($r[autoswap] ? "Yes" : "No");
	$at= $r[autoswap_timeout] / 60.0;
	$cuid = $r[expt_head_uid];
	$suid= $r[expt_swap_uid];
	TBUserInfo($uid, $user_name, $user_email);
	TBUserInfo($cuid, $cname, $cemail);
	TBUserInfo($suid, $sname, $semail);
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
	# Do not send this email if the user is an administrator
	# (adminmode does not matter), and is changing an expt
	# he created or swapped in. Pointless email.
	if (! (ISADMINISTRATOR() &&
	       (!strcmp($uid, $cuid) || !strcmp($uid, $suid)))) {
	    TBMAIL($TBMAIL_OPS,"$pid/$eid swap settings changed",
		   "\nThe swap settings for $pid/$eid have changed.\n".
		   "\nThe reasons and/or timeouts have changed.\n".
		   "\nThe new settings are:\n".
		  #"Swappable:\t$s\t($sr)\n".
		   "Idleswap:\t$i\t(after $it hrs)\t($ir)\n".
		   "Autoswap:\t$a\t(after $at hrs)\n".
		   "\nCreator:\t$cuid ($cname <$cemail>)\n".
		   "Swapper:\t$suid ($sname <$semail>)\n".
		   "\nIf it is necessary to change these settings, ".
		   "please reply to this message \nto notify the user, ".
		   "then change the settings here:\n\n".
		   "$TBBASE/showexp.php3?pid=$pid&eid=$eid\n\n".
		   "Thanks,\nTestbed WWW\n",
		   "From: $user_name <$user_email>\n".
		   "Errors-To: $TBMAIL_WWW");
	}
262
    }
263
264
265
266
267
}

# Dump (possibly updated) experiment record.
if (!isset($edit)) { $edit=0; }
SHOWEXP($exp_pid, $exp_eid, $edit);
268

269
SUBPAGEEND();
270
271
272
273
274
275

#
# Dump the node information.
#
SHOWNODES($exp_pid, $exp_eid);

276
277
278
279
280
281
282
283
if (ISADMIN($uid)) {
    echo "<center>
          <h3>Experiment Stats</h3>
         </center>\n";

    SHOWEXPTSTATS($exp_pid, $exp_eid);
}

284
285
286
287
#
# Standard Testbed Footer
# 
PAGEFOOTER();
288
?>