login.php 6.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
#
# Copyright (c) 2000-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/>.
# 
# }}}
#
chdir("..");
include("defs.php3");
chdir("apt");
include("quickvm_sup.php");
28
$page_title = "Login";
29

30
31
32
33
34
#
# Get current user in case we need an error message.
#
$this_user = CheckLogin($check_status);

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("login",       PAGEARG_STRING,
				 "uid",         PAGEARG_STRING,
				 "password",    PAGEARG_PASSWORD,
				 "refer",       PAGEARG_BOOLEAN,
				 "referrer",    PAGEARG_STRING,
				 "ajax_request",PAGEARG_BOOLEAN);
				 
# See if 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) &&
    isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != "") {
    $referrer = $_SERVER['HTTP_REFERER'];

    # In order to get the auth cookies, pages need to go through https. But,
    # the user may have visited the last page with http. If they did, send them
    # back through https
    $referrer = preg_replace("/^http:/i","https:",$referrer);
} else if (! isset($referrer)) {
    $referrer = null;
}

if (NOLOGINS()) {
    if ($ajax_request) {
	SPITAJAX_ERROR(1, "logins are temporarily disabled");
	exit();
    }
    SPITHEADER();
    SPITUSERERROR("Sorry, logins are temporarily disabled, ".
		  "please try again later.");
67
    echo "<script src='js/lib/require.js' data-main='js/main'></script>";
68
69
70
71
72
73
74
75
76
77
78
    SPITFOOTER();
    return;
}

#
# Spit out the form.
# 
function SPITFORM($uid, $referrer, $error)
{
    global $TBDB_UIDLEN, $TBBASE, $refer;
    
79
80
81
82
83
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Cache-Control: no-cache, max-age=0, must-revalidate, no-store");
    header("Pragma: no-cache");

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    SPITHEADER();
 
    echo "<div class='row'>
          <div class='col-lg-6  col-lg-offset-3
                      col-md-6  col-md-offset-3
                      col-sm-8  col-sm-offset-2
                      col-xs-12 col-xs-offset-0'>\n";
    echo "<form id='quickvm_login_form' role='form'
            method='post' action='login.php'>\n";
    echo "<div class='panel panel-default'>
           <div class='panel-heading'>
              <h3 class='panel-title'>
                 Login</h3></div>
           <div class='panel-body'>\n";

    if ($error) {
        echo "<span class='help-block'><font color=red>";
    	switch ($error) {
        case "failed": 
            echo "Login attempt failed! Please try again.";
            break;
        case "notloggedin":
	    echo "You do not appear to be logged in!";
            break;
        case "timedout":
	    echo "Your login has timed out!";
	    break;
111
112
113
        case "alreadyloggedin":
	    echo "You are already logged in. Logout first?";
	    break;
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
	default:
	    echo "Unknown Error ($error)!";
        }
        echo "</font></span>";
    }
    elseif ($refer) {
        echo "<span class='help-block'>Please login before continuing</span>";
    }

    echo "  <div class='form-group'>
                <input name='uid' id='uid'
		       value='$uid'
                       class='form-control'
                       placeholder='Email or Username' autofocus type='text'>
            </div>
            <div class='form-group'>
                <input name='password' id='password' type='password'
                       class='form-control'
                       placeholder='Password' type='text' />
            </div>
            <button class='btn btn-primary btm-sm'
              type='submit' name='login'>Login
            </button>\n";
    if ($referrer) {
	echo "<input type=hidden name=referrer value=$referrer>\n";
    }
    echo "
            <br> 
           </div>
          </div>
          </form>
        </div>
        </div>\n";
    
148
    echo "<script src='js/lib/require.js' data-main='js/main'></script>";
149
150
151
152
153
154
155
    SPITFOOTER();
    return;
}
#
# If not clicked, then put up a form.
#
if (!$ajax_request && !isset($login)) {
156
157
    SPITFORM(REMEMBERED_ID(), $referrer,
	     ($this_user ? "alreadyloggedin" : null));
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
    return;
}

#
# Login clicked.
#
$STATUS_LOGGEDIN  = 1;
$STATUS_LOGINFAIL = 2;
$login_status     = 0;

if (!isset($uid) || $uid == "" || !isset($password) || $password == "") {
    $login_status = $STATUS_LOGINFAIL;
}
else {
    $dologin_status = DOLOGIN($uid, $password);

    if ($dologin_status == DOLOGIN_STATUS_WEBFREEZE) {
	# Short delay.
	sleep(1);

	SPITHEADER();
	echo "<h3>
              Your account has been frozen due to earlier login attempt
              failures. You must contact $TBMAILADDR to have your account
              restored. <br> <br>
              Please do not attempt to login again; it will not work!
              </h3>\n";
185
        echo "<script src='js/lib/require.js' data-main='js/main'></script>";
186
187
188
189
190
191
192
193
194
195
196
197
198
	SPITFOOTER();
	return;
    }
    else if ($dologin_status == DOLOGIN_STATUS_OKAY) {
	$login_status = $STATUS_LOGGEDIN;
    }
    else {
	# Short delay.
	sleep(1);
	$login_status = $STATUS_LOGINFAIL;
    }
}

199
200
201
202
203
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, max-age=0, must-revalidate, no-store");
header("Pragma: no-cache");

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#
# Failed, then try again with an error message.
# 
if ($login_status == $STATUS_LOGINFAIL) {
    if ($ajax_request) {
	SPITAJAX_ERROR(1, "login failed");
	exit(0);
    }
    SPITFORM($uid, $referrer, "failed");
    return;
}
if ($ajax_request) {
    SPITAJAX_RESPONSE("login sucessful");
    exit();
}
elseif (isset($referrer)) {
    #
    # Zap back to page that started the login request.
    #
    header("Location: $referrer");
}
else {
    #
    # Zap back to front page in secure mode.
    # 
229
    header("Location: $APTBASE/instantiate.php");
230
231
}
?>