add some log options, might make a viewer when i get more samples

This commit is contained in:
zefie
2025-08-10 22:41:31 -04:00
parent 7fe762d3bd
commit d450aa6822
3 changed files with 78 additions and 5 deletions

View File

@@ -1,10 +1,10 @@
var minisrv_service_file = true;
const minisrv_service_file = true;
// write posted log data to disk. should be decrypted by this point (if it was encrypted) if the crypto stream didn't break
request_is_async = true;
data = '';
var fullpath = __dirname + "/ServiceLogPost/" + Math.floor(new Date().getTime() / 1000) + "_" + request_headers.query.type;
const fullpath = __dirname + "/ServiceLogPost/" + Math.floor(new Date().getTime() / 1000) + "_" + request_headers.query.type;
if (socket.ssid) fullpath += "_" + socket.ssid;
fullpath += ".txt";
@@ -23,9 +23,47 @@ Content-length: 0`;
var logdata_outstring_hex = Buffer.from(logdata_outstring, 'utf8').toString('hex');
logdata_outstring_hex += request_headers.post_data.toString(CryptoJS.enc.Hex);
if (minisrv_config.services[service_name].write_logs_to_disk) {
fs.writeFile(fullpath, logdata_outstring_hex, "Hex", function () {
if (!minisrv_config.config.debug_flags.quiet) console.log(" * Wrote POST log data from", wtvshared.filterSSID(socket.ssid), "for", socket.id);
if (minisrv_config.services[service_name].dont_save_chat_logs && request_headers.query.type === 'chat') {
sendToClient(socket, headers, data);
} else {
fs.writeFile(fullpath, logdata_outstring_hex, "Hex", function () {
if (!minisrv_config.config.debug_flags.quiet) console.log(" * Wrote POST log data from", wtvshared.filterSSID(socket.ssid), "for", socket.id);
sendToClient(socket, headers, data);
});
}
fs.readdir(__dirname + "/ServiceLogPost/", function (err, files) {
if (err) {
if (!minisrv_config.config.debug_flags.quiet) console.error("Error reading log directory:", err);
return;
}
var ssid = socket.ssid ? socket.ssid.toString() : '';
var count = files.filter(function (file) {
return ssid && file.includes(ssid);
}).length;
if (count > minisrv_config.services[service_name].max_logs_per_ssid) {
var ssidFiles = files
.filter(function (file) {
return ssid && file.includes(ssid);
})
.map(function (file) {
return {
name: file,
time: fs.statSync(__dirname + "/ServiceLogPost/" + file).mtime.getTime()
};
})
.sort(function (a, b) {
return a.time - b.time;
});
if (ssidFiles.length > 0) {
var oldestFile = ssidFiles[0].name;
fs.unlink(__dirname + "/ServiceLogPost/" + oldestFile, function (err) {
if (err && !minisrv_config.config.debug_flags.quiet) {
console.error("Error deleting oldest log file:", err);
}
});
}
}
});
} else {
sendToClient(socket, headers, data);

View File

@@ -0,0 +1,33 @@
const minisrv_service_file = true;
function getSortedLogFiles(ssid) {
const logDir = path.join(__dirname, './ServiceLogPost');
const files = fs.readdirSync(logDir)
.filter(file => file.endsWith('.txt') && file.includes(ssid))
.map(file => ({
name: file,
time: fs.statSync(path.join(logDir, file)).mtime.getTime()
}))
.sort((a, b) => b.time - a.time)
.map(file => file.name);
return files;
}
// Example usage
const ssid = socket.ssid; // Replace with the actual SSID
const sortedFiles = getSortedLogFiles(ssid);
console.log(sortedFiles);
const notImplementedAlert = new clientShowAlert({
'image': minisrv_config.config.service_logo,
'message': "This feature is not available.",
'buttonlabel1': "Okay",
'buttonaction1': "client:donothing",
'noback': true,
}).getURL();
headers = `300 OK
Content-type: text/html
Location: ${notImplementedAlert}
`

View File

@@ -242,7 +242,9 @@
// wtv-log
"port": 1609,
"connections": 1,
"write_logs_to_disk": false // set this to true to save logs to the error_log_file set above
"write_logs_to_disk": true, // set this to false to not save logs the ServiceLogPost folder
"dont_save_chat_logs": true, // They just take up space unless you want to monitor your user's joins and disconnects, doesn't log messages either way
"max_logs_per_ssid": 50
},
"wtv-favorite": {
// wtv-favorite