menu.php3 23.6 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 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#
# TOPBARCELL - Make a cell for the topbar
#
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\">";
    }
    echo $contents;
    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\" />");
}

59 60 61 62 63
#
# 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
64
function WRITESIDEBARBUTTON($text, $base, $link ) {
65
    $link = "$base/$link";
66
    SIDEBARCELL("<a href=\"$link\">$text</a>");
Chad Barb's avatar
 
Chad Barb committed
67
}
68

Chad Barb's avatar
 
Chad Barb committed
69 70 71
# same as above with "new" gif next to it.
function WRITESIDEBARBUTTON_NEW($text, $base, $link ) {
    $link = "$base/$link";
72
    SIDEBARCELL("<a href=\"$link\">$text</a>&nbsp;<img src=\"/new.gif\" />");
Chad Barb's avatar
 
Chad Barb committed
73 74
}

Chad Barb's avatar
 
Chad Barb committed
75 76 77
# same as above with "cool" gif next to it.
function WRITESIDEBARBUTTON_COOL($text, $base, $link ) {
    $link = "$base/$link";
78
    SIDEBARCELL("<a href=\"$link\">$text</a>&nbsp;<img src=\"/cool.gif\" />");
Chad Barb's avatar
 
Chad Barb committed
79 80
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
81 82
function WRITESIDEBARBUTTON_ABS($text, $base, $link ) {
    $link = "$link";
83
    SIDEBARCELL("<a href=\"$link\">$text</a>\n");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
84 85
}

Chad Barb's avatar
 
Chad Barb committed
86 87
function WRITESIDEBARBUTTON_ABSCOOL($text, $base, $link ) {
    $link = "$link";
88
    SIDEBARCELL("<a href=\"$link\">$text</a>&nbsp;<img src=\"/cool.gif\" />");
Chad Barb's avatar
 
Chad Barb committed
89 90
}

Chad Barb's avatar
 
Chad Barb committed
91 92 93 94 95
# 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";
96
    SIDEBARCELL("<a href=\"$link\">$text</a>",1);
Chad Barb's avatar
 
Chad Barb committed
97 98
}

Chad Barb's avatar
Chad Barb committed
99 100
function WRITESIDEBARLASTBUTTON_COOL($text, $base, $link) {
    $link = "$base/$link";
101
    SIDEBARCELL("<a href=\"$link\">$text</a>&nbsp;<img src=\"/cool.gif\" />",1);
Chad Barb's avatar
Chad Barb committed
102 103
}

Chad Barb's avatar
 
Chad Barb committed
104 105
# writes a message to the sidebar, without clickability.
function WRITESIDEBARNOTICE($text) {
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
    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;

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

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

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

    WRITETOPBARBUTTON("Create a PlanetLab Slice",
        $TBBASE, "plab_advanced.php3");

    WRITETOPBARBUTTON("PlanetLab Nodes",
        $TBBASE, "plabmetrics.php3");

    WRITETOPBARBUTTON("Docs", $TBDOCBASE, "doc.php3");

    if ($newNews) {
	WRITETOPBARBUTTON_NEW("News", $newsBase, "news.php3");
    } else {
	WRITETOPBARBUTTON("News", $newsBase, "news.php3");
    }


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


    WRITETOPBARBUTTON("Advanced Experiment",
        $TBBASE, "beginexp.php3");

    echo "</table>\n";
    echo "<br>\n";

172 173 174 175 176 177 178
}

