mirror of
https://github.com/umami-software/umami.git
synced 2026-02-19 12:05:41 +01:00
Merge 350618471d into 09bc2ee5c8
This commit is contained in:
commit
da61f35a86
1 changed files with 16 additions and 16 deletions
|
|
@ -140,31 +140,31 @@ export async function getClientInfo(request: Request, payload: Record<string, an
|
||||||
export function hasBlockedIp(clientIp: string) {
|
export function hasBlockedIp(clientIp: string) {
|
||||||
const ignoreIps = process.env.IGNORE_IP;
|
const ignoreIps = process.env.IGNORE_IP;
|
||||||
|
|
||||||
if (ignoreIps) {
|
if (!clientIp || !ignoreIps) {
|
||||||
const ips = [];
|
return false;
|
||||||
|
|
||||||
if (ignoreIps) {
|
|
||||||
ips.push(...ignoreIps.split(',').map(n => n.trim()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ips.find(ip => {
|
const ips = ignoreIps.split(',').map(n => n.trim());
|
||||||
|
|
||||||
|
return ips.some(ip => {
|
||||||
if (ip === clientIp) {
|
if (ip === clientIp) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CIDR notation
|
// CIDR notation
|
||||||
if (ip.indexOf('/') > 0) {
|
if (ip.indexOf('/') > 0) {
|
||||||
|
try {
|
||||||
const addr = ipaddr.parse(clientIp);
|
const addr = ipaddr.parse(clientIp);
|
||||||
const range = ipaddr.parseCIDR(ip);
|
const range = ipaddr.parseCIDR(ip);
|
||||||
|
|
||||||
if (addr.kind() === range[0].kind() && addr.match(range)) {
|
if (addr.kind() === range[0].kind() && addr.match(range)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// Ignore parsing errors
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue