@samitouri / QOSami-HFS / commits / 00b177fe

fix: admin/logs: block button not considering block rules with netmask #896

Massimo Melina committed Feb 15, 2025 at 10:23 UTC 00b177fe47bea60bc1c23d2de86148b519ba9f65
2 files changed +2 -3
admin/src/useBlockIp.ts
+1 -2
@@ -1,13 +1,12 @@
1 import { apiCall, useApi } from '@hfs/shared/api'
2 import { createElement as h, useCallback } from 'react'
3 import { toast } from './dialog'
4 -import _ from 'lodash'
4 import { IconBtn, IconBtnProps } from './mui'
5 import { Block } from '@mui/icons-material'
6
7 export function useBlockIp() {
8 const { data, reload } = useApi('get_config', { only: ['block'] })
10 - const isBlocked = useCallback((ip: string) => _.find(data?.block, { ip }), [data])
9 + const isBlocked = useCallback((ip: string) => data?.block?.find((x: any) => x.ip.includes(ip)), [data]) //TODO have a gui version of netMatches, and use that
10 return {
11 iconBtn: (ip: string, comment: string, options: Partial<IconBtnProps>={}) => h(IconBtn, {
12 icon: Block,
src/misc.ts
+1 -1
@@ -42,7 +42,7 @@ export function makeNetMatcher(mask: string, emptyMaskReturns=false) {
42 return () => emptyMaskReturns
43 mask = mask.replaceAll(' ','')
44 mask = mask.replace('localhost', '::1|127.0.0.1')
45 - if (!mask.includes('/'))
45 + if (!mask.includes('/')) // for CIDR we use BlockList
46 return makeMatcher(mask)
47 const all = mask.split('|')
48 const neg = all[0]?.[0] === '!'