mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-03-09 15:40:18 +00:00
Improved user authentication log and added 'authlog' tracing.
This commit is contained in:
parent
2689f4e22a
commit
49e04bd454
3 changed files with 38 additions and 30 deletions
|
@ -739,7 +739,6 @@ function CreateMeshCentralServer(config, args) {
|
|||
obj.syslogjson.log(obj.syslogjson.LOG_INFO, "MeshCentral v" + getCurrentVersion() + " Server Start");
|
||||
}
|
||||
if (typeof config.settings.syslogauth == 'string') {
|
||||
obj.authlog = true;
|
||||
obj.syslogauth = require('modern-syslog');
|
||||
console.log('Starting ' + config.settings.syslogauth + ' auth syslog.');
|
||||
obj.syslogauth.init(config.settings.syslogauth, obj.syslogauth.LOG_PID | obj.syslogauth.LOG_ODELAY, obj.syslogauth.LOG_LOCAL0);
|
||||
|
@ -1231,7 +1230,7 @@ function CreateMeshCentralServer(config, args) {
|
|||
// Linux format /var/log/auth.log
|
||||
if (obj.config.settings.authlog != null) {
|
||||
obj.fs.open(obj.config.settings.authlog, 'a', function (err, fd) {
|
||||
if (err == null) { obj.authlogfile = fd; obj.authlog = true; } else { console.log('ERROR: Unable to open: ' + obj.config.settings.authlog); }
|
||||
if (err == null) { obj.authlogfile = fd; } else { console.log('ERROR: Unable to open: ' + obj.config.settings.authlog); }
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -3642,14 +3641,20 @@ function CreateMeshCentralServer(config, args) {
|
|||
obj.addServerWarning = function (msg, id, args, print) { serverWarnings.push({ msg: msg, id: id, args: args }); if (print !== false) { console.log("WARNING: " + msg); } }
|
||||
|
||||
// auth.log functions
|
||||
obj.authLog = function (server, msg) {
|
||||
obj.authLog = function (server, msg, args) {
|
||||
if (typeof msg != 'string') return;
|
||||
if (obj.syslogauth != null) { try { obj.syslogauth.log(obj.syslogauth.LOG_INFO, msg); } catch (ex) { } }
|
||||
var str = msg;
|
||||
if (args != null) {
|
||||
if (typeof args.sessionid == 'string') { str += ', SessionID: ' + args.sessionid; }
|
||||
if (typeof args.useragent == 'string') { const userAgentInfo = obj.webserver.getUserAgentInfo(args.useragent); str += ', Browser: ' + userAgentInfo.browserStr + ', OS: ' + userAgentInfo.osStr; }
|
||||
}
|
||||
obj.debug('authlog', str);
|
||||
if (obj.syslogauth != null) { try { obj.syslogauth.log(obj.syslogauth.LOG_INFO, str); } catch (ex) { } }
|
||||
if (obj.authlogfile != null) { // Write authlog to file
|
||||
try {
|
||||
const d = new Date(), month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];
|
||||
msg = month + ' ' + d.getDate() + ' ' + obj.common.zeroPad(d.getHours(), 2) + ':' + obj.common.zeroPad(d.getMinutes(), 2) + ':' + d.getSeconds() + ' meshcentral ' + server + '[' + process.pid + ']: ' + msg + ((obj.platform == 'win32') ? '\r\n' : '\n');
|
||||
obj.fs.write(obj.authlogfile, msg, function (err, written, string) { });
|
||||
obj.fs.write(obj.authlogfile, str, function (err, written, string) { });
|
||||
} catch (ex) { console.log(ex); }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue