menu.php3 31.6 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2006 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
$noheaders	  = 0;
12
$autorefresh      = 0;
13
$currentusage     = 1;
14
$currently_busy   = 0;
15
$bodyclosestring  = "";
16

17
18
19
20
21
22
#
# 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	  = "";

Timothy Stack's avatar
   
Timothy Stack committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#
# 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;
}

# Blank space dividers in the menus are handled by adding a class to the menu
# item that starts a new group.
$nextsidebarcl    = "";
$nextsubmenucl    = "";

44
#
45
46
# TOPBARCELL - Make a cell for the topbar. Actually, the name lies, it can be
# used for cells in a bottombar too.
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#
function TOPBARCELL($contents) {
    echo "<td class=\"topbaropt\">";
    echo "<span class=\"topbaroption\">&nbsp;";
    echo $contents;
    echo "&nbsp;</span>";
    echo "</td>";
    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\" />");
}

70
71
72
73
#
# WRITESIDEBARDIVIDER(): Put a bit of whitespace in the sidebar
#
function WRITESIDEBARDIVIDER() {
Timothy Stack's avatar
   
Timothy Stack committed
74
75
76
    global $nextsidebarcl;
    
    $nextsidebarcl = "newgroup";
77
78
}

79
80
81
82
83
#
# 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.
#
Timothy Stack's avatar
   
Timothy Stack committed
84
85
86
function WRITESIDEBARBUTTON($text, $base, $link, $extratext="") {
    global $nextsidebarcl;
    
87
88
    if ($base)
	$link = "$base/$link";
Timothy Stack's avatar
   
Timothy Stack committed
89
90
91
92
93
94
    $cl = "";
    if ($nextsidebarcl != "") {
	$cl = "class='$nextsidebarcl'";
	$nextsidebarcl = "";
    }
    echo "<li $cl><a href=\"$link\">$text</a>$extratext</li>\n";
Chad Barb's avatar
   
Chad Barb committed
95
}
96

Chad Barb's avatar
   
Chad Barb committed
97
# same as above with "new" gif next to it.
Timothy Stack's avatar
   
Timothy Stack committed
98
99
100
101
102
function WRITESIDEBARBUTTON_NEW($text, $base, $link) {
    WRITESIDEBARBUTTON($text,
		       $base,
		       $link,
		       "&nbsp;<img src=\"/new.gif\" />");
Chad Barb's avatar
   
Chad Barb committed
103
104
}

Chad Barb's avatar
   
Chad Barb committed
105
106
107
# same as above with "cool" gif next to it.
function WRITESIDEBARBUTTON_COOL($text, $base, $link ) {
    $link = "$base/$link";
Timothy Stack's avatar
   
Timothy Stack committed
108
    echo "<li><a href=\"$link\">$text</a>&nbsp;<img src=\"/cool.gif\" /></li>\n";
Chad Barb's avatar
   
Chad Barb committed
109
110
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
111
112
function WRITESIDEBARBUTTON_ABS($text, $base, $link ) {
    $link = "$link";
Timothy Stack's avatar
   
Timothy Stack committed
113
    echo "<li><a href=\"$link\">$text</a></li>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
114
115
}

Chad Barb's avatar
   
Chad Barb committed
116
117
function WRITESIDEBARBUTTON_ABSCOOL($text, $base, $link ) {
    $link = "$link";
Timothy Stack's avatar
   
Timothy Stack committed
118
    echo "<li><a href=\"$link\">$text</a>&nbsp;<img src=\"/cool.gif\" /></li>\n";
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) {
Timothy Stack's avatar
   
Timothy Stack committed
123
    echo "<span class='notice'>$text</span>\n";
124
125
126
127
128
129
130
131
132
133
134
135
136
}

#
# 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, $pid, $gid;
    global $TBBASE, $TBDOCBASE, $BASEPATH, $WIKISUPPORT, $MAILMANSUPPORT;
225
    global $BUGDBSUPPORT, $BUGDBURL, $CVSSUPPORT, $CHATSUPPORT;
226
    global $CHECKLOGIN_WIKINAME;
227
    global $THISHOMEBASE;
228
    global $EXPOSETEMPLATES;
229
    $firstinitstate = TBGetFirstInitState();
230
231
232

    #
    # The document base cannot be a mix of secure and nonsecure.
233
    #
Chad Barb's avatar
   
Chad Barb committed
234
    
Timothy Stack's avatar
   
Timothy Stack committed
235
    # create the main menu list
Chad Barb's avatar
   
Chad Barb committed
236
237
238
239
240
241
242
243
244

    #
    # 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 ".
245
		     "WHERE archived=0 ".
Chad Barb's avatar
   
Chad Barb committed
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
		     "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;
	}
    }

