Quality fixes

This commit is contained in:
Sefinek 2024-11-10 03:12:56 +01:00
parent e165737fb0
commit 3402f99b2d
4 changed files with 24 additions and 25 deletions

View file

@ -20,9 +20,9 @@ const fetchBlockedIPs = async () => {
if (events) { if (events) {
const filtered = events.filter(x => const filtered = events.filter(x =>
x.ip !== clientIp.getAddress() && x.ip !== clientIp.getAddress() &&
!whitelist.subdomains.some(subdomain => x.clientRequestHTTPHost.includes(subdomain)) && // Subdomains !whitelist.subdomains.some(subdomain => x.clientRequestHTTPHost?.includes(subdomain)) && // Subdomains
!whitelist.useragents.some(ua => x.userAgent.includes(ua)) && // User-agents !whitelist.userAgents.some(ua => x.userAgent?.includes(ua)) && // User-agents
!whitelist.endpoints.some(endpoint => x.clientRequestPath.includes(endpoint))// Endpoints !whitelist.endpoints.some(endpoint => x.clientRequestPath?.includes(endpoint)) // Endpoints
); );
log('log', `Fetched ${events.length} (filtered ${filtered.length}) events from Cloudflare`); log('log', `Fetched ${events.length} (filtered ${filtered.length}) events from Cloudflare`);
@ -173,8 +173,8 @@ const reportIP = async (event, uri, country, hostname, endpoint, cycleErrorCount
log('log', `- Reported IPs: ${cycleReportedCount}`); log('log', `- Reported IPs: ${cycleReportedCount}`);
log('log', `- Total IPs processed: ${cycleProcessedCount}`); log('log', `- Total IPs processed: ${cycleProcessedCount}`);
log('log', `- Skipped IPs: ${cycleSkippedCount}`); log('log', `- Skipped IPs: ${cycleSkippedCount}`);
log('log', `- Skipped due to Image Requests: ${cycleImageSkippedCount}`); log('log', `- Skipped due to image requests: ${cycleImageSkippedCount}`);
log('log', `- 429 Too Many Requests: ${cycleErrorCounts.blocked}`); log('log', `- Rate-limits: ${cycleErrorCounts.blocked}`);
log('log', `- Other errors: ${cycleErrorCounts.otherErrors}`); log('log', `- Other errors: ${cycleErrorCounts.otherErrors}`);
log('log', '===================== End of Reporting Cycle ====================='); log('log', '===================== End of Reporting Cycle =====================');

View file

@ -1,5 +1,5 @@
const subdomains = ['api.', 'cdn.']; const subdomains = ['api.', 'cdn.'];
const useragents = ['Chrome/129', 'Chrome/130', 'Chrome/131', 'Chrome/132', 'Chrome/133', 'StellaLauncher']; const userAgents = ['Chrome/129', 'Chrome/130', 'Chrome/131', 'Chrome/132', 'StellaLauncher', 'PrepareStella'];
const endpoints = ['/api/', '//video', '//js', '//images', '//imgs', 'favicon.ico']; const endpoints = ['/api/', '//video', '//js', '//images', '//imgs', 'favicon.ico', 'sitemap.xml', 'robots.txt'];
module.exports = { subdomains, useragents, endpoints }; module.exports = { subdomains, userAgents, endpoints };

View file

@ -13,7 +13,7 @@ const fetchIPAddress = async () => {
log('error', 'Failed to retrieve your IP'); log('error', 'Failed to retrieve your IP');
} }
} catch (err) { } catch (err) {
log('error', `Error fetching your IP: ${err.message}`); log('error', `Error fetching your IP: ${err.stack}`);
} }
}; };

View file

@ -7,26 +7,27 @@ const whitelist = require('../scripts/whitelist.js');
const API_URL = `${process.env.SEFINEK_API_URL}/cloudflare-waf-abuseipdb/post`; const API_URL = `${process.env.SEFINEK_API_URL}/cloudflare-waf-abuseipdb/post`;
module.exports = async () => { module.exports = async () => {
const reportedIPs = readReportedIPs().filter(x => const reportedIPs = (readReportedIPs() || []).filter(x =>
x.status === 'REPORTED' && x.status === 'REPORTED' &&
x.ip !== clientIp.getAddress() && x.ip !== clientIp.getAddress() &&
x.hostname !== 'blocklist.sefinek.net' && // Domain x.hostname !== 'blocklist.sefinek.net' && // Domain
!whitelist.subdomains.some(subdomain => x.clientRequestHTTPHost.includes(subdomain)) && // Subdomains !whitelist.subdomains.some(subdomain => x.clientRequestHTTPHost?.includes(subdomain)) && // Subdomains
!whitelist.useragents.some(ua => x.userAgent.includes(ua)) && // User-agents !whitelist.userAgents.some(ua => x.userAgent?.includes(ua)) && // User-agents
!whitelist.endpoints.some(endpoint => x.clientRequestPath.includes(endpoint)) && // Endpoints !whitelist.endpoints.some(endpoint => x.clientRequestPath?.includes(endpoint)) && // Endpoints
!(/crawler|spider|bot/gi).test(x.useragent) && // Bots !(/crawler|spider|bot/gi).test(x.userAgent) &&
!x.sefinekAPI !x.sefinekAPI
); );
if (!reportedIPs.length) return; if (!reportedIPs.length) return;
const uniqueLogs = reportedIPs.reduce((acc, ip) => { const seenIPs = new Set();
if (acc.seen.has(ip.ip)) return acc; const uniqueLogs = reportedIPs.filter(ip => {
acc.seen.add(ip.ip); if (seenIPs.has(ip.ip)) return false;
acc.logs.push(ip); seenIPs.add(ip.ip);
return acc; return true;
}, { seen: new Set(), logs: [] }).logs; });
if (!uniqueLogs?.length) return log('log', 'No unique IPs to send to Sefinek API'); if (!uniqueLogs.length) return log('log', 'No unique IPs to send to Sefinek API');
try { try {
const res = await axios.post(API_URL, { const res = await axios.post(API_URL, {
@ -34,7 +35,7 @@ module.exports = async () => {
rayId: ip.rayId, rayId: ip.rayId,
ip: ip.ip, ip: ip.ip,
endpoint: ip.endpoint, endpoint: ip.endpoint,
useragent: ip.useragent.replace(/"/g, ''), userAgent: ip.userAgent?.replace(/"/g, ''),
action: ip.action, action: ip.action,
country: ip.country, country: ip.country,
timestamp: ip.timestamp, timestamp: ip.timestamp,
@ -45,8 +46,6 @@ module.exports = async () => {
uniqueLogs.forEach(ip => updateSefinekAPIInCSV(ip.rayId, true)); uniqueLogs.forEach(ip => updateSefinekAPIInCSV(ip.rayId, true));
} catch (err) { } catch (err) {
if (err.response?.data?.code !== 'NO_VALID_OR_UNIQUE_IPS') { log('error', `Failed to send logs to Sefinek API. Status: ${err.response?.status}. Message: ${err.response?.data?.message || err.stack}`);
log('error', `Failed to send logs to Sefinek API. Status: ${err.status}. Message: ${err.response?.data?.message || err.stack}`);
}
} }
}; };