menu.php3 27 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5 6
# All rights reserved.
#
7

8
$login_status     = CHECKLOGIN_NOTLOGGEDIN;
9
$login_uid        = 0;
10
$drewheader       = 0;
11
$autorefresh      = 0;
12

13 14 15 16 17 18
#
# This has to be set so we can spit out http or https paths properly!
# Thats because browsers do not like a mix of secure and nonsecure.
# 
$BASEPATH	  = "";

19
#
20 21
# TOPBARCELL - Make a cell for the topbar. Actually, the name lies, it can be
# used for cells in a bottombar too.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#
function TOPBARCELL($contents) {
    echo "<td class=\"topbaropt\">";
    echo "<span class=\"topbaroption\">&nbsp;";
    echo $contents;
    echo "&nbsp;</span>";
    echo "</td>";
    echo "\n";
}

#
# SIDEBARCELL - Make a cell for the sidebar
#
function SIDEBARCELL($contents, $last = 0) {
    echo "<tr>";
    if ($last) {
	echo "<td class=\"menuoptb\">";
    } else {
	echo "<td class=\"menuopt\">";
    }
42
    echo "$contents";
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    echo "</td>";
    echo "</tr>";
    echo "\n";
}

#
# WRITETOPBARBUTTON(text, base, link): Write a button in the topbar
#
function WRITETOPBARBUTTON($text, $base, $link ) {
    $link = "$base/$link";
    TOPBARCELL("<a href=\"$link\">$text</a>");
}
# same as above with "new" gif next to it.
function WRITETOPBARBUTTON_NEW($text, $base, $link ) {
    $link = "$base/$link";
    TOPBARCELL("<a href=\"$link\">$text</a>&nbsp;<img src=\"/new.gif\" />");
}

61 62 63 64 65 66 67
#
# WRITESIDEBARDIVIDER(): Put a bit of whitespace in the sidebar
#
function WRITESIDEBARDIVIDER() {
    global $BASEPATH;
    echo "<tr>";
    echo "<td class=\"menuoptdiv\">";
68
    # We have to put something in this cell, or IE ignores it. But, we do not
69 70 71 72 73 74 75
    # want to make the table row full line-height, so a space will not do.
    echo "<img src=\"$BASEPATH/1px.gif\" border=0 height=1 width=1 />";
    echo "</td>";
    echo "</tr>";
    echo "\n";
}

76 77 78 79 80
#
# WRITESIDEBARBUTTON(text, link): Write a button on the sidebar menu.
# We do not currently try to match the current selection so that its
# link looks different. Not sure its really necessary.
#
Chad Barb's avatar
 
Chad Barb committed
81
function WRITESIDEBARBUTTON($text, $base, $link ) {
82
    $link = "$base/$link";
83
    SIDEBARCELL("<a href=\"$link\">$text</a>");
Chad Barb's avatar
 
Chad Barb committed
84
}
85

Chad Barb's avatar
 
Chad Barb committed
86 87 88
# same as above with "new" gif next to it.
function WRITESIDEBARBUTTON_NEW($text, $base, $link ) {
    $link = "$base/$link";
89
    SIDEBARCELL("<a href=\"$link\">$text</a>&nbsp;<img src=\"/new.gif\" />");
Chad Barb's avatar
 
Chad Barb committed
90 91
}

Chad Barb's avatar
 