#
# WRITESIDEBAR(): Write the menu. The actual menu options the user
# sees depends on the login status and the DB status.
#
function WRITESIDEBAR() {
179 180
    global $login_status, $login_uid;
    global $TBBASE, $TBDOCBASE, $BASEPATH;
181
    global $THISHOMEBASE;
182 183 184

    #
    # The document base cannot be a mix of secure and nonsecure.
185
    #
Chad Barb's avatar
 
Chad Barb committed
186 187 188
    
    # create the main menu table, which also happens to reside in a form
    # (for search.)
Chad Barb's avatar
 
Chad Barb committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218

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

219
    echo "<FORM method=get ACTION=\"/cgi-bin/webglimpse/usr/testbed/webglimpse\">\n";
Chad Barb's avatar
 
Chad Barb committed
220 221 222 223
?>
  <table class="menu" width=220 cellpadding="0" cellspacing="0">
    <tr><td class="menuheader"><b>Information</b></td></tr>
<?php
Chad Barb's avatar
 
Chad Barb committed
224 225 226 227 228 229
    if (0 == strcasecmp($THISHOMEBASE, "emulab.net")) {
	$rootEmulab = 1;
    } else {
	$rootEmulab = 0;
    }

230
    WRITESIDEBARBUTTON("Home", $TBDOCBASE, "index.php3");
231

Chad Barb's avatar
 
Chad Barb committed
232 233

    if ($rootEmulab) {
234
	WRITESIDEBARBUTTON("Other Emulabs", $TBDOCBASE,
Chad Barb's avatar
 
Chad Barb committed
235
			       "docwrapper.php3?docname=otheremulabs.html");
236
	WRITESIDEBARBUTTON("Join Netbed (CD)",
Chad Barb's avatar
 
Chad Barb committed
237 238 239 240 241 242 243 244 245
				$TBDOCBASE, "cdrom.php");
    } else {
	WRITESIDEBARBUTTON_ABS("Utah Emulab", $TBDOCBASE,
			       "http://www.emulab.net/");
	# Link ALWAYS TO UTAH
	WRITESIDEBARBUTTON_ABSCOOL("Join Netbed (CD)",
			       $TBDOCBASE, "http://www.emulab.net/cdrom.php");

    }
Chad Barb's avatar
 
Chad Barb committed
246

Chad Barb's avatar
 
Chad Barb committed
247 248 249 250 251 252
    if ($newNews) {
	WRITESIDEBARBUTTON_NEW("News $newsDate", $newsBase, "news.php3");
    } else {
	WRITESIDEBARBUTTON("News $newsDate", $newsBase, "news.php3");
    }

253
    WRITESIDEBARBUTTON("Documentation", $TBDOCBASE, "doc.php3");
Chad Barb's avatar
 
Chad Barb committed
254 255

    if ($rootEmulab) {
256
	WRITESIDEBARBUTTON("Papers (Oct 28)", $TBDOCBASE, "pubs.php3");
257
	WRITESIDEBARBUTTON("Software <font size=-1> ".
258
			       "(Oct 21)</font>",
259
			       $TBDOCBASE, "software.php3");
Chad Barb's avatar
 
Chad Barb committed
260 261
	WRITESIDEBARBUTTON("People", $TBDOCBASE, "people.php3");
	WRITESIDEBARBUTTON("Photo Gallery", $TBDOCBASE, "gallery/gallery.php3");
262
	WRITESIDEBARBUTTON("Emulab Users", $TBDOCBASE,
Chad Barb's avatar
 
Chad Barb committed
263
			   "doc/docwrapper.php3?docname=users.html");
Chad Barb's avatar
 
Chad Barb committed
264 265 266 267 268 269
	WRITESIDEBARLASTBUTTON("Sponsors", $TBDOCBASE,
			       "docwrapper.php3?docname=sponsors.html");
    } else {
	WRITESIDEBARLASTBUTTON("Projects on Emulab", $TBDOCBASE,
			       "projectlist.php3");
    }
270

Chad Barb's avatar
 
Chad Barb committed
271 272 273 274 275 276
    # create the search bit, then the second table for the Web Interface.
?>
    <tr><td class="menuoptst"><b>Search Documentation:</b></td></tr>
    <tr><td class="menuopts"><input name=query />
      <input type=submit style="font-size:10px;" value="Go" /></td></tr>
      <tr><td class="menuoptsb" style="font-size:12px;" >[
Chad Barb's avatar
 
Chad Barb committed
277 278
      <a href="<?php echo "$TBDOCBASE/search.php3"; ?>">Advanced 
      Search</a> ]</td></tr>
Chad Barb's avatar
 
Chad Barb committed
279
    </td></tr>  
280 281 282 283
<?php # BACK TO PHP
    echo "</table>\n";
    echo "</form>\n";
?>
Chad Barb's avatar
 
Chad Barb committed
284 285
<table class="menu" width=220 cellpadding="0" cellspacing="0">
    <tr><td class="menuheader"><b>Interaction</b></td></tr>
Chad Barb's avatar
 
Chad Barb committed
286
<?php # BACK TO PHP
287

288
    if ($login_status & CHECKLOGIN_LOGGEDIN) {
Chad Barb's avatar
 
Chad Barb committed
289 290
         $freepcs = TBFreePCs();
	 WRITESIDEBARNOTICE( "($freepcs Free PCs.)" );
291
    }
292

293 294 295 296 297 298 299 300
    #
    # 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>",
301 302
			   $TBDOCBASE, "nologins.php3");

