showstuff.php3 80.8 KB
Newer Older
1 2
<?php
#
Leigh Stoller's avatar
Leigh Stoller committed
3
# EMULAB-COPYRIGHT
Leigh Stoller's avatar
Leigh Stoller committed
4
# Copyright (c) 2000-2006 University of Utah and the Flux Group.
Leigh Stoller's avatar
Leigh 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 18
    global $WIKISUPPORT, $CVSSUPPORT, $TBPROJ_DIR, $TBCVSREPO_DIR;
    global $MAILMANSUPPORT, $OPSCVSURL, $USERNODE;
19 20
    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];
42
    # These are now booleans, not actual counts.
Leigh Stoller's avatar
Leigh Stoller committed
43 44
    $proj_ronpcs        = $row[num_ron];
    $proj_plabpcs       = $row[num_pcplab];
45
    $proj_linked        = $row[linked_to_us];
46
    $proj_why           = nl2br($row[why]);
47
    $control_node	= $row[control_node];
48
    $approved           = $row[approved];
49 50
    $expt_count         = $row[expt_count];
    $expt_last          = $row[expt_last];
51
    $wikiname           = $row[wikiname];
52
    $cvsrepo_public     = $row[cvsrepo_public];
53

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

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

68 69 70 71 72 73 74 75 76 77 78 79 80 81
    if ($proj_ronpcs) {
	$proj_ronpcs = "Yes";
    }
    else {
	$proj_ronpcs = "No";
    }
    
    if ($proj_plabpcs) {
	$proj_plabpcs = "Yes";
    }
    else {
	$proj_plabpcs = "No";
    }

82 83 84 85
    if (!$expt_last) {
	$expt_last = "&nbsp";
    }

86 87 88 89 90
    #
    # Generate the table.
    # 
    echo "<tr>
              <td>Name: </td>
91 92
              <td class=\"left\">
                <a href='showproject.php3?pid=$pid'>$pid</a></td>
93 94 95 96 97 98 99 100 101 102
          </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\">
103
                <A href='showuser.php3?target_uid=$proj_head_uid'>
104 105 106 107 108 109 110 111
                     $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";
112 113

    if ($WIKISUPPORT && isset($wikiname)) {
114
	$wikiurl = "gotowiki.php3?redurl=$wikiname/WebHome";
115 116 117 118 119
	
	echo "<tr>
                  <td>Project Wiki:</td>
                  <td class=\"left\">
                      <A href='$wikiurl'>$wikiname</A></td>
120 121 122
              </tr>\n";
    }
    if ($CVSSUPPORT) {
123
	$cvsdir = "$TBCVSREPO_DIR/$pid";
124 125 126 127 128
	$cvsurl = "cvsweb/cvsweb.php3?pid=$pid";
	
	echo "<tr>
                  <td>Project CVS Repository:</td>
                  <td class=\"left\">
129
                      $cvsdir <A href='$cvsurl'>(CVSweb)</A></td>
130
              </tr>\n";
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

	$YesNo = ($cvsrepo_public ? "Yes" : "No");
	$flip  = ($cvsrepo_public ? 0 : 1);
	echo "<tr>
              <td>CVS Repository Publically Readable?:</td>
              <td><a href=toggle.php?pid=$pid&type=cvsrepo_public&value=$flip>
                     $YesNo</a> (Click to toggle)</td>
              </tr>\n";

	if ($cvsrepo_public) {
	    $puburl  = "$OPSCVSURL/?cvsroot=$pid";
	    $pserver = ":pserver:anoncvs@$USERNODE:/cvsrepos/$pid";
		
	    echo "<tr>
                      <td>Public CVSWeb Address:</td>
                      <td><a href=$puburl>" .
		            htmlspecialchars($puburl) . "</a></td>
                  </tr>\n";

	    echo "<tr>
                      <td>CVS pserver Address:</td>
                      <td>" . htmlspecialchars($pserver) . "</td>
                  </tr>\n";
	}
155
    }
156 157 158 159 160 161 162 163 164 165

    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";
Leigh Stoller's avatar
Leigh Stoller committed
166
	    echo "<A href='$mmurl'>(admin access)</A>";
167 168 169 170 171
	}
	echo "    </td>
              </tr>\n";
    }

172 173 174 175 176
    echo "<tr>
              <td>Publicly Visible: </td>
              <td class=\"left\">$proj_public</td>
          </tr>\n";
    
177 178 179 180 181
    echo "<tr>
              <td>Link to Us?: </td>
              <td class=\"left\">$proj_linked</td>
          </tr>\n";
    
182 183 184 185 186
    echo "<tr>
              <td>Funders: </td>
              <td class=\"left\">$proj_funders</td>
          </tr>\n";

187 188 189 190 191 192 193 194 195 196 197
    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>
198
              <td>Planetlab Access: </td>
199 200 201 202
              <td class=\"left\">$proj_plabpcs</td>
          </tr>\n";
    
    echo "<tr>
203
              <td>RON Access: </td>
204
              <td class=\"left\">$proj_ronpcs</td>
205 206 207 208 209 210 211
          </tr>\n";
    
    echo "<tr>
              <td>Created: </td>
              <td class=\"left\">$proj_created</td>
          </tr>\n";
    
212 213 214 215
    #echo "<tr>
    #          <td>Expires: </td>
    #          <td class=\"left\">$proj_expires</td>
    #      </tr>\n";
216
    
217 218 219 220 221 222 223 224 225 226
    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";
    
227 228 229 230 231 232 233 234 235 236
    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";

237
    echo "<tr>
238
              <td colspan='2'>Why?:</td>
239 240 241 242 243 244 245 246 247
          </tr>\n";
    
    echo "<tr>
              <td colspan='2' width=600>$proj_why</td>
          </tr>\n";
    
    echo "</table>\n";
}

