srcIp === getServerIP()
This commit is contained in:
parent
e1bfd289fd
commit
4df9c9c4be
5 changed files with 39 additions and 7 deletions
|
|
@ -2,25 +2,25 @@ exports.MAIN = {
|
|||
// Server
|
||||
UFW_FILE: '/var/log/ufw.log',
|
||||
CACHE_FILE: '/tmp/ufw-abuseipdb-reporter.cache',
|
||||
SERVER_ID: null,
|
||||
SERVER_ID: null, // The server name that will be visible in the reports. If you don't want to define it, leave the value as null.
|
||||
|
||||
// Reporting
|
||||
ABUSEIPDB_API_KEY: '',
|
||||
REPORT_INTERVAL: 12 * 60 * 60 * 1000, // 12h
|
||||
|
||||
// Project
|
||||
GITHUB_REPO: 'https://github.com/sefinek/UFW-AbuseIPDB-Reporter',
|
||||
GITHUB_REPO: 'https://github.com/sefinek/UFW-AbuseIPDB-Reporter', // If you are using a fork, provide the link to the forked repository here.
|
||||
};
|
||||
|
||||
exports.REPORT_COMMENT = (timestamp, srcIp, dstIp, proto, spt, dpt, ttl, len, tos, serverName) => {
|
||||
return `Blocked by UFW ${serverName ? `on ${serverName} ` : ''}[${dpt}/${proto?.toLowerCase()}]
|
||||
Source port: ${spt}
|
||||
Source port: ${spt || 'N/A'}
|
||||
TTL: ${ttl || 'N/A'}
|
||||
Packet length: ${len || 'N/A'}
|
||||
TOS: ${tos || 'N/A'}
|
||||
|
||||
This report (for ${srcIp}) was generated by:
|
||||
https://github.com/sefinek/UFW-AbuseIPDB-Reporter`; // Please do not remove the URL to the repository of this script. I would be really grateful. 💙
|
||||
https://github.com/sefinek/UFW-AbuseIPDB-Reporter`; // Please do not remove this URL; I would be very grateful! Thank you. 💙
|
||||
};
|
||||
|
||||
// See: https://www.abuseipdb.com/categories
|
||||
|
|
|
|||
10
index.js
10
index.js
|
|
@ -1,9 +1,10 @@
|
|||
const fs = require('node:fs');
|
||||
const chokidar = require('chokidar');
|
||||
const isLocalIP = require('./utils/isLocalIP.js');
|
||||
const { reportedIPs, loadReportedIPs, saveReportedIPs, isIPReportedRecently, markIPAsReported } = require('./utils/cache.js');
|
||||
const isLocalIP = require('./services/isLocalIP.js');
|
||||
const { reportedIPs, loadReportedIPs, saveReportedIPs, isIPReportedRecently, markIPAsReported } = require('./services/cache.js');
|
||||
const log = require('./utils/log.js');
|
||||
const axios = require('./services/axios.js');
|
||||
const getServerIP = require('./services/serverIp.js');
|
||||
const config = require('./config.js');
|
||||
const { version } = require('./package.json');
|
||||
const { UFW_FILE, ABUSEIPDB_API_KEY, SERVER_ID, GITHUB_REPO } = config.MAIN;
|
||||
|
|
@ -45,6 +46,11 @@ const processLogLine = async line => {
|
|||
return;
|
||||
}
|
||||
|
||||
if (srcIp === getServerIP()) {
|
||||
log(0, 'Ignoring own IP');
|
||||
return;
|
||||
}
|
||||
|
||||
if (isLocalIP(srcIp)) {
|
||||
log(0, `Ignoring local/private IP: ${srcIp}`);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const fs = require('node:fs');
|
||||
const { CACHE_FILE, REPORT_INTERVAL } = require('../config.js').MAIN;
|
||||
const log = require('./log.js');
|
||||
const log = require('../utils/log.js');
|
||||
|
||||
const reportedIPs = new Map();
|
||||
|
||||
26
services/serverIp.js
Normal file
26
services/serverIp.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
const axios = require('./axios.js');
|
||||
|
||||
let address = null;
|
||||
|
||||
const fetchIPAddress = async () => {
|
||||
if (address) return;
|
||||
|
||||
try {
|
||||
const { data } = await axios.get('https://api.sefinek.net/api/v2/ip');
|
||||
if (data?.success && data?.message) {
|
||||
address = data.message;
|
||||
} else {
|
||||
setTimeout(fetchIPAddress, 20 * 1000);
|
||||
}
|
||||
} catch {
|
||||
setTimeout(fetchIPAddress, 25 * 1000);
|
||||
}
|
||||
};
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
(async () => fetchIPAddress())();
|
||||
} else {
|
||||
address = '::ffff:127.0.0.1';
|
||||
}
|
||||
|
||||
module.exports = () => address;
|
||||
Loading…
Add table
Reference in a new issue