feat(api): 新增节点墙检测自动托管与显隐
新增定时墙检测命令与节点托管字段,自动为开启托管的父 节点创建检测任务,并在 blocked 时自动隐藏节点、normal 时仅恢复由墙检测自动隐藏的节点 更新自动上线服务以尊重 blocked 与自动隐藏状态,避免疑 似被墙节点被重新发布;同时补齐管理端墙检测托管开关、 刷新入口、批量设置与相关测试和知识库同步
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerGfwCheck;
|
||||
|
||||
class ServerAutoOnlineService
|
||||
{
|
||||
@@ -11,6 +12,7 @@ class ServerAutoOnlineService
|
||||
$servers = Server::query()
|
||||
->where('auto_online', true)
|
||||
->get();
|
||||
$gfwStatuses = app(ServerGfwCheckService::class)->getLatestStatusesForServers($servers);
|
||||
|
||||
$result = [
|
||||
'total' => $servers->count(),
|
||||
@@ -21,18 +23,37 @@ class ServerAutoOnlineService
|
||||
];
|
||||
|
||||
foreach ($servers as $server) {
|
||||
$shouldShow = (int) $server->available_status !== Server::STATUS_OFFLINE;
|
||||
$sourceNodeId = (int) ($server->parent_id ?: $server->id);
|
||||
$gfwStatus = $gfwStatuses[$sourceNodeId] ?? null;
|
||||
$isGfwManaged = (bool) ($server->gfw_check_enabled ?? true) && $gfwStatus !== null;
|
||||
$isGfwBlocked = $isGfwManaged && $gfwStatus === ServerGfwCheck::STATUS_BLOCKED;
|
||||
$isGfwHeld = $isGfwManaged
|
||||
&& (bool) $server->gfw_auto_hidden
|
||||
&& $gfwStatus !== ServerGfwCheck::STATUS_NORMAL;
|
||||
$shouldShow = !$isGfwBlocked && !$isGfwHeld && (int) $server->available_status !== Server::STATUS_OFFLINE;
|
||||
$shouldClearGfwAutoHidden = $gfwStatus === ServerGfwCheck::STATUS_NORMAL
|
||||
&& (bool) $server->gfw_auto_hidden;
|
||||
$wasShown = (bool) $server->show;
|
||||
|
||||
if ((bool) $server->show === $shouldShow) {
|
||||
if ($wasShown === $shouldShow && !$shouldClearGfwAutoHidden) {
|
||||
$result['unchanged']++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$server->show = $shouldShow;
|
||||
if ($isGfwBlocked) {
|
||||
$server->gfw_auto_hidden = true;
|
||||
$server->gfw_auto_action_at = time();
|
||||
} elseif ($shouldClearGfwAutoHidden) {
|
||||
$server->gfw_auto_hidden = false;
|
||||
$server->gfw_auto_action_at = time();
|
||||
}
|
||||
$server->save();
|
||||
|
||||
$result['updated']++;
|
||||
$shouldShow ? $result['shown']++ : $result['hidden']++;
|
||||
if ($wasShown !== $shouldShow) {
|
||||
$shouldShow ? $result['shown']++ : $result['hidden']++;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
Reference in New Issue
Block a user