mirror of
https://github.com/umami-software/umami.git
synced 2026-02-14 17:45:38 +01:00
Lookup location for payload IPs. Removed hostname from session id.
This commit is contained in:
parent
e060f2b240
commit
0aad3d8e05
2 changed files with 4 additions and 4 deletions
|
|
@ -87,7 +87,7 @@ export async function POST(request: Request) {
|
||||||
return forbidden();
|
return forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
const sessionId = uuid(websiteId, hostname, ip, userAgent);
|
const sessionId = uuid(websiteId, ip, userAgent);
|
||||||
|
|
||||||
// Find session
|
// Find session
|
||||||
if (!clickhouse.enabled && !cache?.sessionId) {
|
if (!clickhouse.enabled && !cache?.sessionId) {
|
||||||
|
|
|
||||||
|
|
@ -86,13 +86,13 @@ function decodeHeader(s: string | undefined | null): string | undefined | null {
|
||||||
return Buffer.from(s, 'latin1').toString('utf-8');
|
return Buffer.from(s, 'latin1').toString('utf-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getLocation(ip: string = '', headers: Headers) {
|
export async function getLocation(ip: string = '', headers: Headers, hasPayloadIP: boolean) {
|
||||||
// Ignore local ips
|
// Ignore local ips
|
||||||
if (await isLocalhost(ip)) {
|
if (await isLocalhost(ip)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!process.env.SKIP_LOCATION_HEADERS) {
|
if (!hasPayloadIP && !process.env.SKIP_LOCATION_HEADERS) {
|
||||||
// Cloudflare headers
|
// Cloudflare headers
|
||||||
if (headers.get('cf-ipcountry')) {
|
if (headers.get('cf-ipcountry')) {
|
||||||
const country = decodeHeader(headers.get('cf-ipcountry'));
|
const country = decodeHeader(headers.get('cf-ipcountry'));
|
||||||
|
|
@ -147,7 +147,7 @@ export async function getLocation(ip: string = '', headers: Headers) {
|
||||||
export async function getClientInfo(request: Request, payload: Record<string, any>) {
|
export async function getClientInfo(request: Request, payload: Record<string, any>) {
|
||||||
const userAgent = payload?.userAgent || request.headers.get('user-agent');
|
const userAgent = payload?.userAgent || request.headers.get('user-agent');
|
||||||
const ip = payload?.ip || getIpAddress(request.headers);
|
const ip = payload?.ip || getIpAddress(request.headers);
|
||||||
const location = await getLocation(ip, request.headers);
|
const location = await getLocation(ip, request.headers, !!payload?.ip);
|
||||||
const country = payload?.userAgent || location?.country;
|
const country = payload?.userAgent || location?.country;
|
||||||
const subdivision1 = location?.subdivision1;
|
const subdivision1 = location?.subdivision1;
|
||||||
const subdivision2 = location?.subdivision2;
|
const subdivision2 = location?.subdivision2;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue