Quality fixes
This commit is contained in:
parent
e165737fb0
commit
3402f99b2d
4 changed files with 24 additions and 25 deletions
10
index.js
10
index.js
|
|
@ -20,9 +20,9 @@ const fetchBlockedIPs = async () => {
|
|||
if (events) {
|
||||
const filtered = events.filter(x =>
|
||||
x.ip !== clientIp.getAddress() &&
|
||||
!whitelist.subdomains.some(subdomain => x.clientRequestHTTPHost.includes(subdomain)) && // Subdomains
|
||||
!whitelist.useragents.some(ua => x.userAgent.includes(ua)) && // User-agents
|
||||
!whitelist.endpoints.some(endpoint => x.clientRequestPath.includes(endpoint))// Endpoints
|
||||
!whitelist.subdomains.some(subdomain => x.clientRequestHTTPHost?.includes(subdomain)) && // Subdomains
|
||||
!whitelist.userAgents.some(ua => x.userAgent?.includes(ua)) && // User-agents
|
||||
!whitelist.endpoints.some(endpoint => x.clientRequestPath?.includes(endpoint)) // Endpoints
|
||||
);
|
||||
|
||||
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', `- Total IPs processed: ${cycleProcessedCount}`);
|
||||
log('log', `- Skipped IPs: ${cycleSkippedCount}`);
|
||||
log('log', `- Skipped due to Image Requests: ${cycleImageSkippedCount}`);
|
||||
log('log', `- 429 Too Many Requests: ${cycleErrorCounts.blocked}`);
|
||||
log('log', `- Skipped due to image requests: ${cycleImageSkippedCount}`);
|
||||
log('log', `- Rate-limits: ${cycleErrorCounts.blocked}`);
|
||||
log('log', `- Other errors: ${cycleErrorCounts.otherErrors}`);
|
||||
log('log', '===================== End of Reporting Cycle =====================');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const subdomains = ['api.', 'cdn.'];
|
||||
const useragents = ['Chrome/129', 'Chrome/130', 'Chrome/131', 'Chrome/132', 'Chrome/133', 'StellaLauncher'];
|
||||
const endpoints = ['/api/', '//video', '//js', '//images', '//imgs', 'favicon.ico'];
|
||||
const userAgents = ['Chrome/129', 'Chrome/130', 'Chrome/131', 'Chrome/132', 'StellaLauncher', 'PrepareStella'];
|
||||
const endpoints = ['/api/', '//video', '//js', '//images', '//imgs', 'favicon.ico', 'sitemap.xml', 'robots.txt'];
|
||||
|
||||
module.exports = { subdomains, useragents, endpoints };
|
||||
module.exports = { subdomains, userAgents, endpoints };
|
||||
|
|
@ -13,7 +13,7 @@ const fetchIPAddress = async () => {
|
|||
log('error', 'Failed to retrieve your IP');
|
||||
}
|
||||
} catch (err) {
|
||||
log('error', `Error fetching your IP: ${err.message}`);
|
||||
log('error', `Error fetching your IP: ${err.stack}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -7,26 +7,27 @@ const whitelist = require('../scripts/whitelist.js');
|
|||
const API_URL = `${process.env.SEFINEK_API_URL}/cloudflare-waf-abuseipdb/post`;
|
||||
|
||||
module.exports = async () => {
|
||||
const reportedIPs = readReportedIPs().filter(x =>
|
||||
const reportedIPs = (readReportedIPs() || []).filter(x =>
|
||||
x.status === 'REPORTED' &&
|
||||
x.ip !== clientIp.getAddress() &&
|
||||
x.hostname !== 'blocklist.sefinek.net' && // Domain
|
||||
!whitelist.subdomains.some(subdomain => x.clientRequestHTTPHost.includes(subdomain)) && // Subdomains
|
||||
!whitelist.useragents.some(ua => x.userAgent.includes(ua)) && // User-agents
|
||||
!whitelist.endpoints.some(endpoint => x.clientRequestPath.includes(endpoint)) && // Endpoints
|
||||
!(/crawler|spider|bot/gi).test(x.useragent) && // Bots
|
||||
!whitelist.subdomains.some(subdomain => x.clientRequestHTTPHost?.includes(subdomain)) && // Subdomains
|
||||
!whitelist.userAgents.some(ua => x.userAgent?.includes(ua)) && // User-agents
|
||||
!whitelist.endpoints.some(endpoint => x.clientRequestPath?.includes(endpoint)) && // Endpoints
|
||||
!(/crawler|spider|bot/gi).test(x.userAgent) &&
|
||||
!x.sefinekAPI
|
||||
);
|
||||
|
||||
if (!reportedIPs.length) return;
|
||||
|
||||
const uniqueLogs = reportedIPs.reduce((acc, ip) => {
|
||||
if (acc.seen.has(ip.ip)) return acc;
|
||||
acc.seen.add(ip.ip);
|
||||
acc.logs.push(ip);
|
||||
return acc;
|
||||
}, { seen: new Set(), logs: [] }).logs;
|
||||
const seenIPs = new Set();
|
||||
const uniqueLogs = reportedIPs.filter(ip => {
|
||||
if (seenIPs.has(ip.ip)) return false;
|
||||
seenIPs.add(ip.ip);
|
||||
return true;
|
||||
});
|
||||
|
||||
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 {
|
||||
const res = await axios.post(API_URL, {
|
||||
|
|
@ -34,7 +35,7 @@ module.exports = async () => {
|
|||
rayId: ip.rayId,
|
||||
ip: ip.ip,
|
||||
endpoint: ip.endpoint,
|
||||
useragent: ip.useragent.replace(/"/g, ''),
|
||||
userAgent: ip.userAgent?.replace(/"/g, ''),
|
||||
action: ip.action,
|
||||
country: ip.country,
|
||||
timestamp: ip.timestamp,
|
||||
|
|
@ -45,8 +46,6 @@ module.exports = async () => {
|
|||
|
||||
uniqueLogs.forEach(ip => updateSefinekAPIInCSV(ip.rayId, true));
|
||||
} catch (err) {
|
||||
if (err.response?.data?.code !== 'NO_VALID_OR_UNIQUE_IPS') {
|
||||
log('error', `Failed to send logs to Sefinek API. Status: ${err.status}. Message: ${err.response?.data?.message || err.stack}`);
|
||||
}
|
||||
log('error', `Failed to send logs to Sefinek API. Status: ${err.response?.status}. Message: ${err.response?.data?.message || err.stack}`);
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue