gototrac.php3 3.3 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{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/>.
# 
# }}}
23 24 25 26 27 28 29 30 31
#
include("defs.php3");

if (!$TRACSUPPORT) {
    header("Location: index.php3");
    return;
}

# No Pageheader since we spit out a redirection below.
32
$this_user = CheckLoginOrDie();
33
$uid       = $this_user->uid();
34
$isadmin   = ISADMIN();
35

36 37 38 39 40 41
# The user has to be approved, real account.
if (!HASREALACCOUNT($uid)) {
    USERERROR("You may not login to the Emulab Wiki until your account ".
	      "has been approved and is active.", 1);
}

42 43 44 45
#
# Verify page arguments. project_title is the project to zap to.
#
$optargs = OptionalPageArguments("wiki",  PAGEARG_STRING,
46 47 48
				 "login", PAGEARG_BOOLEAN,
				 "do",    PAGEARG_STRING);
				 
49 50
if (!isset($wiki)) {
    $wiki = "emulab";
51
}
52 53 54
if (!isset($login)) {
    $login = 0;
}
55 56 57 58 59 60 61 62
$priv = 0;

if ($wiki == "protogeni-priv") {
    $wiki = "protogeni";
}
elseif ($wiki == "emulab-priv") {
    $wiki = "emulab";
}
Leigh Stoller's avatar
Leigh Stoller committed
63

64
if ($wiki == "geni" || $wiki == "protogeni") {
65
    $geniproject = Project::Lookup("geni");
66 67 68
    if (!$geniproject) {
	USERERROR("There is no such Trac wiki!", 1);
    }
69
    $approved    = 0;
70 71
    if (! ($isadmin ||
	   ($geniproject->IsMember($this_user, $approved) && $approved))) {
72 73
	USERERROR("You do not have permission to access the Trac wiki!", 1);
    }
74 75
    $priv       = 1;
    $wiki       = "protogeni";
76
    $TRACURL    = "https://users.emulab.net/trac/$wiki";
77
    $COOKIENAME = "trac_auth_protogeni";
78
}
79
elseif ($wiki != "emulab") {
80 81
    USERERROR("Unknown Trac wiki $wiki!", 1);
}
82
else {
83 84
    $TRACURL    = "https://${USERNODE}/trac/$wiki";
    $COOKIENAME = "trac_auth_${wiki}";
85
    if (ISADMINISTRATOR() || STUDLY()) {
86 87
	$priv = 1;
    }
88
}
89 90 91 92 93

#
# Look for our cookie. If the browser has it, then there is nothing
# more to do; just redirect the user over to the wiki.
#
94
if (!$login && isset($_COOKIE[$COOKIENAME])) {
Leigh Stoller's avatar
Leigh Stoller committed
95
    $url = $TRACURL;
96 97 98
    if (isset($do)) {
	$url .= "/" . $do;
    }
Leigh Stoller's avatar
Leigh Stoller committed
99
    header("Location: $url");
100 101 102
    return;
}

103 104 105
# Login to private part of wiki.
$privopt = ($priv ? "-p" : "");

106 107 108
#
# Do the xlogin, which gives us back a hash to stick in the cookie.
#
109
SUEXEC($uid, "nobody", "tracxlogin $privopt -w " . escapeshellarg($wiki) .
110
       " $uid " . $_SERVER['REMOTE_ADDR'], SUEXEC_ACTION_DIE);
111 112 113 114

if (!preg_match("/^(\w*)$/", $suexec_output, $matches)) {
    TBERROR($suexec_output, 1);
}
115 116
$hash = $matches[1];

117
setcookie($COOKIENAME, $hash, 0, "/", $TBAUTHDOMAIN, $TBSECURECOOKIES);
118 119 120 121
if ($priv) {
    setcookie($COOKIENAME . "_priv",
	      $hash, 0, "/", $TBAUTHDOMAIN, $TBSECURECOOKIES);
}
122
header("Location: ${TRACURL}/xlogin?user=$uid&hash=$hash" .
123
       (isset($do) ? "&goto=${do}" : ""));
124