Added syslogauth support.

Ylian Saint-Hilaire committed Apr 19, 2020 at 22:37 UTC c398d76e3992c8e1036d1f6e8e28717688576a3d
1 file changed +18 -7
meshcentral.js
+18 -7
@@ -606,9 +606,10 @@ function CreateMeshCentralServer(config, args) {
606 //wincmd.list(function (svc) { console.log(svc); }, true);
607
608 // Setup syslog support
609 - if ((require('os').platform() != 'win32') && ((config.settings.syslog != null) || (config.settings.syslogjson != null))) {
609 + if ((require('os').platform() != 'win32') && ((config.settings.syslog != null) || (config.settings.syslogjson != null) || (config.settings.syslogauth != null))) {
610 if (config.settings.syslog === true) { config.settings.syslog = 'meshcentral'; }
611 if (config.settings.syslogjson === true) { config.settings.syslogjson = 'meshcentral-json'; }
612 + if (config.settings.syslogauth === true) { config.settings.syslogauth = 'meshcentral-auth'; }
613 if (typeof config.settings.syslog == 'string') {
614 obj.syslog = require('modern-syslog');
615 console.log('Starting ' + config.settings.syslog + ' syslog.');
@@ -621,6 +622,12 @@ function CreateMeshCentralServer(config, args) {
622 obj.syslogjson.init(config.settings.syslogjson, obj.syslogjson.LOG_PID | obj.syslogjson.LOG_ODELAY, obj.syslogjson.LOG_LOCAL0);
623 obj.syslogjson.log(obj.syslogjson.LOG_INFO, "MeshCentral v" + getCurrentVerion() + " Server Start");
624 }
625 + if (typeof config.settings.syslogauth == 'string') {
626 + obj.syslogauth = require('modern-syslog');
627 + console.log('Starting ' + config.settings.syslogauth + ' auth syslog.');
628 + obj.syslogauth.init(config.settings.syslogauth, obj.syslogauth.LOG_PID | obj.syslogauth.LOG_ODELAY, obj.syslogauth.LOG_LOCAL0);
629 + obj.syslogauth.log(obj.syslogauth.LOG_INFO, "MeshCentral v" + getCurrentVerion() + " Server Start");
630 + }
631 }
632
633 // Check top level configuration for any unreconized values
@@ -2311,12 +2318,16 @@ function CreateMeshCentralServer(config, args) {
2318 obj.addServerWarning = function(msg, print) { serverWarnings.push(msg); if (print !== false) { console.log("WARNING: " + msg); } }
2319
2320 // auth.log functions
2314 - obj.authLog = function(server, msg) {
2315 - if (obj.authlog == null) return;
2316 - var d = new Date();
2317 - var month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];
2318 - var 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');
2319 - obj.fs.write(obj.authlog, msg, function (err, written, string) { });
2321 + obj.authLog = function (server, msg) {
2322 + if (typeof msg != 'string') return;
2323 + if (obj.syslogauth) { try { obj.syslogauth.log(obj.syslogauth.LOG_INFO, msg); } catch (ex) { } }
2324 + if (obj.authlog != null) { // Write authlog to file
2325 + try {
2326 + var d = new Date(), month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];
2327 + var 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');
2328 + obj.fs.write(obj.authlog, msg, function (err, written, string) { });
2329 + } catch (ex) { }
2330 + }
2331 }
2332
2333 // Return the path of a file into the meshcentral-data path