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(),
|
||||
}),
|
||||
],
|
||||
sourcemap: true,
|
||||
sourcemap: "external",
|
||||
target: "node22",
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
@@ -753,6 +753,10 @@ export function isPathAllowed(pattern: string, path: string): boolean {
|
||||
}
|
||||
|
||||
async function isIpInGeoIP(ip: string, countryCode: string): Promise<boolean> {
|
||||
if (countryCode == "ALL") {
|
||||
return true;
|
||||
}
|
||||
|
||||
const geoIpCacheKey = `geoip:${ip}`;
|
||||
|
||||
let cachedCountryCode: string | undefined = cache.get(geoIpCacheKey);
|
||||
@@ -760,17 +764,15 @@ async function isIpInGeoIP(ip: string, countryCode: string): Promise<boolean> {
|
||||
if (!cachedCountryCode) {
|
||||
try {
|
||||
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()
|
||||
);
|
||||
|
||||
cachedCountryCode = response.data.data.country;
|
||||
cachedCountryCode = response.data.data.countryCode;
|
||||
|
||||
// Cache for longer since IP geolocation doesn't change frequently
|
||||
cache.set(geoIpCacheKey, cachedCountryCode, 300); // 5 minutes
|
||||
|
||||
logger.debug(`IP ${ip} is in country:`, cachedCountryCode);
|
||||
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user