Chad Barb's avatar
 
Chad Barb committed
303 304 305
        if (!$login_uid || !ISADMIN($login_uid)) {	
	    WRITESIDEBARNOTICE("Please Try Again Later");
        }
306
    }
Chad Barb's avatar
 
Chad Barb committed
307

308 309 310
    if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
	if ($login_status & CHECKLOGIN_ACTIVE) {
	    if ($login_status & CHECKLOGIN_PSWDEXPIRED) {
311
		WRITESIDEBARBUTTON("Change Your Password",
312
				   $TBBASE, "moduserinfo.php3");
313
	    }
314 315 316 317 318 319 320 321
	    elseif ($login_status & CHECKLOGIN_WEBONLY) {
		WRITESIDEBARBUTTON("My Emulab",
				   $TBBASE,
				   "showuser.php3?target_uid=$login_uid");
	    
		WRITESIDEBARBUTTON("Update User Information",
				   $TBBASE, "moduserinfo.php3");
	    }
322
	    else {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
323
		WRITESIDEBARBUTTON("My Emulab",
324 325
				   $TBBASE,
				   "showuser.php3?target_uid=$login_uid");
326
	    
327
		if (ISADMIN($login_uid)) {
328 329
		    WRITESIDEBARBUTTON("New Project Approval",
				       $TBBASE, "approveproject_list.php3");
330 331 332

		    WRITESIDEBARBUTTON("Widearea User Approval",
				       $TBBASE, "approvewauser_form.php3");
333 334
		}
		if ($login_status & CHECKLOGIN_TRUSTED) {
335 336 337
                  # Only project/group leaders can do these options
                  # Show a "new" icon if there are people waiting for approval
		  $query_result =
338 339 340
		    DBQueryFatal("select g.* from group_membership as authed ".
				 "left join group_membership as g on ".
				 " g.pid=authed.pid and g.gid=authed.gid ".
341
				 "left join users as u on u.uid=g.uid ".
342
				 "where u.status!='".
343
				 TBDB_USERSTATUS_UNVERIFIED . "' and ".
344 345 346 347 348 349
				 " 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') ".
350 351 352 353 354
				 "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 {
355 356

		      WRITESIDEBARBUTTON("New User Approval",
357
				       $TBBASE, "approveuser_form.php3");
358
		  }
359
		}
360

361 362
                #
                # Since a user can be a member of more than one project,
363 364
                # display this option, and let the form decide if the 
                # user is allowed to do this.
365
                #
Leigh B. Stoller's avatar
Leigh B. Stoller committed
366
		WRITESIDEBARBUTTON("Project List",
367
				   $TBBASE, "showproject_list.php3");
368
	    
369
		if (ISADMIN($login_uid)) {
370 371 372 373
		    WRITESIDEBARBUTTON("User List",
				       $TBBASE, "showuser_list.php3");
		}
	    
Leigh B. Stoller's avatar
Leigh B. Stoller committed
374 375
		WRITESIDEBARBUTTON("Experiment List",
				   $TBBASE, "showexp_list.php3");
376 377
		WRITESIDEBARBUTTON("Begin an Experiment",
				   $TBBASE, "beginexp.php3");
378 379
		WRITESIDEBARBUTTON("ImageIDs and OSIDs",
				   $TBBASE, "showimageid_list.php3");
380
		WRITESIDEBARBUTTON("Update User Information",
381 382
				   $TBBASE, "moduserinfo.php3");
		WRITESIDEBARBUTTON("Node Reservation Status",
383
				   $TBBASE, "nodecontrol_list.php3");
384 385
		WRITESIDEBARBUTTON("Node Up/Down Status",
				   $TBDOCBASE, "updown.php3");
386 387 388
		WRITESIDEBARBUTTON("View Testbed Stats",
				   $TBBASE, "showstats.php3");
		
Chad Barb's avatar
 
Chad Barb committed
389 390 391 392
		if (ISADMIN($login_uid)) {
		    WRITESIDEBARBUTTON("Edit Site Variables",
				       $TBBASE, "editsitevars.php3");
		}
393 394 395 396 397 398 399 400 401 402 403 404 405

		if (ISADMIN($login_uid)) {
		    $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");
		    }
		}		

406 407 408 409
		if ($login_status & CHECKLOGIN_CVSWEB) {
		    WRITESIDEBARBUTTON("CVS Repository",
				       $TBBASE, "cvsweb/cvsweb.php3");
		}
410
	    }
