showstuff.php3 74.2 KB
Newer Older
1 2
<?php
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
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 7
# All rights reserved.
#
#
8 9 10 11 12 13 14 15 16
# This is an included file. No headers or footers.
#
# Functions to dump out various things.  
#

#
# A project
#
function SHOWPROJECT($pid, $thisuid) {
17
    global $WIKISUPPORT, $CVSSUPPORT, $TBPROJ_DIR;
18 19 20
    global $MAILMANSUPPORT;
    global $TBDB_TRUST_GROUPROOT;
    
21
    $query_result =
22 23
	DBQueryFatal("select p.*,g.wikiname ".
		     "  from projects as p ".
24 25
		     "left join groups as g on g.pid=p.pid and g.gid=g.pid ".
		     "where p.pid='$pid'");
26 27
    $row = mysql_fetch_array($query_result);

28 29 30
    echo "<center>
          <h3>Project Profile</h3>
          </center>
31
          <table align=center cellpadding=2 border=1>\n";
32
    
33
    $proj_created	= $row[created];
34
    #$proj_expires	= $row[expires];
35
    $proj_name		= $row[name];
36
    $proj_URL		= $row[URL];
37
    $proj_public        = $row[public];
38
    $proj_funders	= $row[funders];
39 40 41
    $proj_head_uid	= $row[head_uid];
    $proj_members       = $row[num_members];
    $proj_pcs           = $row[num_pcs];
Leigh B. Stoller's avatar
Leigh B. Stoller committed
42 43
    $proj_ronpcs        = $row[num_ron];
    $proj_plabpcs       = $row[num_pcplab];
44
    $proj_linked        = $row[linked_to_us];
45
    $proj_why           = nl2br($row[why]);
46
    $control_node	= $row[control_node];
47
    $approved           = $row[approved];
48 49
    $expt_count         = $row[expt_count];
    $expt_last          = $row[expt_last];
50
    $wikiname           = $row[wikiname];
51

52 53 54 55 56 57 58
    if ($proj_public) {
	$proj_public = "Yes";
    }
    else {
	$proj_public = "No";
    }

59 60 61 62 63 64 65
    if ($proj_linked) {
	$proj_linked = "Yes";
    }
    else {
	$proj_linked = "No";
    }

66 67 68 69
    if (!$expt_last) {
	$expt_last = "&nbsp";
    }

70 71 72 73 74
    #
    # Generate the table.
    # 
    echo "<tr>
              <td>Name: </td>
75 76
              <td class=\"left\">
                <a href='showproject.php3?pid=$pid'>$pid</a></td>
77 78 79 80 81 82 83 84 85 86
          </tr>\n";
    
    echo "<tr>
              <td>Long Name: </td>
              <td class=\"left\">$proj_name</td>
          </tr>\n";
    
    echo "<tr>
              <td>Project Head: </td>
              <td class=\"left\">
87
                <A href='showuser.php3?target_uid=$proj_head_uid'>
88 89 90 91 92 93 94 95
                     $proj_head_uid</A></td>
          </tr>\n";
    
    echo "<tr>
              <td>URL: </td>
              <td class=\"left\">
                  <A href='$proj_URL'>$proj_URL</A></td>
          </tr>\n";
96 97

    if ($WIKISUPPORT && isset($wikiname)) {
98
	$wikiurl = "gotowiki.php3?redurl=$wikiname/WebHome";
99 100 101 102 103
	
	echo "<tr>
                  <td>Project Wiki:</td>
                  <td class=\"left\">
                      <A href='$wikiurl'>$wikiname</A></td>
104 105 106 107 108 109 110 111 112 113
              </tr>\n";
    }
    if ($CVSSUPPORT) {
	$cvsdir = "$TBPROJ_DIR/$pid/CVS";
	$cvsurl = "cvsweb/cvsweb.php3?pid=$pid";
	
	echo "<tr>
                  <td>Project CVS Repository:</td>
                  <td class=\"left\">
                      $cvsdir <A href='$cvsurl'>(cvsweb)</A></td>
114 115
              </tr>\n";
    }
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

    if ($MAILMANSUPPORT) {
	$mmurl   = "gotommlist.php3?pid=$pid";

	echo "<tr>
                  <td>Project Mailing List:</td>
                  <td class=\"left\">
                      <A href='$mmurl'>${pid}-users</A> ";
	if (ISADMIN()) {
	    $mmurl .= "&wantadmin=1";
	    echo "<A href='$mmurl'>(admin)</A>";
	}
	echo "    </td>
              </tr>\n";
    }

132 133 134 135 136
    echo "<tr>
              <td>Publicly Visible: </td>
              <td class=\"left\">$proj_public</td>
          </tr>\n";
    
137 138 139 140 141
    echo "<tr>
              <td>Link to Us?: </td>
              <td class=\"left\">$proj_linked</td>
          </tr>\n";
    
142 143 144 145 146
    echo "<tr>
              <td>Funders: </td>
              <td class=\"left\">$proj_funders</td>
          </tr>\n";

147 148 149 150 151 152 153 154 155 156 157
    echo "<tr>
              <td>#Project Members: </td>
              <td class=\"left\">$proj_members</td>
          </tr>\n";
    
    echo "<tr>
              <td>#PCs: </td>
              <td class=\"left\">$proj_pcs</td>
          </tr>\n";
    
    echo "<tr>
158 159 160 161 162 163 164
              <td>#Planetlab PCs: </td>
              <td class=\"left\">$proj_plabpcs</td>
          </tr>\n";
    
    echo "<tr>
              <td>#RON PCs: </td>
              <td class=\"left\">$proj_ronpcs</td>
165 166 167 168 169 170 171
          </tr>\n";
    
    echo "<tr>
              <td>Created: </td>
              <td class=\"left\">$proj_created</td>
          </tr>\n";
    
172 173 174 175
    #echo "<tr>
    #          <td>Expires: </td>
    #          <td class=\"left\">$proj_expires</td>
    #      </tr>\n";
176
    
177 178 179 180 181 182 183 184 185 186
    echo "<tr>
              <td>Experiments Created:</td>
              <td class=\"left\">$expt_count</td>
          </tr>\n";
    
    echo "<tr>
              <td>Date of last experiment:</td>
              <td class=\"left\">$expt_last</td>
          </tr>\n";
    
187 188 189 190 191 192 193 194 195 196
    echo "<tr>
              <td>Approved?: </td>\n";
    if ($approved) {
	echo "<td class=left><img alt=\"Y\" src=\"greenball.gif\"></td>\n";
    }
    else {
	echo "<td class=left><img alt=\"N\" src=\"redball.gif\"></td>\n";
    }
    echo "</tr>\n";

197
    echo "<tr>
198
              <td colspan='2'>Why?:</td>
199 200 201 202 203 204 205 206 207
          </tr>\n";
    
    echo "<tr>
              <td colspan='2' width=600>$proj_why</td>
          </tr>\n";
    
    echo "</table>\n";
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
208 209 210
#
# A Group
#
211
function SHOWGROUP($pid, $gid, $thisuid) {
212
    global $OURDOMAIN;
213 214
    global $MAILMANSUPPORT;
    global $TBDB_TRUST_GROUPROOT;
215
    
Leigh B. Stoller's avatar
Leigh B. Stoller committed
216 217 218 219
    $query_result =
	DBQueryFatal("SELECT * FROM groups WHERE pid='$pid' and gid='$gid'");
    $row = mysql_fetch_array($query_result);

220 221 222 223
    echo "<center>
          <h3>Group Profile</h3>
          </center>
          <table align=center border=1>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
224 225 226

    $leader	= $row[leader];
    $created	= $row[created];
227
    $description= $row[description];
Leigh B. Stoller's avatar
Leigh B. Stoller committed
228 229 230 231 232
    $expt_count = $row[expt_count];
    $expt_last  = $row[expt_last];
    $unix_gid   = $row[unix_gid];
    $unix_name  = $row[unix_name];

233 234 235 236 237
    if (strcmp($pid,$gid))
	$mail = "$pid-$gid" . "-users@" . $OURDOMAIN;
    else
	$mail = "$pid" . "-users@" . $OURDOMAIN;

Leigh B. Stoller's avatar
Leigh B. Stoller committed
238 239 240 241 242 243
    if (!$expt_last) {
	$expt_last = "&nbsp";
    }

    #
    # Generate the table.
244
    #
Leigh B. Stoller's avatar
Leigh B. Stoller committed
245 246
    echo "<tr>
              <td>GID: </td>
247
              <td class=\"left\">
Chad Barb's avatar
 
Chad Barb committed
248
                <a href='showgroup.php3?pid=$pid&gid=$gid'>$gid</a></td>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
249 250 251 252
          </tr>\n";
    
    echo "<tr>
              <td>PID: </td>
253 254
              <td class=\"left\">
                <a href='showproject.php3?pid=$pid'>$pid</a></td>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
          </tr>\n";
    
    echo "<tr>
              <td>Description: </td>
              <td class=\"left\">$description</td>
          </tr>\n";
    
    echo "<tr>
              <td>Unix GID: </td>
              <td class=\"left\">$unix_gid</td>
          </tr>\n";
    
    echo "<tr>
              <td>Unix Group Name: </td>
              <td class=\"left\">$unix_name</td>
          </tr>\n";
    
    echo "<tr>
              <td>Group Leader: </td>
              <td class=\"left\">
                <A href='showuser.php3?target_uid=$leader'>$leader</A></td>
          </tr>\n";
    
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
    if ($MAILMANSUPPORT) {
	$mmurl   = "gotommlist.php3?pid=$pid&gid=$gid";

	echo "<tr>
                  <td>Email List:</td>
                  <td class=\"left\">
                      <A href='$mmurl'>$mail</A> ";

	if (ISADMIN()) {
	    $mmurl .= "&wantadmin=1";
	    echo "<A href='$mmurl'>(admin)</A>";
	}
	echo "    </td>
              </tr>\n";
    }
    else {
	echo "<tr>
                  <td>Email List: </td>
                  <td class=\"left\">$mail</td>
              </tr>\n";
    }

Leigh B. Stoller's avatar
Leigh B. Stoller committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
    echo "<tr>
              <td>Created: </td>
              <td class=\"left\">$created</td>
          </tr>\n";
    
    echo "<tr>
              <td>Experiments Created:</td>
              <td class=\"left\">$expt_count</td>
          </tr>\n";
    
    echo "<tr>
              <td>Date of last experiment:</td>
              <td class=\"left\">$expt_last</td>
          </tr>\n";
    
    echo "</table>\n";
}

#
# A list of Group members.
#
321
function SHOWGROUPMEMBERS($pid, $gid, $prived = 0) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
322 323 324 325 326 327 328 329
    $query_result =
	DBQueryFatal("SELECT m.*,u.* FROM group_membership as m ".
		     "left join users as u on u.uid=m.uid ".
		     "WHERE pid='$pid' and gid='$gid'");
    
    if (! mysql_num_rows($query_result)) {
	return;
    }
330
    $showdel = (($prived && !strcmp($pid, $gid)) ? 1 : 0);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
331

332 333 334 335 336 337 338 339
    echo "<center>\n";
    if (strcmp($pid, $gid)) {
	echo "<h3>Group Members</h3>\n";
    }
    else {
	echo "<h3>Project Members</h3>\n";
    }
    echo "</center>
340
          <table align=center border=1 cellpadding=1 cellspacing=2>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
341 342

    echo "<tr>
343 344 345 346 347
              <th>Name</th>\n";
    if (strcmp($pid, $gid)) {
	echo "<th>Email</th>\n";
    }
    echo "    <th>UID</th>
348 349 350 351 352
              <th>Privs</th>\n";
    if ($showdel) {
	echo "<th>Remove</th>\n";
    }
    echo "</tr>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
353 354 355 356

    while ($row = mysql_fetch_array($query_result)) {
        $target_uid = $row[uid];
	$usr_name   = $row[usr_name];
357
	$usr_email  = $row[usr_email];
Leigh B. Stoller's avatar
Leigh B. Stoller committed
358 359 360
	$trust      = $row[trust];

        echo "<tr>
361 362 363 364 365
                  <td>$usr_name</td>\n";
	if (strcmp($pid, $gid)) {
	    echo "<td>$usr_email</td>\n";
	}
	echo "    <td>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
366 367
                    <A href='showuser.php3?target_uid=$target_uid'>
                       $target_uid</A>
368 369 370 371
                  </td>\n";
	
	if (TBTrustConvert($trust) != $TBDB_TRUST_NONE) {
	    echo "<td>$trust</td>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
372 373
	}
	else {
374 375 376
	    echo "<td><font color=red>$trust</font></td>\n";
	}
	if ($showdel) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
377
	    echo "<td align=center>
378 379 380
		      <A href='deleteuser.php3?target_uid=$target_uid";
	    echo         "&target_pid=$pid'>
                         <img alt=N src=redball.gif></td>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
381 382 383 384 385 386
	}
	echo "</tr>\n";
    }
    echo "</table>\n";
}

