login.php 8.29 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
include("instance_defs.php");
29
$page_title = "Login";
30

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

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 67
#
# 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.");
68
    echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
69
    echo "<script src='js/lib/bootstrap.js'></script>\n";
70
    echo "<script src='js/lib/require.js' data-main='js/main'></script>";
71 72 73 74 75 76 77 78 79 80
    SPITFOOTER();
    return;
}

#
# Spit out the form.
# 
function SPITFORM($uid, $referrer, $error)
{
    global $TBDB_UIDLEN, $TBBASE, $refer;
81
    global $ISAPT, $ISCLOUD;
82 83
    $pwlab = ($ISAPT ? "Aptlab.net" : "CloudLab.net") .
	" or Emulab.net Username";
84
    
85 86 87 88 89
    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");

90 91 92 93 94 95 96 97 98 99 100 101 102
    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>
103
           <div class='panel-body form-horizontal'>\n";
104 105 106 107 108 109 110 111 112 113 114 115 116

    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;
117 118 119
        case "alreadyloggedin":
	    echo "You are already logged in. Logout first?";
	    break;
120 121 122 123 124 125 126 127 128 129 130
	default:
	    echo "Unknown Error ($error)!";
        }
        echo "</font></span>";
    }
    elseif ($refer) {
        echo "<span class='help-block'>Please login before continuing</span>";
    }
    if ($referrer) {
	echo "<input type=hidden name=referrer value=$referrer>\n";
    }
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
?>
             <div class='form-group'>
                <label for='uid' class='col-sm-2 control-label'>Username</label>
                <div class='col-sm-10'>
                    <input name='uid' class='form-control'
                           placeholder='<?php echo $pwlab ?>'
                           autofocus type='text'>
                </div>
             </div>
             <div class='form-group'>
                <label for='password' class='col-sm-2 control-label'>Password
					  </label>
                <div class='col-sm-10'>
                   <input name='password' class='form-control'
                          placeholder='Password'
                          type='password'>
                </div>
             </div>
             <div class='form-group'>
               <div class='col-sm-offset-2 col-sm-10'>
151
<?php
Leigh Stoller's avatar
Leigh Stoller committed
152
    if (0 && $ISCLOUD) {
153
	?>
154
                 <button class='btn btn-info btn-sm pull-left'
155 156 157 158 159 160
		    type='button'
                    data-toggle="tooltip" data-placement="left"
		    title="You can use your geni credentials to login"
                    id='quickvm_geni_login_button'>Geni User?</button>
        <?php
    }
161 162 163 164 165 166 167
    if ($ISAPT) {
	?>
                 <a class='btn btn-info btn-sm pull-left'
	            href='instantiate.php?asguest=1'
		    type='button'>Continue as Guest</a>
        <?php
    }
168
?>
169 170 171 172 173 174
                 <button class='btn btn-primary btn-sm pull-right'
                         id='quickvm_login_modal_button'
                         type='submit' name='login'>Login</button>
               </div>
             </div>
<?php
175 176 177 178 179 180 181
    echo "
            <br> 
           </div>
          </div>
          </form>
        </div>
        </div>\n";
182 183 184 185 186 187

    if ($ISCLOUD) {
	echo "<script
                src='https://www.emulab.net/protogeni/speaks-for/geni-auth.js'>
              </script>\n";
    }
188
    echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
189
    echo "<script src='js/lib/bootstrap.js'></script>\n";
190
    echo "<script src='js/lib/require.js' data-main='js/login'></script>";
191 192 193 194 195 196 197
    SPITFOOTER();
    return;
}
#
# If not clicked, then put up a form.
#
if (!$ajax_request && !isset($login)) {
198 199
    if ($this_user) {
	if (Instance::UserHasInstances($this_user)) {
Leigh Stoller's avatar
Leigh Stoller committed
200
	    header("Location: $APTBASE/myexperiments.php");
201 202 203 204 205 206 207
	}
	else {
	    header("Location: $APTBASE/instantiate.php");
	}
	return;
    }
    SPITFORM(REMEMBERED_ID(), $referrer, null);
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
    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";
235
        echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
236
        echo "<script src='js/lib/bootstrap.js'></script>\n";
237
        echo "<script src='js/lib/require.js' data-main='js/main'></script>";
238 239 240 241 242 243 244 245 246 247 248 249 250
	SPITFOOTER();
	return;
    }
    else if ($dologin_status == DOLOGIN_STATUS_OKAY) {
	$login_status = $STATUS_LOGGEDIN;
    }
    else {
	# Short delay.
	sleep(1);
	$login_status = $STATUS_LOGINFAIL;
    }
}

251 252 253 254 255
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");

256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
#
# 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 {
278
    if (Instance::UserHasInstances($CHECKLOGIN_USER)) {
279
	header("Location: $APTBASE/myexperiments.php");
280 281 282 283
    }
    else {
	header("Location: $APTBASE/instantiate.php");
    }
284 285
}
?>