267
268
269
270
    echo "<script type='text/javascript' language='javascript'
                  src='${BASEPATH}/textbox.js'></script>\n";
    echo "<h3 class=menuheader>Information</h3><ul class=menu>\n";

Chad Barb's avatar
   
Chad Barb committed
271
272
273
274
275
276
    if (0 == strcasecmp($THISHOMEBASE, "emulab.net")) {
	$rootEmulab = 1;
    } else {
	$rootEmulab = 0;
    }

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

Chad Barb's avatar
   
Chad Barb committed
279
280

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

    }
Chad Barb's avatar
   
Chad Barb committed
288

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

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

    if ($rootEmulab) {
298
	# Leave _NEW here about 2 weeks
299
	WRITESIDEBARBUTTON("Papers and Talks (May 1)", $TBDOCBASE, "pubs.php3");
300
	WRITESIDEBARBUTTON("Software (Jul 18)",
301
			       $TBDOCBASE, "software.php3");
302
303
	#WRITESIDEBARBUTTON("Add Widearea Node (CD)",
	#		    $TBDOCBASE, "cdrom.php");
304

Timothy Stack's avatar
   
Timothy Stack committed
305
	echo "<li><a href=\"$TBDOCBASE/people.php3\">People</a> and " .
306
	     "<a href=\"$TBDOCBASE/gallery/gallery.php3\">Photos</a>" .
307
308
309
310
311
312
	     "</li>";
# with New!
#	echo "<li><a href=\"$TBDOCBASE/people.php3\">People</a> and " .
#	     "<a href=\"$TBDOCBASE/gallery/gallery.php3\">Photos</a>" .
#	     "&nbsp;<img src=\"/new.gif\" />" .
#	     "</li>";
313

Timothy Stack's avatar
   
Timothy Stack committed
314
315
316
317
	echo "<li>Emulab <a href=\"$TBDOCBASE/doc/docwrapper.php3? " .
	     "docname=users.html\">Users</a> and " .
	     "<a href=\"$TBDOCBASE/docwrapper.php3? " .
	     "docname=sponsors.html\">Sponsors</a></li>";
Chad Barb's avatar
   
Chad Barb committed
318
    } else {
319
	# Link ALWAYS TO UTAH
320
321
	#WRITESIDEBARBUTTON_ABSCOOL("Add Widearea Node (CD)",
	#		       $TBDOCBASE, "http://www.emulab.net/cdrom.php");
Timothy Stack's avatar
   
Timothy Stack committed
322
323
	WRITESIDEBARBUTTON("Projects on Emulab", $TBDOCBASE,
		"projectlist.php3");
Chad Barb's avatar
   
Chad Barb committed
324
    }
Timothy Stack's avatar
   
Timothy Stack committed
325
326
327
328
329
330
    
    echo "</ul>\n";

    # The search box.  Placed in a table so the text input fills available
    # space.
    echo "<div id='searchrow'>
331
332
333
        <form method='get' action='$newsBase/search.php3'>
        <table border='0' cellspacing='0' cellpadding='0'><tr>
             <td width='100%'><input class='textInputEmpty' name='query'
Timothy Stack's avatar
   
Timothy Stack committed
334
335
336
                        value='Search String' id='searchbox'
                        onfocus='focus_text(this, \"Search String\")'
                        onblur='blur_text(this, \"Search String\")' /></td>
337
	     <td><input type='submit' id='searchsub' value=Search /></td>
Timothy Stack's avatar
   
Timothy Stack committed
338
339
340
        </table>
        </form>
	</div>\n";
341
342
343
344
345
346
347

    #
    # Cons up a nice message.
    # 
    switch ($login_status & CHECKLOGIN_STATUSMASK) {
    case CHECKLOGIN_LOGGEDIN:
	if ($login_status & CHECKLOGIN_PSWDEXPIRED)
Timothy Stack's avatar
   
Timothy Stack committed
348
	    $login_message = "(Password Expired!)";
349
	elseif ($login_status & CHECKLOGIN_UNAPPROVED)
Timothy Stack's avatar
   
Timothy Stack committed
350
351
352
	    $login_message = "(Unapproved!)";
	else
	    $login_message = 0;
353
354
355
356
357
358
359
360
361
362
	break;
    case CHECKLOGIN_TIMEDOUT:
	$login_message = "Login Timed out.";
	break;
    default:
	$login_message = 0;
	break;
    }

    #
Timothy Stack's avatar
   
Timothy Stack committed
363
    # Now the login box.
364
    # We want the links to the login pages to always be https,