Chad Barb committed
92 93 94
# same as above with "cool" gif next to it.
function WRITESIDEBARBUTTON_COOL($text, $base, $link ) {
    $link = "$base/$link";
95
    SIDEBARCELL("<a href=\"$link\">$text</a>&nbsp;<img src=\"/cool.gif\" />");
Chad Barb's avatar
 
Chad Barb committed
96 97
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
98 99
function WRITESIDEBARBUTTON_ABS($text, $base, $link ) {
    $link = "$link";
100
    SIDEBARCELL("<a href=\"$link\">$text</a>\n");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
101 102
}

Chad Barb's avatar
 
Chad Barb committed
103 104
function WRITESIDEBARBUTTON_ABSCOOL($text, $base, $link ) {
    $link = "$link";
105
    SIDEBARCELL("<a href=\"$link\">$text</a>&nbsp;<img src=\"/cool.gif\" />");
Chad Barb's avatar
 
Chad Barb committed
106 107
}

Chad Barb's avatar
 
Chad Barb committed
108 109 110 111 112
# same as above, but uses a slightly different style sheet so there
# is more padding below the last button.
# The devil is, indeed, in the details.
function WRITESIDEBARLASTBUTTON($text, $base, $link) {
    $link = "$base/$link";
113
    SIDEBARCELL("<a href=\"$link\">$text</a>",1);
Chad Barb's avatar
 
Chad Barb committed
114 115
}

Chad Barb's avatar
Chad Barb committed
116 117
function WRITESIDEBARLASTBUTTON_COOL($text, $base, $link) {
    $link = "$base/$link";
118
    SIDEBARCELL("<a href=\"$link\">$text</a>&nbsp;<img src=\"/cool.gif\" />",1);
Chad Barb's avatar
Chad Barb committed
119 120
}

Chad Barb's avatar
 
Chad Barb committed
121 122
# writes a message to the sidebar, without clickability.
function WRITESIDEBARNOTICE($text) {
123 124 125 126 127 128 129 130 131 132 133 134 135 136
    SIDEBARCELL("<b>$text</b>");
}

#
# Something like the sidebar, but across the top, with only a few options.
# Think Google. For PlanetLab users, but it would be easy enough to make
# others. Still a work in progress.
#
function WRITEPLABTOPBAR() {
    echo "<table class=\"topbar\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" align=\"center\">\n";
    global $login_status, $login_uid;
    global $TBBASE, $TBDOCBASE, $BASEPATH;
    global $THISHOMEBASE;

137 138
    WRITETOPBARBUTTON("Create a Slice",
        $TBBASE, "plab_ez.php3");
139

140
    WRITETOPBARBUTTON("Nodes",
141 142 143 144 145 146 147 148
        $TBBASE, "plabmetrics.php3");

    WRITETOPBARBUTTON("My Testbed",
	$TBBASE,
	"showuser.php3?target_uid=$login_uid");


    WRITETOPBARBUTTON("Advanced Experiment",
149
        $TBBASE, "beginexp_html.php3");
150

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    if ($login_status & CHECKLOGIN_TRUSTED) {
	# Only project/group leaders can do these options
	# Show a "new" icon if there are people waiting for approval
	$query_result =
	DBQueryFatal("select g.* from group_membership as authed ".
		     "left join group_membership as g on ".
		     " g.pid=authed.pid and g.gid=authed.gid ".
		     "left join users as u on u.uid=g.uid ".
		     "where u.status!='".
		     TBDB_USERSTATUS_UNVERIFIED . "' and ".
		     " u.status!='" . TBDB_USERSTATUS_NEWUSER . 
		     "' and g.uid!='$login_uid' and ".
		     "  g.trust='". TBDB_TRUSTSTRING_NONE . "' ".
		     "  and authed.uid='$login_uid' and ".
		     "  (authed.trust='group_root' or ".
		     "   authed.trust='project_root') ".
		     "ORDER BY g.uid,g.pid,g.gid");
	if (mysql_num_rows($query_result) > 0) {
	     WRITETOPBARBUTTON_NEW("Approve Users",
				   $TBBASE, "approveuser_form.php3");
	} else {
	    WRITETOPBARBUTTON("Approve Users",
			       $TBBASE, "approveuser_form.php3");
	}
    }

    WRITETOPBARBUTTON("Log Out", $TBBASE, "logout.php3?next_page=" .
	urlencode($TBBASE . "/login_plab.php3"));

180 181 182
    echo "</table>\n";
    echo "<br>\n";

183 184
}

185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201

#
# Put a few things that PlanetLab users should see, but are non-essential,
# across the bottom of the page rather than the top
#
function WRITEPLABBOTTOMBAR() {
    global $login_status, $login_uid;
    global $TBBASE, $TBDOCBASE, $BASEPATH;
    global $THISHOMEBASE;

    if ($login_uid) {
	$newsBase = $TBBASE; 
    } else {
	$newsBase = $TBDOCBASE;
    }

    echo "
202 203 204
	   <center>
	   <br>
	   <font size=-1>
205
	   <form method=get action=$TBDOCBASE/search.php3>
206 207 208 209
	   [ <a href='$TBDOCBASE/doc.php3'>
		Documentation</a> : <input name=query size = 15/>
		  <input type=submit style='font-size:10px;' value='Search' /> ]
	   [ <a href='$newsBase/news.php3'>
210
		News</a> ]
211 212 213 214
	   </form>
	   </font>
	   <br>
	   </center>\n";
215 216 217

}

218 219 220 221 222
#
# WRITESIDEBAR(): Write the menu. The actual menu options the user
# sees depends on the login status and the DB status.
#
function WRITESIDEBAR() {
223 224
    global $login_status, $login_uid;
    global $TBBASE, $TBDOCBASE, $BASEPATH;
225
    global $THISHOMEBASE;
226 227 228

    #
    # The document base cannot be a mix of secure and nonsecure.
229
    #
Chad Barb's avatar
 
Chad Barb committed
230 231 232
    
    # create the main menu table, which also happens to reside in a form
    # (for search.)
Chad Barb's avatar
 
Chad Barb committed
233 234 235 236 237 238 239 240 241

    #
    # get post time of most recent news;
    # get both displayable version and age in days.
    #
    $query_result = 
	DBQueryFatal("SELECT DATE_FORMAT(date, '%M&nbsp;%e') AS prettydate, ".
		     " (TO_DAYS(NOW()) - TO_DAYS(date)) AS age ".
		     "FROM webnews ".
242
		     "WHERE archived=0 ".
Chad Barb's avatar
 
Chad Barb committed
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
		     "ORDER BY date DESC ".
		     "LIMIT 1");
    $newsDate = "";
    $newNews  = 0;

    #
    # This is so an admin can use the editing features of news.
    #
    if ($login_uid) { # && ISADMIN($login_uid)) { 
	$newsBase = $TBBASE; 
    } else {
	$newsBase = $TBDOCBASE;
    }

    if ($row = mysql_fetch_array($query_result)) {
	$newsDate = "(".$row[prettydate].")";
	if ($row[age] < 7) {
	    $newNews = 1;
	}
    }

264
    echo "<FORM method=get ACTION=$TBDOCBASE/search.php3>\n";
Chad Barb's avatar
 
Chad Barb committed
265
?>
266
  <table class="menu" width=210 cellpadding="0" cellspacing="0">
Chad Barb's avatar
 
Chad Barb committed
267 268
    <tr><td class="menuheader"><b>Information</b></td></tr>
<?php
Chad Barb's avatar
 
Chad Barb committed
269 270 271 272 273 274
    if (0 == strcasecmp($THISHOMEBASE, "emulab.net")) {
	$rootEmulab = 1;
    } else {
	$rootEmulab = 0;
    }

275
    WRITESIDEBARBUTTON("Home", $TBDOCBASE, "index.php3?stayhome=1");
276

Chad Barb's avatar
 
Chad Barb committed
277 278

    if ($rootEmulab) {
279
	WRITESIDEBARBUTTON("Other Emulabs", $TBDOCBASE,
Chad Barb's avatar
 
Chad Barb committed
280 281 282 283 284 285
			       "docwrapper.php3?docname=otheremulabs.html");
    } else {
	WRITESIDEBARBUTTON_ABS("Utah Emulab", $TBDOCBASE,
			       "http://www.emulab.net/");

    }
Chad Barb's avatar
 
Chad Barb committed
286

Chad Barb's avatar
 
Chad Barb committed
287 288 289 290 291 292
    if ($newNews) {
	WRITESIDEBARBUTTON_NEW("News $newsDate", $newsBase, "news.php3");
    } else {
	WRITESIDEBARBUTTON("News $newsDate", $newsBase, "news.php3");
    }

293
    WRITESIDEBARBUTTON("Documentation", $TBDOCBASE, "doc.php3");
Chad Barb's avatar
 
Chad Barb committed
294 295

    if ($rootEmulab) {
296
	WRITESIDEBARBUTTON("Papers (Oct 28)", $TBDOCBASE, "pubs.php3");
297
	WRITESIDEBARBUTTON("Software (Mar 12)",
298
			       $TBDOCBASE, "software.php3");
299 300 301 302 303 304 305 306 307 308
	WRITESIDEBARBUTTON("Add Widearea Node (CD)",
				$TBDOCBASE, "cdrom.php");

	SIDEBARCELL("<a href=\"$TBDOCBASE/people.php3\">People</a> and " .
	            "<a href=\"$TBDOCBASE/gallery/gallery.php3\">Photos</a>");

	SIDEBARCELL("Emulab <a href=\"$TBDOCBASE/doc/docwrapper.php3? " .
		    "docname=users.html\">Users</a> and " .
	            "<a href=\"$TBDOCBASE/docwrapper.php3? " .
		    "docname=sponsors.html\">Sponsors</a>",1);
Chad Barb's avatar
 
Chad Barb committed
309
    } else {
310 311 312
	# Link ALWAYS TO UTAH
	WRITESIDEBARBUTTON_ABSCOOL("Add Widearea Node (CD)",
			       $TBDOCBASE, "http://www.emulab.net/cdrom.php");
Chad Barb's avatar
 
Chad Barb committed
313 314 315
	WRITESIDEBARLASTBUTTON("Projects on Emulab", $TBDOCBASE,
			       "projectlist.php3");
    }
316

Chad Barb's avatar
 
Chad Barb committed
317 318 319
    # create the search bit, then the second table for the Web Interface.
?>
    <tr><td class="menuoptst"><b>Search Documentation:</b></td></tr>
320 321 322
    <tr><td class="menuoptsb"><input name=query size = 15/>
      <input type=submit style="font-size:10px;" value="Go" /><br>
    </td></tr>
323 324 325 326
<?php # BACK TO PHP
    echo "</table>\n";
    echo "</form>\n";
?>
327
<table class="menu" width=210 cellpadding="0" cellspacing="0">
328 329 330
    <tr><td class="menuheader">
      <b>Interaction</b>
    </td></tr>
Chad Barb's avatar
 
Chad Barb committed
331
<?php # BACK TO PHP
332

333
    if ($login_status & CHECKLOGIN_LOGGEDIN) {
Chad Barb's avatar
 
Chad Barb committed
334
         $freepcs = TBFreePCs();
335
	 WRITESIDEBARNOTICE( "($freepcs free PCs)" );
336
    }
337

338 339 340 341 342 343 344 345
    #
    # Basically, we want to let admin people continue to use
    # the web interface even when nologins set. But, we want to make
    # it clear its disabled.
    # 
    if (NOLOGINS()) {
        WRITESIDEBARBUTTON("<font color=red> ".
			   "Web Interface Temporarily Unavailable</font>",
346 347
			   $TBDOCBASE, "nologins.php3");

Chad Barb's avatar
 
Chad Barb committed
348 349 350
        if (!$login_uid || !ISADMIN($login_uid)) {	
	    WRITESIDEBARNOTICE("Please Try Again Later");
        }
351
    }
Chad Barb's avatar
 
Chad Barb committed
352

353 354 355
    if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
	if ($login_status & CHECKLOGIN_ACTIVE) {
	    if ($login_status & CHECKLOGIN_PSWDEXPIRED) {
356
		WRITESIDEBARBUTTON("Change Your Password",
357
				   $TBBASE, "moduserinfo.php3");
358
	    }
359 360 361 362 363 364 365
	    elseif ($login_status & CHECKLOGIN_WEBONLY) {
		WRITESIDEBARBUTTON("My Emulab",
				   $TBBASE,
				   "showuser.php3?target_uid=$login_uid");
	    
		WRITESIDEBARBUTTON("Update User Information",
				   $TBBASE, "moduserinfo.php3");
366 367 368 369 370 371 372 373 374

	        if (ISADMIN($login_uid)) {
		    WRITESIDEBARBUTTON("Approve New Projects",
				       $TBBASE, "approveproject_list.php3");
		    WRITESIDEBARBUTTON("User List",
				       $TBBASE, "showuser_list.php3");
		    WRITESIDEBARBUTTON("New User Approval",
				       $TBBASE, "approveuser_form.php3");
		}
375
	    }
376
	    else {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
377
		WRITESIDEBARBUTTON("My Emulab",
378 379
				   $TBBASE,
				   "showuser.php3?target_uid=$login_uid");
380
	    
381 382 383 384
                # Since a user can be a member of more than one project,
                # display this option, and let the form decide if the 
                # user is allowed to do this.
                #
385

386
		WRITESIDEBARDIVIDER();
387

388 389
 		WRITESIDEBARBUTTON("Begin an Experiment",
				   $TBBASE, "beginexp_html.php3");
390

391 392
		# Put _NEW back when Plab is working again.
		WRITESIDEBARBUTTON("Create a PlanetLab Slice",
393 394 395 396 397 398 399 400 401 402
				       $TBBASE, "plab_ez.php3");

		WRITESIDEBARBUTTON("Experiment List",
				   $TBBASE, "showexp_list.php3");

		WRITESIDEBARDIVIDER();

		WRITESIDEBARBUTTON("Node Status",
				   $TBBASE, "nodecontrol_list.php3");

403 404 405 406 407
		SIDEBARCELL("List <a " .
			"href=\"$TBBASE/showimageid_list.php3\">" .
	        	"ImageIDs</a> or <a " .
	                "href=\"$TBBASE/showosid_list.php3\">OSIDs</a>");

408 409 410
		if ($login_status & CHECKLOGIN_CVSWEB) {
		    WRITESIDEBARBUTTON("CVS Repository",
				       $TBBASE, "cvsweb/cvsweb.php3");
411 412
		}
		if ($login_status & CHECKLOGIN_TRUSTED) {
413
		  WRITESIDEBARDIVIDER();
414 415 416
                  # Only project/group leaders can do these options
                  # Show a "new" icon if there are people waiting for approval
		  $query_result =
417 418 419
		    DBQueryFatal("select g.* from group_membership as authed ".
				 "left join group_membership as g on ".
				 " g.pid=authed.pid and g.gid=authed.gid ".
420
				 "left join users as u on u.uid=g.uid ".
421
				 "where u.status!='".
422
				 TBDB_USERSTATUS_UNVERIFIED . "' and ".
423 424 425 426 427 428
				 " u.status!='" . TBDB_USERSTATUS_NEWUSER . 
				 "' and g.uid!='$login_uid' and ".
				 "  g.trust='". TBDB_TRUSTSTRING_NONE . "' ".
				 "  and authed.uid='$login_uid' and ".
				 "  (authed.trust='group_root' or ".
				 "   authed.trust='project_root') ".
429 430 431 432 433
				 "ORDER BY g.uid,g.pid,g.gid");
		  if (mysql_num_rows($query_result) > 0) {
		    WRITESIDEBARBUTTON_NEW("New User Approval",
					   $TBBASE, "approveuser_form.php3");
		  } else {
434 435

		      WRITESIDEBARBUTTON("New User Approval",
436
				       $TBBASE, "approveuser_form.php3");
437
		  }
438
		}
439
		if (ISADMIN($login_uid)) {
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
		    WRITESIDEBARDIVIDER();

		    SIDEBARCELL("List <a " .
				" href=\"$TBBASE/showproject_list.php3\">" .
		                "Projects</a> or <a " .
		                "href=\"$TBBASE/showuser_list.php3\">Users</a>");

		    WRITESIDEBARBUTTON("View Testbed Stats",
				       $TBBASE, "showstats.php3");

		    WRITESIDEBARBUTTON("Approve New Projects",
				       $TBBASE, "approveproject_list.php3");

		    WRITESIDEBARBUTTON("Approve Widearea User",
				       $TBBASE, "approvewauser_form.php3");
455

Chad Barb's avatar
 
Chad Barb committed
456 457
		    WRITESIDEBARBUTTON("Edit Site Variables",
				       $TBBASE, "editsitevars.php3");
458 459 460 461 462 463 464 465 466 467

		    $query_result
		      = DBQUeryFatal("select new_node_id from new_nodes");
                    if (mysql_num_rows($query_result) > 0) {
		        WRITESIDEBARBUTTON_NEW("Add Testbed Nodes",
				           $TBBASE, "newnodes_list.php3");
		    } else {
		        WRITESIDEBARBUTTON("Add Testbed Nodes",
				           $TBBASE, "newnodes_list.php3");
		    }
468

469
		}
470

471
	    }
472
	}
473
	elseif ($login_status & (CHECKLOGIN_UNVERIFIED|CHECKLOGIN_NEWUSER)) {
474 475
	    WRITESIDEBARBUTTON("New User Verification",
			       $TBBASE, "verifyusr_form.php3");
476
	    WRITESIDEBARBUTTON("Update User Information",
477
			       $TBBASE, "moduserinfo.php3");
478
	}
479
	elseif ($login_status & (CHECKLOGIN_UNAPPROVED)) {
480
	    WRITESIDEBARBUTTON("Update User Information",
481
			       $TBBASE, "moduserinfo.php3");
482
	}
483 484 485
	#
	# Standard options for logged in users!
	# 
486 487 488 489
	WRITESIDEBARDIVIDER();
	SIDEBARCELL("<a href=\"$TBBASE/newproject.php3\">Start</a> or " .
	            "<a href=\"$TBBASE/joinproject.php3\">Join</a> a Project",
		    1);
490
    }
491

492 493
    #WRITESIDEBARLASTBUTTON_COOL("Take our Survey",
    #    $TBDOCBASE, "survey.php3");
494

495 496 497 498 499
    #
    # Cons up a nice message.
    # 
    switch ($login_status & CHECKLOGIN_STATUSMASK) {
    case CHECKLOGIN_LOGGEDIN:
Chad Barb's avatar
Chad Barb committed
500
	$login_message = "'$login_uid' Logged in.";
501 502
	    
	if ($login_status & CHECKLOGIN_PSWDEXPIRED)
Chad Barb's avatar
Chad Barb committed
503
	    $login_message = "$login_message<br>(Password Expired!)";
504
	elseif ($login_status & CHECKLOGIN_UNAPPROVED)
Chad Barb's avatar
Chad Barb committed
505
	    $login_message = "$login_message<br>(Unapproved!)";
506
	break;
507
    case CHECKLOGIN_TIMEDOUT:
Chad Barb's avatar
Chad Barb committed
508
	$login_message = "Login Timed out.";
509
	break;
510 511
    default:
	$login_message = 0;
512
	break;
513 514
    }

Chad Barb's avatar
 
Chad Barb committed
515
    if ($login_message) {
Chad Barb's avatar
 
Chad Barb committed
516
      echo "<tr>";
Chad Barb's avatar
Chad Barb committed
517
      echo "<td class=\"menufooter\" style='padding-top: 6px;' ><center><b>";
Chad Barb's avatar
 
Chad Barb committed
518 519
      echo "$login_message</b></center></td>";
      echo "</tr>";
Chad Barb's avatar
 
Chad Barb committed
520 521
    }

522 523
    #
    # Now the login/logout box. Remember, already inside a table.
524 525
    # We want the links to the login/logout pages to always be https,
    # but the images path depends on whether the page was loaded as
526
    # http or https, since we do not want to mix them, since they
527
    # cause warnings.
528
    # 
529
    if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
Chad Barb's avatar
 
Chad Barb committed
530 531
      echo "<tr>";
      echo "<td class=\"menufooter\" align=center valign=center>";
532
      echo "<a href=\"$TBBASE/logout.php3?target_uid=$login_uid\">";
Chad Barb's avatar
 
Chad Barb committed
533 534 535
      echo "<img alt=\"logoff\" border=0 ";
      echo "src=\"$BASEPATH/logoff.gif\"></a>\n";
      echo "</td></tr>\n";
536
    }