Leigh Stoller's avatar
Leigh Stoller committed
248 249 250
#
# A Group
#
251
function SHOWGROUP($pid, $gid, $thisuid) {
252
    global $OURDOMAIN;
253 254
    global $MAILMANSUPPORT;
    global $TBDB_TRUST_GROUPROOT;
255
    
Leigh Stoller's avatar
Leigh Stoller committed
256 257 258 259
    $query_result =
	DBQueryFatal("SELECT * FROM groups WHERE pid='$pid' and gid='$gid'");
    $row = mysql_fetch_array($query_result);

260 261 262 263
    echo "<center>
          <h3>Group Profile</h3>
          </center>
          <table align=center border=1>\n";
Leigh Stoller's avatar
Leigh Stoller committed
264 265 266

    $leader	= $row[leader];
    $created	= $row[created];
267
    $description= $row[description];
Leigh Stoller's avatar
Leigh Stoller committed
268 269 270 271 272
    $expt_count = $row[expt_count];
    $expt_last  = $row[expt_last];
    $unix_gid   = $row[unix_gid];
    $unix_name  = $row[unix_name];

273 274 275 276 277
    if (strcmp($pid,$gid))
	$mail = "$pid-$gid" . "-users@" . $OURDOMAIN;
    else
	$mail = "$pid" . "-users@" . $OURDOMAIN;

Leigh Stoller's avatar
Leigh Stoller committed
278 279 280 281 282 283
    if (!$expt_last) {
	$expt_last = "&nbsp";
    }

    #
    # Generate the table.
284
    #
Leigh Stoller's avatar
Leigh Stoller committed
285 286
    echo "<tr>
              <td>GID: </td>
287
              <td class=\"left\">
288
                <a href='showgroup.php3?pid=$pid&gid=$gid'>$gid</a></td>
Leigh Stoller's avatar
Leigh Stoller committed
289 290 291 292
          </tr>\n";
    
    echo "<tr>
              <td>PID: </td>
293 294
              <td class=\"left\">
                <a href='showproject.php3?pid=$pid'>$pid</a></td>
Leigh Stoller's avatar
Leigh Stoller committed
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
          </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";
    
318 319 320 321 322 323 324 325 326 327
    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";
328
	    echo "<A href='$mmurl'>(admin page)</A>";
329 330 331 332 333 334 335 336 337 338 339
	}
	echo "    </td>
              </tr>\n";
    }
    else {
	echo "<tr>
                  <td>Email List: </td>
                  <td class=\"left\">$mail</td>
              </tr>\n";
    }

Leigh Stoller's avatar
Leigh Stoller committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
    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.
#
361
function SHOWGROUPMEMBERS($pid, $gid, $prived = 0) {
Leigh Stoller's avatar
Leigh Stoller committed
362 363 364 365 366 367 368 369
    $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;
    }
370
    $showdel = (($prived && !strcmp($pid, $gid)) ? 1 : 0);
Leigh Stoller's avatar
Leigh Stoller committed
371

372 373 374 375 376 377 378 379
    echo "<center>\n";
    if (strcmp($pid, $gid)) {
	echo "<h3>Group Members</h3>\n";
    }
    else {
	echo "<h3>Project Members</h3>\n";
    }
    echo "</center>
380
          <table align=center border=1 cellpadding=1 cellspacing=2>\n";
Leigh Stoller's avatar
Leigh Stoller committed
381 382

    echo "<tr>
383 384 385 386 387
              <th>Name</th>\n";
    if (strcmp($pid, $gid)) {
	echo "<th>Email</th>\n";
    }
    echo "    <th>UID</th>
388 389 390 391 392
              <th>Privs</th>\n";
    if ($showdel) {
	echo "<th>Remove</th>\n";
    }
    echo "</tr>\n";
Leigh Stoller's avatar
Leigh Stoller committed
393 394 395 396

    while ($row = mysql_fetch_array($query_result)) {
        $target_uid = $row[uid];
	$usr_name   = $row[usr_name];
397
	$usr_email  = $row[usr_email];
Leigh Stoller's avatar
Leigh Stoller committed
398 399 400
	$trust      = $row[trust];

        echo "<tr>
401 402 403 404 405
                  <td>$usr_name</td>\n";
	if (strcmp($pid, $gid)) {
	    echo "<td>$usr_email</td>\n";
	}
	echo "    <td>
Leigh Stoller's avatar
Leigh Stoller committed
406 407
                    <A href='showuser.php3?target_uid=$target_uid'>
                       $target_uid</A>
408 409 410 411
                  </td>\n";
	
	if (TBTrustConvert($trust) != $TBDB_TRUST_NONE) {
	    echo "<td>$trust</td>\n";
Leigh Stoller's avatar
Leigh Stoller committed
412 413
	}
	else {
414 415 416
	    echo "<td><font color=red>$trust</font></td>\n";
	}
	if ($showdel) {
Leigh Stoller's avatar
Leigh Stoller committed
417
	    echo "<td align=center>
418 419 420
		      <A href='deleteuser.php3?target_uid=$target_uid";
	    echo         "&target_pid=$pid'>
                         <img alt=N src=redball.gif></td>\n";
Leigh Stoller's avatar
Leigh Stoller committed
421 422 423 424 425 426
	}
	echo "</tr>\n";
    }
    echo "</table>\n";
}

427 428 429 430
#
# A list of groups for a user.
#
function SHOWGROUPMEMBERSHIP($uid) {
431 432
    $none = TBDB_TRUSTSTRING_NONE;
    
433 434
    $query_result =
	DBQueryFatal("SELECT * FROM group_membership ".
435 436
		     "WHERE uid='$uid' and trust!='$none' ".
		     "order by pid");
437 438 439 440 441 442 443 444 445 446 447
    
    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
448 449 450
              <th>PID</th>
              <th>GID</th>
              <th>Privs</th>
451 452 453 454 455 456 457
          </tr>\n";

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

458 459
	if (TBTrustConvert($trust) != $TBDB_TRUST_NONE) {
	    echo "<tr>
460 461 462
              <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";
463 464
	    echo "</tr>\n";
	}
465 466 467 468
    }
    echo "</table>\n";
}