411
	}
412
	elseif ($login_status & (CHECKLOGIN_UNVERIFIED|CHECKLOGIN_NEWUSER)) {
413 414
	    WRITESIDEBARBUTTON("New User Verification",
			       $TBBASE, "verifyusr_form.php3");
415
	    WRITESIDEBARBUTTON("Update User Information",
416
			       $TBBASE, "moduserinfo.php3");
417
	}
418
	elseif ($login_status & (CHECKLOGIN_UNAPPROVED)) {
419
	    WRITESIDEBARBUTTON("Update User Information",
420
			       $TBBASE, "moduserinfo.php3");
421
	}
422 423 424
	#
	# Standard options for logged in users!
	# 
425
	WRITESIDEBARBUTTON("Start Project", $TBBASE, "newproject.php3");
Chad Barb's avatar
 
Chad Barb committed
426
	WRITESIDEBARLASTBUTTON("Join Project",  $TBBASE, "joinproject.php3");
427
    }
428

Chad Barb's avatar
Chad Barb committed
429
    WRITESIDEBARLASTBUTTON_COOL("Take our Survey",
430 431
	    $TBDOCBASE, "survey.php3");

432 433 434 435 436
    #
    # Cons up a nice message.
    # 
    switch ($login_status & CHECKLOGIN_STATUSMASK) {
    case CHECKLOGIN_LOGGEDIN:
Chad Barb's avatar
Chad Barb committed
437
	$login_message = "'$login_uid' Logged in.";
438 439
	    
	if ($login_status & CHECKLOGIN_PSWDEXPIRED)
Chad Barb's avatar
Chad Barb committed
440
	    $login_message = "$login_message<br>(Password Expired!)";
441
	elseif ($login_status & CHECKLOGIN_UNAPPROVED)
Chad Barb's avatar
Chad Barb committed
442
	    $login_message = "$login_message<br>(Unapproved!)";
443
	break;
444
    case CHECKLOGIN_TIMEDOUT:
Chad Barb's avatar
Chad Barb committed
445
	$login_message = "Login Timed out.";
446
	break;
447 448
    default:
	$login_message = 0;
449
	break;
450 451
    }

Chad Barb's avatar
 
