show server config for admins

Signed-off-by: Simon Smith <simonsmith5521@gmail.com>

Simon Smith committed Oct 3, 2023 at 17:20 UTC eb8df307ecf87b5072618144b94ea3c393d44c64
2 files changed +30
meshuser.js
+8
@@ -5292,6 +5292,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5292 'serverclearerrorlog': serverCommandServerClearErrorLog,
5293 'serverconsole': serverCommandServerConsole,
5294 'servererrors': serverCommandServerErrors,
5295 + 'serverconfig': serverCommandServerConfig,
5296 'serverstats': serverCommandServerStats,
5297 'servertimelinestats': serverCommandServerTimelineStats,
5298 'serverupdate': serverCommandServerUpdate,
@@ -6504,6 +6505,13 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
6505 fs.readFile(parent.parent.getConfigFilePath('mesherrors.txt'), 'utf8', function (err, data) { obj.send({ action: 'servererrors', data: data }); });
6506 }
6507
6508 + function serverCommandServerConfig(command) {
6509 + // Load the server config
6510 + var configFilePath = common.joinPath(parent.parent.datapath, (parent.parent.args.configfile ? parent.parent.args.configfile : 'config.json'));
6511 + if (userHasSiteUpdate())
6512 + fs.readFile(configFilePath, 'utf8', function (err, data) { obj.send({ action: 'serverconfig', data: data }); });
6513 + }
6514 +
6515 function serverCommandServerStats(command) {
6516 // Only accept if the "My Server" tab is allowed for this domain
6517 if (domain.myserver === false) return;
views/default.handlebars
+22
@@ -574,6 +574,7 @@
574 <div id="p2ServerActionsGoogleBackup" style="display:none"><div class="p2AccountActions"><span id="p2ServerActionsGoogleBackupCheck" style="display:none"><strong>&#x2713;</strong></span></div><span><a href=# onclick="return server_setupGoogleDriveBackup()">Google Drive backup</a><br /></span></div>
575 <div id="p2ServerActionsVersion"><div class="p2AccountActions"><span style="display:none"><strong>&#x2713;</strong></span></div><a href=# onclick="return server_showVersionDlg()">Check server version</a></div>
576 <div id="p2ServerActionsErrors"><div class="p2AccountActions"><span style="display:none"><strong>&#x2713;</strong></span></div><a href=# onclick="return server_showErrorsDlg()">Show server error log</a></div>
577 + <div id="p2ServerActionsConfig"><div class="p2AccountActions"><span style="display:none"><strong>&#x2713;</strong></span></div><a href=# onclick="return server_showConfigDlg()">Show server config</a></div>
578 </div>
579 <br />
580 </div>
@@ -2157,6 +2158,7 @@
2158 QV('p2ServerActionsRestore', (siteRights & 4) && ((serverFeatures & 2) != 0));
2159 QV('p2ServerActionsVersion', (siteRights & 16) && ((serverFeatures & 4) != 0));
2160 QV('p2ServerActionsErrors', (siteRights & 16) && ((serverFeatures & 8) != 0));
2161 + QV('p2ServerActionsConfig', (siteRights & 16) && ((serverFeatures & 8) != 0));
2162 QV('MainMenuMyFiles', siteRights & 8);
2163 QV('LeftMenuMyFiles', siteRights & 8);
2164 if (((siteRights & 8) == 0) && (xxcurrentView == 5)) { setDialogMode(0); go(1); }
@@ -2755,6 +2757,18 @@
2757 }
2758 break;
2759 }
2760 + case 'serverconfig': {
2761 + if ((xxdialogMode == 2) && (xxdialogTag == 'MeshCentralServerConfig')) {
2762 + if (message.data == null) {
2763 + setDialogMode(2, "MeshCentral Server Config", 1, null, "Server has no config file.");
2764 + } else {
2765 + var x = '<div class="dialogText dialogTextLog"><pre id=d2ServerConfigPre style=overflow:auto>' + EscapeHtml(message.data) + '</pre></div>';
2766 + x += '<br /><div style=float:right><img src=images/link4.png height=10 width=10 title="' + "Download server config" + '" style=cursor:pointer onclick=d2CopyServerConfigToClip()></div>';
2767 + setDialogMode(2, "MeshCentral Server Config", 3, null, x);
2768 + }
2769 + }
2770 + break;
2771 + }
2772 case 'serverconsole': {
2773 p15consoleReceive('serverconsole', message.value);
2774 break;
@@ -12612,6 +12626,14 @@
12626 function server_showErrorsDlgEx() { meshserver.send({ action: 'serverclearerrorlog' }); }
12627 function d2CopyServerErrorsToClip() { saveAs(new Blob([Q('d2ServerErrorsLogPre').innerText], { type: 'application/octet-stream' }), "servererrors.txt"); }
12628
12629 + function server_showConfigDlg() {
12630 + if (xxdialogMode) return false;
12631 + setDialogMode(2, "MeshCentral Config", 1, null, "Loading...", 'MeshCentralServerConfig');
12632 + meshserver.send({ action: 'serverconfig' });
12633 + return false;
12634 + }
12635 + function d2CopyServerConfigToClip() { saveAs(new Blob([Q('d2ServerConfigPre').innerText], { type: 'application/octet-stream' }), "config.json"); }
12636 +
12637 //
12638 // MY MESHS
12639 //