@samitouri / QOSami-HFS / commits / a0daa86b

admin/options: log interface loading

Massimo Melina committed Jun 27, 2023 at 21:11 UTC a0daa86bf280fd3406f7e0dc5084aab458b654aa
3 files changed +11 -3
admin/src/OptionsPage.ts
+1
@@ -132,6 +132,7 @@ export default function OptionsPage() {
132 { k: 'dont_log_net', comp: NetmaskField, label: "Don't log address", md: 3, placeholder: "no exception",
133 helperText: h(WildcardsSupported)
134 },
135 + { k: 'log_gui', comp: BoolField, label: "Log interface loading" },
136 { k: 'proxies', comp: NumberField, min: 0, max: 9, sm: 6, label: "How many HTTP proxies between this server and users?",
137 error: proxyWarning(values, status),
138 helperText: "Wrong number will prevent detection of users' IP address"
src/log.ts
+1
@@ -69,6 +69,7 @@ export const logMw: Koa.Middleware = async (ctx, next) => {
69 await next()
70 console.debug(ctx.status, ctx.method, ctx.path)
71 Promise.race([ once(ctx.res, 'finish'), once(ctx.res, 'close') ]).then(() => {
72 + if (ctx.state.dont_log) return
73 if (dontLogNet.compiled()(ctx.ip)) return
74 const isError = ctx.status >= 400
75 const logger = isError && accessErrorLog || accessLogger
src/serveGuiFiles.ts
+9 -3
@@ -25,6 +25,8 @@ import _ from 'lodash'
25 import { defineConfig } from './config'
26 import { getLangData } from './lang'
27
28 +const logGui = defineConfig('log_gui', false)
29 +
30 // in case of dev env we have our static files within the 'dist' folder'
31 const DEV_STATIC = process.env.DEV ? 'dist/' : ''
32
@@ -33,6 +35,8 @@ function serveStatic(uri: string): Koa.Middleware {
35 let cache: Record<string, Promise<string>> = {}
36 subscribe(customHtmlState, () => cache = {}) // reset cache at every change
37 return async (ctx) => {
38 + if (!logGui.get())
39 + ctx.state.dont_log = true
40 if(ctx.method === 'OPTIONS') {
41 ctx.status = HTTP_NO_CONTENT
42 ctx.set({ Allow: 'OPTIONS, GET' })
@@ -150,9 +154,11 @@ function serveProxied(port: string | undefined, uri: string) { // used for devel
154 : adjustBundlerLinks(ctx, uri, data)
155 }
156 }) )
153 - return function() { //@ts-ignore
154 - return proxy.apply(this,arguments)
155 - }
157 + return function (ctx, next) {
158 + if (!logGui.get())
159 + ctx.state.dont_log = true
160 + return proxy(ctx, next)
161 + } as Koa.Middleware
162 }
163
164 export function serveGuiFiles(proxyPort:string | undefined, uri:string) {