537
    elseif (!NOLOGINS()) {
Chad Barb's avatar
 
Chad Barb committed
538 539
      echo "<tr>";
      echo "<td class=\"menufooter\" align=center valign=center>";
Chad Barb's avatar
Chad Barb committed
540 541 542 543 544 545 546

      echo "<a href=\"$TBBASE/reqaccount.php3\">";
      echo "<img alt=\"Request Account\" border=0 ";
      echo "src=\"$BASEPATH/requestaccount.gif\"></a>";

      echo "<br /><b>or</b><br />";

Chad Barb's avatar
 
Chad Barb committed
547 548 549
      echo "<a href=\"$TBBASE/login.php3\">";
      echo "<img alt=\"logon\" border=0 ";
      echo "src=\"$BASEPATH/logon.gif\"></a>\n";
Chad Barb's avatar
Chad Barb committed
550

Chad Barb's avatar
 
Chad Barb committed
551
      echo "</td></tr>\n";
552
    }
553

554
    #
Chad Barb's avatar
 
Chad Barb committed
555
    # Login message. Set via 'web/message' site variable
556
    #
Chad Barb's avatar
 
Chad Barb committed
557 558
    $message = TBGetSiteVar("web/message");
    if (0 != strcmp($message,"")) {
Robert Ricci's avatar
Robert Ricci committed
559
	WRITESIDEBARNOTICE($message);    	
560
    }