469 470 471 472
#
# A User
#
function SHOWUSER($uid) {
473
    global $WIKISUPPORT;
474 475 476

    $userinfo_result =
	DBQueryFatal("SELECT * from users where uid='$uid'");
477 478

    $row	= mysql_fetch_array($userinfo_result);
479
    #$usr_expires = $row[usr_expires];
480 481
    $usr_email   = $row[usr_email];
    $usr_URL     = $row[usr_URL];
482 483 484 485 486 487 488
    $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];
489
    $usr_phone   = $row[usr_phone];
490 491 492
    $usr_shell   = $row[usr_shell];
    $usr_title   = $row[usr_title];
    $usr_affil   = $row[usr_affil];
493
    $status      = $row[status];
494 495
    $admin       = $row[admin];
    $adminoff    = $row[adminoff];
496 497 498 499
    $notes       = $row[notes];
    $frozen      = $row['weblogin_frozen'];
    $failcount   = $row['weblogin_failcount'];
    $failstamp   = $row['weblogin_failstamp'];
500
    $wikiname    = $row['wikiname'];
501
    $cvsweb      = $row['cvsweb'];
502
    $wikionly    = $row['wikionly'];
503

504 505 506 507 508 509 510 511
    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";
512 513
    if (!strcmp($usr_country, ""))
	$usr_country = "&nbsp";
514 515
    if (!strcmp($notes, ""))
	$notes = "&nbsp";
516

517 518 519 520 521
    #
    # Last Login info.
    #
    if (($lastweblogin = LASTWEBLOGIN($uid)) == 0)
	$lastweblogin = "&nbsp";
522
    if (($lastuserslogininfo = TBUsersLastLogin($uid)) == 0)
523 524 525
	$lastuserslogin = "N/A";
    else {
	$lastuserslogin = $lastuserslogininfo["date"] . " " .
526
		          $lastuserslogininfo["time"];
527 528 529 530 531 532 533 534 535
    }
    
    if (($lastnodelogininfo = TBUidNodeLastLogin($uid)) == 0)
	$lastnodelogin = "N/A";
    else {
	$lastnodelogin = $lastnodelogininfo["date"] . " " .
		         $lastnodelogininfo["time"] . " " .
                         "(" . $lastnodelogininfo["node_id"] . ")";
    }
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
    
    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";
553

554 555 556 557
    echo "<tr>
              <td>Home Page URL:</td>
              <td><A href='$usr_URL'>$usr_URL</A></td>
          </tr>\n";
558 559

    if ($WIKISUPPORT && isset($wikiname)) {
560
	$wikiurl = "gotowiki.php3?redurl=Main/$wikiname";
561 562 563 564 565 566 567
	
	echo "<tr>
                  <td>Emulab Wiki Page:</td>
                  <td class=\"left\">
                      <A href='$wikiurl'>$wikiname</A></td>
              </tr>\n";
    }
568
    
569 570 571 572
    #echo "<tr>
    #          <td>Expiration date:</td>
    #          <td>$usr_expires</td>
    #      </tr>\n";
573 574
    
    echo "<tr>
575
              <td>Address 1:</td>
576 577 578
              <td>$usr_addr</td>
          </tr>\n";
    
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
    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>
595
              <td>ZIP:</td>
596 597
              <td>$usr_zip</td>
          </tr>\n";
598 599 600 601 602

    echo "<tr>
              <td>Country:</td>
              <td>$usr_country</td>
          </tr>\n";
603
    
604 605 606 607
    echo "<tr>
              <td>Phone #:</td>
              <td>$usr_phone</td>
          </tr>\n";
608 609 610 611 612

    echo "<tr>
	      <td>Shell:</td>
	      <td>$usr_shell</td>
          </tr>\n";
613 614 615 616 617 618 619 620 621 622 623
    
    echo "<tr>
              <td>Title/Position:</td>
              <td>$usr_title</td>
         </tr>\n";
    
    echo "<tr>
              <td>Institutional Affiliation:</td>
              <td>$usr_affil</td>
          </tr>\n";
    
624 625 626 627
    echo "<tr>
              <td>Status:</td>
              <td>$status</td>
          </tr>\n";
628

629 630 631 632 633 634 635
    if ($wikionly) {
	echo "<tr>
                  <td><b>Wikionly</b>:</td>
                  <td>Yes</td>
              </tr>\n";
    }

636 637 638 639
    if ($admin) {
	$onoff = ($adminoff ? "Off" : "On");
	$flip  = ($adminoff ? 0 : 1);
	echo "<tr>
640 641 642 643
              <td>Admin (on/off):</td>
              <td>Yes
              <a href=toggle.php?target_uid=$uid&type=adminoff&value=$flip>
              ($onoff)</td>
644 645
              </tr>\n";
    }
646
    
647 648 649 650 651 652 653 654 655 656
    echo "<tr>
              <td>Last Web Login:</td>
              <td>$lastweblogin</td>
          </tr>\n";
    
    echo "<tr>
              <td>Last Users Login:</td>
              <td>$lastuserslogin</td>
          </tr>\n";
    
657 658 659 660
    echo "<tr>
              <td>Last Node Login:</td>
              <td>$lastnodelogin</td>
          </tr>\n";
661 662

    if (ISADMIN()) {
663 664 665 666 667 668 669 670
	$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";
	
671 672 673 674 675 676 677 678 679 680 681
	$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);
	    
682
	    echo "<tr>
683 684
                      <td>Login Failures:</td>
                      <td>$failcount ($when)</td>
685
                  </tr>\n";
686 687 688 689 690
	}
	echo "<tr>
                  <td>Notes:</td>
                  <td>$notes</td>
              </tr>\n";
691
    }
692 693 694 695
    echo "</table>\n";

}

696 697 698
#
# Show an experiment.
#
699
function SHOWEXP($pid, $eid, $short = 0, $sortby = "") {
700
    global $TBDBNAME, $TBDOCBASE;
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
    $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;
    }
716
		
Leigh Stoller's avatar
Leigh Stoller committed
717
    $query_result =
718
	DBQueryFatal("select e.*, s.archive_idx, pl.slicename, ". 
719 720
                     "round(e.minimum_nodes+.1,0) as min_nodes, ".
		     "round(e.maximum_nodes+.1,0) as max_nodes ".
721 722 723
		     " from experiments as e ".
		     "left join experiment_stats as s on s.exptidx=e.idx ".
		     "left join plab_slices as pl".
724
                     " on e.pid = pl.pid and e.eid = pl.eid ".
725
		     "where e.pid='$pid' and e.eid='$eid'");
726
    
Leigh Stoller's avatar
Leigh Stoller committed
727 728 729
    if (($exprow = mysql_fetch_array($query_result)) == 0) {
	TBERROR("Experiment $eid in project $pid is gone!\n", 1);
    }
730

Leigh Stoller's avatar
Leigh Stoller committed
731
    $exp_gid     = $exprow[gid];
732
    $exp_name    = $exprow[expt_name];
733
    $exp_swapped = $exprow[expt_swapped];
734
    $exp_swapuid = $exprow[expt_swap_uid];
735 736 737
    $exp_end     = $exprow[expt_end];
    $exp_created = $exprow[expt_created];
    $exp_head    = $exprow[expt_head_uid];
738
    $exp_state   = $exprow[state];
739
    $exp_shared  = $exprow[shared];
740 741
    $exp_path    = $exprow[path];
    $batchmode   = $exprow[batchmode];
742
    $canceled    = $exprow[canceled];
743
    $attempts    = $exprow[attempts];
744
    $expt_locked = $exprow[expt_locked];
745 746
    $priority    = $exprow[priority];
    $swappable   = $exprow[swappable];
747
    $noswap_reason = $exprow[noswap_reason];
748
    $idleswap    = $exprow[idleswap];
749
    $idleswap_timeout  = $exprow[idleswap_timeout];
750
    $noidleswap_reason = $exprow[noidleswap_reason];
751
    $autoswap    = $exprow[autoswap];
752
    $autoswap_timeout  = $exprow[autoswap_timeout];
753
    $idle_ignore = $exprow[idle_ignore];
754
    $savedisk    = $exprow[savedisk];
755 756
    $swapreqs    = $exprow[swap_requests];
    $lastswapreq = $exprow[last_swap_req];
757
    $minnodes    = $exprow["min_nodes"];
758
    $maxnodes    = $exprow["max_nodes"];
759
    $syncserver  = $exprow["sync_server"];
760 761
    $mem_usage   = $exprow["mem_usage"];
    $cpu_usage   = $exprow["cpu_usage"];
762
    $exp_slice   = $exprow[slicename];
763 764
    $linktest_level = $exprow["linktest_level"];
    $linktest_pid   = $exprow["linktest_pid"];
765 766 767
    $usemodelnet = $exprow["usemodelnet"];
    $mnet_cores  = $exprow["modelnet_cores"];
    $mnet_edges  = $exprow["modelnet_edges"];
768
    $lockdown    = $exprow["lockdown"];
769
    $exptidx     = $exprow["idx"];
770
    $archive_idx = $exprow["archive_idx"];
771

772 773
    $autoswap_hrs= ($autoswap_timeout/60.0);
    $idleswap_hrs= ($idleswap_timeout/60.0);
774 775 776 777
    $noswap = "($noswap_reason)";
    $noidleswap = "($noidleswap_reason)";
    $autoswap_str= $autoswap_hrs." hour".($autoswap_hrs==1 ? "" : "s");
    $idleswap_str= $idleswap_hrs." hour".($idleswap_hrs==1 ? "":"s");
778

779 780 781 782
    if ($swappable)
	$swappable = "Yes";
    else
	$swappable = "<b>No</b> $noswap";
783

784 785 786 787
    if ($idleswap)
	$idleswap = "Yes (after $idleswap_str)";
    else
	$idleswap = "<b>No</b> $noidleswap";
788

789 790 791 792
    if ($autoswap)
	$autoswap = "<b>Yes</b> (after $autoswap_str)";
    else
	$autoswap = "No";
793

794 795 796 797
    if ($idle_ignore)
	$idle_ignore = "<b>Yes</b>";
    else
	$idle_ignore = "No";
798

799 800 801 802 803
    if ($savedisk)
	$savedisk = "<b>Yes</b>";
    else
	$savedisk = "No";

804 805 806 807 808
    if ($expt_locked)
	$expt_locked = "($expt_locked)";
    else
	$expt_locked = "";

809 810 811
    #
    # Generate the table.
    #
Chad Barb's avatar
Chad Barb committed
812
    echo "<table align=center cellpadding=2 cellspacing=2 border=1>\n";
813