Chad Barb committed
452
    if ($login_message) {
Chad Barb's avatar
 
Chad Barb committed
453
      echo "<tr>";
Chad Barb's avatar
Chad Barb committed
454
      echo "<td class=\"menufooter\" style='padding-top: 6px;' ><center><b>";
Chad Barb's avatar
 
Chad Barb committed
455 456
      echo "$login_message</b></center></td>";
      echo "</tr>";
Chad Barb's avatar
 
Chad Barb committed
457 458
    }

459 460
    #
    # Now the login/logout box. Remember, already inside a table.
461 462
    # 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
463
    # http or https, since we do not want to mix them, since they
464
    # cause warnings.
465
    # 
466
    if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
Chad Barb's avatar
 
Chad Barb committed
467 468
      echo "<tr>";
      echo "<td class=\"menufooter\" align=center valign=center>";
469
      echo "<a href=\"$TBBASE/logout.php3?target_uid=$login_uid\">";
Chad Barb's avatar
 
Chad Barb committed
470 471 472
      echo "<img alt=\"logoff\" border=0 ";
      echo "src=\"$BASEPATH/logoff.gif\"></a>\n";
      echo "</td></tr>\n";
473
    }
474
    elseif (!NOLOGINS()) {
Chad Barb's avatar
 
Chad Barb committed
475 476
      echo "<tr>";
      echo "<td class=\"menufooter\" align=center valign=center>";
Chad Barb's avatar
Chad Barb committed
477 478 479 480 481 482 483

      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
484 485 486
      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
487

Chad Barb's avatar
 
Chad Barb committed
488
      echo "</td></tr>\n";
489
    }
490

491
    #
Chad Barb's avatar
 
Chad Barb committed
492
    # Login message. Set via 'web/message' site variable
493
    #
Chad Barb's avatar
 
Chad Barb committed
494 495
    $message = TBGetSiteVar("web/message");
    if (0 != strcmp($message,"")) {
Robert Ricci's avatar
Robert Ricci committed
496
	WRITESIDEBARNOTICE($message);    	
497
    }
Chad Barb's avatar
 
Chad Barb committed
498

Chad Barb's avatar
 
Chad Barb committed
499
    echo "</table>\n";
500 501
}

Chad Barb's avatar
 
Chad Barb committed
502 503 504
#
# spits out beginning part of page
#
505
function PAGEBEGINNING( $title, $nobanner = 0 ) {
Chad Barb's avatar
Chad Barb committed
506 507
    global $BASEPATH, $TBMAINSITE, $THISHOMEBASE;
    global $TBDIR, $WWW;
Chad Barb's avatar
 
Chad Barb committed
508 509
    global $MAINPAGE;

Chad Barb's avatar
Chad Barb committed
510
    $MAINPAGE = !strcmp($TBDIR, "/usr/testbed/"); 
Chad Barb's avatar
 
Chad Barb committed
511 512 513 514 515 516
  
    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>
517 518
            <!--<link rel=\"SHORTCUT ICON\" HREF=\"netbed.ico\">-->
            <link rel=\"SHORTCUT ICON\" HREF=\"netbed.png\" TYPE=\"image/png\">
Chad Barb's avatar
 
Chad Barb committed
519 520 521 522 523 524 525 526 527 528 529
    	    <!-- 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
530
    echo "</style>\n";
Chad Barb's avatar
 
Chad Barb committed
531 532

    if ($TBMAINSITE) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
533 534 535 536 537 538 539
	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
540 541 542

    echo "</head>
            <body bgcolor='#FFFFFF' 
543 544 545
             topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>\n";
    if (! $nobanner ) {
	echo "
Chad Barb's avatar
 
Chad Barb committed
546 547 548 549 550 551 552
            <table cellpadding='0' cellspacing='0' width='100%'>
            <tr>
              <td valign='top' class='bannercell' 
              background='$BASEPATH/headerbgbb.jpg'
              bgcolor=#3D627F ><img width=369 height=100 
              src='$BASEPATH/overlay.".strtolower($THISHOMEBASE).".gif' 
              alt='$THISHOMEBASE - the network testbed' />";
553 554 555 556
	      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
557 558 559 560 561 562
    }

    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
563 564 565 566 567 568 569
}