Chad Barb's avatar
 
Chad Barb committed
561

Chad Barb's avatar
 
Chad Barb committed
562
    echo "</table>\n";
563 564
}

Chad Barb's avatar
 
Chad Barb committed
565 566 567
#
# spits out beginning part of page
#
568
function PAGEBEGINNING( $title, $nobanner = 0 ) {
569
    global $BASEPATH, $TBMAINSITE, $THISHOMEBASE, $ELABINELAB;
Chad Barb's avatar
Chad Barb committed
570
    global $TBDIR, $WWW;
Chad Barb's avatar
 
Chad Barb committed
571
    global $MAINPAGE;
572
    global $TBDOCBASE;
573
    global $autorefresh;
Chad Barb's avatar
 
Chad Barb committed
574

Chad Barb's avatar
Chad Barb committed
575
    $MAINPAGE = !strcmp($TBDIR, "/usr/testbed/"); 
Chad Barb's avatar
 
Chad Barb committed
576 577 578 579 580 581
  
    echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 
          'http://www.w3.org/TR/html4/loose.dtd'>
	<html>
	  <head>
	    <title>$THISHOMEBASE - $title</title>
582 583
            <!--<link rel=\"SHORTCUT ICON\" HREF=\"netbed.ico\">-->
            <link rel=\"SHORTCUT ICON\" HREF=\"netbed.png\" TYPE=\"image/png\">
Chad Barb's avatar
 
Chad Barb committed
584 585
    	    <!-- dumbed-down style sheet for any browser that groks (eg NS47). -->
	    <link REL='stylesheet' HREF='$BASEPATH/common-style.css' TYPE='text/css' />
586 587
    	    <!-- do not import full style sheet into NS47, since it does bad job
            of handling it. NS47 does not understand '@import'. -->
Chad Barb's avatar
 
Chad Barb committed
588 589 590 591 592 593 594
    	    <style type='text/css' media='all'>
            <!-- @import '$BASEPATH/style.css'; -->";

    if (!$MAINPAGE) {
	echo "<!-- @import '$BASEPATH/style-nonmain.css'; -->";
    } 

Leigh B. Stoller's avatar
Leigh B. Stoller committed
595
    echo "</style>\n";
Chad Barb's avatar
 
Chad Barb committed
596 597

    if ($TBMAINSITE) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
598 599 600 601 602 603 604
	echo "<meta NAME=\"keywords\" ".
	           "CONTENT=\"network, emulation, internet, emulator\">\n";
	echo "<meta NAME=\"robots\" ".
	           "CONTENT=\"NOARCHIVE\">\n";
	echo "<meta NAME=\"description\" ".
                   "CONTENT=\"emulab - network emulation testbed home\">\n";
    }
