menu.php3 17.4 KB
Newer Older
1
2
3
4
5
6
7
<?php

$STATUS_NOSTATUS  = 0;
$STATUS_LOGGEDIN  = 1;
$STATUS_LOGGEDOUT = 2;
$STATUS_LOGINFAIL = 3;
$STATUS_TIMEDOUT  = 4;
8
$STATUS_NOLOGINS  = 5;
9
$login_status     = $STATUS_NOSTATUS;
10
$pswd_expired     = 0;
11
12
$login_message    = "";
$error_message    = 0;
13
$login_uid        = 0;
14
$drewheader       = 0;
15
$javacode         = file("java.html");
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	  = "";

23
24
25
26
27
28
#
# 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.
#
function WRITESIDEBARBUTTON($text, $base, $link) {
29
    $link = "$base/$link";
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    
    echo "<!-- Table row for button $text -->
          <tr>
            <td valign=center align=left nowrap>
                <b>
         	 <a class=sidebarbutton href=\"$link\">$text</a>\n";
    #
    # XXX these blanks look bad in lynx, but add required
    #     spacing between menu and body
    #
    echo "       &nbsp;&nbsp;\n";

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

#
# WRITESIDEBAR(): Write the menu. The actual menu options the user
# sees depends on the login status and the DB status.
#
function WRITESIDEBAR() {
52
    global $login_status, $login_message, $error_message, $login_uid;
53
    global $STATUS_NOSTATUS, $STATUS_LOGGEDIN, $STATUS_LOGGEDOUT;
54
    global $STATUS_LOGINFAIL, $STATUS_TIMEDOUT, $STATUS_NOLOGINS;
55
    global $TBBASE, $TBDOCBASE, $TBDBNAME, $BASEPATH, $pswd_expired;
56
    global $THISHOMEBASE;
57
58
59
60

    #
    # The document base cannot be a mix of secure and nonsecure.
    # 
61
62
63

    echo "<table cellspacing=2 cellpadding=2 border=0 width=150>\n";

64
    WRITESIDEBARBUTTON("Home", $TBDOCBASE, "index.php3");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
65
    WRITESIDEBARBUTTON("News (new Nov 29)", $TBDOCBASE,
66
		       "docwrapper.php3?docname=news.html");
67
68
    WRITESIDEBARBUTTON("Tutorial", $TBDOCBASE, "tutorial/tutorial.php3");
    WRITESIDEBARBUTTON("FAQ", $TBDOCBASE, "faq.php3");
69
    WRITESIDEBARBUTTON("Documentation", $TBDOCBASE, "doc.php3");
70
    WRITESIDEBARBUTTON("Search Documentation", $TBDOCBASE, "search.php3");
71
    WRITESIDEBARBUTTON("Publications", $TBDOCBASE, "pubs.php3");
72
    WRITESIDEBARBUTTON("People", $TBDOCBASE, "people.php3");
73
    WRITESIDEBARBUTTON("The Gallery", $TBDOCBASE, "gallery/gallery.php3");
74
    WRITESIDEBARBUTTON("Projects Using $THISHOMEBASE", $TBDOCBASE,
75
		       "projectlist.php3");
76

77
78
    $freepcs = TBFreePCs();

79
80
81
    echo "<tr>
            <td height=30 valign=center align=center nowrap>
             <b><span class=sidebarbutton>
82
83
84
85
86
87
                  Web Interface Options\n";

    if ($login_status == $STATUS_LOGGEDIN) {
	echo "    <br>($freepcs Free PCs)\n";
    }
    echo "      </span>
88
89
90
91
             </b>
            </td>
          </tr>\n";

92
    if ($login_status == $STATUS_NOLOGINS) {
93
94
95
        WRITESIDEBARBUTTON("Web Interface Temporarily Unavailable",
			   $TBDOCBASE, "nologins.php3");

96
97
98
99
100
101
102
103
	echo "<tr>
               <td height=30 valign=center align=center nowrap>
                  <b><span class=sidebarbutton>
                       Please Try Again Later
                     </span>
                  </b>
               </td>
              </tr>\n";
104
    }
105
    elseif ($login_status == $STATUS_LOGGEDIN) {
106
107
108
	$query_result =
	    DBQueryFatal("SELECT status,admin ".
			 "FROM users WHERE uid='$login_uid'");
109
110
111
112
113
114
115
116
	$row = mysql_fetch_row($query_result);
	$status = $row[0];
	$admin  = $row[1];

        #
        # See if group_root in any projects, not just the last one in the DB!
        #
	$query_result = mysql_db_query($TBDBNAME,
Leigh B. Stoller's avatar
Leigh B. Stoller committed
117
118
119
		"SELECT trust FROM group_membership ".
		"WHERE uid='$login_uid' and ".
		"      (trust='group_root' or trust='project_root')");
120
121
122
123
124
125
126
	if (mysql_num_rows($query_result)) {
	    $trusted = 1;
	}
	else {
	    $trusted = 0;
	}

127
128
	if ($status == "active" && $pswd_expired) {
	    WRITESIDEBARBUTTON("Change your Password",
129
			       $TBBASE, "moduserinfo.php3");
130
131
	}
	elseif ($status == "active") {
132
	    WRITESIDEBARBUTTON("My $THISHOMEBASE",
133
134
135
			       $TBBASE,
			       "showuser.php3?target_uid=$login_uid");
	    
136
137
138
139
140
	    if ($admin) {
		WRITESIDEBARBUTTON("New Project Approval",
				   $TBBASE, "approveproject_list.php3");
	    }
	    if ($trusted) {
Jay Lepreau's avatar
Jay Lepreau committed
141
                # Only project leaders can do these options
142
143
144
145
146
147
148
149
150
151
		WRITESIDEBARBUTTON("New User Approval",
				   $TBBASE, "approveuser_form.php3");
	    }
	    #
            # 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.
	    #
	    WRITESIDEBARBUTTON("Project Information",
			       $TBBASE, "showproject_list.php3");
152
153
154
155
156
157
158
159
	    
	    if ($admin) {
		WRITESIDEBARBUTTON("User List",
				   $TBBASE, "showuser_list.php3");
		WRITESIDEBARBUTTON("Node Control",
				   $TBBASE, "nodecontrol_list.php3");
	    }
	    
160
	    WRITESIDEBARBUTTON("Begin an Experiment",
161
			       $TBBASE, "beginexp.php3");
162
163
164
	    WRITESIDEBARBUTTON("Experiment Information",
			       $TBBASE, "showexp_list.php3");
	    WRITESIDEBARBUTTON("Update user information",
165
			       $TBBASE, "moduserinfo.php3");
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
	    WRITESIDEBARBUTTON("Node Reservation Status",
			       $TBBASE, "reserved.php3");
	    WRITESIDEBARBUTTON("Node Up/Down Status",
			       $TBDOCBASE, "updown.php3");
                    
	}
	elseif (($status == "newuser") || ($status == "unverified")) {
	    WRITESIDEBARBUTTON("New User Verification",
			       $TBBASE, "verifyusr_form.php3");
	}
	elseif ($status == "unapproved") {
	    $error_message = "Your account has not been approved yet. ".
		             "Please try back later";
	}
    }
    #
    # Standard options for anyone.
    #
184
    if ($login_status != $STATUS_NOLOGINS) {
185
186
	WRITESIDEBARBUTTON("Start Project", $TBBASE, "newproject.php3");
	WRITESIDEBARBUTTON("Join Project",  $TBBASE, "joinproject.php3");
187
    }
188
189
190

    switch ($login_status) {
    case $STATUS_LOGGEDIN:
191
	$login_message = "$login_uid Logged In";
192
193
	if ($pswd_expired)
	    $login_message = "$login_message<br>(Password Expired!)";
194
195
196
197
198
199
200
201
202
203
	break;
    case $STATUS_LOGGEDOUT:
	$login_message = "Logged Out";
	break;
    case $STATUS_LOGINFAIL:
	$login_message = "Login Failed";
	break;
    case $STATUS_TIMEDOUT:
	$login_message = "Login Timed Out";
	break;
204
205
206
    case $STATUS_NOLOGINS:
	$login_message = "Please Try Again Later";
	break;
207
208
209
210
    }

    #
    # Now the login/logout box. Remember, already inside a table.
211
212
    # 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
213
    # http or https, since we do not want to mix them, since they
214
    # cause warnings.
215
216
217
    # 
    if ($login_status == $STATUS_LOGGEDIN) {
	echo "<tr>
218
219
220
221
222
               <td align=center height=50 valign=center>
                <a href=\"$TBBASE/logout.php3?uid=$login_uid\">
	           <img alt=\"logout\" border=0
                        src=\"$BASEPATH/logoff.gif\"></a>
               </td>
223
224
225
226
              </tr>\n";
    }
    else {
	echo "<tr>
227
               <td align=center height=50 valign=center>
228
                <a href=\"$TBBASE/login.php3\">
229
230
231
	           <img alt=\"logon\" border=0
                        src=\"$BASEPATH/logon.gif\"></a>
               </td>
232
233
              </tr>\n";
    }
234

235
236
237
238
239
240
241
242
243
244
245
    if ($login_message) {
	echo "<tr>
                <td align=center>
                 <b>
                   <span class=sidebarbutton>
                      $login_message
                   </span>
                 <b>
                </td>
              </tr>\n";
    }
246
    #
247
    # MOTD. Set this with the webcontrol script.
248
    #
249
250
251
252
253
254
255
256
257
    # The blinking is for Mike, who says he really likes it. 
    #
    $query_result = mysql_db_query($TBDBNAME,
	"SELECT message FROM loginmessage");
    
    if (mysql_num_rows($query_result)) {
    	$row = mysql_fetch_row($query_result);
	$message = $row[0];
    
258
259
	echo "<tr>
                <td align=center>
260
                 <b>
261
262
                   <span class=sidebarbutton>
                    <font size=\"+1\" color=RED>
263
                      $message
264
265
                    </font>
                   </span>
266
                 <b>
267
268
269
                </td>
              </tr>\n";
    }
270
271
272
273
274
275
276
277
278
    echo "</table>
          <br>\n";
}

#
# WRITEBANNER(): write the page banner for a page.
# Called by _STARTPAGE
#
function WRITEBANNER($title) {
279
    global $BANNERCOLOR, $THISPROJECT, $THISHOMEBASE, $BASEPATH;
280
281

    echo "<!-- This is the page Banner -->\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
282

283
284
285
286
287
#    echo "
#                <a href='$BASEPATH/pix/merge-med.jpg'>
#                   <img src='$BASEPATH/pix/merge-mini.jpg'
#                        border=2 align=right></a>
#            \n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
288
289
    
    echo "<table cellpadding=0 cellspacing=0 border=0 width=50%>";
290
    echo "<tr>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
291
            <td align=left valign=top width=\"0%\">
292
293
294
             <table cellpadding=5 cellspacing=0 border=0 bgcolor=\"#880000\">
              <tr>
                <td>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
295
                 <b><font size=5 color=white face=Helvetica>
296
                        $THISHOMEBASE
297
298
299
300
301
302
                    </font>
                 </b>
                </td>
              </tr>
             </table>
            </td>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
303
            <td align=left valign=top width=100%>
304
305
306
                <table cellpadding=5 cellspacing=0 border=0
                         bgcolor=$BANNERCOLOR>
                  <tr>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
307
                   <td nowrap>
308
                     <b>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
309
                       <font size=5 face=helvetica color=\"#000000\">
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
                            $THISPROJECT
                       </font>
                     </b>
                   </td>
                  <tr>
                </table>
            </td>
          </tr>
          </table>\n";
}

#
# _WRITETITLE(title): write the page title for a page.
# Called by _STARTPAGE
#
function WRITETITLE($title) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
326
    global $TITLECOLOR, $BASEPATH;
327
328
329
330
    
    echo "<!-- This is the page Title -->
          <table width=\"100%\">
            <tr>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
331
               <td width=\"10%\" align=left>\n";
332
333
334
                 #
                 # Insert a small logo here if you like.
                 #
Leigh B. Stoller's avatar
Leigh B. Stoller committed
335
    
336
337
    echo "     </td>
               <td align=left>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
338
                   <b><font size=5 color=$TITLECOLOR>$title</font></b>
339
340
341
342
343
344
345
346
347
               </td>
            </tr>
          </table>\n";
}

#
# Spit out a vanilla page header.
#
function PAGEHEADER($title) {
348
    global $login_status, $TBAUTHTIMEOUT, $login_uid;
349
    global $STATUS_NOSTATUS, $STATUS_LOGGEDIN, $STATUS_LOGGEDOUT;
350
351
    global $STATUS_LOGINFAIL, $STATUS_TIMEDOUT, $STATUS_NOLOGINS;
    global $TBBASE, $TBDOCBASE, $TBDBNAME;
352
353
    global $CHECKLOGIN_NOTLOGGEDIN, $CHECKLOGIN_LOGGEDIN;
    global $CHECKLOGIN_TIMEDOUT, $CHECKLOGIN_MAYBEVALID;
354
    global $CHECKLOGIN_PSWDEXPIRED, $THISHOMEBASE
355
    global $BASEPATH, $SSL_PROTOCOL, $javacode, $drewheader, $pswd_expired;
356
    global $TBMAINSITE;
357
358

    $drewheader = 1;
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374

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

376
    #
377
    # Figure out who is logged in, if anyone.
378
    # 
379
380
381
382
383
384
385
386
387
388
    if (($known_uid = GETUID()) != FALSE) {
        #
        # Check to make sure the UID is logged in (not timed out).
        #
        $status = CHECKLOGIN($known_uid);
	switch ($status) {
	case $CHECKLOGIN_NOTLOGGEDIN:
	    $login_status = $STATUS_NOSTATUS;
	    $login_uid    = 0;
	    break;
389
390
	case $CHECKLOGIN_PSWDEXPIRED:
	    $pswd_expired = 1;
391
392
393
394
395
396
397
398
399
	case $CHECKLOGIN_LOGGEDIN:
	case $CHECKLOGIN_MAYBEVALID:
	    $login_status = $STATUS_LOGGEDIN;
	    $login_uid    = $known_uid;
	    break;
	case $CHECKLOGIN_TIMEDOUT:
	    $login_status = $STATUS_TIMEDOUT;
	    $login_uid    = 0;
	    break;
400
401
402
	}
    }

403
404
405
406
407
408
409
    #
    # Check for NOLOGINS. This is complicated by the fact that we
    # want to allow admin types to continue using the web interface,
    # and logout anyone else that is currently logged in!
    #
    if ($login_status == $STATUS_LOGGEDIN && NOLOGINS()) {
	$query_result = mysql_db_query($TBDBNAME,
410
		"SELECT admin FROM users WHERE uid='$login_uid'");
411
412
413
414
	$row = mysql_fetch_row($query_result);
	$admin  = $row[0];

	if (!$admin) {
415
	    DOLOGOUT($login_uid);
416
417
418
419
420
421
422
	    $login_status = $STATUS_NOLOGINS;
	}
    }
    elseif (NOLOGINS()) {
	$login_status = $STATUS_NOLOGINS;
    }

423
424
425
426
427
428
429
430
431
432
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    
    if (isset($SSL_PROTOCOL)) {
	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"); 
    }
433

434
435
    echo "<html>
          <head>
436
           <title>$THISHOMEBASE - $title</title>\n";
437

438
439
    $timeo  = ($TBAUTHTIMEOUT + 120) * 1000;

440
441
442
443
444
445
446
447
448
    #
    # If logged in, initialize the refresh process.
    # 
    if ($login_status == $STATUS_LOGGEDIN) {
	echo "<noscript>
                <META HTTP-EQUIV=\"refresh\" CONTENT=\"$timeo\">
              </noscript>\n";
	echo "<script language=\"JavaScript\">
                <!--
449
                  var sURL  = \"$TBDOCBASE/index.php3\";
450

451
452
                  function doLoad(timeo) {
                    setTimeout(\"refresh()\", timeo );
453
454
455
                  }
                //-->
              </script>\n";
456
457
        #
        # Shove the rest of the Java code through to the output. 
458
459
460
461
        #
	for ($i = 0; $i < count($javacode); $i++) {
	    echo "$javacode[$i]";
	}
462
    }
463
464
465
466
467
468

    if ($TBMAINSITE) {
	echo "  <meta NAME=\"keywords\"
                      CONTENT=\"network, emulation, internet, emulator\">
                <meta NAME=\"ROBOTS\" CONTENT=\"NOARCHIVE\">\n";
    }
469
    
470
471
472
473
#    echo " <meta HTTP-EQUIV=\"Cache-Control\"
#                 CONTENT=\"post-check=30,pre-check=60\">\n";

    echo " <link rel=\"stylesheet\" href=\"$BASEPATH/tbstyle.css\"
474
475
476
477
478
479
480
                 type=\"text/css\">
          </head>\n";

    #
    # If logged in, start the refresh process.
    # 
    if ($login_status == $STATUS_LOGGEDIN) {
481
	echo "<body onload='doLoad($timeo)'>\n";
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
    }
    else {
	echo "<body>\n";
    }

    WRITEBANNER($title);
    WRITETITLE($title);

    echo "<br>
          <!-- Under banner is a table with two columns: menu and content -->
          <table cellpadding=3 width=\"100%\" height=\"60%\" border=2>
          <tr>
           <!-- everthing is in a single row: two tables side-by-side -->

           <!-- MENU -->
           <td valign=top>\n";
    
    WRITESIDEBAR();

    echo " </td>

           <!-- PAGE BODY -->
           <td valign=top align=left width=\"85%\">
Leigh B. Stoller's avatar
Leigh B. Stoller committed
505

506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
               <!-- Content follows this macro ... -->\n";
}

#
# ENDPAGE(): This terminates the table started above.
# 
function ENDPAGE() {
    echo "     <!-- ... end of page content. -->
            </td>
           </tr>
          </table>
          <br>
          <hr size=2 noshade>\n";
}

#
# Spit out a vanilla page footer.
#
function PAGEFOOTER() {
525
    global $TBDOCBASE, $TBMAILADDR, $THISHOMEBASE;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
526
    global $TBMAINSITE, $SSL_PROTOCOL;
527
528
529
530
531

    ENDPAGE();

    echo "<!-- Force full window! -->
	  <base target=_top>
532
          <center>[<a href=\"$TBDOCBASE\">$THISHOMEBASE Home</a>]</center>
533
534
535
536
537
538
539
          <center>
           [<a href=\"http://www.cs.utah.edu/flux/\">Flux Research Group</a>]
           [<a href=\"http://www.cs.utah.edu/\">School of Computing</a>]
           [<a href=\"http://www.utah.edu/\">University of Utah</a>]
          </center>
         <p align=right>
         <font size=-2>
540
541
542
543
544
          Problems? Contact $TBMAILADDR\n";

    if ($TBMAINSITE) {
	echo "<p>
              <a href=\"$TBDOCBASE/netemu.php3\"></a>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
545
546
547
548
549
550
551
552

	if (! isset($SSL_PROTOCOL)) {
	    echo "<a href=http://www.addme.com>
	             <img width=8 height=2
	                 src='http://www.addme.com/link8.gif'
   	                 alt='Add Me!' border=0>
	          </a>\n";
	}
553
554
555
    }

    echo "</font>
556
557
558
          </body>
          </html>\n";
}
559
560
561
562
563
564
565
566
567
568
569
570

function PAGEERROR($msg) {
    global $drewheader;

    if (! $drewheader)
	PAGEHEADER("");

    echo "$msg\n";

    PAGEFOOTER();
    die("");
}
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624

#
# Sub Page/Menu Stuff
#
function WRITESUBMENUBUTTON($text, $link) {
    echo "<!-- Table row for button $text -->
          <tr>
            <td valign=center align=left nowrap>
                <b>
         	 <a class=sidebarbutton href='$link'>$text</a>\n";
    #
    # XXX these blanks look bad in lynx, but add required
    #     spacing between menu and body
    #
    echo "       &nbsp;&nbsp;\n";

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

#
# Start/End a page within a page. 
#
function SUBPAGESTART() {
    echo "<table cellspacing=2 cellpadding=2 width='85%' border=0>\n
            <tr>\n
              <td valign=top>\n";
}

function SUBPAGEEND() {
    echo "    </td>\n
            </tr>\n
          </table>\n";
}

#
# 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) {
    echo "      <table cellspacing=2 cellpadding=2 border=0 width=200>\n
                  <tr>\n
                    <td align=center><b>$title</b></td>\n
                  </tr>\n
                  <tr></tr>\n";
}

function SUBMENUEND() {
    echo "      </table>\n
              </td>\n
              <td valign=top align=left width='85%'>\n";
}

625
?>