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

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

12 13 14 15 16 17
#
# 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	  = "";

18
#
19 20
# TOPBARCELL - Make a cell for the topbar. Actually, the name lies, it can be
# used for cells in a bottombar too.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#
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\">";
    }
41
    echo "$contents";
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    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\" />");
}

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#
# WRITESIDEBARDIVIDER(): Put a bit of whitespace in the sidebar
#
function WRITESIDEBARDIVIDER() {
    global $BASEPATH;
    echo "<tr>";
    echo "<td class=\"menuoptdiv\">";
    # We have to put something in this cell, or IE ignores it. But, we don't
    # 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";
}

75 76 77 78 79
#
# 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
80
function WRITESIDEBARBUTTON($text, $base, $link ) {
81
    $link = "$base/$link";
82
    SIDEBARCELL("<a href=\"$link\">$text</a>");
Chad Barb's avatar
 
Chad Barb committed
83
}
84

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

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

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

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

Chad Barb's avatar
 
Chad Barb committed
107 108 109 110 111
# 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";
112
    SIDEBARCELL("<a href=\"$link\">$text</a>",1);
Chad Barb's avatar
 
Chad Barb committed
113 114
}

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

Chad Barb's avatar
 
Chad Barb committed
120 121
# writes a message to the sidebar, without clickability.
function WRITESIDEBARNOTICE($text) {
122 123 124 125 126 127 128 129 130 131 132 133 134 135
    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;

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

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

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


    WRITETOPBARBUTTON("Advanced Experiment",
        $TBBASE, "beginexp.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
    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"));

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

182 183
}

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

#
# 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 "
201 202 203 204 205 206 207 208
	   <center>
	   <br>
	   <font size=-1>
	   <form method=get action='/cgi-bin/webglimpse/usr/testbed/webglimpse'>
	   [ <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'>
209
		News</a> ]
210 211 212 213
	   </form>
	   </font>
	   <br>
	   </center>\n";
214 215 216

}

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

    #
    # The document base cannot be a mix of secure and nonsecure.
228
    #
Chad Barb's avatar
 
Chad Barb committed
229 230 231
    
    # create the main menu table, which also happens to reside in a form
    # (for search.)
Chad Barb's avatar
 
Chad Barb committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261

    #
    # 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 ".
		     "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;
	}
    }

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

273
    WRITESIDEBARBUTTON("Home", $TBDOCBASE, "index.php3");
274

Chad Barb's avatar
 
Chad Barb committed
275 276

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

    }
Chad Barb's avatar
 
Chad Barb committed
284

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

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

    if ($rootEmulab) {
294
	WRITESIDEBARBUTTON("Papers (Oct 28)", $TBDOCBASE, "pubs.php3");
295
	WRITESIDEBARBUTTON("Software <font size=-1> ".
296
			       "(Oct 21)</font>",
297
			       $TBDOCBASE, "software.php3");
298 299 300 301 302 303 304 305 306 307
	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
308
    } else {
309 310 311
	# Link ALWAYS TO UTAH
	WRITESIDEBARBUTTON_ABSCOOL("Add Widearea Node (CD)",
			       $TBDOCBASE, "http://www.emulab.net/cdrom.php");
Chad Barb's avatar
 
Chad Barb committed
312 313 314
	WRITESIDEBARLASTBUTTON("Projects on Emulab", $TBDOCBASE,
			       "projectlist.php3");
    }
315

Chad Barb's avatar
 
Chad Barb committed
316 317 318
    # create the search bit, then the second table for the Web Interface.
?>
    <tr><td class="menuoptst"><b>Search Documentation:</b></td></tr>
319 320 321 322
    <tr><td class="menuoptsb"><input name=query size = 15/>
      <input type=submit style="font-size:10px;" value="Go" /><br>
      [ <a href="<?php echo "$TBDOCBASE/search.php3"; ?>">Advanced Search</a> ]
    </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 366
	    elseif ($login_status & CHECKLOGIN_WEBONLY) {
		WRITESIDEBARBUTTON("My Emulab",
				   $TBBASE,
				   "showuser.php3?target_uid=$login_uid");
	    
		WRITESIDEBARBUTTON("Update User Information",
				   $TBBASE, "moduserinfo.php3");
	    }
