diff --git a/index.js b/index.js index 6e3098e..22e02b3 100644 --- a/index.js +++ b/index.js @@ -46,7 +46,7 @@ const reportIP = async (event, hostname, endpoint, userAgent, country, cycleErro if (!uri) { logToCSV(event.rayName, event.clientIP, hostname, endpoint, event.userAgent, 'Failed - Missing URL', country); - log('warn', `Missing URL ${event.clientIP}; URI: ${uri};`); + log('warn', `Missing URL ${event.clientIP}; URI: ${uri}`); return false; } @@ -58,7 +58,7 @@ const reportIP = async (event, hostname, endpoint, userAgent, country, cycleErro if (uri.length > MAX_URL_LENGTH) { logToCSV(event.rayName, event.clientIP, hostname, endpoint, event.userAgent, 'Failed - URL too long', country); - log('log', `URL too long ${event.clientIP}; URI: ${uri};`); + log('log', `URL too long ${event.clientIP}; URI: ${uri}`); return false; } @@ -76,7 +76,7 @@ const reportIP = async (event, hostname, endpoint, userAgent, country, cycleErro } catch (err) { if (err.response?.status === 429) { logToCSV(event.rayName, event.clientIP, hostname, endpoint, event.userAgent, 'Failed - 429 Too Many Requests', country); - log('info', `Rate limited (429) while reporting ${event.clientIP}; URI: ${uri};`); + log('info', `Rate limited (429) while reporting ${event.clientIP}; URI: ${uri}`); cycleErrorCounts.blocked++; } else { log('error', `Error ${err.response?.status} while reporting ${event.clientIP}; URI: ${uri}; (${err.response?.data})`); diff --git a/scripts/sefinekAPI.js b/scripts/sefinekAPI.js index a1be03f..f8dc2cc 100644 --- a/scripts/sefinekAPI.js +++ b/scripts/sefinekAPI.js @@ -2,13 +2,11 @@ const { axios } = require('../services/axios.js'); const { readReportedIPs, updateSefinekAPIInCSV } = require('./csv.js'); const log = require('./log.js'); -const SEFINEK_API_URL = `${process.env.NODE_ENV === 'production' ? 'https://api.sefinek.net' : 'http://127.0.0.1:4010'}/api/v2/cloudflare-waf-abuseipdb/post`; +const SEFINEK_API_URL = process.env.SEFINEK_API_URL || `${process.env.NODE_ENV === 'production' ? 'https://api.sefinek.net' : 'http://127.0.0.1:4010'}/api/v2/cloudflare-waf-abuseipdb/post`; module.exports = async () => { const reportedIPs = readReportedIPs().filter(ip => ip.action === 'Reported' && ip.sefinekAPI === 'false'); - if (reportedIPs.length === 0) { - return log('info', 'No reported IPs with action "Reported" and SefinekAPI false to send to Sefinek API'); - } + if (reportedIPs.length === 0) return log('info', 'No IPs with action "Reported" and SefinekAPI false to send to Sefinek API'); const uniqueLogs = reportedIPs.reduce((acc, ip) => { if (!acc.seen.has(ip.ip)) { @@ -18,7 +16,7 @@ module.exports = async () => { return acc; }, { seen: new Set(), logs: [] }).logs; - if (uniqueLogs.length === 0) return log('info', 'No unique IPs to send'); + if (uniqueLogs.length === 0) return log('info', 'No unique IPs to send to Sefinek API'); try { const res = await axios.post(SEFINEK_API_URL, { @@ -32,10 +30,10 @@ module.exports = async () => { })) }); - log('info', `Logs (${res.data.count}) sent to Sefinek API. Status: ${res.status}`); + log('info', `Successfully sent ${res.data.count} logs to Sefinek API. Status: ${res.status}`); uniqueLogs.forEach(ip => updateSefinekAPIInCSV(ip.rayId, true)); } catch (err) { - log('error', `Failed to send logs to Sefinek API. Error: ${err.message}`); + log('error', `Failed to send logs to Sefinek API. Status: ${err.response?.status || err.status}. Message: ${err.response?.data?.message || 'Unknown error.'}`); } -}; +}; \ No newline at end of file