Unlink scripts submodule and commit contents as normal directory
This commit is contained in:
1 parent
4f7dea111f
commit
6488b3ea85
48 files changed
+2876
-1
No files matched your search
@@ -0,0 +1,25 @@
|
||||
const fs = require('node:fs/promises');
|
||||
const path = require('node:path');
|
||||
const ipSanitizer = require('./ipSanitizer.js');
|
||||
const logger = require('../scripts/logger.js');
|
||||
const resolvePath = require('./pathResolver.js');
|
||||
const { LOG_IP_HISTORY_ENABLED, LOG_IP_HISTORY_DIR } = require('../config.js').MAIN;
|
||||
|
||||
const BASE_DIR = resolvePath(LOG_IP_HISTORY_DIR);
|
||||
|
||||
module.exports = async (ip, metadata = {}) => {
|
||||
if (!LOG_IP_HISTORY_ENABLED || !ip) return;
|
||||
|
||||
const { honeypot = 'unknown', comment } = metadata;
|
||||
const logEntry = `[${new Date().toISOString()}] ${ipSanitizer(comment)}\n`;
|
||||
|
||||
const ipDir = path.join(BASE_DIR, ip);
|
||||
const logFile = path.join(ipDir, `${honeypot.toUpperCase()}.txt`);
|
||||
|
||||
try {
|
||||
await fs.mkdir(ipDir, { recursive: true });
|
||||
await fs.appendFile(logFile, logEntry);
|
||||
} catch (err) {
|
||||
logger.error(`Failed to write IP log for ${ip}: ${err.message}`);
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user