367
	    else {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
368
		WRITESIDEBARBUTTON("My Emulab",
369 370
				   $TBBASE,
				   "showuser.php3?target_uid=$login_uid");
371
	    
372 373 374 375
                # 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.
                #
376

377
		WRITESIDEBARDIVIDER();
378 379 380 381 382 383 384 385 386

                if (ISADMINISTRATOR()) {
 		    WRITESIDEBARBUTTON("Begin an Experiment",
				       $TBBASE, "beginexp_html.php3");
                }
                else {
 		    WRITESIDEBARBUTTON("Begin an Experiment",
				       $TBBASE, "beginexp.php3");
                }
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404

		WRITESIDEBARBUTTON_NEW("Create a PlanetLab Slice",
				       $TBBASE, "plab_ez.php3");

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

		WRITESIDEBARDIVIDER();

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

		WRITESIDEBARBUTTON("ImageIDs and OSIDs",
				   $TBBASE, "showimageid_list.php3");
		
		if ($login_status & CHECKLOGIN_CVSWEB) {
		    WRITESIDEBARBUTTON("CVS Repository",
				       $TBBASE, "cvsweb/cvsweb.php3");
405 406
		}
		if ($login_status & CHECKLOGIN_TRUSTED) {
407
		  WRITESIDEBARDIVIDER();
408 409 410
                  # Only project/group leaders can do these options
                  # Show a "new" icon if there are people waiting for approval
		  $query_result =
411 412 413
		    DBQueryFatal("select g.* from group_membership as authed ".
				 "left join group_membership as g on ".
				 " g.pid=authed.pid and g.gid=authed.gid ".
414
				 "left join users as u on u.uid=g.uid ".
415
				 "where u.status!='".
416
				 TBDB_USERSTATUS_UNVERIFIED . "' and ".
417 418 419 420 421 422
				 " 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') ".
423 424 425 426 427
				 "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 {
428 429

		      WRITESIDEBARBUTTON("New User Approval",
430
				       $TBBASE, "approveuser_form.php3");
431
		  }
432
		}
433
		if (ISADMIN($login_uid)) {
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
		    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");
449

Chad Barb's avatar
 
Chad Barb committed
450 451
		    WRITESIDEBARBUTTON("Edit Site Variables",
				       $TBBASE, "editsitevars.php3");
452 453 454 455 456 457 458 459 460 461

		    $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");
		    }
462

463
		}
464

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

486 487
    #WRITESIDEBARLASTBUTTON_COOL("Take our Survey",
    #    $TBDOCBASE, "survey.php3");
488

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

Chad Barb's avatar
 
Chad Barb committed
509
    if ($login_message) {
Chad Barb's avatar
 
Chad Barb committed
510
      echo "<tr>";
Chad Barb's avatar
Chad Barb committed
511
      echo "<td class=\"menufooter\" style='padding-top: 6px;' ><center><b>";
Chad Barb's avatar
 
Chad Barb committed
512 513
      echo "$login_message</b></center></td>";
      echo "</tr>";
Chad Barb's avatar
 
Chad Barb committed
514 515
    }

516 517
    #
    # Now the login/logout box. Remember, already inside a table.
518 519
    # 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
520
    # http or https, since we do not want to mix them, since they
521
    # cause warnings.
522
    # 
523
    if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
Chad Barb's avatar
 
Chad Barb committed
524 525
      echo "<tr>";
      echo "<td class=\"menufooter\" align=center valign=center>";
526
      echo "<a href=\"$TBBASE/logout.php3?target_uid=$login_uid\">";
Chad Barb's avatar
 
Chad Barb committed
527 528 529
      echo "<img alt=\"logoff\" border=0 ";
      echo "src=\"$BASEPATH/logoff.gif\"></a>\n";
      echo "</td></tr>\n";