Chad Barb's avatar
 
Chad Barb committed
605 606
    echo "</head>
            <body bgcolor='#FFFFFF' 
607
             topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>\n";
608 609 610 611
    
    if ($autorefresh) {
	echo "<meta HTTP-EQUIV=\"Refresh\" CONTENT=\"$autorefresh\">\n";
    }
612
    if (! $nobanner ) {
613 614 615 616 617 618
	echo "<map name=overlaymap>
                 <area shape=rect coords=\"100,60,369,100\"
                       href='http://www.emulab.net/index.php3'>
                 <area shape=rect coords=\"0,0,369,100\"
                       href='$TBDOCBASE/index.php3'>
              </map>
Chad Barb's avatar
 
Chad Barb committed
619 620 621 622
            <table cellpadding='0' cellspacing='0' width='100%'>
            <tr>
              <td valign='top' class='bannercell' 
              background='$BASEPATH/headerbgbb.jpg'
623
              bgcolor=#3D627F>
624 625 626 627 628 629 630 631 632
              <img width=369 height=100 border=0 usemap=\"#overlaymap\" ";

	if ($ELABINELAB) {
	    echo "src='$BASEPATH/overlay.elabinelab.gif' ";
	}
	else {
	    echo "src='$BASEPATH/overlay.".strtolower($THISHOMEBASE).".gif' ";
	}
	echo "alt='$THISHOMEBASE - the network testbed'>\n";
633 634 635 636
	      if (!$MAINPAGE) {
		  echo "<font size='+1' color='#CCFFCC'>&nbsp;<b>$WWW</b></font>";
	      }
	      echo "</td></tr></table>\n";
Chad Barb's avatar
 
Chad Barb committed
637 638 639 640 641 642
    }

    echo "<table cellpadding='8' cellspacing='0' height='100%' width='100%'>
            <tr height='100%'>
              <td valign='top' class='leftcell' bgcolor='#ccddee'>
              <!-- sidebar begins -->";