387 388 389 390
#
# A list of groups for a user.
#
function SHOWGROUPMEMBERSHIP($uid) {
391 392
    $none = TBDB_TRUSTSTRING_NONE;
    
393 394
    $query_result =
	DBQueryFatal("SELECT * FROM group_membership ".
395 396
		     "WHERE uid='$uid' and trust!='$none' ".
		     "order by pid");
397 398 399 400 401 402 403 404 405 406 407
    
    if (! mysql_num_rows($query_result)) {
	return;
    }

    echo "<center>
          <h3>Group Membership</h3>
          </center>
          <table align=center border=1 cellpadding=1 cellspacing=2>\n";

    echo "<tr>
Chad Barb's avatar
 
Chad Barb committed
408 409 410
              <th>PID</th>
              <th>GID</th>
              <th>Privs</th>
411 412 413 414 415 416 417
          </tr>\n";

    while ($row = mysql_fetch_array($query_result)) {
	$pid   = $row[pid];
	$gid   = $row[gid];
	$trust = $row[trust];

418 419
	if (TBTrustConvert($trust) != $TBDB_TRUST_NONE) {
	    echo "<tr>
420 421 422
              <td><a href='showproject.php3?pid=$pid'>$pid</a></td>
              <td><a href='showgroup.php3?pid=$pid&gid=$gid'>$gid</a></td>
              <td>$trust</td>\n";
423 424
	    echo "</tr>\n";
	}
425 426 427 428
    }
    echo "</table>\n";
}