530
    }
531
    elseif (!NOLOGINS()) {
Chad Barb's avatar
 
Chad Barb committed
532 533
      echo "<tr>";
      echo "<td class=\"menufooter\" align=center valign=center>";
Chad Barb's avatar
Chad Barb committed
534 535 536 537 538 539 540

      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
541 542 543
      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
544

Chad Barb's avatar
 
Chad Barb committed
545
      echo "</td></tr>\n";
546
    }
547

548
    #
Chad Barb's avatar
 
Chad Barb committed
549
    # Login message. Set via 'web/message' site variable
550
    #
Chad Barb's avatar
 
Chad Barb committed
551 552
    $message = TBGetSiteVar("web/message");
    if (0 != strcmp($message,"")) {
Robert Ricci's avatar
Robert Ricci committed
553
	WRITESIDEBARNOTICE($message);    	
554
    }
Chad Barb's avatar
 
Chad Barb committed
555

Chad Barb's avatar
 
Chad Barb committed
556
    echo "</table>\n";
557 558
}

Chad Barb's avatar
 
Chad Barb committed
559 560 561
#
# spits out beginning part of page
#
562
function PAGEBEGINNING( $title, $nobanner = 0 ) {
Chad Barb's avatar
Chad Barb committed
563 564
    global $BASEPATH, $TBMAINSITE, $THISHOMEBASE;
    global $TBDIR, $WWW;
Chad Barb's avatar
 
Chad Barb committed
565
    global $MAINPAGE;
566
    global $TBDOCBASE;
Chad Barb's avatar
 
Chad Barb committed
567

Chad Barb's avatar
Chad Barb committed
568
    $MAINPAGE = !strcmp($TBDIR, "/usr/testbed/"); 
Chad Barb's avatar
 
Chad Barb committed
569 570 571 572 573 574
  
    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>
575 576
            <!--<link rel=\"SHORTCUT ICON\" HREF=\"netbed.ico\">-->
            <link rel=\"SHORTCUT ICON\" HREF=\"netbed.png\" TYPE=\"image/png\">
Chad Barb's avatar
 
Chad Barb committed
577 578 579 580 581 582 583 584 585 586 587
    	    <!-- dumbed-down style sheet for any browser that groks (eg NS47). -->
	    <link REL='stylesheet' HREF='$BASEPATH/common-style.css' TYPE='text/css' />
    	    <!-- don't import full style sheet into NS47, since it does a bad job
            of handling it. NS47 doesn't understand '@import'. -->
    	    <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
588
    echo "</style>\n";
Chad Barb's avatar
 
Chad Barb committed
589 590

    if ($TBMAINSITE) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
591 592 593 594 595 596 597
	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
598 599 600

    echo "</head>
            <body bgcolor='#FFFFFF' 
601 602 603
             topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>\n";
    if (! $nobanner ) {
	echo "
Chad Barb's avatar
 
Chad Barb committed
604 605 606 607
            <table cellpadding='0' cellspacing='0' width='100%'>
            <tr>
              <td valign='top' class='bannercell' 
              background='$BASEPATH/headerbgbb.jpg'
608 609
              bgcolor=#3D627F ><a href='$TBDOCBASE/index.php3'><img width=369
	      height=100 border=0
Chad Barb's avatar
 
Chad Barb committed
610
              src='$BASEPATH/overlay.".strtolower($THISHOMEBASE).".gif' 
611
              alt='$THISHOMEBASE - the network testbed' /></a>";
612 613 614 615
	      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
616 617 618 619 620 621
    }

    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
622 623 624 625 626 627 628
}

#
# finishes sidebar td
#
function FINISHSIDEBAR()
{
Chad Barb's avatar
 
Chad Barb committed
629
    echo "<!-- sidebar ends -->
Chad Barb's avatar
 
Chad Barb committed
630
        </td>
Chad Barb's avatar
 
Chad Barb committed
631
        <td valign='top' width='100%' class='rightcell'>
632
          <!-- content body table -->
Chad Barb's avatar
 
Chad Barb committed
633
          <table class='content' width='100%' cellpadding='0' cellspacing='0'>
Chad Barb's avatar
 
Chad Barb committed
634
            <tr>
Chad Barb's avatar
 
Chad Barb committed
635
              <td class='contentheader'>";
Chad Barb's avatar
 
Chad Barb committed
636 637
}

