Account for rejected admin forms and the dedicated HN admin host
This commit is contained in:
1 parent
bf145846a6
commit
e52531894e
4 files changed
+27
-5
No files matched your search
@@ -105,6 +105,7 @@ class AuthController extends Controller
|
||||
$userId = $this->mailLinkService->handleTokenLogin($verify);
|
||||
|
||||
if (!$userId) {
|
||||
\App\Support\XbAdminLogin::rejected($request);
|
||||
return response()->json([
|
||||
'message' => __('Token error')
|
||||
], 400);
|
||||
@@ -113,6 +114,7 @@ class AuthController extends Controller
|
||||
$user = \App\Models\User::find($userId);
|
||||
|
||||
if (!$user) {
|
||||
\App\Support\XbAdminLogin::rejected($request);
|
||||
return response()->json([
|
||||
'message' => __('User not found')
|
||||
], 400);
|
||||
|
||||
@@ -19,6 +19,12 @@ class AuthLogin extends FormRequest
|
||||
];
|
||||
}
|
||||
|
||||
protected function failedValidation(\Illuminate\Contracts\Validation\Validator $validator)
|
||||
{
|
||||
\App\Support\XbAdminLogin::rejected($this, $this->input('email'));
|
||||
parent::failedValidation($validator);
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -12,10 +12,11 @@ final class XbAdminLogin
|
||||
{
|
||||
private static function begin(Request $request, $user)
|
||||
{
|
||||
if (!$user || !$user->is_admin) {
|
||||
$profile = $request->server->get('XB_INSTANCE') ?? config('site.profile');
|
||||
$adminHost = $profile === 'hn' && strtolower(explode(':', (string) $request->server->get('HTTP_HOST'))[0]) === 'admin.hardnerd.net';
|
||||
if ($user ? !$user->is_admin : !$adminHost) {
|
||||
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))) {
|
||||
@@ -25,12 +26,25 @@ final class XbAdminLogin
|
||||
return Ticket::begin($instance, $request->server->all());
|
||||
}
|
||||
|
||||
public static function password(Request $request, string $email, callable $verify, callable $issue): array
|
||||
private static function account($email)
|
||||
{
|
||||
if (!is_string($email) || $email === '' || strlen($email) > 254) {
|
||||
return null;
|
||||
}
|
||||
// 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 $query->first(['id','is_admin']);
|
||||
}
|
||||
|
||||
public static function rejected(Request $request, $email = null): void
|
||||
{
|
||||
self::handle($request, self::account($email), fn () => [false, null], fn () => null);
|
||||
}
|
||||
|
||||
public static function password(Request $request, string $email, callable $verify, callable $issue): array
|
||||
{
|
||||
$candidate = self::account($email);
|
||||
return self::handle($request, $candidate, $verify, $issue);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,4 +30,4 @@
|
||||
|
||||
### Web 管理员登录保护
|
||||
|
||||
DPL、HN 和福云按运行实例各自处理管理员密码登录及快捷登录。已验证的管理员快捷登录在生成登录凭据前检查来源 IP。会员的密码和快捷登录沿用原有认证及响应。共享表单中的无效快捷码无法归属到具体账号,按原有认证规则拒绝。管理员来源 IP 在滚动 24 小时内第 7 次失败后封禁 30 天,成功保留失败记录。每个实例向自己的 TeleHub 调用方提交结果、时间与可信来源 IP,目标为管理员私聊。
|
||||
DPL、HN 和福云按运行实例各自处理管理员密码登录及快捷登录。已验证的管理员快捷登录在生成登录凭据前检查来源 IP。会员的密码和快捷登录沿用原有认证及响应。HN 已登记的独立管理域名对未知账号或无效快捷码也计入后台失败。共享表单中的无效快捷码无法归属到具体账号,按原有认证规则拒绝。管理员来源 IP 在滚动 24 小时内第 7 次失败后封禁 30 天,成功保留失败记录。每个实例向自己的 TeleHub 调用方提交结果、时间与可信来源 IP,目标为管理员私聊。
|
||||
Reference in new issue
Block a user