admin/internet: geo-firewall will ignore LAN IPs

Massimo Melina committed Feb 4, 2024 at 17:08 UTC 8c661878d91db4ae3b085cea769b4e69ef505b3c
2 files changed +3 -2
admin/src/InternetPage.ts
+1
@@ -144,6 +144,7 @@ export default function InternetPage() {
144 k: CFG.geo_allow_unknown,
145 comp: SelectField,
146 label: "When country cannot be determined",
147 + helperText: "Local IPs are ignored",
148 options: { Allow: true, Block: false },
149 },
150 ]
src/geo.ts
+2 -2
@@ -1,5 +1,5 @@
1 import { defineConfig } from './config'
2 -import { CFG, DAY, httpStream, isLocalHost, unzip } from './misc'
2 +import { CFG, DAY, httpStream, isIpLan, isLocalHost, unzip } from './misc'
3 import { stat, rename, unlink } from 'node:fs/promises'
4 import { IP2Location } from 'ip2location-nodejs'
5 import _ from 'lodash'
@@ -17,7 +17,7 @@ setInterval(checkFiles, DAY) // keep updated at run-time
17 export const ip2country = _.memoize((ip: string) => ip2location.getCountryShortAsync(ip).then(v => v === '-' ? '' : v, () => ''))
18
19 export const geoFilter: Middleware = async (ctx, next) => {
20 - if (enabled.get() && !isLocalHost(ctx)) {
20 + if (enabled.get() && !isLocalHost(ctx) && !isIpLan(ctx.ip)) {
21 const { connection } = ctx.state
22 const country = connection.country ??= await ip2country(ctx.ip)
23 if (country)