#
# finishes sidebar td
#
function FINISHSIDEBAR()
{
Chad Barb's avatar
 
Chad Barb committed
570
    echo "<!-- sidebar ends -->
Chad Barb's avatar
 
Chad Barb committed
571
        </td>
Chad Barb's avatar
 
Chad Barb committed
572
        <td valign='top' width='100%' class='rightcell'>
573
          <!-- content body table -->
Chad Barb's avatar
 
Chad Barb committed
574
          <table class='content' width='100%' cellpadding='0' cellspacing='0'>
Chad Barb's avatar
 
Chad Barb committed
575
            <tr>
Chad Barb's avatar
 
Chad Barb committed
576
              <td class='contentheader'>";
Chad Barb's avatar
 
Chad Barb committed
577 578
}

579 580 581
#
# Spit out a vanilla page header.
#
582
function PAGEHEADER($title,$view = array()) {
583 584
    global $login_status, $login_uid, $TBBASE, $TBDOCBASE, $THISHOMEBASE;
    global $BASEPATH, $SSL_PROTOCOL, $drewheader;
585
    global $TBMAINSITE;
586 587

    $drewheader = 1;
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603

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

605
    #
606
    # Figure out who is logged in, if anyone.
607
    # 
608 609 610 611
    if (($known_uid = GETUID()) != FALSE) {
        #
        # Check to make sure the UID is logged in (not timed out).
        #
612 613 614
        $login_status = CHECKLOGIN($known_uid);
	if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
	    $login_uid = $known_uid;
615 616 617
	}
    }

618
    #
619 620
    # Check for NOLOGINS. 
    # We want to allow admin types to continue using the web interface,
621 622
    # and logout anyone else that is currently logged in!
    #
623 624 625 626
    if (NOLOGINS() && $login_uid && !ISADMIN($login_uid)) {
	DOLOGOUT($login_uid);
	$login_status = CHECKLOGIN_NOTLOGGEDIN;
	$login_uid    = 0;
627
    }
628
    
629 630
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    
631
    if (1) {
632 633 634 635 636 637 638
	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
639

640 641 642 643 644 645 646 647 648
    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
649
    FINISHSIDEBAR();
650
    echo "<h2 class=\"nomargin\">\n";
Chad Barb's avatar
 
Chad Barb committed
651

652
    if ($login_uid && ISADMINISTRATOR()) {
Chad Barb's avatar
 
Chad Barb committed
653
	if (ISADMIN($login_uid)) {
654
	    echo "<a href=toggle.php?target_uid=$login_uid&type=adminoff&value=1>
Chad Barb's avatar
 
Chad Barb committed
655 656 657 658
	             <img src='/redball.gif'
                          border=0 alt='Admin On'></a>\n";
	}
	else {
659
	    echo "<a href=toggle.php?target_uid=$login_uid&type=adminoff&value=0>
Chad Barb's avatar
 
Chad Barb committed
660 661 662
	             <img src='/greenball.gif'
                          border=0 alt='Admin Off'></a>\n";
	}
663
    }
664 665
    $now = date("D M d g:ia T");
    echo "$title</h2></td>\n";
666
    echo "<td class=contentheader align=right>\n";
Robert Ricci's avatar
Robert Ricci committed
667 668
    if ($login_uid) {
	echo "<font size=-1>'<b>$login_uid</b>' Logged in.<br>$now</font>\n";
669 670
    }
    else {
Robert Ricci's avatar
Robert Ricci committed
671
	echo "$now";
Chad Barb's avatar
 
Chad Barb committed
672 673 674 675
    }
    echo "</td>";
    echo "</tr>\n";
    echo "<tr><td colspan=3 class=\"contentbody\" width=*>";
Chad Barb's avatar
 
Chad Barb committed
676
    echo "<!-- begin content -->\n";
677 678 679
    if ($view['show_topbar'] == "plab") {
	WRITEPLABTOPBAR();
    }
680 681 682 683 684 685
}

#
# ENDPAGE(): This terminates the table started above.
# 
function ENDPAGE() {
Chad Barb's avatar
 
Chad Barb committed
686 687
  echo "</td></tr></table>";
  echo "</td></tr></table>";
688 689 690 691 692 693
}

#
# Spit out a vanilla page footer.
#
function PAGEFOOTER() {
694
    global $TBDOCBASE, $TBMAILADDR, $THISHOMEBASE;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
695
    global $TBMAINSITE, $SSL_PROTOCOL;
696

697 698
    $today = getdate();
    $year  = $today["year"];
Chad Barb's avatar
 
Chad Barb committed
699

700
    echo "<!-- end content -->
Chad Barb's avatar
 
Chad Barb committed
701
              </td>
702 703 704 705 706
            </tr>
            <tr>
              <td colspan=2 class=contentbody>
	        <center>
                <font size=-1>
707 708 709 710 711 712
		[ <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> ]
713 714
		</font>
		<br>
Chad Barb's avatar
 
Chad Barb committed
715
                <!-- begin copyright -->
716
                <font size=-2>
717 718 719 720
                <a href='$TBDOCBASE/docwrapper.php3?docname=copyright.html'>
                    Copyright &copy; 2000-$year The University of Utah</a>
                </font>
                <br>
721 722
		</center>
                <p align=right>
Chad Barb's avatar
 
Chad Barb committed
723 724
		  <font size=-2>
                    Problems?
725
	            Contact $TBMAILADDR.
Chad Barb's avatar
 
Chad Barb committed
726 727
                  </font>
                </p>
728
                <!-- end copyright -->\n";
Chad Barb's avatar
 
Chad Barb committed
729 730

    ENDPAGE();
731

Leigh B. Stoller's avatar
Leigh B. Stoller committed
732 733 734
    # 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
735
    echo "</body></html>\n";
736
}
737 738 739 740 741

function PAGEERROR($msg) {
    global $drewheader;

    if (! $drewheader)
742
	PAGEHEADER("Page Error");
743 744 745 746 747 748

    echo "$msg\n";

    PAGEFOOTER();
    die("");
}
749 750 751 752 753

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


756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
    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
771
    echo "<!-- begin subpage -->";
Chad Barb's avatar
 
Chad Barb committed
772
    echo "<table class=\"stealth\"
773
	  cellspacing='0' cellpadding='0' width='100%' border='0'>\n
774
            <tr>\n
Chad Barb's avatar
 
Chad Barb committed
775
              <td class=\"stealth\"valign=top>\n";
776 777 778 779 780 781
}

function SUBPAGEEND() {
    echo "    </td>\n
            </tr>\n
          </table>\n";
Chad Barb's avatar
 
Chad Barb committed
782
    echo "<!-- end subpage -->";
783 784 785 786 787 788 789
}

#
# 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
790 791
?>
    <!-- begin submenu -->
792
    <table class='menu' cellpadding="0" cellspacing="0"
Chad Barb's avatar
 
Chad Barb committed
793
	style="margin-right: 6px;" >
Chad Barb's avatar
 
Chad Barb committed
794 795 796 797
      <tr>
        <td class="menuheader"><b><?php echo "$title";?></b></td>
      </tr>
<?php
798 799 800
}

function SUBMENUEND() {
Chad Barb's avatar
 
Chad Barb committed
801 802 803 804
?>
    </table>
    <!-- end submenu -->
  </td>
805
  <td class="stealth" valign=top align=left width='100%'>
Chad Barb's avatar
 
Chad Barb committed
806
<?php
807 808
}

809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
# 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
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843

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

844
?>