365
366
367
    # but the images path depends on whether the page was loaded as
    # http or https, since we do not want to mix them, since they
    # cause warnings.
368
369
370
    #
    if (! ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) &&
	!NOLOGINS()) {
Timothy Stack's avatar
   
Timothy Stack committed
371
372
373
374
375
	echo "<div id='loginbox'>";

	if ($login_message) {
	    echo "<strong>$login_message</strong>";
	}
376
377
378
379

	if (!$firstinitstate) {
	    echo "<a href=\"$TBBASE/reqaccount.php3\">";
	    echo "<img alt=\"Request Account\" border=0 ";
380
	    echo "src=\"$BASEPATH/requestaccount.gif\" width=\"144\" height=\"32\"></a>";
381

Timothy Stack's avatar
   
Timothy Stack committed
382
	    echo "<strong>or</strong>";
383
384
385
386
	}

	echo "<a href=\"$TBBASE/login.php3\">";
	echo "<img alt=\"logon\" border=0 ";
387
	echo "src=\"$BASEPATH/logon.gif\" width=\"144\" height=\"32\"></a>\n";
388

Timothy Stack's avatar
   
Timothy Stack committed
389
	echo "</div>";
390
391
392
393
394
395
396
    }

    #
    # Login message. Set via 'web/message' site variable
    #
    $message = TBGetSiteVar("web/message");
    if (0 != strcmp($message,"")) {
Timothy Stack's avatar
   
Timothy Stack committed
397
	WRITESIDEBARNOTICE($message);
398
399
    }

400
401
402
403
404
405
    #
    # 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()) {
Timothy Stack's avatar
   
Timothy Stack committed
406
407
	echo "<a id='webdisabled' href='$TBDOCBASE/nologins.php3'>".
	    "Web Interface Temporarily Unavailable</a>";
408

Chad Barb's avatar
   
Chad Barb committed
409
410
411
        if (!$login_uid || !ISADMIN($login_uid)) {	
	    WRITESIDEBARNOTICE("Please Try Again Later");
        }
Timothy Stack's avatar
   
Timothy Stack committed
412
413
414
415
416
    }

    # Start Interaction section if going to spit out interaction options.
    if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
	echo "<h3 class='menuheader'>Experimentation</h3>
417
              <ul class='menu'>\n";
418
    }
Chad Barb's avatar
   
Chad Barb committed
419

