Feat: add ignore log

This commit is contained in:
unitwk 2022-11-19 10:53:49 +08:00
parent fab1952638
commit 5a2e0e30ed
6 changed files with 17 additions and 10 deletions

View File

@ -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 };

View File

@ -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

View File

@ -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}} 数据流通道身份验证成功",

View File

@ -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

View File

@ -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();
});

View File

@ -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);
}