1.5.0: CronJob for Sefinek API
This commit is contained in:
parent
120c0e3b68
commit
8d8cbe9303
5 changed files with 11 additions and 12 deletions
|
|
@ -34,8 +34,8 @@ exports.CONFIG = {
|
||||||
// Secret key for api.sefinek.net
|
// Secret key for api.sefinek.net
|
||||||
SECRET_TOKEN: '',
|
SECRET_TOKEN: '',
|
||||||
|
|
||||||
// How often should the log (reported_ips.csv) be analyzed and sent to the Sefinek API? In hours.
|
// How often should the log (reported_ips.csv) be analyzed and sent to the Sefinek API?
|
||||||
INTERVAL: 60 * 60 * 1000, // Frequency for analyzing and submitting logs to the Sefinek API
|
REPORT_SCHEDULE: '0 */1 * * *',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
5
index.js
5
index.js
|
|
@ -160,9 +160,8 @@ const cron = async () => {
|
||||||
log(0, 'Loading data, please wait...');
|
log(0, 'Loading data, please wait...');
|
||||||
|
|
||||||
// Sefinek API
|
// Sefinek API
|
||||||
// await SefinekAPI();
|
if (CONFIG.SEFINEK_API.REPORT_TO_SEFIN_API && CONFIG.SEFINEK_API.SECRET_TOKEN && CONFIG.SEFINEK_API.REPORT_SCHEDULE) {
|
||||||
if (CONFIG.SEFINEK_API.REPORT_TO_SEFIN_API && CONFIG.SEFINEK_API.INTERVAL && CONFIG.SEFINEK_API.SECRET_TOKEN) {
|
new CronJob(CONFIG.SEFINEK_API.REPORT_SCHEDULE, SefinekAPI, null, true, 'UTC');
|
||||||
setInterval(SefinekAPI, CONFIG.SEFINEK_API.INTERVAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ready
|
// Ready
|
||||||
|
|
|
||||||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "cf-waf-to-abuseipdb",
|
"name": "cf-waf-to-abuseipdb",
|
||||||
"version": "1.4.1",
|
"version": "1.5.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "cf-waf-to-abuseipdb",
|
"name": "cf-waf-to-abuseipdb",
|
||||||
"version": "1.4.1",
|
"version": "1.5.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.8.2",
|
"axios": "^1.8.2",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "cf-waf-to-abuseipdb",
|
"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.",
|
"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",
|
"homepage": "https://github.com/sefinek/Cloudflare-WAF-To-AbuseIPDB",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ const { SEFINEK_API } = require('../config.js').CONFIG;
|
||||||
|
|
||||||
module.exports = async () => {
|
module.exports = async () => {
|
||||||
const reportedIPs = (readReportedIPs() || []).filter(x => x.status === 'REPORTED' && x.ip !== fetchServerIP() && !x.sefinekAPI);
|
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 seenIPs = new Set();
|
||||||
const uniqueLogs = reportedIPs.filter(ip => {
|
const uniqueLogs = reportedIPs.filter(ip => {
|
||||||
|
|
@ -15,7 +15,7 @@ module.exports = async () => {
|
||||||
return true;
|
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 {
|
try {
|
||||||
// http://127.0.0.1:4010/api/v2/cloudflare-waf-abuseipdb
|
// http://127.0.0.1:4010/api/v2/cloudflare-waf-abuseipdb
|
||||||
|
|
@ -31,13 +31,13 @@ module.exports = async () => {
|
||||||
})),
|
})),
|
||||||
}, { headers: { 'Authorization': SEFINEK_API.SECRET_TOKEN } });
|
}, { 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));
|
uniqueLogs.forEach(ip => updateSefinekAPIInCSV(ip.rayId, true));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!err.response?.data?.message?.includes('No valid or unique')) {
|
if (!err.response?.data?.message?.includes('No valid or unique')) {
|
||||||
const msg = err.response?.data?.message[0] || err.response?.data?.message || err.message;
|
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}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Loading…
Add table
Reference in a new issue