420
    if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
	if ($firstinitstate != null) {    
	    if ($firstinitstate == "createproject") {
		WRITESIDEBARBUTTON("Create First Project",
				   $TBBASE, "newproject.php3");
	    }
	    elseif ($firstinitstate == "approveproject") {
		$firstinitpid = TBGetFirstInitPid();
		
		WRITESIDEBARBUTTON("Approve First Project",
				   $TBBASE,
				   "approveproject.php3?pid=$firstinitpid".
				   "&approval=approve");
	    }
	}
	elseif ($login_status & CHECKLOGIN_ACTIVE) {
436
	    if ($login_status & CHECKLOGIN_PSWDEXPIRED) {
437
		WRITESIDEBARBUTTON("Change Your Password",
438
				   $TBBASE, "moduserinfo.php3");
439
	    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
440
	    elseif ($login_status & (CHECKLOGIN_WEBONLY|CHECKLOGIN_WIKIONLY)) {
441
442
443
		WRITESIDEBARBUTTON("My Emulab",
				   $TBBASE,
				   "showuser.php3?target_uid=$login_uid");
444
445
446
447
448

		if ($WIKISUPPORT && $CHECKLOGIN_WIKINAME != "") {
		    $wikiname = $CHECKLOGIN_WIKINAME;
		
		    WRITESIDEBARBUTTON_ABSCOOL("My Wikis",
449
450
			       "gotowiki.php3?redurl=Main/$wikiname",
			       "gotowiki.php3?redurl=Main/$wikiname");
451
		}
452

453
454
455
		WRITESIDEBARBUTTON("Update User Information",
				   $TBBASE, "moduserinfo.php3");
	    }
456
	    else {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
457
		WRITESIDEBARBUTTON("My Emulab",
458
459
				   $TBBASE,
				   "showuser.php3?target_uid=$login_uid");
460

461
		#
462
463
464
465
                # 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.
                #
466
467
 		WRITESIDEBARBUTTON("Begin an Experiment",
				   $TBBASE, "beginexp_html.php3");
468
469
470
471
472

		if ($EXPOSETEMPLATES) {
		    WRITESIDEBARBUTTON("Create a Template",
				       $TBBASE, "template_create.php");
		}
473
	
474
475
		# Put _NEW back when Plab is working again.
		WRITESIDEBARBUTTON("Create a PlanetLab Slice",
476
477
478
479
480
481
				       $TBBASE, "plab_ez.php3");

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

		WRITESIDEBARDIVIDER();
Timothy Stack's avatar
   
Timothy Stack committed
482
		
483
		WRITESIDEBARBUTTON("Node Status",
484
485
				   $TBBASE, "nodecontrol_list.php3");

Timothy Stack's avatar
   
Timothy Stack committed
486
		echo "<li>List <a " .
487
488
			"href=\"$TBBASE/showimageid_list.php3\">" .
	        	"ImageIDs</a> or <a " .
Timothy Stack's avatar
   
Timothy Stack committed
489
	                "href=\"$TBBASE/showosid_list.php3\">OSIDs</a></li>";
490

491
		if ($login_status & CHECKLOGIN_TRUSTED) {
492
		  WRITESIDEBARDIVIDER();
493
494
495
                  # Only project/group leaders can do these options
                  # Show a "new" icon if there are people waiting for approval
		  $query_result =
496
497
498
		    DBQueryFatal("select g.* from group_membership as authed ".
				 "left join group_membership as g on ".
				 " g.pid=authed.pid and g.gid=authed.gid ".
499
				 "left join users as u on u.uid=g.uid ".
500
				 "where u.status!='".
501
				 TBDB_USERSTATUS_UNVERIFIED . "' and ".
502
503
504
505
506
507
				 " 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') ".
508
509
510
511
512
				 "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 {
513
514

		      WRITESIDEBARBUTTON("New User Approval",
515
				       $TBBASE, "approveuser_form.php3");
516
		  }
517
		}
518
	    }
519
	}
520
	elseif ($login_status & (CHECKLOGIN_UNVERIFIED|CHECKLOGIN_NEWUSER)) {
521
522
	    WRITESIDEBARBUTTON("New User Verification",
			       $TBBASE, "verifyusr_form.php3");
523
	    WRITESIDEBARBUTTON("Update User Information",
524
			       $TBBASE, "moduserinfo.php3");
525
	}
526
	elseif ($login_status & (CHECKLOGIN_UNAPPROVED)) {
527
	    WRITESIDEBARBUTTON("Update User Information",
528
			       $TBBASE, "moduserinfo.php3");
529
	}
530
531
	#
	# Standard options for logged in users!
532
533
	#
	if (!$firstinitstate) {
Timothy Stack's avatar
   
Timothy Stack committed
534
535
	    echo "<li class='newgroup'><a href=\"$TBBASE/newproject.php3\">Start</a> or " .
		"<a href=\"$TBBASE/joinproject.php3\">Join</a> a Project</li>";
536
	}
537
    }
538
539
    #WRITESIDEBARLASTBUTTON_COOL("Take our Survey",
    #    $TBDOCBASE, "survey.php3");
540

541
    # Terminate Interaction menu.
542
    if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
543
        # Logout option. No longer take up space with an image.
Timothy Stack's avatar
   
Timothy Stack committed
544
545
	WRITESIDEBARBUTTON("<b>Logout</b>",
			   $TBBASE, "logout.php3?target_uid=$login_uid");
546
	
Timothy Stack's avatar
   
Timothy Stack committed
547
	echo "</ul>\n";
548
    }
Chad Barb's avatar
Chad Barb committed
549

550
    # And now the Collaboration menu.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
551
552
553
    if (($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) &&
	($WIKISUPPORT || $MAILMANSUPPORT || $BUGDBSUPPORT ||
	 $CVSSUPPORT  || $CHATSUPPORT)) {
Timothy Stack's avatar
   
Timothy Stack committed
554
	echo "<h3 class='menuheader'>Collaboration</h3>
555
              <ul class='menu'>";
Timothy Stack's avatar
   
Timothy Stack committed
556

557
558
559
560
561
	if ($WIKISUPPORT && $CHECKLOGIN_WIKINAME != "") {
	    $wikiname = $CHECKLOGIN_WIKINAME;
		
	    WRITESIDEBARBUTTON("My Wikis", $TBBASE,
			       "gotowiki.php3?redurl=Main/$wikiname");
562
	}
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
	if ($MAILMANSUPPORT || $BUGDBSUPPORT) {
	    if (!isset($pid) || $pid == "") {
		$query_result =
		    DBQueryFatal("select pid from group_membership where ".
				 "uid='$login_uid' and pid=gid and ".
				 "trust!='none' ".
				 "order by date_approved asc limit 1");
		if (mysql_num_rows($query_result)) {
		    $row = mysql_fetch_array($query_result);
		    $firstpid = $row[pid];
		}
	    }
	}
	if ($MAILMANSUPPORT) {
	    $mmurl  = "showmmlists.php3?target_uid=$login_uid";
	    WRITESIDEBARBUTTON("My Mailing Lists", $TBBASE, $mmurl);
	}
	if ($BUGDBSUPPORT) {
	    $bugdburl = "gotobugdb.php3";
		    
	    if (isset($pid) && !empty($pid)) {
		$bugdburl .= "?project_title=$pid";
	    }
	    elseif (isset($firstpid)) {
		$bugdburl .= "?project_title=$firstpid";
	    }
	    WRITESIDEBARBUTTON("My Bug Databases", $TBBASE, $bugdburl);
	}
	if ($CVSSUPPORT) {
592
593
	    WRITESIDEBARBUTTON("My CVS Repositories", $TBBASE,
			       "listrepos.php3?target_uid=$login_uid");
594
	}
595
596
	if ($CHATSUPPORT) {
	    WRITESIDEBARBUTTON("My Chat Buddies", $TBBASE,
597
598
			       "mychat.php3?target_uid=$login_uid");
	}
Timothy Stack's avatar
   
Timothy Stack committed
599
	echo "</ul>\n";
600
    }
