Commit 5137fd26 authored by Kirk Webb's avatar Kirk Webb

Rework alternate domain detection and setup.

If an alternate_domans_THISHOMEBASE.php file is present, include it.
This file should contain alternate page view options and global
variable overrides (see code for SetDomainDefs() in defs.php3).
parent 407c136f
<?php
#
# Copyright (c) 2014 University of Utah and the Flux Group.
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -21,35 +21,24 @@
#
# }}}
#
require("defs.php3");
$optargs = OptionalPageArguments("stayhome", PAGEARG_BOOLEAN);
# Alternate domain def structures. The first element of the outermost
# array is the regex pattern to match against $_SERVER['SERVER_NAME'].
# The second element is another array that contains key-value pairs
# for various top-level variable overrides. See SetDomainDefs() in
# defs.php3 for more info.
#
# The point of this is to redirect logged in users to their My Emulab
# page.
# PhantomNet view declaration
#
CheckRedirect();
$PNET_DOMVIEW = array('hide_sidebar' => 0, 'hide_banner' => 0,
'show_topbar' => "pnet", 'show_bottombar' => 'pnet',
'hide_copyright' => 0, 'show_pnet' => 1);
PAGEHEADER("PhantomNet - Mobility Testbed", NULL, $RSS_HEADER_PNNEWS);
$ALTERNATE_DOMAINS[] =
array('phantom',
array('THISHOMEBASE' => 'PhantomNet',
'DOMVIEW' => $PNET_DOMVIEW
));
#
# Show special banner message, if set.
#
$message = TBGetSiteVar("web/banner");
if ($message != "") {
echo "<center><font color=Red size=+1>\n";
echo "$message\n";
echo "</font></center><br>\n";
}
#
# PhantomNet front page content.
#
readfile("index-phantomnet.html");
#
# Standard Testbed Footer
#
PAGEFOOTER();
?>
?>
\ No newline at end of file
......@@ -181,30 +181,16 @@ $RSS_HEADER_PNNEWS =
"title=\"PhantomNet News\" href=\"$TBDOCBASE/news-rss.php3?phantomnet=1\"/>";
#
# Below is an inelegant solution for changing aspects of the UI based on
# the incoming apache virtual server name (for PhantomNet).
#
$IS_PNET = 0;
if (strpos($_SERVER['SERVER_NAME'],'phantom') !== false) {
$WWWHOST = $_SERVER['SERVER_NAME'];
$OURDOMAIN = implode(".", array_slice(explode(".",$WWWHOST),1));
$WWW = $WWWHOST;
$THISHOMEBASE = "PhantomNet";
$TBAUTHDOMAIN = ".$OURDOMAIN";
$TBBASE = "https://$WWWHOST";
$TBDOCBASE = "http://$WWWHOST";
$TBWWW = "<$TBBASE/>";
$WIKINODE = "wiki.$OURDOMAIN";
$WIKIDOCS = "http://${WIKINODE}/wikidocs/wiki";
$IS_PNET = 1;
# See if we should override any of the global web variables based on the
# virtual domain. We include a site-dependent definitions file.
#
$ALTERNATE_DOMAINS = array();
$DOMVIEW = NULL;
$altdomfile = strtolower("alternate_domains_${OURDOMAIN}.php");
if (file_exists($altdomfile)) {
include($altdomfile);
}
#
# PhantomNet view declaration
#
$PNETVIEW = array('hide_sidebar' => 1, 'hide_banner' => 0,
'show_topbar' => "pnet", 'show_bottombar' => 'pnet',
'hide_copyright' => 0, 'show_pnet' => 1);
SetDomainDefs();
#
# Database constants and the like.
......@@ -672,6 +658,59 @@ function CheckRedirect() {
}
}
#
# Loop over the $ALTERNATE_DOMAINS global array and see if the incoming
# request asked for a virtual domain for which we have an alternate set
# of definitions and/or view.
#
# Return 1 if a domain in the array matched, 0 otherwise. Has MAJOR
# side effects: updates/overrides many top-level variables.
#
function SetDomainDefs()
{
global $WWWHOST, $OURDOMAIN, $WWW, $THISHOMEBASE, $TBAUTHDOMAIN, $TBBASE;
global $TBDOCBASE, $TBWWW, $WIKINODE, $TBMAINSITE;
global $ALTERNATE_DOMAINS;
foreach ($ALTERNATE_DOMAINS as list($dpat, $ovr)) {
if (preg_match($dpat, $_SERVER['SERVER_NAME']) == 1) {
# Replacement defs derived from the virtual domain itself.
$WWWHOST = $_SERVER['SERVER_NAME'];
$OURDOMAIN = implode(".", array_slice(explode(".",$WWWHOST),1));
$WWW = $WWWHOST;
$TBAUTHDOMAIN = ".$OURDOMAIN";
$TBBASE = "https://$WWWHOST";
$TBDOCBASE = "http://$WWWHOST";
$TBWWW = "<$TBBASE/>";
# Defs that may be overriden in the domain's configuration array
if (isset($ovr['THISHOMEBASE'])) {
$THISHOMEBASE = $ovr['THISHOMEBASE'];
}
if (isset($ovr['WIKINODE'])) {
$WIKINODE = $ovr['WIKINODE'];
} else {
$WIKINODE = "wiki.$OURDOMAIN";
}
if (isset($ovr['WIKIDOCS'])) {
$WIKIDOCS = $ovr['WIKIDOCS'];
} else {
$WIKIDOCS = "http://${WIKINODE}/wikidocs/wiki";
}
if (isset($ovr['DOMVIEW'])) {
$DOMVIEW = $ovr['DOMVIEW'];
}
# Given that this is an alternate domain, clear TBMAINSITE
$TBMAINSITE = 0;
# Bail after the first domain match.
return 1;
}
}
return 0;
}
#
# If the page was accessed via http redirect to https and exit
# otherwise do nothing
......
......@@ -1041,7 +1041,6 @@ function PAGEHEADER($title, $view = NULL, $extra_headers = NULL,
global $TBBASE, $TBDOCBASE, $THISHOMEBASE;
global $BASEPATH, $drewheader, $autorefresh;
global $TBMAINSITE;
global $IS_PNET, $PNETVIEW;
$drewheader = 1;
if (isset($_GET['refreshrate']) && is_numeric($_GET['refreshrate'])) {
......@@ -1058,12 +1057,14 @@ function PAGEHEADER($title, $view = NULL, $extra_headers = NULL,
#
# If no view options were specified, get the ones for the current user.
# if no user specific view, see if we are coming in via Phantomnet.
# if no user specific view, see if we are coming in via a virtual domain
# with an alternate view.
#
if (!$view) {
$view = GETUSERVIEW();
if (empty($view) && $IS_PNET) {
$view = $PNETVIEW;
# See if there is a domain override.
if (empty($view)) {
$view = GETDOMVIEW();
}
}
......@@ -1209,7 +1210,6 @@ function PAGEFOOTER($view = NULL) {
global $TBDOCBASE, $TBMAILADDR, $THISHOMEBASE, $BASEPATH, $TBBASE;
global $TBMAINSITE, $bodyclosestring, $currently_busy;
global $login_user, $javascript_debug, $sortedtables;
global $IS_PNET, $PNETVIEW;
if ($currently_busy) {
CLEARBUSY();
......@@ -1218,12 +1218,13 @@ function PAGEFOOTER($view = NULL) {
#
# If no view options were specified, get the ones for the current user.
# if no user specific view, see if we are coming in via Phantomnet.
# if no user specific view, see if we are coming in via a virtual
# domain with an alternate view.
#
if (!$view) {
$view = GETUSERVIEW();
if (empty($view) && $IS_PNET) {
$view = $PNETVIEW;
if (empty($view)) {
$view = GETDOMVIEW();
}
}
......@@ -1482,6 +1483,20 @@ function GETUSERVIEW() {
}
}
#
# Get a view, based on incoming virtual domain name. See SetDomainDefs()
# in defs.php3 for more details.
#
function GETDOMAINVIEW() {
global $DOMVIEW;
if (isset($DOMVIEW)) {
return $DOMVIEW;
}
return array();
}
#
# Do we view something.
#
......
<!--
Copyright (c) 2014 University of Utah and the Flux Group.
{{{EMULAB-LICENSE
This file is part of the Emulab network testbed software.
This file is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
This file is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
License for more details.
You should have received a copy of the GNU Affero General Public License
along with this file. If not, see <http://www.gnu.org/licenses/>.
}}}
-->
<!--- This exists to redirect to the PHP script -->
<html>
<head>
<title>PhantomNet.Org</title>
<META HTTP-EQUIV="Refresh" Content= "0; URL=index.php3" ALT="PhantomNet home page">
</head>
</html>
include_path = ".:.."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment