-
Notifications
You must be signed in to change notification settings - Fork 0
/
hotspotlogin.php
156 lines (135 loc) · 4.41 KB
/
hotspotlogin.php
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
28
29
30
31
32
33
34
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
111
112
113
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
148
149
150
151
152
153
154
155
156
<?php
/**
* This is the central script for processing all authentication activity
*
* It is called on first page load, and on auth callbacks
* It is also called via ajax for subsequent non-auth requests
*
* @copyright 2013 Bluepod Media Ltd
* @author Barry Jones <barry@onalldevices.com>
*/
// Initialisation
require_once('php/app.php');
$loginpath = $_SERVER['PHP_SELF'];
$reloadurl = 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
// Grab request params
$form = array();
$isxhr = $utils->getRequestVar('isxhr');
$form['action'] = $utils->getRequestVar('action');
$form['called'] = $utils->getRequestVar('called');
$form['callback'] = $utils->getRequestVar('callback');
$form['username'] = $utils->getRequestVar('username');
$form['password'] = $utils->getRequestVar('password');
$form['challenge'] = $utils->getRequestVar('challenge');
$form['button'] = $utils->getRequestVar('button');
$form['logout'] = $utils->getRequestVar('logout');
$form['prelogin'] = $utils->getRequestVar('prelogin');
$form['res'] = $utils->getRequestVar('res');
$form['uamip'] = $utils->getRequestVar('uamip');
$form['uamport'] = $utils->getRequestVar('uamport');
$form['userurl'] = $utils->getRequestVar('userurl');
$form['timeleft'] = $utils->getRequestVar('timeleft');
$form['redirurl'] = $utils->getRequestVar('redirurl');
$form['reply'] = $utils->getRequestVar('reply');
$form['userurl'] = $utils->getRequestVar('userurl');
// Force SSL
if (!($_SERVER['HTTPS'] == 'on')) {
if ($isxhr){
sendJSONError($lang['errornonssl']);
} else {
$utils->setFlash('pageerror', $lang['errornonssl']);
buildErrorView();
}
exit(0);
}
// Process login status
switch($form['res']) {
case 'success': $result = 1; break; // If login successful
case 'failed': $result = 2; break; // If login failed
case 'logoff': $result = 3; break; // If logout successful
case 'already': $result = 4; break; // If tried to login while already logged in
case 'notyet': $result = 5; break; // If not logged in yet
case 'smartclient': $result = 6; break; // If login from smart client
case 'popup1': $result = 11; break; // If requested a logging in pop up window
case 'popup2': $result = 12; break; // If requested a success pop up window
case 'popup3': $result = 13; break; // If requested a logout pop up window
default: $result = 0; // Default: It was not a form request
}
// Check for daemon error
if ($result == 0){
if ($isxhr){
sendJSONError($lang['daemon_error']);
} else {
$utils->setFlash('pageerror', $lang['daemon_error']);
buildErrorView($lang['title_loginfailed']);
}
exit(0);
}
// Clean form inputs
array_map(array($db, 'escape'), $form);
// Process auth actions
switch ($result){
case 1: // Successful login
// Store login cookie
setcookie(
$cookiename,
json_encode($_SESSION['daloauth']),
(time() + $cookieexpire),
'/'
);
$utils->redirect($postloginurl);
break;
case 2: // Unsuccessful login
$utils->setFlash('pageerror', $lang['login_failed']);
buildView();
break;
case 3: // Logout and clear auth cookie
setcookie(
$cookiename,
json_encode($_SESSION['daloauth']),
(time() - 10),
'/'
);
$utils->redirect($exturl);
break;
case 4: // Already logged in
case 12:
$utils->redirect($postloginurl);
break;
case 5: // Nothing tried yet
// Process standard form actions
switch ($form['action']){
case 'login':
doLogin($form);
break;
case "register":
registerNewUser();
break;
case "getsecurityquestion":
$question = getSecurityQuestion($form['username']);
if ($question === false){
sendJSONError($lang['forgot_password_no_question']);
} else {
sendJSONResponse(array(
"question" => $question
));
}
break;
case "fetchpassword":
$form['answer'] = $utils->getRequestVar('answer');
$form['answer'] = $db->escape($form['answer']);
$answer = getPassword($form['username'], $form['answer']);
if ($answer === false){
sendJSONError($lang['forgot_password_invalid_answer']);
} else {
sendJSONResponse(array(
"password" => $answer
));
}
break;
default:
buildView();
}
break;
}
exit(0);