mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-01 12:29:35 +01:00
Fixed console command. Updated packages.
This commit is contained in:
parent
9118f24668
commit
d501410a63
@ -175,6 +175,6 @@
|
|||||||
"tar": "^6.1.2",
|
"tar": "^6.1.2",
|
||||||
"ts-jest": "^29.1.2",
|
"ts-jest": "^29.1.2",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^5.4.3"
|
"typescript": "^5.5.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,12 @@ export function TestConsole({ websiteId }: { websiteId: string }) {
|
|||||||
router.push(`/console/${value}`);
|
router.push(`/console/${value}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleClick() {
|
function handleRunScript() {
|
||||||
window['umami'].track({ url: '/page-view', referrer: 'https://www.google.com' });
|
window['umami'].track(props => ({
|
||||||
|
...props,
|
||||||
|
url: '/page-view',
|
||||||
|
referrer: 'https://www.google.com',
|
||||||
|
}));
|
||||||
window['umami'].track('track-event-no-data');
|
window['umami'].track('track-event-no-data');
|
||||||
window['umami'].track('track-event-with-data', {
|
window['umami'].track('track-event-with-data', {
|
||||||
test: 'test-data',
|
test: 'test-data',
|
||||||
@ -44,7 +48,7 @@ export function TestConsole({ websiteId }: { websiteId: string }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleIdentifyClick() {
|
function handleRunIdentify() {
|
||||||
window['umami'].identify({
|
window['umami'].identify({
|
||||||
userId: 123,
|
userId: 123,
|
||||||
name: 'brian',
|
name: 'brian',
|
||||||
@ -145,10 +149,10 @@ export function TestConsole({ websiteId }: { websiteId: string }) {
|
|||||||
</div>
|
</div>
|
||||||
<div className={styles.group}>
|
<div className={styles.group}>
|
||||||
<div className={styles.header}>Javascript events</div>
|
<div className={styles.header}>Javascript events</div>
|
||||||
<Button id="manual-button" variant="primary" onClick={handleClick}>
|
<Button id="manual-button" variant="primary" onClick={handleRunScript}>
|
||||||
Run script
|
Run script
|
||||||
</Button>
|
</Button>
|
||||||
<Button id="manual-button" variant="primary" onClick={handleIdentifyClick}>
|
<Button id="manual-button" variant="primary" onClick={handleRunIdentify}>
|
||||||
Run identify
|
Run identify
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,9 +2,9 @@ import path from 'path';
|
|||||||
import { getClientIp } from 'request-ip';
|
import { getClientIp } from 'request-ip';
|
||||||
import { browserName, detectOS } from 'detect-browser';
|
import { browserName, detectOS } from 'detect-browser';
|
||||||
import isLocalhost from 'is-localhost-ip';
|
import isLocalhost from 'is-localhost-ip';
|
||||||
|
import ipaddr from 'ipaddr.js';
|
||||||
import maxmind from 'maxmind';
|
import maxmind from 'maxmind';
|
||||||
import { safeDecodeURIComponent } from 'next-basics';
|
import { safeDecodeURIComponent } from 'next-basics';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DESKTOP_OS,
|
DESKTOP_OS,
|
||||||
MOBILE_OS,
|
MOBILE_OS,
|
||||||
@ -137,3 +137,31 @@ export async function getClientInfo(req: NextApiRequestCollect) {
|
|||||||
|
|
||||||
return { userAgent, browser, os, ip, country, subdivision1, subdivision2, city, device };
|
return { userAgent, browser, os, ip, country, subdivision1, subdivision2, city, device };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hasBlockedIp(req: NextApiRequestCollect) {
|
||||||
|
const ignoreIps = process.env.IGNORE_IP;
|
||||||
|
|
||||||
|
if (ignoreIps) {
|
||||||
|
const ips = [];
|
||||||
|
|
||||||
|
if (ignoreIps) {
|
||||||
|
ips.push(...ignoreIps.split(',').map(n => n.trim()));
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientIp = getIpAddress(req);
|
||||||
|
|
||||||
|
return ips.find(ip => {
|
||||||
|
if (ip === clientIp) return true;
|
||||||
|
|
||||||
|
// CIDR notation
|
||||||
|
if (ip.indexOf('/') > 0) {
|
||||||
|
const addr = ipaddr.parse(clientIp);
|
||||||
|
const range = ipaddr.parseCIDR(ip);
|
||||||
|
|
||||||
|
if (addr.kind() === range[0].kind() && addr.match(range)) return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import ipaddr from 'ipaddr.js';
|
|
||||||
import { isbot } from 'isbot';
|
import { isbot } from 'isbot';
|
||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import {
|
import {
|
||||||
@ -12,7 +11,7 @@ import {
|
|||||||
} from 'next-basics';
|
} from 'next-basics';
|
||||||
import { COLLECTION_TYPE, HOSTNAME_REGEX, IP_REGEX } from 'lib/constants';
|
import { COLLECTION_TYPE, HOSTNAME_REGEX, IP_REGEX } from 'lib/constants';
|
||||||
import { secret, visitSalt, uuid } from 'lib/crypto';
|
import { secret, visitSalt, uuid } from 'lib/crypto';
|
||||||
import { getIpAddress } from 'lib/detect';
|
import { hasBlockedIp } from 'lib/detect';
|
||||||
import { useCors, useSession, useValidate } from 'lib/middleware';
|
import { useCors, useSession, useValidate } from 'lib/middleware';
|
||||||
import { CollectionType, YupRequest } from 'lib/types';
|
import { CollectionType, YupRequest } from 'lib/types';
|
||||||
import { saveEvent, saveSessionData } from 'queries';
|
import { saveEvent, saveSessionData } from 'queries';
|
||||||
@ -166,31 +165,3 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
|
|||||||
|
|
||||||
return methodNotAllowed(res);
|
return methodNotAllowed(res);
|
||||||
};
|
};
|
||||||
|
|
||||||
function hasBlockedIp(req: NextApiRequestCollect) {
|
|
||||||
const ignoreIps = process.env.IGNORE_IP;
|
|
||||||
|
|
||||||
if (ignoreIps) {
|
|
||||||
const ips = [];
|
|
||||||
|
|
||||||
if (ignoreIps) {
|
|
||||||
ips.push(...ignoreIps.split(',').map(n => n.trim()));
|
|
||||||
}
|
|
||||||
|
|
||||||
const clientIp = getIpAddress(req);
|
|
||||||
|
|
||||||
return ips.find(ip => {
|
|
||||||
if (ip === clientIp) return true;
|
|
||||||
|
|
||||||
// CIDR notation
|
|
||||||
if (ip.indexOf('/') > 0) {
|
|
||||||
const addr = ipaddr.parse(clientIp);
|
|
||||||
const range = ipaddr.parseCIDR(ip);
|
|
||||||
|
|
||||||
if (addr.kind() === range[0].kind() && addr.match(range)) return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user