601

602
603
    # Optional ADMIN menu.
    if ($login_status & CHECKLOGIN_LOGGEDIN && ISADMIN($login_uid)) {
Timothy Stack's avatar
   
Timothy Stack committed
604
	echo "<h3 class='menuheader'>Administration</h3>
605
              <ul class='menu'>";
606
	
Timothy Stack's avatar
   
Timothy Stack committed
607
608
609
610
	echo "<li>List <a " .
	    " href=\"$TBBASE/showproject_list.php3\">" .
	    "Projects</a> or <a " .
	    "href=\"$TBBASE/showuser_list.php3\">Users</a></li>";
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634

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

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

	WRITESIDEBARBUTTON("Edit Site Variables",
			   $TBBASE, "editsitevars.php3");

	WRITESIDEBARBUTTON("Edit Knowledge Base",
			   $TBBASE, "kb-manage.php3");
		    
	$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");
	}
	WRITESIDEBARBUTTON("Approve Widearea User",
			   $TBBASE, "approvewauser_form.php3");
Chad Barb's avatar
   
Chad Barb committed
635

636
	# Link ALWAYS TO UTAH
Timothy Stack's avatar
   
Timothy Stack committed
637
638
639
	WRITESIDEBARBUTTON("Add Widearea Node (CD)",
			   $TBDOCBASE, "http://www.emulab.net/cdrom.php");
	echo "</ul>\n";
640
    }
641
642
}

643
644
645
646
647
648
#
# Simple version of above, that just writes the given menu.
# 
function WRITESIMPLESIDEBAR($menudefs) {
    $menutitle = $menudefs['title'];
    
Timothy Stack's avatar
   
Timothy Stack committed
649
    echo "<h3 class='menuheader'>$menutitle</h3>
650
          <ul class='menu'>";
651
652
653
654
655

    each($menudefs);    
    while (list($key, $val) = each($menudefs)) {
	WRITESIDEBARBUTTON("$key", null, "$val");
    }
Timothy Stack's avatar
   
Timothy Stack committed
656
    echo "</ul>\n";
657
658
}

Chad Barb's avatar
   