814 815 816 817 818
    if (!$short) {
	echo "<tr>
                <td>Name: </td>
                <td class=left>$eid</td>
              </tr>\n";
819

820
	echo "<tr>
Leigh Stoller's avatar
Leigh Stoller committed
821
                <td>Description: </td>
822 823
                <td class=\"left\">$exp_name</td>
              </tr>\n";
824

825 826 827 828 829
	echo "<tr>
                <td>Project: </td>
                <td class=\"left\">
                  <a href='showproject.php3?pid=$pid'>$pid</a></td>
              </tr>\n";
830

831 832 833 834 835 836
        echo "<tr>
                <td>Group: </td>
                <td class=\"left\">
                  <a href='showgroup.php3?pid=$pid&gid=$exp_gid'>$exp_gid</a>
                </td>
              </tr>\n";
837 838 839 840 841 842 843

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

846 847 848
    echo "<tr>
            <td>Experiment Head: </td>
            <td class=\"left\">
849
              <a href='showuser.php3?target_uid=$exp_head'>$exp_head</a></td>
850 851
          </tr>\n";

852 853 854 855
    if (!$short) {
	echo "<tr>
                <td>Created: </td>
                <td class=\"left\">$exp_created</td>
856
              </tr>\n";
857

858 859 860 861 862 863
	if ($exp_swapped) {
	    echo "<tr>
                    <td>Last Swap/Modify: </td>
                    <td class=\"left\">$exp_swapped ($exp_swapuid)</td>
                  </tr>\n";
	}
864

865 866 867 868 869 870 871 872 873 874 875 876 877
	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";
878

879
	echo "<tr>
880 881 882 883
                <td><a href='$TBDOCBASE/docwrapper.php3?".
	               "docname=swapping.html#autoswap'>Max. Duration:</a></td>
                <td class=\"left\">$autoswap</td>
              </tr>\n";
884 885 886 887 888 889

	echo "<tr>
                <td><a href='$TBDOCBASE/docwrapper.php3?".
	               "docname=swapping.html#swapstatesave'>Save State:</a></td>
                <td class=\"left\">$savedisk</td>
              </tr>\n";
890

891 892 893 894 895 896 897 898 899 900 901
	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";
902

903 904 905 906
        echo "<tr>
                <td>Status: </td>
                <td class=\"left\">$exp_state $expt_locked</td>
              </tr>\n";
907 908 909 910 911 912 913 914 915 916 917 918 919

	if ($linktest_pid) {
	    $linktest_running = "<b>(Linktest Running)</b>";
	}
	else {
	    $linktest_running = "";
	}

	echo "<tr>
                <td><a href='doc/docwrapper.php3?docname=linktest.html'>".
	            "Linktest Level</a>: </td>
                <td class=\"left\">$linktest_level $linktest_running</td>
              </tr>\n";
920
    }
921

922
    if (count($nodecounts)) {
923
	echo "<tr>
924 925
                 <td>Reserved Nodes: </td>
                 <td class=\"left\">\n";
926 927 928
	while (list ($class, $count) = each($nodecounts)) {
	    echo "$count ($class) &nbsp ";
	}
929 930 931 932
	echo "   </td>
              </tr>\n";
    }
    elseif (!$short) {
933 934
	if ($minnodes!="") {
	    echo "<tr>
935
                      <td>Min/Max Nodes: </td>
936
                      <td class=\"left\"><font color=green>
937
                          $minnodes/$maxnodes (estimates)</font></td>
938 939 940
                  </tr>\n";
	}
	else {
941
	    echo "<tr>
942 943 944
                      <td>Minumum Nodes: </td>
                      <td class=\"left\"><font color=green>Unknown</font></td>
                  </tr>\n";
945
	}
946
    }
947 948 949 950 951 952
    if (!$short) {
	if ($mem_usage || $cpu_usage) {
	    echo "<tr>
                      <td>Mem Usage Est: </td>
                      <td class=\"left\">$mem_usage</td>
                  </tr>\n";
953

954 955 956 957 958
	    echo "<tr>
                      <td>CPU Usage Est: </td>
                      <td class=\"left\">$cpu_usage</td>
                  </tr>\n";
	}
959

960 961 962
	$lastact = TBGetExptLastAct($pid,$eid);
	$idletime = TBGetExptIdleTime($pid,$eid);
	$stale = TBGetExptIdleStale($pid,$eid);
963
    
964 965 966 967 968
	if ($lastact != -1) {
	    echo "<tr>
                      <td>Last Activity: </td>
                      <td class=\"left\">$lastact</td>
                  </tr>\n";
969

970
	    if ($stale) { $str = "(stale)"; } else { $str = ""; }
971
	
972 973 974 975 976
	    echo "<tr>
                      <td>Idle Time: </td>
                      <td class=\"left\">$idletime hours $str</td>
                  </tr>\n";
	}
977

978 979 980 981 982
	if (! ($swapreqs=="" || $swapreqs==0)) {
	    echo "<tr>
                      <td>Swap Requests: </td>
                      <td class=\"left\">$swapreqs</td>
                  </tr>\n";
983

984 985 986 987 988
	    echo "<tr>
                      <td>Last Swap Req.: </td>
                      <td class=\"left\">$lastswapreq</td>
                  </tr>\n";
	}
989 990 991 992 993 994 995 996 997

	$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";
998
    }
999

1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
    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";
    }
1011

1012
    if ($canceled) {
1013
	echo "<tr>
1014 1015
                 <td>Cancel Flag: </td>
                 <td class=\"left\">$canceled</td>
1016 1017 1018
              </tr>\n";
    }

1019
    if (!$short) {
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
	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";

	}
1035 1036 1037 1038 1039 1040
	if (isset($syncserver)) {
	    echo "<tr>
                      <td>Sync Server: </td>
                      <td class=\"left\">$syncserver</td>
                  </tr>\n";
	}
1041 1042
        echo "<tr>
                  <td>Index: </td>
1043 1044 1045 1046
                  <td class=\"left\">$exptidx";
	if ($archive_idx)
	    echo " ($archive_idx) ";
	echo " </td>
1047
              </tr>\n";
1048 1049
    }

1050 1051 1052
    echo "</table>\n";
}

