menu.php3 15 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 57 58 59

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

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

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

76 77
    $freepcs = TBFreePCs();

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

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

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

95 96 97 98 99 100 101 102
	echo "<tr>
               <td height=30 valign=center align=center nowrap>
                  <b><span class=sidebarbutton>
                       Please Try Again Later
                     </span>
                  </b>
               </td>
              </tr>\n";
103
    }
104
    elseif ($login_status == $STATUS_LOGGEDIN) {
105 106 107
	$query_result =
	    DBQueryFatal("SELECT status,admin ".
			 "FROM users WHERE uid='$login_uid'");
108 109 110 111 112 113 114 115
	$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
116 117 118
		"SELECT trust FROM group_membership ".
		"WHERE uid='$login_uid' and ".
		"      (trust='group_root' or trust='project_root')");
119 120 121 122 123 124 125
	if (mysql_num_rows($query_result)) {
	    $trusted = 1;
	}
	else {
	    $trusted = 0;
	}

126 127 128 129 130
	if ($status == "active" && $pswd_expired) {
	    WRITESIDEBARBUTTON("Change your Password",
			       $TBBASE, "modusr_form.php3");
	}
	elseif ($status == "active") {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
131
	    WRITESIDEBARBUTTON("My Emulab.Net",
132 133 134
			       $TBBASE,
			       "showuser.php3?target_uid=$login_uid");
	    
135 136 137 138 139
	    if ($admin) {
		WRITESIDEBARBUTTON("New Project Approval",
				   $TBBASE, "approveproject_list.php3");
	    }
	    if ($trusted) {
Jay Lepreau's avatar
Jay Lepreau committed
140
                # Only project leaders can do these options
141 142 143 144 145 146 147 148 149 150
		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");
151 152 153 154 155 156 157 158
	    
	    if ($admin) {
		WRITESIDEBARBUTTON("User List",
				   $TBBASE, "showuser_list.php3");
		WRITESIDEBARBUTTON("Node Control",
				   $TBBASE, "nodecontrol_list.php3");
	    }
	    
159 160 161 162
	    WRITESIDEBARBUTTON("Begin an Experiment",
			       $TBBASE, "beginexp_form.php3");
	    WRITESIDEBARBUTTON("Experiment Information",
			       $TBBASE, "showexp_list.php3");
163 164
	    WRITESIDEBARBUTTON("Create a Batch Experiment",
			       $TBBASE, "batchexp_form.php3");
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
	    WRITESIDEBARBUTTON("Update user information",
			       $TBBASE, "modusr_form.php3");
	    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.
    #
185 186 187 188
    if ($login_status != $STATUS_NOLOGINS) {
	WRITESIDEBARBUTTON("Start Project", $TBBASE, "newproject_form.php3");
	WRITESIDEBARBUTTON("Join Project",  $TBBASE, "addusr.php3");
    }
189 190 191

    switch ($login_status) {
    case $STATUS_LOGGEDIN:
192
	$login_message = "$login_uid Logged In";
193 194
	if ($pswd_expired)
	    $login_message = "$login_message<br>(Password Expired!)";
195 196 197 198 199 200 201 202 203 204
	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;
205 206 207
    case $STATUS_NOLOGINS:
	$login_message = "Please Try Again Later";
	break;
208 209 210 211
    }

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

236 237 238 239 240 241 242 243 244 245 246
    if ($login_message) {
	echo "<tr>
                <td align=center>
                 <b>
                   <span class=sidebarbutton>
                      $login_message
                   </span>
                 <b>
                </td>
              </tr>\n";
    }
247
    #
248
    # MOTD. Set this with the webcontrol script.
249
    #
250 251 252 253 254 255 256 257 258
    # 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];
    
259 260
	echo "<tr>
                <td align=center>
261
                 <b>
262 263
                   <span class=sidebarbutton>
                    <font size=\"+1\" color=RED>
264
                      $message
265 266
                    </font>
                   </span>
267
                 <b>
268 269 270
                </td>
              </tr>\n";
    }
271 272 273 274 275 276 277 278 279 280 281 282
    echo "</table>
          <br>\n";
}

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

    echo "<!-- This is the page Banner -->\n";
