mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-07-30 16:59:15 +02:00
ban countries and change url
This commit is contained in:
+21
-8
@@ -167,13 +167,13 @@ function handleConnect(clientIp, currentUsers, ws, request, callback) {
|
|||||||
inFlightPromise.then((info) => processConnection(clientIp, info, currentUsers, ws, request, callback));
|
inFlightPromise.then((info) => processConnection(clientIp, info, currentUsers, ws, request, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
let bannedASCache = { data: null, timestamp: 0 };
|
let bannedASCache = { data: null, countries: null, timestamp: 0 };
|
||||||
|
|
||||||
function fetchBannedAS(callback) {
|
function fetchBannedAS(callback) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (bannedASCache.data && now - bannedASCache.timestamp < 10 * 60 * 1000) return callback(bannedASCache.data);
|
if (bannedASCache.data && bannedASCache.countries && now - bannedASCache.timestamp < 10 * 60 * 1000) return callback(bannedASCache.data, bannedASCache.countries);
|
||||||
|
|
||||||
const req = https.get("https://flerken.zapto.org:5000/banned_as.json", { family: 4 }, (banResponse) => {
|
const req = https.get("https://data.fmtuner.net/banned_as.json", { family: 4 }, (banResponse) => {
|
||||||
let banData = "";
|
let banData = "";
|
||||||
|
|
||||||
banResponse.on("data", (chunk) => banData += chunk);
|
banResponse.on("data", (chunk) => banData += chunk);
|
||||||
@@ -181,11 +181,12 @@ function fetchBannedAS(callback) {
|
|||||||
banResponse.on("end", () => {
|
banResponse.on("end", () => {
|
||||||
try {
|
try {
|
||||||
const bannedAS = JSON.parse(banData).banned_as || [];
|
const bannedAS = JSON.parse(banData).banned_as || [];
|
||||||
bannedASCache = { data: bannedAS, timestamp: now };
|
const bannedCountries = JSON.parse(banData).banned_countries || [];
|
||||||
callback(bannedAS);
|
bannedASCache = { data: bannedAS, countries: bannedCountries, timestamp: now };
|
||||||
|
callback(bannedAS, bannedCountries);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error parsing banned AS list:", error);
|
console.error("Error parsing banned AS list:", error);
|
||||||
callback([]); // Default to allowing user
|
callback(["*"], []); // Default to blocking the user
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -209,8 +210,8 @@ function processConnection(clientIp, locationInfo, currentUsers, ws, request, ca
|
|||||||
const options = { year: "numeric", month: "numeric", day: "numeric", hour: "2-digit", minute: "2-digit" };
|
const options = { year: "numeric", month: "numeric", day: "numeric", hour: "2-digit", minute: "2-digit" };
|
||||||
const connectionTime = new Date().toLocaleString([], options);
|
const connectionTime = new Date().toLocaleString([], options);
|
||||||
|
|
||||||
fetchBannedAS((bannedAS) => {
|
fetchBannedAS((bannedAS, bannedCountries) => {
|
||||||
if (bannedAS.some((as) => locationInfo.as?.includes(as))) {
|
if ((bannedAS.some((as) => locationInfo.as?.includes(as))) || bannedAS.includes("*")) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const lastSeen = recentBannedIps.get(clientIp) || 0;
|
const lastSeen = recentBannedIps.get(clientIp) || 0;
|
||||||
|
|
||||||
@@ -222,6 +223,18 @@ function processConnection(clientIp, locationInfo, currentUsers, ws, request, ca
|
|||||||
return callback("User banned");
|
return callback("User banned");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bannedCountries.some((c) => locationInfo.country?.includes(c))) {
|
||||||
|
const now = Date.now();
|
||||||
|
const lastSeen = recentBannedIps.get(clientIp) || 0;
|
||||||
|
|
||||||
|
if (now - lastSeen > 300 * 1000) {
|
||||||
|
consoleCmd.logWarn(`Banned country list client kicked (${clientIp})`);
|
||||||
|
recentBannedIps.set(clientIp, now);
|
||||||
|
}
|
||||||
|
|
||||||
|
return callback("User banned");
|
||||||
|
}
|
||||||
|
|
||||||
const userLocation =
|
const userLocation =
|
||||||
locationInfo && locationInfo.country !== undefined
|
locationInfo && locationInfo.country !== undefined
|
||||||
? [
|
? [
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<meta property="og:title" content="FM-DX WebServer [<%= tunerName %>]">
|
<meta property="og:title" content="FM-DX WebServer [<%= tunerName %>]">
|
||||||
<meta property="og:type" content="website">
|
<meta property="og:type" content="website">
|
||||||
<meta property="og:image" content="https://flerken.zapto.org:5000/img/webserver_icon.png">
|
<meta property="og:image" content="https://data.fmtuner.net/img/webserver_icon.png">
|
||||||
<meta property="og:description" content="Server description: <%= tunerDescMeta %>.">
|
<meta property="og:description" content="Server description: <%= tunerDescMeta %>.">
|
||||||
|
|
||||||
<!-- Audio streaming -->
|
<!-- Audio streaming -->
|
||||||
|
|||||||
Reference in New Issue
Block a user