1053 1054 1055
#
# Show a listing of experiments by user/pid/gid
#
1056
function SHOWEXPLIST($type,$fromuid,$id,$gid = "") {
1057 1058
    global $TB_EXPTSTATE_SWAPPED, $TB_EXPTSTATE_SWAPPING;
    
1059 1060 1061 1062 1063 1064 1065 1066
    if ($type == "USER") {
	$where = "expt_head_uid='$id'";
	$title = "Current";
    } elseif ($type == "PROJ") {
	$where = "e.pid='$id'";
	$title = "Project";
	$nopid = 1;
    } elseif ($type == "GROUP") {
1067
	$where = "e.pid='$id' and e.gid='$gid'";
1068 1069 1070 1071 1072 1073
	$title = "Group";
	$nopid = 1;
    } else {
	$where = "e.eid='$id'";
	$title = "Bad id '$id'!";
    }
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096

    if (ISADMIN()) {
	$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");
    }
    else {
	$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 ".
			 "left join group_membership as g on g.pid=e.pid and ".
			 "     g.gid=e.gid and g.uid='$fromuid' ".
			 "where g.uid is not null and ($where) ".
			 "group by e.pid,e.eid order by e.state,e.eid");
    }
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
    
    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>
1113 1114
              <th align=center>Nodes [1]</th>
              <th align=center>Hours Idle [2]</th>
1115 1116 1117
              <th>Description</th>
          </tr>\n";

1118 1119 1120
	$idlemark = "<b>*</b>";
	$stalemark = "<b>?</b>";
	
1121 1122 1123
	while ($row = mysql_fetch_array($query_result)) {
	    $pid  = $row[pid];
	    $eid  = $row[eid];
1124
	    $state= $row[state];
1125 1126 1127
	    $nodes= $row["nodes"];
	    $minnodes = $row["min_nodes"];
	    $idlehours = TBGetExptIdleTime($pid,$eid);
1128 1129
	    $stale = TBGetExptIdleStale($pid,$eid);
	    $ignore = $row["idle_ignore"];
1130
	    $name = $row[expt_name];
1131
	    if ($nodes==0) {
1132
		$nodes = "<font color=green>$minnodes</font>";
1133 1134
	    } elseif ($row[swap_requests] > 0) {
		$nodes .= $idlemark;
1135 1136 1137 1138 1139 1140 1141 1142
	    }

	    if ($nopid) {
		$pidrow="";
	    } else {
		$pidrow="\n<td>".
		    "<A href='showproject.php3?pid=$pid'>$pid</A></td>";
	    }
1143 1144 1145 1146 1147 1148

	    $idlestr = $idlehours;
	    if ($idlehours > 0) {
		if ($stale) { $idlestr .= $stalemark; }
		if ($ignore) { $idlestr = "($idlestr)"; $parens=1; }
	    } elseif ($idlehours == -1) { $idlestr = "&nbsp;"; }
1149 1150 1151
	    
	    echo "<tr>$pidrow
                 <td><A href='showexp.php3?pid=$pid&eid=$eid'>$eid</A></td>
1152
		 <td>$state</td>
1153
                 <td align=center>$nodes</td>
1154
                 <td align=center>$idlestr</td>
1155 1156 1157 1158
                 <td>$name</td>
             </tr>\n";
	}
	echo "</table>\n";
1159 1160 1161
	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".
1162
	    "show a rough estimate of the minimum number of \n".
1163 1164 1165 1166 1167 1168
	    "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) {
1169
            # do not show this unless we did it... most users should not ever
1170 1171 1172 1173 1174
	    # 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";

1175
    }
1176 1177
}

1178 1179 1180
#
# Show Node information for an experiment.
#
Mike Hibler's avatar
Mike Hibler committed
1181
function SHOWNODES($pid, $eid, $sortby, $showclass) {
1182
    global $SCRIPT_NAME;
1183
    global $TBOPSPID;
1184
    
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
    #
    # 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";
1209
    }
1210

1211 1212 1213
    # XXX
    if ($pid == "emulab-ops" && $eid == "hwdown") {
	$showlastlog = 1;
Mike Hibler's avatar
Mike Hibler committed
1214 1215 1216
	if (empty($showclass)) {
	    $showclass = "no-pcplabphys";
	}
1217 1218 1219 1220 1221
    }
    else {
	$showlastlog = 0;
    }	

Mike Hibler's avatar
Mike Hibler committed
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
    if (!empty($showclass)) {
	$classclause = "";
	$noclassclause = "";
	$opts = explode(",", $showclass);
	foreach ($opts as $opt) {
	    if (preg_match("/^no-([-\w]+)$/", $opt, $matches)) {
		if (!empty($noclassclause)) {
		    $noclassclause .= ",";
		}
		$noclassclause .= "'$matches[1]'";
	    } elseif ($opt == "all") {
		$classclause = "";
		$noclassclause = "";
	    } else {
		if (!empty($classclause)) {
		    $classclause .= ",";
		}
		$classclause .= "'$opt'";
	    }
	}
	if (!empty($classclause)) {
	    $classclause = "and nt.class in (" . $classclause . ")";
	}
	if (!empty($noclassclause)) {
	    $noclassclause = "and nt.class not in (" . $noclassclause . ")";
	}
    }

1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
    #
    # Discover whether to show or hide certain columns
    #
    $colcheck_query_result = 
      DBQueryFatal("SELECT sum(oi.OS = 'Windows') as winoscount, ".
                   "       sum(nt.isplabdslice) as plabcount ".
                   "from reserved as r ".
                   "left join nodes as n on n.node_id=r.node_id ".
                   "left join os_info as oi on n.def_boot_osid=oi.osid ".
                   "left join node_types as nt on n.type = nt.type ".
                   "WHERE r.eid='$eid' and r.pid='$pid'");
    $colcheckrow = mysql_fetch_array($colcheck_query_result);
    $anywindows = $colcheckrow[winoscount];
    $anyplab    = $colcheckrow[plabcount];