638 639 640
#
# Spit out a vanilla page header.
#
641
function PAGEHEADER($title, $view = NULL) {
642 643
    global $login_status, $login_uid, $TBBASE, $TBDOCBASE, $THISHOMEBASE;
    global $BASEPATH, $SSL_PROTOCOL, $drewheader;
644
    global $TBMAINSITE;
645 646

    $drewheader = 1;
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662

    #
    # 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;
    }
663

664
    #
665
    # Figure out who is logged in, if anyone.
666
    # 
667 668 669 670
    if (($known_uid = GETUID()) != FALSE) {
        #
        # Check to make sure the UID is logged in (not timed out).
        #
671 672 673
        $login_status = CHECKLOGIN($known_uid);
	if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
	    $login_uid = $known_uid;
674 675 676
	}
    }

677 678 679 680 681 682 683
    #
    # If no view options were specified, get the ones for the current user
    #
    if (!$view) {
	$view = GETUSERVIEW();
    }

684
    #
685 686
    # Check for NOLOGINS. 
    # We want to allow admin types to continue using the web interface,
687 688
    # and logout anyone else that is currently logged in!
    #
689 690 691 692
    if (NOLOGINS() && $login_uid && !ISADMIN($login_uid)) {
	DOLOGOUT($login_uid);
	$login_status = CHECKLOGIN_NOTLOGGEDIN;
	$login_uid    = 0;
693
    }
694
    
695 696
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    
697
    if (1) {
698 699 700 701 702 703 704
	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
705

706 707 708 709 710 711 712 713 714
    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
715
    FINISHSIDEBAR();
716
    echo "<h2 class=\"nomargin\">\n";
Chad Barb's avatar
 
Chad Barb committed
717

718
    if ($login_uid && ISADMINISTRATOR()) {
Chad Barb's avatar
 
Chad Barb committed
719
	if (ISADMIN($login_uid)) {
720
	    echo "<a href=toggle.php?target_uid=$login_uid&type=adminoff&value=1>
Chad Barb's avatar
 
Chad Barb committed
721 722 723 724
	             <img src='/redball.gif'
                          border=0 alt='Admin On'></a>\n";
	}
	else {
725
	    echo "<a href=toggle.php?target_uid=$login_uid&type=adminoff&value=0>
Chad Barb's avatar
 
Chad Barb committed
726 727 728
	             <img src='/greenball.gif'
                          border=0 alt='Admin Off'></a>\n";
	}
729
    }
730 731
    $now = date("D M d g:ia T");
    echo "$title</h2></td>\n";
732
    echo "<td class=contentheader align=right>\n";
Robert Ricci's avatar
Robert Ricci committed
733 734
    if ($login_uid) {
	echo "<font size=-1>'<b>$login_uid</b>' Logged in.<br>$now</font>\n";
735 736
    }
    else {
Robert Ricci's avatar
Robert Ricci committed
737
	echo "$now";
Chad Barb's avatar
 
Chad Barb committed
738 739 740 741
    }
    echo "</td>";
    echo "</tr>\n";
    echo "<tr><td colspan=3 class=\"contentbody\" width=*>";
Chad Barb's avatar
 
Chad Barb committed
742
    echo "<!-- begin content -->\n";
743 744 745
    if ($view['show_topbar'] == "plab") {
	WRITEPLABTOPBAR();
    }
746 747 748 749 750 751
}

#
# ENDPAGE(): This terminates the table started above.
# 
function ENDPAGE() {
Chad Barb's avatar
 
Chad Barb committed
752 753
  echo "</td></tr></table>";
  echo "</td></tr></table>";
754 755 756 757 758
}

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

