|
@@ -184,6 +184,20 @@ if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'recover') {
|
184
|
184
|
|
185
|
185
|
} // End password recovery
|
186
|
186
|
|
|
187
|
+else if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'newlocation') {
|
|
188
|
+ if (isset($_REQUEST['key'])) {
|
|
189
|
+ if ($ASNCache = $Cache->get_value('new_location_'.$_REQUEST['key'])) {
|
|
190
|
+ $Cache->cache_value('new_location_'.$ASNCache['UserID'].'_'.$ASNCache['ASN'], true);
|
|
191
|
+ require('newlocation.php');
|
|
192
|
+ die();
|
|
193
|
+ } else {
|
|
194
|
+ error(403);
|
|
195
|
+ }
|
|
196
|
+ } else {
|
|
197
|
+ error(403);
|
|
198
|
+ }
|
|
199
|
+} // End new location
|
|
200
|
+
|
187
|
201
|
// Normal login
|
188
|
202
|
else {
|
189
|
203
|
$Validate->SetFields('username', true, 'regex', 'You did not enter a valid username.', array('regex' => USERNAME_REGEX));
|
|
@@ -235,6 +249,46 @@ else {
|
235
|
249
|
WHERE Username = '".db_string($_POST['username'])."'");
|
236
|
250
|
}
|
237
|
251
|
if ($Enabled == 1) {
|
|
252
|
+
|
|
253
|
+ // Check if the current login attempt is from a location previously logged in from
|
|
254
|
+ if (apc_exists('DBKEY')) {
|
|
255
|
+ $DB->query("
|
|
256
|
+ SELECT IP
|
|
257
|
+ FROM users_history_ips
|
|
258
|
+ WHERE UserID = $UserID");
|
|
259
|
+ $IPs = $DB->to_array(false, MYSQLI_NUM);
|
|
260
|
+ $QueryParts = array();
|
|
261
|
+ foreach ($IPs as $i => $IP) {
|
|
262
|
+ $IPs[$i] = DBCrypt::decrypt($IP[0]);
|
|
263
|
+ }
|
|
264
|
+ $IPs = array_unique($IPs);
|
|
265
|
+ if (count($IPs) > 0) { // Always allow first login
|
|
266
|
+ foreach ($IPs as $IP) {
|
|
267
|
+ $QueryParts[] = "(StartIP<=INET6_ATON('$IP') AND EndIP>=INET6_ATON('$IP'))";
|
|
268
|
+ }
|
|
269
|
+ $DB->query('SELECT ASN FROM geoip_asn WHERE '.implode(' OR ', $QueryParts));
|
|
270
|
+ $PastASNs = array_column($DB->to_array(false, MYSQLI_NUM), 0);
|
|
271
|
+ $DB->query("SELECT ASN FROM geoip_asn WHERE StartIP<=INET_ATON('$_SERVER[REMOTE_ADDR]') AND EndIP>=INET_ATON('$_SERVER[REMOTE_ADDR]')");
|
|
272
|
+ list($CurrentASN) = $DB->next_record();
|
|
273
|
+
|
|
274
|
+ if (!in_array($CurrentASN, $PastASNs)) {
|
|
275
|
+ // Never logged in from this location before
|
|
276
|
+ if ($Cache->get_value('new_location_'.$UserID.'_'.$CurrentASN) !== true) {
|
|
277
|
+ $DB->query("
|
|
278
|
+ SELECT
|
|
279
|
+ UserName,
|
|
280
|
+ Email
|
|
281
|
+ FROM users_main
|
|
282
|
+ WHERE ID = $UserID");
|
|
283
|
+ list($Username, $Email) = $DB->next_record();
|
|
284
|
+ Users::authLocation($UserID, $Username, $CurrentASN, DBCrypt::decrypt($Email));
|
|
285
|
+ require('newlocation.php');
|
|
286
|
+ die();
|
|
287
|
+ }
|
|
288
|
+ }
|
|
289
|
+ }
|
|
290
|
+ }
|
|
291
|
+
|
238
|
292
|
$SessionID = Users::make_secret(64);
|
239
|
293
|
$KeepLogged = ($_POST['keeplogged'] ?? false) ? 1 : 0;
|
240
|
294
|
setcookie('session', $SessionID, (time()+60*60*24*365)*$KeepLogged, '/', '', true, true);
|