timestamp

This commit is contained in:
Sefinek 2024-12-25 16:43:24 +01:00
parent e872525221
commit 2d57e66b0f

View file

@ -15,14 +15,16 @@ let fileOffset = 0;
const reportToAbuseIPDb = async (logData, categories, comment) => { const reportToAbuseIPDb = async (logData, categories, comment) => {
try { try {
const { data } = await axios.post('https://api.abuseipdb.com/api/v2/report', new URLSearchParams({ ip: logData.srcIp, categories, comment }), { const { data } = await axios.post('https://api.abuseipdb.com/api/v2/report', new URLSearchParams({
headers: { 'Key': ABUSEIPDB_API_KEY }, ip: logData.srcIp,
}); categories,
comment,
}), { headers: { 'Key': ABUSEIPDB_API_KEY } });
log(0, `Reported ${logData.srcIp} (${logData.dpt}/${logData.proto}); Categories ${categories}; Abuse: ${data.data.abuseConfidenceScore}%`); log(0, `Reported ${logData.srcIp} [${logData.dpt}/${logData.proto}]; ID: ${logData.id}; Categories ${categories}; Abuse: ${data.data.abuseConfidenceScore}%`);
return true; return true;
} catch (err) { } catch (err) {
log(2, `Failed to report ${logData.srcIp} (${logData.dpt}/${logData.proto}); ${err.message}\n${JSON.stringify(err.response.data?.errors || err.response.data)}`); log(2, `Failed to report ${logData.srcIp} [${logData.dpt}/${logData.proto}]; ID: ${logData.id}; ${err.message}\n${JSON.stringify(err.response.data?.errors || err.response.data)}`);
return false; return false;
} }
}; };
@ -30,8 +32,12 @@ const reportToAbuseIPDb = async (logData, categories, comment) => {
const processLogLine = async line => { const processLogLine = async line => {
if (!line.includes('[UFW BLOCK]')) return log(1, `Ignoring line: ${line}`); if (!line.includes('[UFW BLOCK]')) return log(1, `Ignoring line: ${line}`);
const oldTime = line.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[+-]\d{2}:\d{2})?/)?.[0];
const timestampMatch = line.match(/\[(\d+\.\d+)\]/);
const newTime = timestampMatch ? parseFloat(timestampMatch[1]) : null;
const logData = { const logData = {
timestamp: line.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[+-]\d{2}:\d{2})?/)?.[0] || null, timestampOld: oldTime || null,
timestampNew: newTime || null,
In: line.match(/IN=([\d.]+)/)?.[1] || null, In: line.match(/IN=([\d.]+)/)?.[1] || null,
Out: line.match(/OUT=([\d.]+)/)?.[1] || null, Out: line.match(/OUT=([\d.]+)/)?.[1] || null,
srcIp: line.match(/SRC=([\d.]+)/)?.[1] || null, srcIp: line.match(/SRC=([\d.]+)/)?.[1] || null,