From 5117d680234aeec17321be7a7830347fbb5b7743 Mon Sep 17 00:00:00 2001 From: Sefinek Date: Sun, 18 Aug 2024 15:36:55 +0200 Subject: [PATCH] Some update --- index.js | 22 +++++++++++----------- package-lock.json | 4 ++-- scripts/csv.js | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 1418f7d..d6b5566 100644 --- a/index.js +++ b/index.js @@ -42,13 +42,13 @@ const isIPReportedRecently = (ip, reportedIPs) => { const reportIP = async (event, url, country, cycleErrorCounts) => { 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)`); return false; } 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)`); return false; } @@ -60,18 +60,18 @@ const reportIP = async (event, url, country, cycleErrorCounts) => { comment: generateComment(event) }, { 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}`); return true; } catch (err) { if (err.response) { if (err.response.status === 429) { - logToCSV(new Date(), event.rayName, event.clientIP, url, 'Failed - 429 Too Many Requests', country); - log('warn', `Rate limited (429) while reporting: ${event.clientIP}; URI: ${url};`); + logToCSV(event.rayName, event.clientIP, url, 'Failed - 429 Too Many Requests', country); + log('info', `Rate limited (429) while reporting: ${event.clientIP}; URI: ${url};`); cycleErrorCounts.blocked++; } 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++; } } else { @@ -115,11 +115,11 @@ const reportIP = async (event, url, country, cycleErrorCounts) => { if (isImageRequest(event.clientRequestPath)) { cycleImageSkippedCount++; if (!wasImageRequestLogged(ip, reportedIPs)) { - logToCSV(new Date(), event.rayName, ip, url, 'Skipped - Image Request', country); - if (!imageRequestLogged) { - log('info', 'Skipping image requests in this cycle...'); - imageRequestLogged = true; - } + logToCSV(event.rayName, ip, url, 'Skipped - Image Request', country); + + if (imageRequestLogged) return; + log('info', 'Skipping image requests in this cycle...'); + imageRequestLogged = true; } continue; diff --git a/package-lock.json b/package-lock.json index 1612330..0b6c884 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "node-cf-waf-abuseipdb", + "name": "cf-waf-abuseipdb", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "node-cf-waf-abuseipdb", + "name": "cf-waf-abuseipdb", "version": "1.0.0", "license": "MIT", "dependencies": { diff --git a/scripts/csv.js b/scripts/csv.js index 915e533..f426b1d 100644 --- a/scripts/csv.js +++ b/scripts/csv.js @@ -16,9 +16,9 @@ const checkCSVSize = () => { } }; -const logToCSV = (timestamp, rayid, ip, endpoint, action, country) => { +const logToCSV = (rayId, ip, endpoint, action, country) => { 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); };