283
    echo "<table cellpadding=0 cellspacing=0 border=0>";
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
    echo "<tr>
            <td align=left width=\"0%\">
             <table cellpadding=5 cellspacing=0 border=0 bgcolor=\"#880000\">
              <tr>
                <td>
                 <b><font size=15 color=white face=Helvetica>
                     $THISHOMEBASE
                    </font>
                 </b>
                </td>
              </tr>
             </table>
            </td>
            <td align=left width=\"100%\">
                <table cellpadding=5 cellspacing=0 border=0
                         bgcolor=$BANNERCOLOR>
                  <tr>
                   <td>
                     <b>
                       <font size=15 face=helvetica color=\"#000000\">
                            $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) {
    global $TITLECOLOR;
    
    echo "<!-- This is the page Title -->
          <table width=\"100%\">
            <tr>
               <td width=\"15%\" align=left>\n";
                 #
                 # Insert a small logo here if you like.
                 #
    echo "     </td>
               <td align=left>
                   <b><font size=\"+3\" color=$TITLECOLOR>$title</font></b>
               </td>
            </tr>
          </table>\n";
}

#
# Spit out a vanilla page header.
#
function PAGEHEADER($title) {
341
    global $login_status, $TBAUTHTIMEOUT, $login_uid;
342
    global $STATUS_NOSTATUS, $STATUS_LOGGEDIN, $STATUS_LOGGEDOUT;
343 344
    global $STATUS_LOGINFAIL, $STATUS_TIMEDOUT, $STATUS_NOLOGINS;
    global $TBBASE, $TBDOCBASE, $TBDBNAME;
345 346
    global $CHECKLOGIN_NOTLOGGEDIN, $CHECKLOGIN_LOGGEDIN;
    global $CHECKLOGIN_TIMEDOUT, $CHECKLOGIN_MAYBEVALID;
347 348 349 350
    global $CHECKLOGIN_PSWDEXPIRED;
    global $BASEPATH, $SSL_PROTOCOL, $javacode, $drewheader, $pswd_expired;

    $drewheader = 1;
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366

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

368
    #
369
    # Figure out who is logged in, if anyone.
370
    # 
371 372 373 374 375 376 377 378 379 380
    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;
381 382
	case $CHECKLOGIN_PSWDEXPIRED:
	    $pswd_expired = 1;
383 384 385 386 387 388 389 390 391
	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;
392 393 394
	}
    }

395 396 397 398 399 400 401
    #
    # 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,
402
		"SELECT admin FROM users WHERE uid='$login_uid'");
403 404 405 406
	$row = mysql_fetch_row($query_result);
	$admin  = $row[0];

	if (!$admin) {
407
	    DOLOGOUT($login_uid);
408 409 410 411 412 413 414
	    $login_status = $STATUS_NOLOGINS;
	}
    }
    elseif (NOLOGINS()) {
	$login_status = $STATUS_NOLOGINS;
    }

415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
    echo "<html>
          <head>
           <title>Emulab.Net - $title</title>\n";

    #
    # If logged in, initialize the refresh process.
    # 
    if ($login_status == $STATUS_LOGGEDIN) {
	$timeo = $TBAUTHTIMEOUT + 120;
	echo "<noscript>
                <META HTTP-EQUIV=\"refresh\" CONTENT=\"$timeo\">
              </noscript>\n";
	$timeo *= 1000;
	echo "<script language=\"JavaScript\">
                <!--
430 431
                  var sURL = \"$TBDOCBASE/index.php3\";

432 433 434 435 436
                  function doLoad() {
                    setTimeout(\"refresh()\", $timeo );
                  }
                //-->
              </script>\n";
437 438
        #
        # Shove the rest of the Java code through to the output. 
439 440 441 442
        #
	for ($i = 0; $i < count($javacode); $i++) {
	    echo "$javacode[$i]";
	}
443 444
    }
    
445 446
    echo " <meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">
           <link rel=\"stylesheet\" href=\"$BASEPATH/tbstyle.css\"
447 448 449 450 451 452 453 454 455 456 457 458 459 460
                 type=\"text/css\">
          </head>\n";

    #
    # If logged in, start the refresh process.
    # 
    if ($login_status == $STATUS_LOGGEDIN) {
	echo "<body onload=\"doLoad()\">\n";
    }
    else {
	echo "<body>\n";
    }

    echo "<basefont size=4>\n";
461

462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
    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%\">
               <basefont size=4>
               <!-- 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() {
500
    global $TBDOCBASE, $TBMAILADDR;
501 502 503 504 505

    ENDPAGE();

    echo "<!-- Force full window! -->
	  <base target=_top>
506
          <center>[<a href=\"$TBDOCBASE\">Emulab.Net Home</a>]</center>
507 508 509 510 511 512 513
          <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>
514 515
          Problems? Contact $TBMAILADDR
          </font>
516 517 518
          </body>
          </html>\n";
}
519 520 521 522 523 524 525 526 527 528 529 530

function PAGEERROR($msg) {
    global $drewheader;

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

    echo "$msg\n";

    PAGEFOOTER();
    die("");
}
531
?>