429 430 431 432
#
# A User
#
function SHOWUSER($uid) {
433
    global $WIKISUPPORT;
434 435 436

    $userinfo_result =
	DBQueryFatal("SELECT * from users where uid='$uid'");
437 438

    $row	= mysql_fetch_array($userinfo_result);
439
    #$usr_expires = $row[usr_expires];
440 441
    $usr_email   = $row[usr_email];
    $usr_URL     = $row[usr_URL];
442 443 444 445 446 447 448
    $usr_addr    = $row[usr_addr];
    $usr_addr2   = $row[usr_addr2];
    $usr_city    = $row[usr_city];
    $usr_state   = $row[usr_state];
    $usr_zip     = $row[usr_zip];
    $usr_country = $row[usr_country];
    $usr_name    = $row[usr_name];
449
    $usr_phone   = $row[usr_phone];
450 451 452
    $usr_shell   = $row[usr_shell];
    $usr_title   = $row[usr_title];
    $usr_affil   = $row[usr_affil];
453
    $status      = $row[status];
454 455
    $admin       = $row[admin];
    $adminoff    = $row[adminoff];
456 457 458 459
    $notes       = $row[notes];
    $frozen      = $row['weblogin_frozen'];
    $failcount   = $row['weblogin_failcount'];
    $failstamp   = $row['weblogin_failstamp'];
460
    $wikiname    = $row['wikiname'];
461
    $cvsweb      = $row['cvsweb'];
462

463 464 465 466 467 468 469 470
    if (!strcmp($usr_addr2, ""))
	$usr_addr2 = "&nbsp";
    if (!strcmp($usr_city, ""))
	$usr_city = "&nbsp";
    if (!strcmp($usr_state, ""))
	$usr_state = "&nbsp";
    if (!strcmp($usr_zip, ""))
	$usr_zip = "&nbsp";
Chad Barb's avatar
 
Chad Barb committed
471 472
    if (!strcmp($usr_country, ""))
	$usr_country = "&nbsp";
473 474
    if (!strcmp($notes, ""))
	$notes = "&nbsp";
475

476 477 478 479 480
    #
    # Last Login info.
    #
    if (($lastweblogin = LASTWEBLOGIN($uid)) == 0)
	$lastweblogin = "&nbsp";
481
    if (($lastuserslogininfo = TBUsersLastLogin($uid)) == 0)
482 483 484
	$lastuserslogin = "N/A";
    else {
	$lastuserslogin = $lastuserslogininfo["date"] . " " .
485
		          $lastuserslogininfo["time"];
486 487 488 489 490 491 492 493 494
    }
    
    if (($lastnodelogininfo = TBUidNodeLastLogin($uid)) == 0)
	$lastnodelogin = "N/A";
    else {
	$lastnodelogin = $lastnodelogininfo["date"] . " " .
		         $lastnodelogininfo["time"] . " " .
                         "(" . $lastnodelogininfo["node_id"] . ")";
    }
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
    
    echo "<table align=center border=1>\n";
    
    echo "<tr>
              <td>Username:</td>
              <td>$uid</td>
          </tr>\n";
    
    echo "<tr>
              <td>Full Name:</td>
              <td>$usr_name</td>
          </tr>\n";
    
    echo "<tr>
              <td>Email Address:</td>
              <td>$usr_email</td>
          </tr>\n";
512

513 514 515 516
    echo "<tr>
              <td>Home Page URL:</td>
              <td><A href='$usr_URL'>$usr_URL</A></td>
          </tr>\n";
517 518

    if ($WIKISUPPORT && isset($wikiname)) {
519
	$wikiurl = "gotowiki.php3?redurl=Main/$wikiname";
520 521 522 523 524 525 526
	
	echo "<tr>
                  <td>Emulab Wiki Page:</td>
                  <td class=\"left\">
                      <A href='$wikiurl'>$wikiname</A></td>
              </tr>\n";
    }
527
    
528 529 530 531
    #echo "<tr>
    #          <td>Expiration date:</td>
    #          <td>$usr_expires</td>
    #      </tr>\n";
532 533
    
    echo "<tr>
534
              <td>Address 1:</td>
535 536 537
              <td>$usr_addr</td>
          </tr>\n";
    
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
    echo "<tr>
              <td>Address 2:</td>
              <td>$usr_addr2</td>
          </tr>\n";
    
    echo "<tr>
              <td>City:</td>
              <td>$usr_city</td>
          </tr>\n";
    
    echo "<tr>
              <td>State:</td>
              <td>$usr_state</td>
          </tr>\n";
    
    echo "<tr>
Chad Barb's avatar
 
Chad Barb committed
554
              <td>ZIP:</td>
555 556
              <td>$usr_zip</td>
          </tr>\n";
Chad Barb's avatar
 
Chad Barb committed
557 558 559 560 561

    echo "<tr>
              <td>Country:</td>
              <td>$usr_country</td>
          </tr>\n";
562
    
563 564 565 566
    echo "<tr>
              <td>Phone #:</td>
              <td>$usr_phone</td>
          </tr>\n";
Chad Barb's avatar
 
Chad Barb committed
567 568 569 570 571

    echo "<tr>
	      <td>Shell:</td>
	      <td>$usr_shell</td>
          </tr>\n";
572 573 574 575 576 577 578 579 580 581 582
    
    echo "<tr>
              <td>Title/Position:</td>
              <td>$usr_title</td>
         </tr>\n";
    
    echo "<tr>
              <td>Institutional Affiliation:</td>
              <td>$usr_affil</td>
          </tr>\n";
    
583 584 585 586
    echo "<tr>
              <td>Status:</td>
              <td>$status</td>
          </tr>\n";
587 588 589 590 591

    if ($admin) {
	$onoff = ($adminoff ? "Off" : "On");
	$flip  = ($adminoff ? 0 : 1);
	echo "<tr>
592 593 594 595
              <td>Admin (on/off):</td>
              <td>Yes
              <a href=toggle.php?target_uid=$uid&type=adminoff&value=$flip>
              ($onoff)</td>
596 597
              </tr>\n";
    }
598
    
599 600 601 602 603 604 605 606 607 608
    echo "<tr>
              <td>Last Web Login:</td>
              <td>$lastweblogin</td>
          </tr>\n";
    
    echo "<tr>
              <td>Last Users Login:</td>
              <td>$lastuserslogin</td>
          </tr>\n";
    
609 610 611 612
    echo "<tr>
              <td>Last Node Login:</td>
              <td>$lastnodelogin</td>
          </tr>\n";
613 614

    if (ISADMIN()) {
615 616 617 618 619 620 621 622
	$cvswebflip = ($cvsweb ? 0 : 1);

	echo "<tr>
                  <td>CVSWeb Access:</td>
                  <td>$cvsweb (<a href=toggle.php?target_uid=$uid".
	                      "&type=cvsweb&value=$cvswebflip>Toggle</a>)
              </tr>\n";
	
623 624 625 626 627 628 629 630 631 632 633
	$freezeflip = ($frozen ? 0 : 1);
	
	echo "<tr>
                  <td>Web Freeze:</td>
                  <td>$frozen (<a href=toggle.php?target_uid=$uid".
	                          "&type=webfreeze&value=$freezeflip>Toggle</a>)
              </tr>\n";
	
	if ($frozen && $failstamp && $failcount) {
	    $when = strftime("20%y-%m-%d %H:%M:%S", $failstamp);
	    
634
	    echo "<tr>
635 636
                      <td>Login Failures:</td>
                      <td>$failcount ($when)</td>
637
                  </tr>\n";
638 639 640 641 642
	}
	echo "<tr>
                  <td>Notes:</td>
                  <td>$notes</td>
              </tr>\n";
643
    }
644 645 646 647
    echo "</table>\n";

}

648 649 650
#
# Show an experiment.
#
651
function SHOWEXP($pid, $eid, $short = 0, $sortby = "") {
652
    global $TBDBNAME, $TBDOCBASE;
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
    $nodecounts  = array();

    # Node counts, by class. 
    $query_result =
	DBQueryFatal("select nt.class,count(*) from reserved as r ".
		     "left join nodes as n on n.node_id=r.node_id ".
		     "left join node_types as nt on n.type=nt.type ".
		     "where pid='$pid' and eid='$eid' group by nt.class");

    while ($row = mysql_fetch_array($query_result)) {
	$class = $row[0];
	$count = $row[1];
	
	$nodecounts[$class] = $count;
    }
668
		
Leigh B. Stoller's avatar
Leigh B. Stoller committed
669
    $query_result =
670
	DBQueryFatal("select e.*, pl.slicename, ". 
671 672
                     "round(e.minimum_nodes+.1,0) as min_nodes, ".
		     "round(e.maximum_nodes+.1,0) as max_nodes ".
673 674
		     " from experiments as e left join plab_slices as pl".
                     " on e.pid = pl.pid and e.eid = pl.eid ".
675
		     "where e.pid='$pid' and e.eid='$eid'");
676
    
Leigh B. Stoller's avatar
Leigh B. Stoller committed
677 678 679
    if (($exprow = mysql_fetch_array($query_result)) == 0) {
	TBERROR("Experiment $eid in project $pid is gone!\n", 1);
    }
680

Leigh B. Stoller's avatar
Leigh B. Stoller committed
681
    $exp_gid     = $exprow[gid];
682
    $exp_name    = $exprow[expt_name];
683
    $exp_swapped = $exprow[expt_swapped];
684
    $exp_swapuid = $exprow[expt_swap_uid];
685 686 687
    $exp_end     = $exprow[expt_end];
    $exp_created = $exprow[expt_created];
    $exp_head    = $exprow[expt_head_uid];
688
    $exp_state   = $exprow[state];
689
    $exp_shared  = $exprow[shared];
690 691
    $exp_path    = $exprow[path];
    $batchmode   = $exprow[batchmode];
692
    $canceled    = $exprow[canceled];
693
    $attempts    = $exprow[attempts];
694
    $expt_locked = $exprow[expt_locked];
695 696
    $priority    = $exprow[priority];
    $swappable   = $exprow[swappable];
697
    $noswap_reason = $exprow[noswap_reason];
698
    $idleswap    = $exprow[idleswap];
699
    $idleswap_timeout  = $exprow[idleswap_timeout];
700
    $noidleswap_reason = $exprow[noidleswap_reason];
701
    $autoswap    = $exprow[autoswap];
702
    $autoswap_timeout  = $exprow[autoswap_timeout];
703
    $idle_ignore = $exprow[idle_ignore];
704 705
    $swapreqs    = $exprow[swap_requests];
    $lastswapreq = $exprow[last_swap_req];
706
    $minnodes    = $exprow["min_nodes"];
707
    $maxnodes    = $exprow["max_nodes"];
708
    $syncserver  = $exprow["sync_server"];
709 710
    $mem_usage   = $exprow["mem_usage"];
    $cpu_usage   = $exprow["cpu_usage"];
711
    $exp_slice   = $exprow[slicename];
712
    $linktest    = $exprow["linktest_level"];
713 714 715
    $usemodelnet = $exprow["usemodelnet"];
    $mnet_cores  = $exprow["modelnet_cores"];
    $mnet_edges  = $exprow["modelnet_edges"];
716
    $lockdown    = $exprow["lockdown"];
717

718 719
    $autoswap_hrs= ($autoswap_timeout/60.0);
    $idleswap_hrs= ($idleswap_timeout/60.0);
720 721 722 723
    $noswap = "($noswap_reason)";
    $noidleswap = "($noidleswap_reason)";
    $autoswap_str= $autoswap_hrs." hour".($autoswap_hrs==1 ? "" : "s");
    $idleswap_str= $idleswap_hrs." hour".($idleswap_hrs==1 ? "":"s");
724

725 726 727 728
    if ($swappable)
	$swappable = "Yes";
    else
	$swappable = "<b>No</b> $noswap";
729

730 731 732 733
    if ($idleswap)
	$idleswap = "Yes (after $idleswap_str)";
    else
	$idleswap = "<b>No</b> $noidleswap";
734

735 736 737 738
    if ($autoswap)
	$autoswap = "<b>Yes</b> (after $autoswap_str)";
    else
	$autoswap = "No";
739

740 741 742 743
    if ($idle_ignore)
	$idle_ignore = "<b>Yes</b>";
    else
	$idle_ignore = "No";
744

745 746 747 748 749
    if ($expt_locked)
	$expt_locked = "($expt_locked)";
    else
	$expt_locked = "";

750 751 752
    #
    # Generate the table.
    #
Chad Barb's avatar
 
Chad Barb committed
753
    echo "<table align=center cellpadding=2 cellspacing=2 border=1>\n";
754

755 756 757 758 759
    if (!$short) {
	echo "<tr>
                <td>Name: </td>
                <td class=left>$eid</td>
              </tr>\n";
760

761
	echo "<tr>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
762
                <td>Description: </td>
763 764
                <td class=\"left\">$exp_name</td>
              </tr>\n";
765

766 767 768 769 770
	echo "<tr>
                <td>Project: </td>
                <td class=\"left\">
                  <a href='showproject.php3?pid=$pid'>$pid</a></td>
              </tr>\n";
771

772 773 774 775 776 777
        echo "<tr>
                <td>Group: </td>
                <td class=\"left\">
                  <a href='showgroup.php3?pid=$pid&gid=$exp_gid'>$exp_gid</a>
                </td>
              </tr>\n";
778 779 780 781 782 783 784

        if (isset($exp_slice)) {
          echo "<tr>
                  <td>Planetlab Slice: </td>
                  <td class=\"left\">$exp_slice</td>
                </tr>\n";
        }
785
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
786

787 788 789
    echo "<tr>
            <td>Experiment Head: </td>
            <td class=\"left\">
790
              <a href='showuser.php3?target_uid=$exp_head'>$exp_head</a></td>
791 792
          </tr>\n";

793 794 795 796
    if (!$short) {
	echo "<tr>
                <td>Created: </td>
                <td class=\"left\">$exp_created</td>
797
              </tr>\n";
798

799 800 801 802 803 804
	if ($exp_swapped) {
	    echo "<tr>
                    <td>Last Swap/Modify: </td>
                    <td class=\"left\">$exp_swapped ($exp_swapuid)</td>
                  </tr>\n";
	}
805

806 807 808 809 810 811 812 813 814 815 816 817 818
	if (ISADMIN()) {
	    echo "<tr>
                    <td><a href='$TBDOCBASE/docwrapper.php3?".
		           "docname=swapping.html#swapping'>Swappable:</a></td>
                    <td class=\"left\">$swappable</td>
                  </tr>\n";
	}
    
	echo "<tr>
                  <td><a href='$TBDOCBASE/docwrapper.php3?".
	                 "docname=swapping.html#idleswap'>Idle-Swap:</a></td>
                  <td class=\"left\">$idleswap</td>
              </tr>\n";
819

820
	echo "<tr>
821 822 823 824
                <td><a href='$TBDOCBASE/docwrapper.php3?".
	               "docname=swapping.html#autoswap'>Max. Duration:</a></td>
                <td class=\"left\">$autoswap</td>
              </tr>\n";
825

826 827 828 829 830 831 832 833 834 835 836
	if (ISADMIN()) {
	    echo "<tr>
                    <td>Idle Ignore:</td>
                    <td class=\"left\">$idle_ignore</td>
                 </tr>\n";
	}
    
	echo "<tr>
                <td>Path: </td>
                <td class=left>$exp_path</td>
              </tr>\n";
837

838 839 840 841
        echo "<tr>
                <td>Status: </td>
                <td class=\"left\">$exp_state $expt_locked</td>
              </tr>\n";
842
    }
843

844
    if (count($nodecounts)) {
845
	echo "<tr>
846 847
                 <td>Reserved Nodes: </td>
                 <td class=\"left\">\n";
848 849 850
	while (list ($class, $count) = each($nodecounts)) {
	    echo "$count ($class) &nbsp ";
	}
851 852 853 854
	echo "   </td>
              </tr>\n";
    }
    elseif (!$short) {
855 856
	if ($minnodes!="") {
	    echo "<tr>
857
                      <td>Min/Max Nodes: </td>
858
                      <td class=\"left\"><font color=green>
859
                          $minnodes/$maxnodes (estimates)</font></td>
860 861 862
                  </tr>\n";
	}
	else {
863
	    echo "<tr>
864 865 866
                      <td>Minumum Nodes: </td>
                      <td class=\"left\"><font color=green>Unknown</font></td>
                  </tr>\n";
867
	}
868
    }
869 870 871 872 873 874
    if (!$short) {
	if ($mem_usage || $cpu_usage) {
	    echo "<tr>
                      <td>Mem Usage Est: </td>
                      <td class=\"left\">$mem_usage</td>
                  </tr>\n";
875

876 877 878 879 880
	    echo "<tr>
                      <td>CPU Usage Est: </td>
                      <td class=\"left\">$cpu_usage</td>
                  </tr>\n";
	}
881

882 883 884
	$lastact = TBGetExptLastAct($pid,$eid);
	$idletime = TBGetExptIdleTime($pid,$eid);
	$stale = TBGetExptIdleStale($pid,$eid);
885
    
886 887 888 889 890
	if ($lastact != -1) {
	    echo "<tr>
                      <td>Last Activity: </td>
                      <td class=\"left\">$lastact</td>
                  </tr>\n";
891

892
	    if ($stale) { $str = "(stale)"; } else { $str = ""; }
893
	
894 895 896 897 898
	    echo "<tr>
                      <td>Idle Time: </td>
                      <td class=\"left\">$idletime hours $str</td>
                  </tr>\n";
	}
899

900 901 902 903 904
	if (! ($swapreqs=="" || $swapreqs==0)) {
	    echo "<tr>
                      <td>Swap Requests: </td>
                      <td class=\"left\">$swapreqs</td>
                  </tr>\n";
905

906 907 908 909 910
	    echo "<tr>
                      <td>Last Swap Req.: </td>
                      <td class=\"left\">$lastswapreq</td>
                  </tr>\n";
	}
911 912 913 914 915 916 917 918 919

	$lockflip = ($lockdown ? 0 : 1);
	$lockval  = ($lockdown ? "Yes" : "No");
	echo "<tr>
                   <td>Locked Down:</td>
                   <td>$lockval (<a href=toggle.php?pid=$pid&eid=$eid".
	                            "&type=lockdown&value=$lockflip>Toggle</a>)
                   </td>
              </tr>\n";
920
    }
921

922 923 924 925 926 927 928 929 930 931 932
    if ($batchmode) {
	    echo "<tr>
                    <td>Batch Mode: </td>
                    <td class=\"left\">Yes</td>
                  </tr>\n";

	    echo "<tr>
                    <td>Start Attempts: </td>
                    <td class=\"left\">$attempts</td>
                  </tr>\n";
    }
933

934
    if ($canceled) {
935
	echo "<tr>
936 937
                 <td>Cancel Flag: </td>
                 <td class=\"left\">$canceled</td>
938 939 940
              </tr>\n";
    }

941
    if (!$short) {
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
	if ($usemodelnet) {
	    echo "<tr>
                      <td>Use Modelnet: </td>
                      <td class=\"left\">Yes</td>
                  </tr>\n";
	    echo "<tr>
                      <td>Modelnet Phys Core Nodes: </td>
                      <td class=\"left\">$mnet_cores</td>
                  </tr>\n";
	    echo "<tr>
                      <td>Modelnet Phys Edge Nodes: </td>
                      <td class=\"left\">$mnet_edges</td>
                  </tr>\n";

	}
957 958 959 960 961 962
	if (isset($syncserver)) {
	    echo "<tr>
                      <td>Sync Server: </td>
                      <td class=\"left\">$syncserver</td>
                  </tr>\n";
	}
963 964 965 966 967 968
	if ($linktest) {
	    echo "<tr>
                      <td>Linktest Level: </td>
                      <td class=\"left\">$linktest</td>
                  </tr>\n";
	}
969 970
    }

971 972 973
    echo "</table>\n";
}

974 975 976
#
# Show a listing of experiments by user/pid/gid
#
977
function SHOWEXPLIST($type,$id,$gid = "") {
978 979
    global $TB_EXPTSTATE_SWAPPED, $TB_EXPTSTATE_SWAPPING;
    
980 981 982 983 984 985 986 987
    if ($type == "USER") {
	$where = "expt_head_uid='$id'";
	$title = "Current";
    } elseif ($type == "PROJ") {
	$where = "e.pid='$id'";
	$title = "Project";
	$nopid = 1;
    } elseif ($type == "GROUP") {
988
	$where = "e.pid='$id' and e.gid='$gid'";
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
	$title = "Group";
	$nopid = 1;
    } else {
	$where = "e.eid='$id'";
	$title = "Bad id '$id'!";
    }
    
    $query_result =
	DBQueryFatal("select e.*,count(r.node_id) as nodes, ".
		     "round(minimum_nodes+.1,0) as min_nodes ".
		     "from experiments as e ".
		     "left join reserved as r on e.pid=r.pid and e.eid=r.eid ".
		     "where $where ".
		     "group by e.pid,e.eid order by e.state,e.eid");
    
    if (mysql_num_rows($query_result)) {
	echo "<center>
          <h3>$title Experiments</h3>
          </center>
          <table align=center border=1 cellpadding=2 cellspacing=2>\n";

	if ($nopid) {
	    $pidrow="";
	} else {
	    $pidrow="\n<th>PID</th>";
	}
	
	echo "<tr>$pidrow
              <th>EID</th>
              <th>State</th>
1019 1020
              <th align=center>Nodes [1]</th>
              <th align=center>Hours Idle [2]</th>
1021 1022 1023
              <th>Description</th>
          </tr>\n";

1024 1025 1026
	$idlemark = "<b>*</b>";
	$stalemark = "<b>?</b>";
	
1027 1028 1029
	while ($row = mysql_fetch_array($query_result)) {
	    $pid  = $row[pid];
	    $eid  = $row[eid];
1030
	    $state= $row[state];
1031 1032 1033
	    $nodes= $row["nodes"];
	    $minnodes = $row["min_nodes"];
	    $idlehours = TBGetExptIdleTime($pid,$eid);
1034 1035
	    $stale = TBGetExptIdleStale($pid,$eid);
	    $ignore = $row["idle_ignore"];
1036
	    $name = $row[expt_name];
1037
	    if ($nodes==0) {
1038
		$nodes = "<font color=green>$minnodes</font>";
1039 1040
	    } elseif ($row[swap_requests] > 0) {
		$nodes .= $idlemark;
1041 1042 1043 1044 1045 1046 1047 1048
	    }

	    if ($nopid) {
		$pidrow="";
	    } else {
		$pidrow="\n<td>".
		    "<A href='showproject.php3?pid=$pid'>$pid</A></td>";
	    }
1049 1050 1051 1052 1053 1054

	    $idlestr = $idlehours;
	    if ($idlehours > 0) {
		if ($stale) { $idlestr .= $stalemark; }
		if ($ignore) { $idlestr = "($idlestr)"; $parens=1; }
	    } elseif ($idlehours == -1) { $idlestr = "&nbsp;"; }
1055 1056 1057
	    
	    echo "<tr>$pidrow
                 <td><A href='showexp.php3?pid=$pid&eid=$eid'>$eid</A></td>
1058
		 <td>$state</td>
1059
                 <td align=center>$nodes</td>
1060
                 <td align=center>$idlestr</td>
1061 1062 1063 1064
                 <td>$name</td>
             </tr>\n";
	}
	echo "</table>\n";
1065 1066 1067
	echo "<table align=center cellpadding=0 class=stealth><tr>\n".
	    "<td class=stealth align=left><font size=-1><ol>\n".
	    "<li>Node counts in <font color=green><b>green</b></font>\n".
1068
	    "show a rough estimate of the minimum number of \n".
1069 1070 1071 1072 1073 1074
	    "nodes <br>required to swap in.\n".
	    "They account for delay nodes, but not for node types, etc.\n".
	    "<li>A $stalemark indicates that the data is stale, and ".
	    "at least one node in the experiment has not <br>reported ".
	    "on its proper schedule.\n"; 
	if ($parens) {
1075
            # do not show this unless we did it... most users should not ever
1076 1077 1078 1079 1080
	    # need to know that some expts have their idleness ignored
	    echo "Values are in parenthesis for idle-ignore experiments.\n";
	}
	echo "</ol></font></td></tr></table>\n";

1081
    }
1082 1083
}

1084 1085 1086
#
# Show Node information for an experiment.
#
1087
function SHOWNODES($pid, $eid, $sortby) {
1088
    global $SCRIPT_NAME;
1089
    global $TBOPSPID;
1090
    
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
    #
    # If this is an expt in emulab-ops, we also want to see the reserved
    # time. Note that vname might not be useful, but show it anyway.
    #
    # XXX The above is not always true. There are also real experiments in
    # emulab-ops.
    #
    if (!isset($sortby)) {
	$sortclause = "n.type,n.priority";
    }
    elseif ($sortby == "vname") {
	$sortclause = "r.vname";
    }
    elseif ($sortby == "rsrvtime-up") {
	$sortclause = "rsrvtime asc";
    }
    elseif ($sortby == "rsrvtime-down") {
	$sortclause = "rsrvtime desc";
    }
    elseif ($sortby == "nodeid") {
	$sortclause = "n.node_id";
    }
    else {
	$sortclause = "n.type,n.priority";
1115
    }
1116

1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
    # XXX
    if ($pid == "emulab-ops" && $eid == "hwdown") {
	$showlastlog = 1;
    }
    else {
	$showlastlog = 0;
    }	

    if ($showlastlog) {
	#
	# We need to extract, for each node, just the latest nodelog message.
	# I could not figure out how to do this in a single select so instead
	# create a temporary table of node_id and latest log message date
	# for all reserved nodes to re-join with nodelog to extract the latest
	# log message.
	#
	DBQueryFatal("CREATE TEMPORARY TABLE nodelogtemp ".
		     "SELECT r.node_id, MAX(reported) AS reported ".
		     "FROM reserved AS r ".
		     "LEFT JOIN nodelog AS l ON r.node_id=l.node_id ".
1137
		     "WHERE r.eid='$eid' and r.pid='$pid' ".
1138 1139 1140 1141 1142 1143 1144 1145
		     "GROUP BY r.node_id");
	#
	# Now join this table and nodelog with the standard set of tables
	# to get all the info we need.  Note the inner join with the temp
	# table, this is faster and still safe since it has an entry for
	# every reserved node.
	#
	$query_result =