1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
    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 ".
1277
		     "WHERE r.eid='$eid' and r.pid='$pid' ".
1278 1279 1280 1281 1282 1283 1284 1285
		     "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 =
1286 1287
	    DBQueryFatal("SELECT r.*,n.*,nt.isvirtnode,nt.isplabdslice, ".
                         " oi.OS,tip.tipname,wa.site,wa.hostname, ".
1288 1289 1290 1291 1292
		         " ns.status as nodestatus, ".
		         " date_format(rsrv_time,\"%Y-%m-%d&nbsp;%T\") as rsrvtime, ".
		         "nl.reported,nl.entry ".
		         "from reserved as r ".
		         "left join nodes as n on n.node_id=r.node_id ".
1293
                         "left join widearea_nodeinfo as wa on wa.node_id=n.phys_nodeid ".
1294 1295
		         "left join node_types as nt on nt.type=n.type ".
		         "left join node_status as ns on ns.node_id=r.node_id ".
1296
		         "left join os_info as oi on n.def_boot_osid=oi.osid ".
1297
			 "left join tiplines as tip on tip.node_id=r.node_id ".
1298 1299 1300 1301
		         "inner join nodelogtemp as t on t.node_id=r.node_id ".
		         "left join nodelog as nl on nl.node_id=r.node_id and nl.reported=t.reported ".

		         "WHERE r.eid='$eid' and r.pid='$pid' ".
Mike Hibler's avatar
Mike Hibler committed
1302
			 "$classclause $noclassclause".
1303 1304 1305 1306 1307
		         "ORDER BY $sortclause");
	DBQueryFatal("DROP table nodelogtemp");
    }
    else {
	$query_result =
1308 1309
	    DBQueryFatal("SELECT r.*,n.*,nt.isvirtnode,nt.isplabdslice, ".
                         " oi.OS,tip.tipname,wa.site,wa.hostname, ".
1310 1311 1312 1313
		         " ns.status as nodestatus, ".
		         " date_format(rsrv_time,\"%Y-%m-%d&nbsp;%T\") as rsrvtime ".
		         "from reserved as r ".
		         "left join nodes as n on n.node_id=r.node_id ".
1314
                         "left join widearea_nodeinfo as wa on wa.node_id=n.phys_nodeid ".
1315 1316
		         "left join node_types as nt on nt.type=n.type ".
		         "left join node_status as ns on ns.node_id=r.node_id ".
1317
		         "left join os_info as oi on n.def_boot_osid=oi.osid ".
1318
			 "left join tiplines as tip on tip.node_id=r.node_id ".
1319
		         "WHERE r.eid='$eid' and r.pid='$pid' ".
Mike Hibler's avatar
Mike Hibler committed
1320
			 "$classclause $noclassclause".
1321 1322
		         "ORDER BY $sortclause");
    }
