REPORT_SCHEDULE

This commit is contained in:
Sefinek 2025-03-10 20:31:56 +01:00
parent 5da993d6a6
commit 8f6dfc03d9
4 changed files with 91 additions and 60 deletions

View file

@ -7,8 +7,8 @@ exports.CONFIG = {
}, },
CYCLES: { CYCLES: {
// Main interval (in minutes) of each cycle // Schedule for running cron jobs for reporting to AbuseIPDB.
CYCLE_INTERVAL: 120 * 60 * 1000, REPORT_SCHEDULE: '0 */2 * * *',
// The minimum time (in hours) that must pass after reporting an IP address before it can be reported again. // The minimum time (in hours) that must pass after reporting an IP address before it can be reported again.
// The required time is >= 15 minutes, according to AbuseIPDB API limits. // The required time is >= 15 minutes, according to AbuseIPDB API limits.
@ -19,7 +19,7 @@ exports.CONFIG = {
MAX_URL_LENGTH: 780, MAX_URL_LENGTH: 780,
// Additional delay (in milliseconds) after each successful IP report to avoid overloading the AbuseIPDB API. // Additional delay (in milliseconds) after each successful IP report to avoid overloading the AbuseIPDB API.
SUCCESS_COOLDOWN: 30, SUCCESS_COOLDOWN: 20,
// Interval for refreshing your IP address (in minutes). // Interval for refreshing your IP address (in minutes).
// This ensures that WAF violations originating from your IP address are not reported to AbuseIPDB. // This ensures that WAF violations originating from your IP address are not reported to AbuseIPDB.

View file

@ -1,3 +1,4 @@
const { CronJob } = require('cron');
const axios = require('./services/axios.js'); const axios = require('./services/axios.js');
const { CONFIG, GENERATE_COMMENT } = require('./config.js'); const { CONFIG, GENERATE_COMMENT } = require('./config.js');
const PAYLOAD = require('./services/payload.js'); const PAYLOAD = require('./services/payload.js');
@ -100,30 +101,15 @@ const reportIP = async (event, uri, country, hostname, endpoint, cycleErrorCount
} }
}; };
(async () => { let cycleId = 1;
log(0, 'Loading data, please wait...');
// Sefinek API const cron = async () => {
// await SefinekAPI();
if (CONFIG.SEFINEK_API.REPORT_TO_SEFIN_API && CONFIG.SEFINEK_API.INTERVAL && CONFIG.SEFINEK_API.SECRET_TOKEN) {
setInterval(SefinekAPI, CONFIG.SEFINEK_API.INTERVAL);
}
// Ready
process.send && process.send('ready');
// AbuseIPDB
let cycleId = 1;
while (true) {
const whitelist = await getFilters(); const whitelist = await getFilters();
log(0, `===================== Reporting Cycle No. ${cycleId} =====================`); log(0, `===================== Reporting Cycle No. ${cycleId} =====================`);
const blockedIPEvents = await fetchBlockedIPs(whitelist); const blockedIPEvents = await fetchBlockedIPs(whitelist);
if (!blockedIPEvents) { if (!blockedIPEvents) return log(1, 'No events fetched, skipping cycle...');
log(1, 'No events fetched, skipping cycle...');
continue;
}
const serverIP = fetchServerIP(); const serverIP = fetchServerIP();
if (!serverIP) log(1, `Server IP address is missing! Received: ${serverIP}`); if (!serverIP) log(1, `Server IP address is missing! Received: ${serverIP}`);
@ -166,8 +152,23 @@ const reportIP = async (event, uri, country, hostname, endpoint, cycleErrorCount
log(0, `- Other errors: ${cycleErrorCounts.otherErrors}`); log(0, `- Other errors: ${cycleErrorCounts.otherErrors}`);
log(0, '===================== End of Reporting Cycle ====================='); log(0, '===================== End of Reporting Cycle =====================');
log(0, `Waiting ${formatDelay(CONFIG.CYCLES.CYCLE_INTERVAL)} (${CONFIG.CYCLES.CYCLE_INTERVAL} ms)...`);
cycleId++; cycleId++;
await new Promise(resolve => setTimeout(resolve, CONFIG.CYCLES.CYCLE_INTERVAL)); await new Promise(resolve => setTimeout(resolve));
};
(async () => {
log(0, 'Loading data, please wait...');
// Sefinek API
// await SefinekAPI();
if (CONFIG.SEFINEK_API.REPORT_TO_SEFIN_API && CONFIG.SEFINEK_API.INTERVAL && CONFIG.SEFINEK_API.SECRET_TOKEN) {
setInterval(SefinekAPI, CONFIG.SEFINEK_API.INTERVAL);
} }
// Ready
process.send && process.send('ready');
// AbuseIPDB
new CronJob(CONFIG.CYCLES.REPORT_SCHEDULE, cron, null, true, 'UTC');
await cron();
})(); })();

29
package-lock.json generated
View file

@ -10,6 +10,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^1.8.2", "axios": "^1.8.2",
"cron": "^4.1.0",
"ipaddr.js": "^2.2.0" "ipaddr.js": "^2.2.0"
}, },
"devDependencies": { "devDependencies": {
@ -27,6 +28,12 @@
"node": "^18.18.0 || ^20.9.0 || >=21.1.0" "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
} }
}, },
"node_modules/@types/luxon": {
"version": "3.4.2",
"resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.4.2.tgz",
"integrity": "sha512-TifLZlFudklWlMBfhubvgqTXRzLDI5pCbGa4P8a3wPyUQSW+1xQ5eDsreP9DWHX3tjq1ke96uYG/nwundroWcA==",
"license": "MIT"
},
"node_modules/asynckit": { "node_modules/asynckit": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
@ -69,6 +76,19 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/cron": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/cron/-/cron-4.1.0.tgz",
"integrity": "sha512-wmcuXr2qP0UZStYgwruG6jC2AYSO9n5VMm2t93hmcEXEjWY3S2bsXe3sfGUrTs/uQ1AvRCrZ0Pp9Q032L/V9tw==",
"license": "MIT",
"dependencies": {
"@types/luxon": "~3.4.0",
"luxon": "~3.5.0"
},
"engines": {
"node": ">=18.x"
}
},
"node_modules/delayed-stream": { "node_modules/delayed-stream": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
@ -291,6 +311,15 @@
"node": ">= 10" "node": ">= 10"
} }
}, },
"node_modules/luxon": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/luxon/-/luxon-3.5.0.tgz",
"integrity": "sha512-rh+Zjr6DNfUYR3bPwJEnuwDdqMbxZW7LOQfUN4B54+Cl+0o5zaU9RJ6bcidfDtC1cWCZXQ+nvX8bf6bAji37QQ==",
"license": "MIT",
"engines": {
"node": ">=12"
}
},
"node_modules/math-intrinsics": { "node_modules/math-intrinsics": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",

View file

@ -20,6 +20,7 @@
}, },
"dependencies": { "dependencies": {
"axios": "^1.8.2", "axios": "^1.8.2",
"cron": "^4.1.0",
"ipaddr.js": "^2.2.0" "ipaddr.js": "^2.2.0"
}, },
"devDependencies": { "devDependencies": {