Chad Barb committed
659
660
661
#
# spits out beginning part of page
#
662
663
function PAGEBEGINNING( $title, $nobanner = 0, $nocontent = 0,
        $extra_headers = NULL ) {
664
    global $BASEPATH, $TBMAINSITE, $THISHOMEBASE, $ELABINELAB;
Chad Barb's avatar
Chad Barb committed
665
    global $TBDIR, $WWW;
Chad Barb's avatar
   
Chad Barb committed
666
    global $MAINPAGE;
667
    global $TBDOCBASE;
668
    global $autorefresh, $currentusage;
Chad Barb's avatar
   
Chad Barb committed
669

670
671
    $MAINPAGE = !strcmp($TBDIR, "/usr/testbed/");

Chad Barb's avatar
   
Chad Barb committed
672
673
674
675
676
    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>
677
678
            <!--<link rel=\"SHORTCUT ICON\" HREF=\"netbed.ico\">-->
            <link rel=\"SHORTCUT ICON\" HREF=\"netbed.png\" TYPE=\"image/png\">
Chad Barb's avatar
   
Chad Barb committed
679
    	    <!-- dumbed-down style sheet for any browser that groks (eg NS47). -->
680
	    <link rel='stylesheet' href='$BASEPATH/common-style.css' type='text/css' />
681
682
    	    <!-- 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
683
    	    <style type='text/css' media='all'>
Timothy Stack's avatar
   
Timothy Stack committed
684
            <!-- @import url($BASEPATH/style.css); -->";
Chad Barb's avatar
   
Chad Barb committed
685

686
    if (!$MAINPAGE) {
Timothy Stack's avatar
   
Timothy Stack committed
687
	echo "<!-- @import url($BASEPATH/style-nonmain.css); -->";
688
    } 
Chad Barb's avatar
   
Chad Barb committed
689

Leigh B. Stoller's avatar
Leigh B. Stoller committed
690
    echo "</style>\n";
Chad Barb's avatar
   
Chad Barb committed
691
692

    if ($TBMAINSITE) {
693
694
	echo "<meta name=\"keywords\" ".
	           "content=\"network, emulation, internet, emulator, ".
Leigh B. Stoller's avatar
Leigh B. Stoller committed
695
	           "mobile, wireless, robotic\">\n";
696
697
698
699
	echo "<meta name=\"robots\" ".
	           "content=\"NOARCHIVE\">\n";
	echo "<meta name=\"description\" ".
                   "content=\"emulab - network emulation testbed home\">\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
700
    }
701
702
703
    if ($extra_headers) {
        echo $extra_headers;
    }
Chad Barb's avatar
   
Chad Barb committed
704
705
    echo "</head>
            <body bgcolor='#FFFFFF' 
706
             topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>\n";
707
708
    
    if ($autorefresh) {
709
	echo "<meta HTTP-EQUIV=\"Refresh\" content=\"$autorefresh\">\n";
710
    }
711
712
713
    echo "<script type='text/javascript' language='javascript'
                  src='${BASEPATH}/emulab_sup.js'></script>\n";

714
    if (! $nobanner ) {
715
716
	echo "<map name='overlaymap'>
                 <area shape=\"rect\" coords=\"100,60,339,100\"
717
                       href='http://www.emulab.net/index.php3'>
718
                 <area shape=\"rect\" coords=\"0,0,339,100\"
719
720
                       href='$TBDOCBASE/index.php3'>
              </map>
721
722
            <div class='bannercell'>\n";
	if ($currentusage) {
723
724
	    echo "<iframe src='$BASEPATH/currentusage.php3' class='usageframe'
                          scrolling='no' frameborder='0'></iframe>\n";
725
	}
726
	echo "<img height='100' border='0' usemap=\"#overlaymap\" ";
727
728

	if ($ELABINELAB) {
729
	    echo "width='239' ";
730
731
732
	    echo "src='$BASEPATH/overlay.elabinelab.gif' ";
	}
	else {
733
	    echo "width='339' ";
734
735
736
	    echo "src='$BASEPATH/overlay.".strtolower($THISHOMEBASE).".gif' ";
	}
	echo "alt='$THISHOMEBASE - the network testbed'>\n";
737
        if (0 && !$MAINPAGE) {
Timothy Stack's avatar
   
Timothy Stack committed
738
	     echo "<span class='devpagename'>$WWW</span>";
739
	}
Timothy Stack's avatar
   
Timothy Stack committed
740
        echo "</div>\n";
741
742
    }
    if (! $nocontent ) {
Timothy Stack's avatar
   
Timothy Stack committed
743
	echo "<div class='leftcell'>
744
                  <!-- sidebar begins -->";
Chad Barb's avatar
   
Chad Barb committed
745
    }
Chad Barb's avatar
   
Chad Barb committed
746
747
748
749
750
}

#
# finishes sidebar td
#
751
function FINISHSIDEBAR($contentname = "content", $nocontent = 0)
Chad Barb's avatar
   
Chad Barb committed
752
{
753
    global $TBMAINSITE;
754
755
756
757
758
759
760
761

    if (!$nocontent) {
	if (!$TBMAINSITE) {
	    #
	    # It is a violation of Emulab licensing restrictions to remove
	    # this logo!
	    #
	    echo "       <a class='builtwith' href='http://www.emulab.net'>
762
                         <img src='$BASEPATH/builtwith.png'></a>";
763
764
765
	}
	echo "<!-- sidebar ends -->
              </div>";
766
    }
767
768

    echo "
Timothy Stack's avatar
   
Timothy Stack committed
769
770
        <div class='$contentname'>
          <!-- content body -->";
Chad Barb's avatar
   
Chad Barb committed
771
772
}

