Files
UFW-AbuseIPDB-Reporter/scripts/ipSanitizer.js
T

16 lines
450 B
JavaScript

const { getServerIPs } = require('./services/ipFetcher.js');
let ipPattern = null;
const buildPattern = () => {
const ips = getServerIPs();
if (!ips.length) return null;
const escaped = ips.map(i => i.replace(/[.:\\[\](){}^$*+?|]/g, '\\$&'));
return new RegExp(escaped.join('|'), 'g');
};
module.exports = str => {
if (ipPattern === null) ipPattern = buildPattern() || false;
return ipPattern ? str.replace(ipPattern, '[SOME-IP]') : str;
};