mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-28 22:00:51 +00:00
Geoblocking works
This commit is contained in:
@@ -63,7 +63,7 @@ esbuild
|
|||||||
packagePath: getPackagePaths(),
|
packagePath: getPackagePaths(),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
sourcemap: true,
|
sourcemap: "external",
|
||||||
target: "node22",
|
target: "node22",
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|||||||
@@ -753,6 +753,10 @@ export function isPathAllowed(pattern: string, path: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function isIpInGeoIP(ip: string, countryCode: string): Promise<boolean> {
|
async function isIpInGeoIP(ip: string, countryCode: string): Promise<boolean> {
|
||||||
|
if (countryCode == "ALL") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const geoIpCacheKey = `geoip:${ip}`;
|
const geoIpCacheKey = `geoip:${ip}`;
|
||||||
|
|
||||||
let cachedCountryCode: string | undefined = cache.get(geoIpCacheKey);
|
let cachedCountryCode: string | undefined = cache.get(geoIpCacheKey);
|
||||||
@@ -760,17 +764,15 @@ async function isIpInGeoIP(ip: string, countryCode: string): Promise<boolean> {
|
|||||||
if (!cachedCountryCode) {
|
if (!cachedCountryCode) {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(
|
const response = await axios.get(
|
||||||
`${config.getRawConfig().managed?.endpoint}/api/v1/geoip/${ip}`,
|
`${config.getRawConfig().managed?.endpoint}/api/v1/hybrid/geoip/${ip}`,
|
||||||
await tokenManager.getAuthHeader()
|
await tokenManager.getAuthHeader()
|
||||||
);
|
);
|
||||||
|
|
||||||
cachedCountryCode = response.data.data.country;
|
cachedCountryCode = response.data.data.countryCode;
|
||||||
|
|
||||||
// Cache for longer since IP geolocation doesn't change frequently
|
// Cache for longer since IP geolocation doesn't change frequently
|
||||||
cache.set(geoIpCacheKey, cachedCountryCode, 300); // 5 minutes
|
cache.set(geoIpCacheKey, cachedCountryCode, 300); // 5 minutes
|
||||||
|
|
||||||
logger.debug(`IP ${ip} is in country:`, cachedCountryCode);
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (axios.isAxiosError(error)) {
|
if (axios.isAxiosError(error)) {
|
||||||
logger.error("Error fetching config in verify session:", {
|
logger.error("Error fetching config in verify session:", {
|
||||||
@@ -788,5 +790,7 @@ async function isIpInGeoIP(ip: string, countryCode: string): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug(`IP ${ip} is in country: ${cachedCountryCode}`);
|
||||||
|
|
||||||
return cachedCountryCode?.toUpperCase() === countryCode.toUpperCase();
|
return cachedCountryCode?.toUpperCase() === countryCode.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user