Files
nexusphp/public/takelogin.php

116 lines
3.6 KiB
PHP
Raw Normal View History

2020-12-26 01:42:23 +08:00
<?php
2021-01-13 19:32:26 +08:00
require_once("../include/bittorrent.php");
2020-12-26 01:42:23 +08:00
header("Content-Type: text/html; charset=utf-8");
if (!mkglobal("username:password"))
die();
dbconn();
require_once(get_langfile_path("", false, get_langfolder_cookie()));
failedloginscheck ();
cur_user_check () ;
$ip = getip();
2020-12-26 01:42:23 +08:00
function bark($text = "")
{
global $lang_takelogin;
$text = ($text == "" ? $lang_takelogin['std_login_fail_note'] : $text);
stderr($lang_takelogin['std_login_fail'], $text,false);
}
if ($iv == "yes")
check_code ($_POST['imagehash'], $_POST['imagestring'],'login.php',true);
2021-06-10 21:07:20 +08:00
$res = sql_query("SELECT id, passhash, secret, enabled, status, two_step_secret FROM users WHERE username = " . sqlesc($username));
2020-12-26 01:42:23 +08:00
$row = mysql_fetch_array($res);
if (!$row)
failedlogins();
if ($row['status'] == 'pending')
failedlogins($lang_takelogin['std_user_account_unconfirmed']);
2021-06-10 21:07:20 +08:00
if (!empty($row['two_step_secret'])) {
if (empty($_POST['two_step_code'])) {
failedlogins($lang_takelogin['std_require_two_step_code']);
}
$ga = new \PHPGangsta_GoogleAuthenticator();
if (!$ga->verifyCode($row['two_step_secret'], $_POST['two_step_code'])) {
failedlogins($lang_takelogin['std_invalid_two_step_code']);
}
}
$log = "user: {$row['id']}, ip: $ip";
2023-01-31 16:38:21 +08:00
if ($row["passhash"] != md5($row["secret"] . $password . $row["secret"])) {
login_failedlogins();
}
$locationInfo = get_ip_location_from_geoip($ip);
$thisLoginLog = \App\Models\LoginLog::query()->create([
'ip' => $ip,
'uid' => $row['id'],
2023-02-06 14:25:05 +08:00
'country' => $locationInfo['country_en'] ?? '',
'city' => $locationInfo['city_en'] ?? '',
2023-01-31 16:38:21 +08:00
'client' => 'Web',
]);
$lastLoginLog = \App\Models\LoginLog::query()->where('uid', $row['id'])->orderBy('id', 'desc')->first();
if (
$lastLoginLog && $lastLoginLog->country && $lastLoginLog->city
&& $locationInfo['country_en'] && $locationInfo['city_en']
&& ($lastLoginLog->country != $locationInfo['country_en'] || $lastLoginLog->city != $locationInfo['city_en'])
) {
$command = sprintf("user:login_notify --this_id=%s --last_id=%s", $thisLoginLog->id, $lastLoginLog->id);
do_log("[LOGIN_NOTIFY], user: {$row['id']}, $command");
2023-04-09 02:33:37 +08:00
executeCommand($command, "string", true, false);
2023-01-31 16:38:21 +08:00
}
2020-12-26 01:42:23 +08:00
if ($row["enabled"] == "no")
bark($lang_takelogin['std_account_disabled']);
2021-01-19 21:50:21 +08:00
if (isset($_POST["securelogin"]) && $_POST["securelogin"] == "yes")
2020-12-26 01:42:23 +08:00
{
$securelogin_indentity_cookie = true;
2022-10-30 17:30:24 +08:00
/**
* Not IP related
* @since 1.8.0
*/
// $passh = md5($row["passhash"].$ip);
$passh = md5($row["passhash"]);
$log .= ", secure login == yeah, passhash: {$row['passhash']}, ip: $ip, md5: $passh";
2020-12-26 01:42:23 +08:00
}
else
{
$securelogin_indentity_cookie = false;
$passh = md5($row["passhash"]);
2022-08-25 22:07:57 +08:00
$log .= ", passhash: {$row['passhash']}, md5: $passh";
2020-12-26 01:42:23 +08:00
}
2021-01-19 21:50:21 +08:00
if ($securelogin=='yes' || (isset($_POST["ssl"]) && $_POST["ssl"] == "yes"))
2020-12-26 01:42:23 +08:00
{
$pprefix = "https://";
$ssl = true;
}
else
{
$pprefix = "http://";
$ssl = false;
}
2021-01-19 21:50:21 +08:00
if ($securetracker=='yes' || (isset($_POST["trackerssl"] ) && $_POST["trackerssl"] == "yes"))
2020-12-26 01:42:23 +08:00
{
$trackerssl = true;
}
else
{
$trackerssl = false;
}
2022-08-25 22:07:57 +08:00
do_log($log);
2021-01-19 21:50:21 +08:00
if (isset($_POST["logout"]) && $_POST["logout"] == "yes")
2020-12-26 01:42:23 +08:00
{
logincookie($row["id"], $passh,1,900,$securelogin_indentity_cookie, $ssl, $trackerssl);
//sessioncookie($row["id"], $passh,true);
}
2021-06-10 21:07:20 +08:00
else
2020-12-26 01:42:23 +08:00
{
2023-03-04 23:28:47 +08:00
logincookie($row["id"], $passh,1,get_setting('system.cookie_valid_days', 365) * 86400,$securelogin_indentity_cookie, $ssl, $trackerssl);
2020-12-26 01:42:23 +08:00
//sessioncookie($row["id"], $passh,false);
}
if (!empty($_POST["returnto"]))
2021-03-31 03:17:33 +08:00
header("Location: " . $pprefix . "$BASEURL/{$_POST['returnto']}");
2020-12-26 01:42:23 +08:00
else
header("Location: " . $pprefix . "$BASEURL/index.php");
?>