Chad Barb's avatar
 
Chad Barb committed
643 644 645 646 647 648 649
}

#
# finishes sidebar td
#
function FINISHSIDEBAR()
{
Chad Barb's avatar
 
Chad Barb committed
650
    echo "<!-- sidebar ends -->
Chad Barb's avatar
 
Chad Barb committed
651
        </td>
Chad Barb's avatar
 
Chad Barb committed
652
        <td valign='top' width='100%' class='rightcell'>
653
          <!-- content body table -->
Chad Barb's avatar
 
Chad Barb committed
654
          <table class='content' width='100%' cellpadding='0' cellspacing='0'>
Chad Barb's avatar
 
Chad Barb committed
655
            <tr>
Chad Barb's avatar
 
Chad Barb committed
656
              <td class='contentheader'>";
Chad Barb's avatar
 
Chad Barb committed
657 658
}

659 660 661
#
# Spit out a vanilla page header.
#
662
function PAGEHEADER($title, $view = NULL) {
663
    global $login_status, $login_uid, $TBBASE, $TBDOCBASE, $THISHOMEBASE;
664
    global $BASEPATH, $SSL_PROTOCOL, $drewheader, $autorefresh;
665
    global $TBMAINSITE;
666 667

    $drewheader = 1;
668 669 670
    if (isset($_GET['refreshrate']) && is_numeric($_GET['refreshrate'])) {
	$autorefresh = $_GET['refreshrate'];
    }
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686

    #
    # Determine the proper basepath, which depends on whether the page
    # was loaded as http or https. This lets us be consistent in the URLs
    # we spit back, so that users do not get those pesky warnings. These
    # warnings are generated when a page *loads* (say, images, style files),
    # a mix of http and https. Links can be mixed, and in fact when there
    # is no login active, we want to spit back http for the documentation,
    # but https for the start/join pages.
    #
    if (isset($SSL_PROTOCOL)) {
	$BASEPATH = $TBBASE;
    }
    else {
	$BASEPATH = $TBDOCBASE;
    }
687

688
    #
689
    # Figure out who is logged in, if anyone.
690
    # 
691 692 693 694
    if (($known_uid = GETUID()) != FALSE) {
        #
        # Check to make sure the UID is logged in (not timed out).
        #
695 696 697
        $login_status = CHECKLOGIN($known_uid);
	if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
	    $login_uid = $known_uid;
698 699 700
	}
    }

