Some fixes

This commit is contained in:
Sefinek 2024-09-05 19:23:58 +02:00
parent e57c1a33c9
commit 44e3d34677
2 changed files with 9 additions and 11 deletions

View file

@ -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})`);

View file

@ -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.'}`);
}
};
};