auto_basic as regexp

Massimo Melina committed Sep 14, 2025 at 17:30 UTC 38c38469e1b38ca0b92e898db9f8d88e70417af7
2 files changed +6 -6
config.md
+3 -2
@@ -119,11 +119,12 @@ Configuration can be done in several ways
119 - `geo_list` list of country codes to be used as white-list or black-list. Default is none.
120 - `geo_allow_unknown` set false to disconnect connections for which country cannot be determined. Works only if `geo_allow` is set. Default is true.
121 - `dynamic_dns_url` URL to be requested to keep a domain updated with your latest IP address.
122 - Optionally, you can append “>” followed by a regular expression to determine a successful answer, otherwise status code will be used.
123 - Multiple URLs are supported, and you can specify one for each line.
122 + Optionally, you can append “>” followed by a regular expression to determine a successful answer, otherwise status code will be used.
123 + Multiple URLs are supported, and you can specify one for each line.
124 - `outbound_proxy` if you need outgoing http(s) requests to pass through an HTTP proxy. E.g.: `http://user:password@localhost:8888`. Default is none.
125 Setting one will trigger a test request to google.com. You can skip this with env HFS_SKIP_PROXY_TEST=1 .
126 - `auto_basic` automatically detect (based on user-agent) when the basic web interface should be served, to support legacy browsers. Default is true. No UI.
127 + You can disable it setting it to `false`, or recognize additional user-agents by setting a regular expression.
128 - `authorization_header` support Authentication HTTP header. Default is true. No UI.
129 - `cache_control_disk_files` number of seconds after which the browser should bypass the cache and check the server for an updated version of the file. Default is 5. No UI.
130 - `disable_custom_html` disable the content of `custom_html`. Default is false.
src/basicWeb.ts
+3 -4
@@ -8,7 +8,7 @@ import _ from 'lodash'
8 import { title } from './adminApis'
9 import { getSection } from './customHtml'
10
11 -const autoBasic = defineConfig('auto_basic', true)
11 +const autoBasic = defineConfig<boolean|string, null|RegExp>('auto_basic', true, v => _.isString(v) ? new RegExp(v, 'i') : null)
12
13 export function basicWeb(ctx: Koa.Context, node: VfsNode) {
14 const { get } = ctx.query
@@ -60,8 +60,7 @@ export function basicWeb(ctx: Koa.Context, node: VfsNode) {
60
61 export function detectBasicAgent(ctx: Koa.Context) {
62 const ua = ctx.get('user-agent')
63 - const v = autoBasic.get()
64 - return v && (/^$|Mozilla\/4|WebKit\/([234]\d\d|5[012]\d|53[0123456])[. ]|Trident|Lynx|curl|Firefox\/(\d|[1234]\d)\./.test(ua)
65 - || _.isString(v) && ua.includes(v))
63 + return autoBasic.get() && /^$|Mozilla\/4|WebKit\/([234]\d\d|5[012]\d|53[0123456])[. ]|Trident|Lynx|curl|Firefox\/(\d|[1234]\d)\./.test(ua)
64 + || autoBasic.compiled()?.test(ua)
65 }
66