773
774
775
#
# Spit out a vanilla page header.
#
776
function PAGEHEADER($title, $view = NULL, $extra_headers = NULL) {
777
    global $login_status, $login_uid, $TBBASE, $TBDOCBASE, $THISHOMEBASE;
778
    global $BASEPATH, $SSL_PROTOCOL, $drewheader, $autorefresh;
779
    global $TBMAINSITE;
780
781

    $drewheader = 1;
782
783
784
    if (isset($_GET['refreshrate']) && is_numeric($_GET['refreshrate'])) {
	$autorefresh = $_GET['refreshrate'];
    }
785

786
    #
787
    # Figure out who is logged in, if anyone.
788
    # 
789
790
791
792
    if (($known_uid = GETUID()) != FALSE) {
        #
        # Check to make sure the UID is logged in (not timed out).
        #
793
794
795
        $login_status = CHECKLOGIN($known_uid);
	if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
	    $login_uid = $known_uid;
796
797
798
	}
    }

799
800
801
802
803
804
805
    #
    # If no view options were specified, get the ones for the current user
    #
    if (!$view) {
	$view = GETUSERVIEW();
    }

806
    #
807
808
    # Check for NOLOGINS. 
    # We want to allow admin types to continue using the web interface,
809
810
    # and logout anyone else that is currently logged in!
    #
811
812
813
814
    if (NOLOGINS() && $login_uid && !ISADMIN($login_uid)) {
	DOLOGOUT($login_uid);
	$login_status = CHECKLOGIN_NOTLOGGEDIN;
	$login_uid    = 0;
815
    }
816
    
817
818
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    
819
    if (1) {
820
821
822
823
824
825
826
	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
827

828
829
830
831
832
    if (isset($view['hide_banner'])) {
	$nobanner = 1;
    } else {
	$nobanner = 0;
    }
Timothy Stack's avatar
   
Timothy Stack committed
833
    $contentname = "content";
834
    $nocontent = isset($view['hide_sidebar']) && !isset($view['menu']);
Timothy Stack's avatar
   
Timothy Stack committed
835
    PAGEBEGINNING( $title, $nobanner,
836
		   $nocontent,
Timothy Stack's avatar
   
Timothy Stack committed
837
		   $extra_headers );
838
839
840
    if (!isset($view['hide_sidebar'])) {
	WRITESIDEBAR();
    }
841
842
843
    elseif (isset($view['menu'])) {
	WRITESIMPLESIDEBAR($view['menu']);
    }
Timothy Stack's avatar
   
Timothy Stack committed
844
845
846
    else {
	$contentname = "fullcontent";
    }
847
    FINISHSIDEBAR($contentname, $nocontent);
Chad Barb's avatar
   
Chad Barb committed
848

Timothy Stack's avatar
   
Timothy Stack committed
849
850
851
852
853
854
    echo "<div class='contentbody'>";
    echo "<div id='logintime'>";
    echo "<span id='loggedin'>";
    $now = date("D M d g:ia T");
    if ($login_uid) {
	echo "<span class='uid'>$login_uid</span> Logged in.";
855
    }
Timothy Stack's avatar
   
Timothy Stack committed
856
857
858
859
    echo "</span>";
    echo "<span class='timestamp'>$now</span>\n";
    echo "</div>";
    
860
861
862
863
    $major = "";
    $minor = "";
    $build = "";
    TBGetVersionInfo($major, $minor, $build);
864
865
866
867
    if ($view['hide_versioninfo'] == 1)
	$versioninfo = "";
    else
	$versioninfo = "Vers: $major.$minor Build: $build";
Timothy Stack's avatar
   
Timothy Stack committed
868
869
870
871
872
    echo "<div id='versioninfo'>$versioninfo</div>";

    echo "<h2 class='contenttitle'>\n";
    if ($login_uid && ISADMINISTRATOR()) {
	if (ISADMIN($login_uid)) {
873
874
	    echo "<a href=\"$TBBASE/toggle.php?target_uid=$login_uid&type=adminon&value=0\"><img src='/redball.gif'
                          border='0' alt='Admin On'></a>\n";
Timothy Stack's avatar
   
Timothy Stack committed
875
876
	}
	else {
877
878
	    echo "<a href=\"$TBBASE/toggle.php?target_uid=$login_uid&type=adminon&value=1\"><img src='/greenball.gif'
                          border='0' alt='Admin Off'></a>\n";
Timothy Stack's avatar
   
Timothy Stack committed
879
	}
Chad Barb's avatar
   
Chad Barb committed
880
    }
Timothy Stack's avatar
   
Timothy Stack committed
881
882
    echo "$title</h2>\n";

Chad Barb's avatar
   
Chad Barb committed
883
    echo "<!-- begin content -->\n";
884
885
886
    if ($view['show_topbar'] == "plab") {
	WRITEPLABTOPBAR();
    }
887
888
889
}

#
Timothy Stack's avatar
   
