login.php3 4.02 KB
Newer Older
1 2
<?php
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
3
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5 6
# All rights reserved.
#
7 8
require("defs.php3");

9 10 11 12 13 14 15 16 17
#
# These two for verification.
# 
if (!isset($key) || !strcmp($key, "")) {
    $key = 0;
}
if (!isset($vuid) || !strcmp($vuid, "")) {
    $vuid = 0;
}
18 19 20 21
# Allow adminmode to be passed along.
if (!isset($adminmode)) {
    $adminmode = 0;
}
22 23 24 25 26 27 28 29 30 31
# Allow referrer to be passed along.
if (!isset($referrer) || !strcmp($referrer, "")) {
    $referrer = 0;
}
# Referrer page requested that it be passed along so that it can be
# redisplayed after login. Save the referrer for form below.
if (isset($refer) && $refer &&
    isset($HTTP_REFERER) && strcmp($HTTP_REFERER, "")) {
    $referrer = $HTTP_REFERER;
}
32

33
#
34 35 36
# Must not be logged in already!
# 
if (($known_uid = GETUID()) != FALSE) {
37 38 39 40 41 42 43 44 45
    if (CHECKLOGIN($known_uid) & CHECKLOGIN_LOGGEDIN) {
	#
	# If doing a verification, zap to that page.
	#
	if ($key && (!$vuid || !strcmp($vuid, $known_uid))) {
	    header("Location: $TBBASE/verifyusr.php3?key=$key");
	    return;
	}

46 47 48 49 50 51 52 53 54
	PAGEHEADER("Login");

	echo "<h3>
              You are still logged in. Please log out first if you want
              to log in as another user!
              </h3>\n";
	    
	PAGEFOOTER();
	die("");
55 56
    }
}
57 58 59 60

#
# Spit out the form.
# 
61
function SPITFORM($uid, $key, $referrer, $failed, $adminmode)
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
{
    global $TBDB_UIDLEN, $TBBASE;
    
    PAGEHEADER("Login");

    if ($failed) {
	echo "<center>
              <font size=+1 color=red>
	      Login attempt failed! Please try again.
              </font>
              </center><br>\n";
    }

    echo "<center>
          <font size=+1>
          Please login to our secure server.<br>
          (You must have cookies enabled)
          </font>
          </center>\n";

82 83 84 85
    $keyarg = "";
    if ($key)
	$keyarg = "?key=$key";

86
    echo "<table align=center border=1>
87
          <form action='${TBBASE}/login.php3${keyarg}' method=post>
88 89 90 91 92 93
          <tr>
              <td>Username:</td>
              <td><input type=text
                         value=\"$uid\"
                         name=uid size=$TBDB_UIDLEN></td>
          </tr>
94
          <tr>
95 96 97 98 99 100
              <td>Password:</td>
              <td><input type=password name=password size=12></td>
          </tr>
          <tr>
             <td align=center colspan=2>
                 <b><input type=submit value=Login name=login></b></td>
101 102 103 104 105
          </tr>\n";
    
    if ($referrer) {
	echo "<input type=hidden name=referrer value=$referrer>\n";
    }
106 107 108
    if ($adminmode) {
	echo "<input type=hidden name=adminmode value=1>\n";
    }
109 110

    echo "</form>
111 112 113 114 115
          </table>\n";

    echo "<center><h2>
          <a href='password.php3'>Forgot your password?</a>
          </h2></center>\n";
116 117
}

118 119 120
#
# Do not bother if NOLOGINS!
#
121
if (0 && NOLOGINS()) {
122 123 124 125 126 127 128 129 130 131 132 133
    PAGEHEADER("Login");
	    
    echo "<center>
          <font size=+1 color=red>
	   Logins are temporarily disabled. Please try again later.
          </font>
          </center><br>\n";

    PAGEFOOTER();
    die("");
}

134 135 136 137
#
# If not clicked, then put up a form.
#
if (! isset($login)) {
138 139
    if ($vuid)
	$known_uid = $vuid;
140
    SPITFORM($known_uid, $key, $referrer, 0, $adminmode);
141
    PAGEFOOTER();
142 143 144 145
    return;
}

#
146
# Login clicked.
147 148 149 150 151
#
$STATUS_LOGGEDIN  = 1;
$STATUS_LOGINFAIL = 2;
$login_status     = 0;

152 153 154 155 156
if (!isset($uid) ||
    strcmp($uid, "") == 0) {
    $login_status = $STATUS_LOGINFAIL;
}
else {
157
    if (DOLOGIN($uid, $password, $adminmode)) {
158 159 160 161 162 163
	$login_status = $STATUS_LOGINFAIL;
    }
    else {
	$login_status = $STATUS_LOGGEDIN;
    }
}
164

165 166 167 168
#
# Failed, then try again with an error message.
# 
if ($login_status == $STATUS_LOGINFAIL) {
169
    SPITFORM($uid, $key, $referrer, 1, $adminmode);
170 171 172
    PAGEFOOTER();
    return;
}
173

174 175 176 177 178 179
if ($key) {
    #
    # If doing a verification, zap to that page.
    #
    header("Location: $TBBASE/verifyusr.php3?key=$key");
}
180 181 182 183 184 185
elseif ($referrer) {
    #
    # Zap back to page that started the login request.
    #
    header("Location: $referrer");
}
186 187 188 189 190 191
else {
    #
    # Zap back to front page in secure mode.
    # 
    header("Location: $TBBASE/");
}
192 193
return;

194
?>