763 764 765 766
    if (!$view) {
	$view = GETUSERVIEW();
    }

767 768
    $today = getdate();
    $year  = $today["year"];
Chad Barb's avatar
 
Chad Barb committed
769

770 771 772 773 774 775
    echo "<!-- end content -->\n";
    if ($view['show_bottombar'] == "plab") {
	WRITEPLABBOTTOMBAR();
    }

    echo "
Chad Barb's avatar
 
Chad Barb committed
776
              </td>
777 778
            </tr>
            <tr>
779 780 781
              <td colspan=2 class=contentbody>\n";
    if (!$view['hide_copyright']) {
	echo "
782 783
	        <center>
                <font size=-1>
784 785 786 787 788 789
		[ <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> ]
790 791
		</font>
		<br>
Chad Barb's avatar
 
Chad Barb committed
792
                <!-- begin copyright -->
793
                <font size=-2>
794 795 796 797
                <a href='$TBDOCBASE/docwrapper.php3?docname=copyright.html'>
                    Copyright &copy; 2000-$year The University of Utah</a>
                </font>
                <br>
798 799 800
		</center>\n";
    }
    echo "
801
                <p align=right>
Chad Barb's avatar
 
Chad Barb committed
802 803
		  <font size=-2>
                    Problems?
804
	            Contact $TBMAILADDR.
Chad Barb's avatar
 
Chad Barb committed
805 806
                  </font>
                </p>
807
                <!-- end copyright -->\n";
Chad Barb's avatar
 
Chad Barb committed
808 809

    ENDPAGE();
810

Leigh B. Stoller's avatar
Leigh B. Stoller committed
811 812 813
    # 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
814
    echo "</body></html>\n";
815
}
816 817 818 819 820

function PAGEERROR($msg) {
    global $drewheader;

    if (! $drewheader)
821
	PAGEHEADER("Page Error");
822 823 824 825 826 827

    echo "$msg\n";

    PAGEFOOTER();
    die("");
}
828 829 830 831 832

#
# Sub Page/Menu Stuff
#
function WRITESUBMENUBUTTON($text, $link) {
Chad Barb's avatar
 
Chad Barb committed
833 834


835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
    echo "<!-- Table row for button $text -->
          <tr>
            <td valign=center align=left nowrap>
                <b>
         	 <a class=sidebarbutton href='$link'>$text</a>\n";

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

#
# Start/End a page within a page. 
#
function SUBPAGESTART() {
Chad Barb's avatar
 
Chad Barb committed
850
    echo "<!-- begin subpage -->";
Chad Barb's avatar
 
Chad Barb committed
851
    echo "<table class=\"stealth\"
852
	  cellspacing='0' cellpadding='0' width='100%' border='0'>\n
853
            <tr>\n
Chad Barb's avatar
 
Chad Barb committed
854
              <td class=\"stealth\"valign=top>\n";
855 856 857 858 859 860
}

function SUBPAGEEND() {
    echo "    </td>\n
            </tr>\n
          </table>\n";
Chad Barb's avatar
 
Chad Barb committed
861
    echo "<!-- end subpage -->";
862 863 864 865 866 867 868
}

#
# 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
869 870
?>
    <!-- begin submenu -->
871
    <table class='menu' cellpadding="0" cellspacing="0"
Chad Barb's avatar
 
Chad Barb committed
872
	style="margin-right: 6px;" >
Chad Barb's avatar
 
Chad Barb committed
873 874 875 876
      <tr>
        <td class="menuheader"><b><?php echo "$title";?></b></td>
      </tr>
<?php
877 878 879
}

function SUBMENUEND() {
Chad Barb's avatar
 
Chad Barb committed
880 881 882 883
?>
    </table>
    <!-- end submenu -->
  </td>
884
  <td class="stealth" valign=top align=left width='100%'>
Chad Barb's avatar
 
Chad Barb committed
885
<?php
886 887
}

888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
# 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
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922

# 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
}

923 924 925 926 927 928 929 930 931 932 933 934 935 936
#
# 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();
    }
}

937
?>