admin/logs: new option "log spam requests" (off by default)
Massimo Melina committed
May 3, 2024 at 12:20 UTC
21ddc20097eacdff34b02feb5df005483899b93c
3 files changed
+7
-3
admin/src/LogsPage.ts
+2
-1
@@ -77,7 +77,8 @@ export default function LogsPage() {
77
},
78
{ k: CFG.log_gui, sm: 6, comp: BoolField, label: "Log interface loading", helperText: "Some requests are necessary to load the interface" },
79
{ k: CFG.log_api, sm: 6, comp: BoolField, label: "Log API requests", helperText: "Requests for commands" },
80
- { k: CFG.log_ua, sm: 6, comp: BoolField, label: "Log User-Agent", helperText: "Contains browser and possibly OS information" },
80
+ { k: CFG.log_ua, sm: 6, comp: BoolField, label: "Log User-Agent", helperText: "Contains browser and possibly OS information. Can double the size of your logs on disk." },
81
+ { k: CFG.log_spam, sm: 6, comp: BoolField, label: "Log spam requests", helperText: md`Spam are *failed* requests that are considered attacks aimed *not* to HFS and therefore harmless` },
82
]
83
}
84
})
src/cross.ts
+1
-1
@@ -24,7 +24,7 @@ export const FRONTEND_OPTIONS = {
24
export const SORT_BY_OPTIONS = ['name', 'extension', 'size', 'time']
25
export const THEME_OPTIONS = { auto: '', light: 'light', dark: 'dark' }
26
export const CFG = constMap(['geo_enable', 'geo_allow', 'geo_list', 'geo_allow_unknown', 'dynamic_dns_url',
27
- 'log', 'error_log', 'log_rotation', 'dont_log_net', 'log_gui', 'log_api', 'log_ua',
27
+ 'log', 'error_log', 'log_rotation', 'dont_log_net', 'log_gui', 'log_api', 'log_ua', 'log_spam',
28
'max_downloads', 'max_downloads_per_ip', 'max_downloads_per_account', 'roots', 'force_address'])
29
export const LIST = { add: '+', remove: '-', update: '=', props: 'props', ready: 'ready', error: 'e' }
30
export type Dict<T=any> = Record<string, T>
src/log.ts
+4
-1
@@ -9,7 +9,7 @@ import { stat } from 'fs/promises'
9
import _ from 'lodash'
10
import { createFileWithPath, prepareFolder } from './util-files'
11
import { getCurrentUsername } from './auth'
12
-import { DAY, makeNetMatcher, tryJson, Dict, Falsy, CFG, strinsert, repeat } from './misc'
12
+import { DAY, makeNetMatcher, tryJson, Dict, Falsy, CFG, strinsert, repeat, HTTP_NOT_FOUND } from './misc'
13
import { extname } from 'path'
14
import events from './events'
15
import { getConnection } from './connections'
@@ -66,6 +66,7 @@ errorLogFile.sub(path => {
66
const logRotation = defineConfig(CFG.log_rotation, 'weekly')
67
const dontLogNet = defineConfig(CFG.dont_log_net, '127.0.0.1|::1', v => makeNetMatcher(v))
68
const logUA = defineConfig(CFG.log_ua, false)
69
+const logSpam = defineConfig(CFG.log_spam, false)
70
71
const debounce = _.debounce(cb => cb(), 1000)
72
@@ -75,6 +76,8 @@ export const logMw: Koa.Middleware = async (ctx, next) => {
76
ctx.state.completed = Promise.race([ once(ctx.res, 'finish'), once(ctx.res, 'close') ])
77
await next()
78
console.debug(ctx.status, ctx.method, ctx.originalUrl)
79
+ if (ctx.status === HTTP_NOT_FOUND && !logSpam.get()
80
+ && /wlwmanifest.xml$|robots.txt$|\.(php)$|cgi/.test(ctx.path)) return
81
const conn = getConnection(ctx) // collect reference before close
82
// don't await, as we don't want to hold the middlewares chain
83
ctx.state.completed.then(() => {