. # # }}} # $APTHOST = "$WWWHOST"; $APTBASE = "$TBBASE/apt"; $APTMAIL = $TBMAIL_OPS; $APTTITLE = "APT"; $FAVICON = "aptlab.ico"; $APTLOGO = "aptlogo.png"; $APTSTYLE = "apt.css"; $ISAPT = 1; # # Global flag to disable accounts. We do this on some pages which # should not display login/account info. # $disable_accounts = 0; # # So, we could be coming in on the alternate APT address (virtual server) # which causes cookie problems. I need to look into avoiding this problem # but for now, just change the global value of the TBAUTHDOMAIN when we do. # The downside is that users will have to log in twice if they switch back # and forth. # if ($TBMAINSITE && $_SERVER["SERVER_NAME"] == "www.aptlab.net") { $TBAUTHDOMAIN = ".aptlab.net"; $APTHOST = "www.aptlab.net"; $WWWHOST = "www.aptlab.net"; $APTBASE = "https://www.aptlab.net"; $APTMAIL = "APT Operations "; } elseif ($TBMAINSITE && $_SERVER["SERVER_NAME"] == "www.cloudlab.us") { $TBAUTHDOMAIN = ".cloudlab.us"; $APTHOST = "www.cloudlab.us"; $WWWHOST = "www.cloudlab.us"; $APTBASE = "https://www.cloudlab.us"; $APTMAIL = "Cloud Lab Operations "; $APTTITLE = "CloudLab"; $FAVICON = "cloudlab.ico"; $APTLOGO = "cloudlogo.png"; $APTSTYLE = "cloudlab.css"; $ISAPT = 0; } # # Redefine this so APT errors are styled properly. Called by PAGEERROR();. # $PAGEERROR_HANDLER = function($msg, $status_code = 0) { global $drewheader, $ISAPT; if (! $drewheader) { SPITHEADER(); } echo $msg; echo "\n"; echo "\n"; echo "\n"; echo "\n"; SPITFOOTER(); die(""); }; function SPITHEADER($thinheader = 0) { global $TBMAINSITE, $APTTITLE, $FAVICON, $APTLOGO, $APTSTYLE, $ISAPT; global $login_user, $login_status; global $disable_accounts, $page_title, $drewheader; $title = $APTTITLE; if (isset($page_title)) { $title .= " - $page_title"; } $height = ($thinheader ? 150 : 250); $drewheader = 1; # # Figure out who is logged in, if anyone. # if (($login_user = CheckLogin($status)) != null) { $login_status = $status; $login_uid = $login_user->uid(); } echo " $title \n"; echo "\n"; if ($TBMAINSITE && file_exists("../google-analytics.php")) { readfile("../google-analytics.php"); } echo "
\n"; SpitLoginModal("quickvm_login_modal"); echo "
\n"; } function SPITFOOTER() { global $ISAPT; $groupname = ($ISAPT ? "apt-users" : "cloudlab-users"); echo "
\n"; SpitNSFModal(); echo "
\n"; } function SPITUSERERROR($msg) { PAGEERROR($msg, 0); } # # Does not return; page exits. # function SPITAJAX_RESPONSE($value) { $results = array( 'code' => 0, 'value' => $value ); echo json_encode($results); } function SPITAJAX_ERROR($code, $msg) { $results = array( 'code' => $code, 'value' => $msg ); echo json_encode($results); } function SPITNULLREQUIRE() { echo "\n"; echo "\n"; echo "\n"; } # # Spit out an info tooltip. # function SpitToolTip($info) { echo " ". " ". "\n"; } # # Spit out the verify modal. We are not using real password authentication # like the rest of the Emulab website. Assumed to be inside of a form # that handles a create button. # function SpitVerifyModal($id, $label) { echo " \n"; } # # Spit out the login modal. # function SpitLoginModal($id) { global $APTTITLE, $ISAPT; $pwlab = ($ISAPT ? "Aptlab.net" : "CloudLab.net") . " or Emulab.net Username"; $pwlab = "'$pwlab'"; ?> \n"; } # # Please Wait. # function SpitWaitModal($id) { echo " \n"; } # # Oops modal. # function SpitOopsModal($id) { echo " \n"; } function SpitNSFModal() { global $ISAPT; $nsfnumber = ($ISAPT ? "CNS-1338155" : "CNS-1302688"); echo " \n"; } # # Generate an authentication object to pass to the browser that # is passed to the web server on boss. This is used to grant # permission to the user to invoke ssh to a local node using their # emulab generated (no passphrase) key. This is basically a clone # of what GateOne does, but that code was a mess. # function SSHAuthObject($uid, $nodeid) { global $USERNODE; $file = "/usr/testbed/etc/sshauth.key"; # # We need the secret that is shared with ops. # $fp = fopen($file, "r"); if (! $fp) { TBERROR("Error opening $file", 0); return null; } $key = fread($fp, 128); fclose($fp); if (!$key) { TBERROR("Could not get key from $file", 0); return null; } $key = chop($key); $stuff = GENHASH(); $now = time(); $authobj = array('uid' => $uid, 'stuff' => $stuff, 'nodeid' => $nodeid, 'timestamp' => $now, 'baseurl' => "https://${USERNODE}", 'signature_method' => 'HMAC-SHA1', 'api_version' => '1.0', 'signature' => hash_hmac('sha1', $uid . $stuff . $nodeid . $now, $key), ); return json_encode($authobj); } # # This is a little odd; since we are using our local CM to create # the experiment, we can just ask for the graphic directly. # function GetTopoMap($uid, $pid, $eid) { global $TBSUEXEC_PATH; $xmlstuff = ""; if ($fp = popen("$TBSUEXEC_PATH nobody nobody webvistopology ". "-x -s $uid $pid $eid", "r")) { while (!feof($fp) && connection_status() == 0) { $string = fgets($fp); if ($string) { $xmlstuff .= $string; } } return $xmlstuff; } else { return ""; } } # # Redirect request to https # function RedirectSecure() { global $APTHOST; if (!isset($_SERVER["SSL_PROTOCOL"])) { header("Location: https://$APTHOST". $_SERVER['REQUEST_URI']); exit(); } } # # Redirect to the login page() # function RedirectLoginPage() { # HTTP_REFERER will not work reliably when redirecting so # pass in the URI for this page as an argument header("Location: login.php?referrer=". urlencode($_SERVER['REQUEST_URI'])); } ?>