701 702 703 704 705 706 707
    #
    # If no view options were specified, get the ones for the current user
    #
    if (!$view) {
	$view = GETUSERVIEW();
    }

708
    #
709 710
    # Check for NOLOGINS. 
    # We want to allow admin types to continue using the web interface,
711 712
    # and logout anyone else that is currently logged in!
    #
713 714 715 716
    if (NOLOGINS() && $login_uid && !ISADMIN($login_uid)) {
	DOLOGOUT($login_uid);
	$login_status = CHECKLOGIN_NOTLOGGEDIN;
	$login_uid    = 0;
717
    }
718
    
719 720
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    
721
    if (1) {
722 723 724 725 726 727 728
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
	header("Cache-Control: no-cache, must-revalidate");
	header("Pragma: no-cache");
    }
    else {
	header("Expires: " . gmdate("D, d M Y H:i:s", time() + 300) . " GMT"); 
    }
Chad Barb's avatar
 
Chad Barb committed
729

730 731 732 733 734 735 736 737 738
    if (isset($view['hide_banner'])) {
	$nobanner = 1;
    } else {
	$nobanner = 0;
    }
    PAGEBEGINNING( $title, $nobanner );
    if (!isset($view['hide_sidebar'])) {
	WRITESIDEBAR();
    }
Chad Barb's avatar
 
Chad Barb committed
739
    FINISHSIDEBAR();
740
    echo "<h2 class=\"nomargin\">\n";
Chad Barb's avatar
 
Chad Barb committed
741

742
    if ($login_uid && ISADMINISTRATOR()) {
Chad Barb's avatar
 
Chad Barb committed
743
	if (ISADMIN($login_uid)) {
744
	    echo "<a href=$TBBASE/toggle.php?target_uid=$login_uid&type=adminoff&value=1>
Chad Barb's avatar
 
Chad Barb committed
745 746 747 748
	             <img src='/redball.gif'
                          border=0 alt='Admin On'></a>\n";
	}
	else {
749
	    echo "<a href=$TBBASE/toggle.php?target_uid=$login_uid&type=adminoff&value=0>
Chad Barb's avatar
 
Chad Barb committed
750 751 752
	             <img src='/greenball.gif'
                          border=0 alt='Admin Off'></a>\n";
	}
753
    }
754 755
    $now = date("D M d g:ia T");
    echo "$title</h2></td>\n";
756
    echo "<td class=contentheader align=right>\n";
Robert Ricci's avatar
Robert Ricci committed
757 758
    if ($login_uid) {
	echo "<font size=-1>'<b>$login_uid</b>' Logged in.<br>$now</font>\n";
759 760
    }
    else {
Robert Ricci's avatar
Robert Ricci committed
761
	echo "$now";
Chad Barb's avatar
 
Chad Barb committed
762 763 764 765
    }
    echo "</td>";
    echo "</tr>\n";
    echo "<tr><td colspan=3 class=\"contentbody\" width=*>";
Chad Barb's avatar
 
Chad Barb committed
766
    echo "<!-- begin content -->\n";
767 768 769
    if ($view['show_topbar'] == "plab") {
	WRITEPLABTOPBAR();
    }
770 771 772 773 774 775
}

#
# ENDPAGE(): This terminates the table started above.
# 
function ENDPAGE() {
Chad Barb's avatar
 
Chad Barb committed
776 777
  echo "</td></tr></table>";
  echo "</td></tr></table>";
778 779 780 781 782
}

