Some update

This commit is contained in:
Sefinek 2024-08-18 15:36:55 +02:00
parent 622124f196
commit 5117d68023
3 changed files with 15 additions and 15 deletions

View file

@ -42,13 +42,13 @@ const isIPReportedRecently = (ip, reportedIPs) => {
const reportIP = async (event, url, country, cycleErrorCounts) => { const reportIP = async (event, url, country, cycleErrorCounts) => {
if (!url) { if (!url) {
logToCSV(new Date(), event.rayName, event.clientIP, url, 'Failed - Missing URL', country); logToCSV(event.rayName, event.clientIP, url, 'Failed - Missing URL', country);
log('warn', `Error while reporting: ${event.clientIP}; URI: ${url}; (Missing URL)`); log('warn', `Error while reporting: ${event.clientIP}; URI: ${url}; (Missing URL)`);
return false; return false;
} }
if (url.length > MAX_URL_LENGTH) { if (url.length > MAX_URL_LENGTH) {
logToCSV(new Date(), event.rayName, event.clientIP, url, 'Failed - URL too long', country); logToCSV(event.rayName, event.clientIP, url, 'Failed - URL too long', country);
log('warn', `Error 422 while reporting: ${event.clientIP}; URI: ${url}; (URL too long)`); log('warn', `Error 422 while reporting: ${event.clientIP}; URI: ${url}; (URL too long)`);
return false; return false;
} }
@ -60,18 +60,18 @@ const reportIP = async (event, url, country, cycleErrorCounts) => {
comment: generateComment(event) comment: generateComment(event)
}, { headers: headers.ABUSEIPDB }); }, { headers: headers.ABUSEIPDB });
logToCSV(new Date(), event.rayName, event.clientIP, url, 'Reported', country); logToCSV(event.rayName, event.clientIP, url, 'Reported', country);
log('info', `Reported: ${event.clientIP}; URI: ${url}`); log('info', `Reported: ${event.clientIP}; URI: ${url}`);
return true; return true;
} catch (err) { } catch (err) {
if (err.response) { if (err.response) {
if (err.response.status === 429) { if (err.response.status === 429) {
logToCSV(new Date(), event.rayName, event.clientIP, url, 'Failed - 429 Too Many Requests', country); logToCSV(event.rayName, event.clientIP, url, 'Failed - 429 Too Many Requests', country);
log('warn', `Rate limited (429) while reporting: ${event.clientIP}; URI: ${url};`); log('info', `Rate limited (429) while reporting: ${event.clientIP}; URI: ${url};`);
cycleErrorCounts.blocked++; cycleErrorCounts.blocked++;
} else { } else {
log('warn', `Error ${err.response.status} while reporting: ${event.clientIP}; URI: ${url}; (${err.response.data})`); log('error', `Error ${err.response.status} while reporting: ${event.clientIP}; URI: ${url}; (${err.response.data})`);
cycleErrorCounts.otherErrors++; cycleErrorCounts.otherErrors++;
} }
} else { } else {
@ -115,12 +115,12 @@ const reportIP = async (event, url, country, cycleErrorCounts) => {
if (isImageRequest(event.clientRequestPath)) { if (isImageRequest(event.clientRequestPath)) {
cycleImageSkippedCount++; cycleImageSkippedCount++;
if (!wasImageRequestLogged(ip, reportedIPs)) { if (!wasImageRequestLogged(ip, reportedIPs)) {
logToCSV(new Date(), event.rayName, ip, url, 'Skipped - Image Request', country); logToCSV(event.rayName, ip, url, 'Skipped - Image Request', country);
if (!imageRequestLogged) {
if (imageRequestLogged) return;
log('info', 'Skipping image requests in this cycle...'); log('info', 'Skipping image requests in this cycle...');
imageRequestLogged = true; imageRequestLogged = true;
} }
}
continue; continue;
} }

4
package-lock.json generated
View file

@ -1,11 +1,11 @@
{ {
"name": "node-cf-waf-abuseipdb", "name": "cf-waf-abuseipdb",
"version": "1.0.0", "version": "1.0.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "node-cf-waf-abuseipdb", "name": "cf-waf-abuseipdb",
"version": "1.0.0", "version": "1.0.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View file

@ -16,9 +16,9 @@ const checkCSVSize = () => {
} }
}; };
const logToCSV = (timestamp, rayid, ip, endpoint, action, country) => { const logToCSV = (rayId, ip, endpoint, action, country) => {
checkCSVSize(); checkCSVSize();
const logLine = `${timestamp.toISOString()},${rayid},${ip},${endpoint},${action},${country}\n`; const logLine = `${new Date().toISOString()},${rayId},${ip},${endpoint},${action},${country}\n`;
fs.appendFileSync(CSV_FILE_PATH, logLine); fs.appendFileSync(CSV_FILE_PATH, logLine);
}; };