diff --git a/src/const.ts b/src/const.ts index 978c14a..868d3d8 100755 --- a/src/const.ts +++ b/src/const.ts @@ -15,4 +15,6 @@ const FILENAME_BLACKLIST = ["\\", "/", ".", "'", '"', "?", "*", "<", ">"]; const LOCAL_PRESET_LANG_PATH = path.normalize(path.join(process.cwd(), "language")); -export { FILENAME_BLACKLIST, PTY_PATH, LOCAL_PRESET_LANG_PATH, FRPC_PATH }; +const IGNORE = "[IGNORE_LOG]"; + +export { FILENAME_BLACKLIST, PTY_PATH, LOCAL_PRESET_LANG_PATH, FRPC_PATH, IGNORE }; diff --git a/src/entity/commands/pty/pty_start.ts b/src/entity/commands/pty/pty_start.ts index 21fd7fe..a65af40 100755 --- a/src/entity/commands/pty/pty_start.ts +++ b/src/entity/commands/pty/pty_start.ts @@ -168,7 +168,7 @@ export default class PtyStartCommand extends InstanceCommand { // create process adapter const ptySubProcessCfg = await this.readPtySubProcessConfig(subProcess); const processAdapter = new ProcessAdapter(subProcess, ptySubProcessCfg.pid); - logger.info(`PTY Process Config: ${JSON.stringify(ptySubProcessCfg)}`); + logger.info(`pty.exe response: ${JSON.stringify(ptySubProcessCfg)}`); // After reading the configuration, Need to check the process status // The "processAdapter.pid" here represents the process created by the PTY process diff --git a/src/i18n/language/zh_cn.json b/src/i18n/language/zh_cn.json index af1bab1..2d2448c 100755 --- a/src/i18n/language/zh_cn.json +++ b/src/i18n/language/zh_cn.json @@ -140,7 +140,7 @@ "auth_router": { "notAccess": "会话 {{id}}({{address}}) 试图无权限访问 {{event}} 现已阻止.", - "illegalAccess": "权限不足,非法访问", + "illegalAccess": "非法访问", "access": "会话 {{id}}({{address}}) 验证身份成功", "disconnect": "会话 {{id}}({{address}}) 因长时间未验证身份而断开连接" }, @@ -181,7 +181,7 @@ }, "stream_router": { - "unauthorizedAccess": "权限不足,非法访问", + "IGNOREAccess": "非法访问", "taskNotExist": "任务不存在", "instanceNotExist": "实例不存在", "authSuccess": "会话 {{id}} {{address}} 数据流通道身份验证成功", diff --git a/src/routers/auth_router.ts b/src/routers/auth_router.ts index 1b62fda..0a0a884 100755 --- a/src/routers/auth_router.ts +++ b/src/routers/auth_router.ts @@ -6,6 +6,7 @@ import * as protocol from "../service/protocol"; import { globalConfiguration } from "../entity/config"; import logger from "../service/log"; import RouterContext from "../entity/ctx"; +import { IGNORE } from "../const"; // latest verification time const AUTH_TIMEOUT = 6000; @@ -24,7 +25,7 @@ routerApp.use(async (event, ctx, _, next) => { return await next(); } logger.warn($t("auth_router.notAccess", { id: socket.id, address: socket.handshake.address, event: event })); - return protocol.error(ctx, "error", $t("auth_router.illegalAccess")); + return protocol.error(ctx, "error", IGNORE); }); // log output middleware diff --git a/src/routers/stream_router.ts b/src/routers/stream_router.ts index a77c38c..3e2bcec 100755 --- a/src/routers/stream_router.ts +++ b/src/routers/stream_router.ts @@ -8,6 +8,7 @@ import InstanceSubsystem from "../service/system_instance"; import logger from "../service/log"; import SendCommand from "../entity/commands/cmd"; import SendInput from "../entity/commands/input"; +import { IGNORE } from "../const"; // Authorization authentication middleware routerApp.use(async (event, ctx, data, next) => { @@ -18,7 +19,7 @@ routerApp.use(async (event, ctx, data, next) => { if (ctx.session.stream && ctx.session.stream.check === true && ctx.session.type === "STREAM") { return await next(); } - return protocol.error(ctx, "error", $t("stream_router.unauthorizedAccess")); + return protocol.error(ctx, "error", IGNORE); } return await next(); }); diff --git a/src/service/protocol.ts b/src/service/protocol.ts index 1eaf1e8..e3e11a7 100755 --- a/src/service/protocol.ts +++ b/src/service/protocol.ts @@ -4,6 +4,7 @@ import { $t } from "../i18n"; import { Socket } from "socket.io"; import RouterContext from "../entity/ctx"; import logger from "./log"; +import { IGNORE } from "../const"; // Define network protocols and common send/broadcast/parse functions, the client should also have this file @@ -39,8 +40,9 @@ export function responseError(ctx: RouterContext, err: Error | string, config?: if (err) errinfo = err.toString(); else errinfo = err; const packet = new Packet(ctx.uuid, STATUS_ERR, ctx.event, errinfo); - // Ignore insufficient permission errors because restarting the daemon did not refresh the page - if (err.toString().includes("[Unauthorized Access]")) return ctx.socket.emit(ctx.event, packet); + // Ignore + if (err.toString().includes(IGNORE)) return ctx.socket.emit(ctx.event, packet); + if (!config?.notPrintErr) logger.warn($t("protocol.socketErr", { id: ctx.socket.id, address: ctx.socket.handshake.address, event: ctx.event }), err); ctx.socket.emit(ctx.event, packet); @@ -53,8 +55,9 @@ export function msg(ctx: RouterContext, event: string, data: any) { export function error(ctx: RouterContext, event: string, err: any) { const packet = new Packet(ctx.uuid, STATUS_ERR, event, err); - // Ignore insufficient permission errors because restarting the daemon did not refresh the page - if (err.toString().includes("[Unauthorized Access]")) return ctx.socket.emit(ctx.event, packet); + // Ignore + if (err.toString().includes(IGNORE)) return ctx.socket.emit(ctx.event, packet); + logger.warn($t("protocol.socketErr", { id: ctx.socket.id, address: ctx.socket.handshake.address, event: ctx.event }), err); ctx.socket.emit(event, packet); }