mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Compare commits
No commits in common. "fd2e2047cdf400da1deccec062a570ed1540b4d5" and "518f0b66c6be828adaea5b64eefe3b659bc47dfb" have entirely different histories.
fd2e2047cd
...
518f0b66c6
2 changed files with 3 additions and 14 deletions
|
|
@ -10,16 +10,6 @@ import { safeDecodeURIComponent } from '@/lib/url';
|
|||
const MAXMIND = 'maxmind';
|
||||
|
||||
const PROVIDER_HEADERS = [
|
||||
// Umami custom headers (cloud mode only)
|
||||
...(process.env.CLOUD_MODE
|
||||
? [
|
||||
{
|
||||
countryHeader: 'x-umami-client-country',
|
||||
regionHeader: 'x-umami-client-region',
|
||||
cityHeader: 'x-umami-client-city',
|
||||
},
|
||||
]
|
||||
: []),
|
||||
// Cloudflare headers
|
||||
{
|
||||
countryHeader: 'cf-ipcountry',
|
||||
|
|
@ -70,13 +60,13 @@ function decodeHeader(s: string | undefined | null): string | undefined | null {
|
|||
return Buffer.from(s, 'latin1').toString('utf-8');
|
||||
}
|
||||
|
||||
export async function getLocation(ip: string = '', headers: Headers, skipHeaders: boolean) {
|
||||
export async function getLocation(ip: string = '', headers: Headers, hasPayloadIP: boolean) {
|
||||
// Ignore local ips
|
||||
if (!ip || (await isLocalhost(ip))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!skipHeaders && !process.env.SKIP_LOCATION_HEADERS) {
|
||||
if (!hasPayloadIP && !process.env.SKIP_LOCATION_HEADERS) {
|
||||
for (const provider of PROVIDER_HEADERS) {
|
||||
const countryHeader = headers.get(provider.countryHeader);
|
||||
if (countryHeader) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
export const IP_ADDRESS_HEADERS = [
|
||||
...(process.env.CLOUD_MODE ? ['x-umami-client-ip'] : []), // Umami custom header (cloud mode only)
|
||||
'true-client-ip', // CDN
|
||||
'cf-connecting-ip', // Cloudflare
|
||||
'fastly-client-ip', // Fastly
|
||||
|
|
@ -32,7 +31,7 @@ export function getIpAddress(headers: Headers) {
|
|||
}
|
||||
|
||||
if (header === 'forwarded') {
|
||||
const match = ip.match(/for=(\[?[0-9a-fA-F:.]+]?)/);
|
||||
const match = ip.match(/for=(\[?[0-9a-fA-F:.]+\]?)/);
|
||||
|
||||
if (match) {
|
||||
return match[1];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue