This commit is contained in:
Sefinek 2024-08-17 23:05:35 +02:00
parent 301fa84032
commit 66a842846d

View file

@ -11,6 +11,7 @@ const log = require('./scripts/log.js');
const COOLDOWN_MS = 2000; const COOLDOWN_MS = 2000;
const REPORTED_IP_COOLDOWN_MS = 7 * 60 * 60 * 1000; const REPORTED_IP_COOLDOWN_MS = 7 * 60 * 60 * 1000;
const MAX_URL_LENGTH = 2000;
const fetchBlockedIPs = async () => { const fetchBlockedIPs = async () => {
try { try {
@ -39,6 +40,18 @@ const isIPReportedRecently = (ip, reportedIPs) => {
}; };
const reportIP = async (event, url, country, cycleErrorCounts) => { const reportIP = async (event, url, country, cycleErrorCounts) => {
if (!url) {
logToCSV(new Date(), event.rayName, event.clientIP, url, 'Failed - URL too long', country);
log('fail', `Error while reporting: ${event.clientIP}; URL: ${url}; (Missing URL)`);
return false;
}
if (url.length > MAX_URL_LENGTH) {
logToCSV(new Date(), event.rayName, event.clientIP, url, 'Failed - URL too long', country);
log('fail', `Error 422 while reporting: ${event.clientIP}; URL: ${url}; (URL too long)`);
return false;
}
try { try {
await axios.post('https://api.abuseipdb.com/api/v2/report', { await axios.post('https://api.abuseipdb.com/api/v2/report', {
ip: event.clientIP, ip: event.clientIP,
@ -57,7 +70,7 @@ const reportIP = async (event, url, country, cycleErrorCounts) => {
log('warn', `Rate limited (429) while reporting: ${event.clientIP}; URL: ${url};`); log('warn', `Rate limited (429) while reporting: ${event.clientIP}; URL: ${url};`);
cycleErrorCounts.blocked++; cycleErrorCounts.blocked++;
} else { } else {
log('error', `Error ${err.response.status} while reporting: ${event.clientIP}; URL: ${url}; Message: ${err.response.data}`); log('fail', `Error ${err.response.status} while reporting: ${event.clientIP}; URL: ${url}; (${err.response.data})`);
cycleErrorCounts.otherErrors++; cycleErrorCounts.otherErrors++;
} }
} else { } else {