#
# Spit out a vanilla page footer.
#
783
function PAGEFOOTER($view = NULL) {
784
    global $TBDOCBASE, $TBMAILADDR, $THISHOMEBASE;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
785
    global $TBMAINSITE, $SSL_PROTOCOL;
786

787 788 789 790
    if (!$view) {
	$view = GETUSERVIEW();
    }

791 792
    $today = getdate();
    $year  = $today["year"];
Chad Barb's avatar
 
Chad Barb committed
793

794 795 796 797 798 799
    echo "<!-- end content -->\n";
    if ($view['show_bottombar'] == "plab") {
	WRITEPLABBOTTOMBAR();
    }

    echo "
Chad Barb's avatar
 
Chad Barb committed
800
              </td>
801 802
            </tr>
            <tr>
803 804 805
              <td colspan=2 class=contentbody>\n";
    if (!$view['hide_copyright']) {
	echo "
806 807
	        <center>
                <font size=-1>
808 809 810 811 812 813
		[ <a href=http://www.cs.utah.edu/flux/>
                    The&nbsp;Flux&nbsp;Research&nbsp;Group</a> ]
		[ <a href=http://www.cs.utah.edu/>
                    School&nbsp;of&nbsp;Computing</a> ]
		[ <a href=http://www.utah.edu/>
                    The&nbsp;University&nbsp;of&nbsp;Utah</a> ]
814 815
		</font>
		<br>
Chad Barb's avatar
 
Chad Barb committed
816
                <!-- begin copyright -->
817
                <font size=-2>
818 819 820 821
                <a href='$TBDOCBASE/docwrapper.php3?docname=copyright.html'>
                    Copyright &copy; 2000-$year The University of Utah</a>
                </font>
                <br>
822 823 824
		</center>\n";
    }
    echo "
825
                <p align=right>
Chad Barb's avatar
 
Chad Barb committed
826 827
		  <font size=-2>
                    Problems?
828
	            Contact $TBMAILADDR.
Chad Barb's avatar
 
Chad Barb committed
829 830
                  </font>
                </p>
831
                <!-- end copyright -->\n";
Chad Barb's avatar
 
Chad Barb committed
832 833

    ENDPAGE();
834

Leigh B. Stoller's avatar
Leigh B. Stoller committed
835 836 837
    # Plug the home site from all others.
    echo "\n<p><a href=\"www.emulab.net/netemu.php3\"></a>\n";

Chad Barb's avatar
 
Chad Barb committed
838
    echo "</body></html>\n";
839
}
840 841 842 843 844

function PAGEERROR($msg) {
    global $drewheader;

    if (! $drewheader)
845
	PAGEHEADER("Page Error");
846 847 848 849 850 851

    echo "$msg\n";

    PAGEFOOTER();
    die("");
}
852 853 854 855

#
# Sub Page/Menu Stuff
#
856
function WRITESUBMENUBUTTON($text, $link, $target = "") {
Chad Barb's avatar
 
Chad Barb committed
857

858 859 860 861 862 863
    #
    # Optional 'target' agument, so that we can pop up new windows
    #
    if ($target) {
	$targettext = "target='$target'";
    }
Chad Barb's avatar
 
Chad Barb committed
864

865 866 867 868
    echo "<!-- Table row for button $text -->
          <tr>
            <td valign=center align=left nowrap>
                <b>
869
         	 <a class=sidebarbutton href='$link' $targettext>$text</a>\n";
870 871 872 873 874 875 876 877 878 879

    echo "      </b>
            </td>
          </tr>\n";
}

#
# Start/End a page within a page. 
#
function SUBPAGESTART() {
Chad Barb's avatar
 
Chad Barb committed
880
    echo "<!-- begin subpage -->";
Chad Barb's avatar
 
Chad Barb committed
881
    echo "<table class=\"stealth\"
882
	  cellspacing='0' cellpadding='0' width='100%' border='0'>\n
883
            <tr>\n
Chad Barb's avatar
 
Chad Barb committed
884
              <td class=\"stealth\"valign=top>\n";
885 886 887 888 889 890
}

function SUBPAGEEND() {
    echo "    </td>\n
            </tr>\n
          </table>\n";
Chad Barb's avatar
 
Chad Barb committed
891
    echo "<!-- end subpage -->";
892 893 894 895 896 897 898
}

#
# Start/End a sub menu, located in the upper left of the main frame.
# Note that these cannot be used outside of the SUBPAGE macros above.
#
function SUBMENUSTART($title) {
Chad Barb's avatar
 
Chad Barb committed
899 900
?>
    <!-- begin submenu -->
901
    <table class='menu' cellpadding="0" cellspacing="0"
Chad Barb's avatar
 
Chad Barb committed
902
	style="margin-right: 6px;" >
Chad Barb's avatar
 
Chad Barb committed
903 904 905 906
      <tr>
        <td class="menuheader"><b><?php echo "$title";?></b></td>
      </tr>
<?php
907 908 909
}

function SUBMENUEND() {
Chad Barb's avatar
 
Chad Barb committed
910 911 912 913
?>
    </table>
    <!-- end submenu -->
  </td>
914
  <td class="stealth" valign=top align=left width='100%'>
Chad Barb's avatar
 
Chad Barb committed
915
<?php
916 917
}

918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
# Start a new section in an existing submenu
# This includes ending the one before it
function SUBMENUSECTION($title) {
    SUBMENUSECTIONEND();
?>
      <!-- new submenu section -->
      <tr>
        <td class="menuheader"><b><?php echo "$title";?></b></td>
      </tr>
<?php
}

# End a submenu section - only need this on the last one of the table.
function SUBMENUSECTIONEND() {
?>
      <tr height=5><td></td></tr>
<?php
}
Chad Barb's avatar
 
Chad Barb committed
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952

# These are here so you can wedge something else under the menu in the left column.

function SUBMENUEND_2A() {
?>
    </table>
    <!-- end submenu -->
<?php
}

function SUBMENUEND_2B() {
?>
  </td>
  <td class="stealth" valign=top align=left width='85%'>
<?php
}

953 954 955 956 957 958 959 960 961 962 963 964 965 966
#
# Get a view, for use with PAGEHEADER and PAGEFOOTER, for the current user
#
function GETUSERVIEW() {
    if (GETUID() && ISPLABUSER()) {
	return array('hide_sidebar' => 1, 'hide_banner' => 1,
	    'show_topbar' => "plab", 'show_bottombar' => 'plab',
	    'hide_copyright' => 1);
    } else {
	# Most users get the default view
	return array();
    }
}

967
?>