1323 1324
    
    if (mysql_num_rows($query_result)) {
1325 1326 1327 1328 1329
	echo "<center>
              <h3>Reserved Nodes</h3>
              </center>
              <table align=center border=1>
              <tr>
1330
                <th><a href=\"$SCRIPT_NAME?pid=$pid&eid=$eid".
Mike Hibler's avatar
Mike Hibler committed
1331 1332
	                        "&sortby=nodeid&showclass=$showclass\">
				Node ID</a></th>
1333
                <th><a href=\"$SCRIPT_NAME?pid=$pid&eid=$eid".
Mike Hibler's avatar
Mike Hibler committed
1334 1335
	                 "&sortby=vname&showclass=$showclass\">
				Name</a></th>\n";
1336 1337 1338 1339 1340 1341 1342

        # Only show 'Site' column if there are plab nodes.
        if ($anyplab) {
            echo "  <th>Site</th>
                    <th>Widearea<br>Hostname</th>\n";
        }

1343 1344 1345
	if ($pid == $TBOPSPID) {
	    echo "<th>Reserved<br>
                      <a href=\"$SCRIPT_NAME?pid=$pid&eid=$eid".
Mike Hibler's avatar
Mike Hibler committed
1346
		         "&sortby=rsrvtime-up&showclass=$showclass\">Up</a> or 
1347
                      <a href=\"$SCRIPT_NAME?pid=$pid&eid=$eid".
Mike Hibler's avatar
Mike Hibler committed
1348
		         "&sortby=rsrvtime-down&showclass=$showclass\">Down</a>
1349 1350 1351
                  </th>\n";
	}
	echo "  <th>Type</th>
1352 1353
                <th>Default OSID</th>
                <th>Node<br>Status</th>
1354
                <th>Hours<br>Idle[<b>1</b>]</th>
1355 1356 1357 1358 1359
                <th>Startup<br>Status[<b>2</b>]</th>\n";
	if ($showlastlog) {
	    echo "  <th>Last Log<br>Time</th>
		    <th>Last Log Message</th>\n";
	}
1360

1361
        echo "  <th><a href=\"docwrapper.php3?docname=ssh-mime.html\">SSH</a></th>
1362 1363
                <th><a href=\"faq.php3#tiptunnel\">Console</a></th> .
                <th>Log</th>";
1364 1365 1366 1367 1368 1369 1370 1371

	# Only put out a RDP column header if there are any Windows nodes.
	if ($anywindows) {
            echo "  <th>
                        <a href=\"docwrapper.php3?docname=rdp-mime.html\">RDP</a>
                    </th>\n";
	}
	echo "  </tr>\n";
1372

1373
	$stalemark = "<b>?</b>";
1374
	$count = 0;
1375

1376 1377
	while ($row = mysql_fetch_array($query_result)) {
	    $node_id = $row[node_id];
1378 1379
	    $vname   = $row[vname];
	    $rsrvtime= $row[rsrvtime];
1380
	    $type    = $row[type];
1381 1382
            $wasite  = $row[site];
            $wahost  = $row[hostname];
1383 1384
	    $def_boot_osid = $row[def_boot_osid];
	    $startstatus   = $row[startstatus];
1385
	    $status        = $row[nodestatus];
1386
	    $bootstate     = $row[eventstate];
1387
	    $isvirtnode    = $row[isvirtnode];
1388
            $isplabdslice  = $row[isplabdslice];
1389
	    $tipname       = $row[tipname];
1390
	    $iswindowsnode = $row[OS]=='Windows';
1391 1392 1393 1394 1395 1396 1397 1398
	    $idlehours = TBGetNodeIdleTime($node_id);
	    $stale = TBGetNodeIdleStale($node_id);

	    $idlestr = $idlehours;
	    if ($idlehours > 0) {
		if ($stale) { $idlestr .= $stalemark; }
		if ($ignore) { $idlestr = "($idlestr)"; $parens=1; }
	    } elseif ($idlehours == -1) { $idlestr = "&nbsp;"; }
1399

1400 1401 1402
	    if (!$vname)
		$vname = "--";

1403 1404 1405 1406 1407
	    if ($count & 1) {
		echo "<tr></tr>\n";
	    }
	    $count++;

1408
	    echo "<tr>
1409
                    <td><A href='shownode.php3?node_id=$node_id'>$node_id</a></td>
1410
                    <td>$vname</td>\n";
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420

            if ($isplabdslice) {
              echo "  <td>$wasite</td>
                      <td>$wahost</td>\n";
            }
            elseif ($anyplab) {
              echo "  <td>&nbsp</td>
                      <td>&nbsp</td>\n";
            }

1421 1422 1423
	    if ($pid == $TBOPSPID)
		echo "<td>$rsrvtime</td>\n";
            echo "  <td>$type</td>\n";
1424 1425 1426
	    if ($def_boot_osid) {
		echo "<td>";
		SPITOSINFOLINK($def_boot_osid);
1427
		echo "</td>\n";
1428
	    }
1429 1430
	    else
		echo "<td>&nbsp</td>\n";
1431 1432 1433 1434 1435 1436

	    if ($bootstate != "ISUP") {
		echo "  <td>$status ($bootstate)</td>\n";
	    } else {
		echo "  <td>$status</td>\n";
	    }
1437
	    
1438
	    echo "  <td>$idlestr</td>
1439 1440
                    <td align=center>$startstatus</td>\n";

1441 1442
	    if ($showlastlog) {
		echo "  <td>$row[reported]</td>\n";
1443 1444 1445
		echo "  <td>$row[entry] 
                            (<a href='shownodelog.php3?node_id=$node_id'>LOG</a>)
                        </td>\n";
1446 1447
	    }

1448
	    echo "  <td align=center>
1449 1450 1451 1452
                        <A href='nodessh.php3?node_id=$node_id'>
                        <img src=\"ssh.gif\" alt=s></A>
                    </td>\n";

1453
	    if ($isvirtnode || !isset($tipname) || $tipname = '') {
1454 1455 1456 1457
		echo "<td>&nbsp</td>\n";
	    }
	    else {
		echo "  <td align=center>
1458 1459 1460
                            <A href='nodetipacl.php3?node_id=$node_id'>
                            <img src=\"console.gif\" alt=c></A>
                        </td>\n";
1461 1462 1463 1464 1465 1466

		echo "  <td align=center>
                            <A href='showconlog.php3?node_id=$node_id".
		                  "&linecount=200'>
                            <img src=\"/icons/f.gif\" alt='console log'></A>
                        </td>\n";
1467
	    }
1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478

	    if ($iswindowsnode) {
		echo "  <td align=center>
                            <A href='noderdp.php3?node_id=$node_id'>
                            <img src=\"rdp.gif\" alt=r></A>
                        </td>\n";
	    }
	    elseif ($anywindows) {
		echo "  <td>&nbsp</td>\n";
	    }

1479
	    echo "</tr>\n";
1480 1481
	}
	echo "</table>\n";
1482 1483
	echo "<h4><blockquote><blockquote><blockquote>
              <ol>
1484 1485
	        <li>A $stalemark indicates that the data is stale, and
	            the node has not reported on its proper schedule. 
1486
                <li>Exit value of the node startup command. A value of
1487
                        666 indicates a testbed internal error.
1488 1489
              </ol>
              </blockquote></blockquote></blockquote></h4>\n";
1490 1491 1492
    }
}

1493 1494 1495 1496
#
# Show OS INFO record.
#
function SHOWOSINFO($osid) {
1497 1498
    $query_result =
	DBQueryFatal("SELECT * FROM os_info WHERE osid='$osid'");
1499 1500 1501

    $osrow = mysql_fetch_array($query_result);

1502
    $os_description = $osrow[description];
1503 1504 1505 1506 1507
    $os_OS          = $osrow[OS];
    $os_version     = $osrow[version];
    $os_path        = $osrow[path];
    $os_magic       = $osrow[magic];
    $os_osfeatures  = $osrow[osfeatures];
1508
    $os_op_mode     = $osrow[op_mode];
1509
    $os_pid         = $osrow[pid];
1510 1511
    $os_shared      = $osrow[shared];
    $os_osname      = $osrow[osname];
1512 1513
    $creator        = $osrow[creator];
    $created        = $osrow[created];
1514
    $mustclean      = $osrow[mustclean];
1515
    $nextosid       = $osrow[nextosid];
1516
    $max_concurrent = $osrow[max_concurrent];
1517
    $reboot_waittime= $osrow[reboot_waittime];
1518 1519 1520 1521 1522 1523 1524 1525 1526