Timothy Stack committed
890
# ENDPAGE(): This terminates the div started above.
891
892
# 
function ENDPAGE() {
Timothy Stack's avatar
   
Timothy Stack committed
893
  echo "</div>";
894
895
896
897
898
}

#
# Spit out a vanilla page footer.
#
899
function PAGEFOOTER($view = NULL) {
900
    global $TBDOCBASE, $TBMAILADDR, $THISHOMEBASE, $BASEPATH, $TBBASE;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
901
    global $TBMAINSITE, $SSL_PROTOCOL, $bodyclosestring, $currently_busy;
902
903
904
905
906

    if ($currently_busy) {
	CLEARBUSY();
	$currently_busy = 0;
    }
907

908
909
910
911
    if (!$view) {
	$view = GETUSERVIEW();
    }

912
913
    $today = getdate();
    $year  = $today["year"];
Chad Barb's avatar
   
Chad Barb committed
914

915
    echo "<!-- end content -->\n";
Timothy Stack's avatar
   
Timothy Stack committed
916

917
918
919
920
921
    if ($view['show_bottombar'] == "plab") {
	WRITEPLABBOTTOMBAR();
    }

    echo "
922
              <div class='contentfooter'>\n";
923
924
    if (!$view['hide_copyright']) {
	echo "
Timothy Stack's avatar
   
Timothy Stack committed
925
                <ul class='navlist'>
926
927
928
929
930
931
		<li>[&nbsp;<a href=\"http://www.cs.utah.edu/flux/\"
                    >Flux&nbsp;Research&nbsp;Group</a>&nbsp;]</li>
	        <li>[&nbsp;<a href=\"http://www.cs.utah.edu/\"
                    >School&nbsp;of&nbsp;Computing</a>&nbsp;]</li>
		<li>[&nbsp;<a href=\"http://www.utah.edu/\"
                    >University&nbsp;of&nbsp;Utah</a>&nbsp;]</li>
Timothy Stack's avatar
   
Timothy Stack committed
932
                </ul>
Chad Barb's avatar
   
Chad Barb committed
933
                <!-- begin copyright -->
Timothy Stack's avatar
   
Timothy Stack committed
934
                <span class='copyright'>
935
936
                <a href='$TBDOCBASE/docwrapper.php3?docname=copyright.html'>
                    Copyright &copy; 2000-$year The University of Utah</a>
Timothy Stack's avatar
   
Timothy Stack committed
937
                </span>\n";
938
    }
Timothy Stack's avatar
   
Timothy Stack committed
939
940
941
942
943
944
945
946
    echo "
                <p class='contact'>
                    Problems?
	            Contact $TBMAILADDR.
                </p>
                <!-- end copyright -->\n";
    echo "</div>";
    echo "</div>";
Chad Barb's avatar
   
Chad Barb committed
947
948

    ENDPAGE();
949

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

953
    # This has to be after all the tooltip definitions.
954
955
    echo "<script type='text/javascript' src='${TBBASE}/js/wz_tooltip.js'>".
	"</script>";
956
957
    echo $bodyclosestring;
    echo "\n";
Chad Barb's avatar
   
Chad Barb committed
958
    echo "</body></html>\n";
959
}
960
961

function PAGEERROR($msg) {
962
    global $drewheader, $noheaders;
963

964
    if (! $drewheader && ! $noheaders) {
965
	PAGEHEADER("Page Error");
966
    }
967
968
969

    echo "$msg\n";

970
971
    if (! $noheaders) 
	PAGEFOOTER();
972
973
    die("");
}
974
975
976
977

#
# Sub Page/Menu Stuff
#
978
function WRITESUBMENUBUTTON($text, $link, $target = "") {
Timothy Stack's avatar
   
Timothy Stack committed
979
    global $nextsubmenucl;
Chad Barb's avatar
   
Chad Barb committed
980

981
982
983
984
985
986
    #
    # Optional 'target' agument, so that we can pop up new windows
    #
    if ($target) {
	$targettext = "target='$target'";
    }
Timothy Stack's avatar
   
Timothy Stack committed
987
988
989
990
991
    $cl = "";
    if ($nextsubmenucl != "") {
	$cl = "class='$nextsubmenucl'";
	$nextsubmenucl = "";
    }
Chad Barb's avatar
   
Chad Barb committed
992

Timothy Stack's avatar
   
Timothy Stack committed
993
    echo "<li $cl><a href='$link' $targettext>$text</a></li>\n";
994
995
}

996
function WRITESUBMENUDIVIDER() {
Timothy Stack's avatar
   
Timothy Stack committed
997
998
999
    global $nextsubmenucl;
    
    $nextsubmenucl = "newgroup";
1000
}