1.5.0: CronJob for Sefinek API

This commit is contained in:
Sefinek 2025-03-10 23:38:30 +01:00
parent 120c0e3b68
commit 8d8cbe9303
5 changed files with 11 additions and 12 deletions

View file

@ -34,8 +34,8 @@ exports.CONFIG = {
// Secret key for api.sefinek.net
SECRET_TOKEN: '',
// How often should the log (reported_ips.csv) be analyzed and sent to the Sefinek API? In hours.
INTERVAL: 60 * 60 * 1000, // Frequency for analyzing and submitting logs to the Sefinek API
// How often should the log (reported_ips.csv) be analyzed and sent to the Sefinek API?
REPORT_SCHEDULE: '0 */1 * * *',
},
};

View file

@ -160,9 +160,8 @@ const cron = 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);
if (CONFIG.SEFINEK_API.REPORT_TO_SEFIN_API && CONFIG.SEFINEK_API.SECRET_TOKEN && CONFIG.SEFINEK_API.REPORT_SCHEDULE) {
new CronJob(CONFIG.SEFINEK_API.REPORT_SCHEDULE, SefinekAPI, null, true, 'UTC');
}
// Ready

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "cf-waf-to-abuseipdb",
"version": "1.4.1",
"version": "1.5.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "cf-waf-to-abuseipdb",
"version": "1.4.1",
"version": "1.5.0",
"license": "MIT",
"dependencies": {
"axios": "^1.8.2",

View file

@ -1,6 +1,6 @@
{
"name": "cf-waf-to-abuseipdb",
"version": "1.4.1",
"version": "1.5.0",
"description": "Node.js script for automatically reporting incidents to AbuseIPDB using data obtained from Cloudflare WAF.",
"homepage": "https://github.com/sefinek/Cloudflare-WAF-To-AbuseIPDB",
"bugs": {

View file

@ -6,7 +6,7 @@ const { SEFINEK_API } = require('../config.js').CONFIG;
module.exports = async () => {
const reportedIPs = (readReportedIPs() || []).filter(x => x.status === 'REPORTED' && x.ip !== fetchServerIP() && !x.sefinekAPI);
if (!reportedIPs.length) return;
if (!reportedIPs.length) return log(0, 'Sefinek API: No data to report');
const seenIPs = new Set();
const uniqueLogs = reportedIPs.filter(ip => {
@ -15,7 +15,7 @@ module.exports = async () => {
return true;
});
if (!uniqueLogs.length) return log(0, 'No unique IPs to send to Sefinek API');
if (!uniqueLogs.length) return log(0, 'Sefinek API: No unique IPs to send');
try {
// http://127.0.0.1:4010/api/v2/cloudflare-waf-abuseipdb
@ -31,13 +31,13 @@ module.exports = async () => {
})),
}, { headers: { 'Authorization': SEFINEK_API.SECRET_TOKEN } });
log(0, `Successfully sent ${uniqueLogs.length} logs to Sefinek API! Status: ${res.status}`);
log(0, `Sefinek API: Successfully sent ${uniqueLogs.length} logs! Status: ${res.status}`);
uniqueLogs.forEach(ip => updateSefinekAPIInCSV(ip.rayId, true));
} catch (err) {
if (!err.response?.data?.message?.includes('No valid or unique')) {
const msg = err.response?.data?.message[0] || err.response?.data?.message || err.message;
log(2, `Failed to send logs to Sefinek API! Status: ${err.response?.status ?? 'Unknown'}; Message: ${typeof msg === 'object' ? JSON.stringify(msg) : msg}`);
log(2, `Sefinek API: Failed to send logs! Status: ${err.response?.status ?? 'Unknown'}; Message: ${typeof msg === 'object' ? JSON.stringify(msg) : msg}`);
}
}
};