Protect administrator password and quick logins independently for DPL HN and FUC
This commit is contained in:
1 parent
3a0f499769
commit
bf145846a6
3 files changed
+85
-10
No files matched your search
@@ -74,14 +74,14 @@ class AuthController extends Controller
|
||||
$email = $request->input('email');
|
||||
$password = $request->input('password');
|
||||
|
||||
[$success, $result] = $this->loginService->login($email, $password);
|
||||
|
||||
[$success, $result] = \App\Support\XbAdminLogin::password($request, $email,
|
||||
fn () => $this->loginService->login($email, $password),
|
||||
fn ($user) => (new AuthService($user))->generateAuthData()
|
||||
);
|
||||
if (!$success) {
|
||||
return $this->fail($result);
|
||||
}
|
||||
|
||||
$authService = new AuthService($result);
|
||||
return $this->success($authService->generateAuthData());
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,11 +118,10 @@ class AuthController extends Controller
|
||||
], 400);
|
||||
}
|
||||
|
||||
$authService = new AuthService($user);
|
||||
|
||||
return response()->json([
|
||||
'data' => $authService->generateAuthData()
|
||||
]);
|
||||
$auth = \App\Support\XbAdminLogin::verified($request, $user,
|
||||
fn ($account) => (new AuthService($account))->generateAuthData()
|
||||
);
|
||||
return response()->json(['data' => $auth]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use TeleHub\WebAdmin\GuardUnavailable;
|
||||
use TeleHub\WebAdmin\LoginBlocked;
|
||||
use TeleHub\WebAdmin\Ticket;
|
||||
|
||||
final class XbAdminLogin
|
||||
{
|
||||
private static function begin(Request $request, $user)
|
||||
{
|
||||
if (!$user || !$user->is_admin) {
|
||||
return null;
|
||||
}
|
||||
$profile = $request->server->get('XB_INSTANCE') ?? config('site.profile');
|
||||
$instances = ['dpl' => 'xb-dpl', 'hn' => 'xb-hn', 'fuc-xb-test' => 'xb-fuc'];
|
||||
$instance = $instances[$profile] ?? null;
|
||||
if (!$instance || (!app()->environment('production') && !is_dir('/run/web-admin-login-'.$instance))) {
|
||||
return null;
|
||||
}
|
||||
require_once '/opt/web-admin-login/current/Ticket.php';
|
||||
return Ticket::begin($instance, $request->server->all());
|
||||
}
|
||||
|
||||
public static function password(Request $request, string $email, callable $verify, callable $issue): array
|
||||
{
|
||||
// Match the account lookup used by this backend, including older releases.
|
||||
$query = method_exists(User::class, 'scopeByEmail') || method_exists(User::class, 'byEmail')
|
||||
? User::byEmail($email) : User::where('email', $email);
|
||||
$candidate = $query->first(['id','is_admin']);
|
||||
return self::handle($request, $candidate, $verify, $issue);
|
||||
}
|
||||
|
||||
public static function verified(Request $request, $user, callable $issue)
|
||||
{
|
||||
[, $data] = self::handle($request, $user, fn () => [true, $user], $issue);
|
||||
return $data;
|
||||
}
|
||||
|
||||
private static function handle(Request $request, $candidate, callable $verify, callable $issue): array
|
||||
{
|
||||
try {
|
||||
$ticket = self::begin($request, $candidate);
|
||||
try {
|
||||
[$success, $result] = $verify();
|
||||
if ($success) {
|
||||
// Account privileges may have changed during authentication.
|
||||
if ($ticket === null && $result->is_admin && (!$candidate || !$candidate->is_admin)) {
|
||||
$ticket = self::begin($request, $result);
|
||||
}
|
||||
$result = $issue($result);
|
||||
}
|
||||
} catch (\Throwable $error) {
|
||||
if ($ticket !== null) {
|
||||
$ticket->finish('error');
|
||||
}
|
||||
throw $error;
|
||||
}
|
||||
if ($ticket !== null) {
|
||||
$ticket->finish($success ? 'success' : 'failure');
|
||||
}
|
||||
return [$success, $result];
|
||||
} catch (LoginBlocked $error) {
|
||||
abort(429, '该来源 IP 已触发管理员登录保护。');
|
||||
} catch (GuardUnavailable $error) {
|
||||
abort(503, '管理员登录保护暂不可用,请稍后重试。');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,3 +27,7 @@
|
||||
这些说明用于辅助 AI 接手,不代表 AI 会在聊天结束后自动持续运行。应用定时任务在服务器执行,AI 维护任务需要会话或明确配置的自动化来启动。
|
||||
|
||||
正式维护文档放在 docs/maintenance/,纳入 Git 并随相关代码一起更新。项目根目录 AGENTS.md 是 AI 自动接手入口;运行日志、截图、临时脚本与任务产物放在 codex/output/,继续默认忽略。受保护备份和私密配置按运行环境保存,不提交 Git。
|
||||
|
||||
### Web 管理员登录保护
|
||||
|
||||
DPL、HN 和福云按运行实例各自处理管理员密码登录及快捷登录。已验证的管理员快捷登录在生成登录凭据前检查来源 IP。会员的密码和快捷登录沿用原有认证及响应。共享表单中的无效快捷码无法归属到具体账号,按原有认证规则拒绝。管理员来源 IP 在滚动 24 小时内第 7 次失败后封禁 30 天,成功保留失败记录。每个实例向自己的 TeleHub 调用方提交结果、时间与可信来源 IP,目标为管理员私聊。
|
||||
Reference in new issue
Block a user