历史版本在被控端上注册过 na-gui 等旧名计划任务,漏删会留下「端口被占、 新版本起不来」的幽灵任务。误删用户自己的任务则是比漏删严重得多的 生产事故 —— 故只按白名单删。 - scripts/lib/scheduled-tasks.mjs(新):TASK_WHITELIST(nodeagent / na-gui / nodeagent-console,只增不改)+ planTaskCleanup 纯函数 (查询结果注入,白名单外一律不删、精确匹配大小写敏感、重复名去重)。 - scripts/uninstall.ps1:卸载末尾按白名单逐个注销(-ccontains 存在性 检查 + 动作进日志)。 - scripts/control.ps1:新增 cleanup 子命令(ValidateSet + Clear-StaleTasks), Uninstall-Agent 复用同一白名单;control.cmd 菜单加第 8 项 (CRLF 安全插入,纯 ASCII 不变)。 - tests/unit/na-gui-cleanup.test.mjs(新,10 例):白名单命中才删 / 白名单外零动作 / 空列表 / 重复名 / 脏输入 + ps1 源码守卫与跨端 一致性守卫(白名单 mjs 与 ps1 漂移即红 —— 注入故障实测 2 处变红, 恢复后全绿)。
87 lines
2.7 KiB
Batchfile
87 lines
2.7 KiB
Batchfile
@echo off
|
|
REM ============================================================================
|
|
REM nodeagent - control menu (Windows)
|
|
REM
|
|
REM Double-click this file to manage an already-installed agent:
|
|
REM 1) status - task / process / port / config at a glance
|
|
REM 2) start - start the scheduled task
|
|
REM 3) stop - stop the scheduled task
|
|
REM 4) restart - stop then start
|
|
REM 5) logs - tail the agent's audit log
|
|
REM 6) uninstall - remove task + firewall rule (7) purge config and exit
|
|
REM 8) cleanup - remove stale nodeagent tasks (whitelist only)
|
|
REM
|
|
REM Usage: control.cmd [port]
|
|
REM port defaults to 8765; pass it only if the agent uses another.
|
|
REM
|
|
REM Pure ASCII on purpose - see the note in install.cmd. The heavy lifting
|
|
REM (and all Chinese output) lives in control.ps1, which carries a UTF-8 BOM
|
|
REM so Windows PowerShell 5.1 parses it correctly.
|
|
REM ============================================================================
|
|
setlocal EnableExtensions
|
|
|
|
set "HERE=%~dp0"
|
|
set "HELPER=%HERE%control.ps1"
|
|
set "PORT=%~1"
|
|
if not defined PORT set "PORT=8765"
|
|
|
|
if not exist "%HELPER%" (
|
|
echo [x] control.ps1 not found next to this file.
|
|
echo Folder: "%HERE%"
|
|
if not defined CI pause
|
|
exit /b 1
|
|
)
|
|
|
|
:MENU
|
|
cls
|
|
echo ==========================================================
|
|
echo nodeagent control console
|
|
echo ==========================================================
|
|
echo 1) Status
|
|
echo 2) Start agent
|
|
echo 3) Stop agent
|
|
echo 4) Restart agent
|
|
echo 5) Show recent audit log
|
|
echo 6) Uninstall ^(keep config^)
|
|
echo 7) Uninstall and purge config
|
|
echo 8) Cleanup stale tasks
|
|
echo Q) Quit
|
|
echo ==========================================================
|
|
echo.
|
|
|
|
set "CHOICE="
|
|
REM <nul makes `set /p` fail immediately -> CHOICE stays empty. Combined with
|
|
REM CI (see below) that exits instead of looping forever on piped/empty stdin.
|
|
set /p "CHOICE=Select: "
|
|
|
|
if not defined CHOICE (
|
|
if defined CI goto :QUIT
|
|
echo.
|
|
echo (no input - exiting)
|
|
goto :QUIT
|
|
)
|
|
|
|
if /i "%CHOICE%"=="Q" goto :QUIT
|
|
if "%CHOICE%"=="1" call :RUN status
|
|
if "%CHOICE%"=="2" call :RUN start
|
|
if "%CHOICE%"=="3" call :RUN stop
|
|
if "%CHOICE%"=="4" call :RUN restart
|
|
if "%CHOICE%"=="5" call :RUN logs
|
|
if "%CHOICE%"=="6" call :RUN uninstall
|
|
if "%CHOICE%"=="7" call :RUN uninstall-purge
|
|
if "%CHOICE%"=="8" call :RUN cleanup
|
|
goto :MENU
|
|
|
|
:QUIT
|
|
endlocal
|
|
exit /b 0
|
|
|
|
:RUN
|
|
REM %1 = subcommand forwarded to control.ps1
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File "%HELPER%" -Action %1 -Port %PORT%
|
|
echo.
|
|
if not defined CI pause
|
|
goto :MENU
|
|
REM unreachable; keeps `call :RUN` from falling through if the goto is removed
|
|
exit /b 0
|