Fixed web site no localstorage, MongoDB backup with URL.
Ylian Saint-Hilaire committed
Jan 29, 2020 at 10:31 UTC
f2961e3d42da26369521abb5149862c6a4af4331
3 files changed
+37
-27
agents/meshcore.js
+2
-2
@@ -1230,7 +1230,7 @@ function createMeshCore(agent) {
1230
var bash = fs.existsSync('/bin/bash') ? '/bin/bash' : false;
1231
var sh = fs.existsSync('/bin/sh') ? '/bin/sh' : false;
1232
var script = false;
1233
- if (this.httprequest.xoptions.script)
1233
+ if (this.httprequest.xoptions && this.httprequest.xoptions.script)
1234
{
1235
try
1236
{
@@ -1244,7 +1244,7 @@ function createMeshCore(agent) {
1244
}
1245
} catch (ex) { }
1246
}
1247
- var python = (this.httprequest.xoptions.python && fs.existsSync('/usr/bin/python')) ? '/usr/bin/python' : false;
1247
+ var python = (this.httprequest.xoptions && this.httprequest.xoptions.python && fs.existsSync('/usr/bin/python')) ? '/usr/bin/python' : false;
1248
var shell = bash || sh;
1249
1250
var env = { HISTCONTROL: 'ignoreboth', TERM: 'xterm' };
db.js
+3
-1
@@ -973,6 +973,7 @@ module.exports.CreateDB = function (parent, func) {
973
if (parent.config.settings.autobackup && parent.config.settings.autobackup.backuppath) { backupPath = parent.config.settings.autobackup.backuppath; }
974
try { parent.fs.mkdirSync(backupPath); } catch (e) { }
975
const dbname = (parent.args.mongodbname) ? (parent.args.mongodbname) : 'meshcentral';
976
+ const dburl = parent.args.mongodb;
977
const currentDate = new Date();
978
const fileSuffix = currentDate.getFullYear() + '-' + padNumber(currentDate.getMonth() + 1, 2) + '-' + padNumber(currentDate.getDate(), 2) + '-' + padNumber(currentDate.getHours(), 2) + '-' + padNumber(currentDate.getMinutes(), 2);
979
const newAutoBackupFile = 'meshcentral-autobackup-' + fileSuffix;
@@ -985,7 +986,8 @@ module.exports.CreateDB = function (parent, func) {
986
var mongoDumpPath = 'mongodump';
987
if (parent.config.settings.autobackup && parent.config.settings.autobackup.mongodumppath) { mongoDumpPath = parent.config.settings.autobackup.mongodumppath; }
988
const child_process = require('child_process');
988
- const cmd = '\"' + mongoDumpPath + '\" --db \"' + dbname + '\" --archive=\"' + newBackupPath + '.archive\"';
989
+ const cmd = '\"' + mongoDumpPath + '\" --db=\"' + dbname + '\" --archive=\"' + newBackupPath + '.archive\"';
990
+ if (dburl) { cmd = '\"' + mongoDumpPath + '\" --url=\"' + dburl + '\" --db=\"' + dbname + '\" --archive=\"' + newBackupPath + '.archive\"'; }
991
var backupProcess = child_process.exec(cmd, { cwd: backupPath }, function (error, stdout, stderr) {
992
try {
993
backupProcess = null;
views/default.handlebars
+32
-24
@@ -1114,7 +1114,7 @@
1114
var webState = '{{{webstate}}}';
1115
if (webState != '') { webState = JSON.parse(decodeURIComponent(webState)); }
1116
for (var i in webState) { localStorage.setItem(i, webState[i]); }
1117
- if (!webState.loctag) { delete localStorage.removeItem('loctag'); }
1117
+ if (!webState.loctag) { try { delete localStorage.removeItem('loctag'); } catch (ex) { } }
1118
1119
var args;
1120
var autoReconnect = true;
@@ -1221,6 +1221,7 @@
1221
1222
// Setup logout control
1223
var logoutControl = '';
1224
+ if (logoutControls)
1225
if (logoutControls.name != null) { logoutControl = format("Welcome {0}.", logoutControls.name); }
1226
if (logoutControls.logoutUrl != null) { logoutControl += format(' <a href=\"' + logoutControls.logoutUrl + '\" style="color:white">' + "Logout" + '</a>'); }
1227
if (args.hide & 1) { QH('logoutControlSpan2', logoutControl); } else { QH('logoutControlSpan', logoutControl); }
@@ -1274,9 +1275,11 @@
1275
setInterval(updateDeviceTimeline, 120000); // Check every 2 minutes
1276
1277
// Load desktop settings
1277
- var t = localStorage.getItem('desktopsettings');
1278
+ var t = null;
1279
+ try { t = localStorage.getItem('desktopsettings'); } catch (ex) {}
1280
if (t != null) { desktopsettings = JSON.parse(t); }
1279
- t = localStorage.getItem('multidesktopsettings');
1281
+ t = null;
1282
+ try { t = localStorage.getItem('multidesktopsettings'); } catch (ex) {}
1283
if (t != null) { multidesktopsettings = JSON.parse(t); }
1284
applyDesktopSettings();
1285
@@ -2198,22 +2201,24 @@
2201
switch (message.event.action) {
2202
case 'userWebState': {
2203
// New user web state, update the web page as needed
2201
- if (localStorage != null) {
2202
- var oldShowRealNames = localStorage.getItem('showRealNames');
2203
- var oldUiMode = localStorage.getItem('uiMode');
2204
- var oldSort = localStorage.getItem('sort');
2205
- var oldLoctag = localStorage.getItem('loctag');
2206
-
2207
- var webstate = JSON.parse(message.event.state);
2208
- for (var i in webstate) { localStorage.setItem(i, webstate[i]); }
2209
-
2210
- // Update the web page
2211
- if ((webstate.deskAspectRatio != null) && (webstate.deskAspectRatio != deskAspectRatio)) { deskAspectRatio = webstate.deskAspectRatio; deskAdjust(); }
2212
- if ((webstate.showRealNames != null) && (webstate.showRealNames != oldShowRealNames)) { showRealNames = Q('RealNameCheckBox').checked = (webstate.showRealNames == '1'); masterUpdate(6); }
2213
- if ((webstate.uiMode != null) && (webstate.uiMode != oldUiMode)) { userInterfaceSelectMenu(parseInt(webstate.uiMode)); }
2214
- if ((webstate.sort != null) && (webstate.sort != oldSort)) { document.getElementById('sortselect').selectedIndex = sort = parseInt(webstate.sort); masterUpdate(6); }
2215
- if ((webstate.loctag != null) && (webstate.loctag != oldLoctag)) { if (webstate.loctag != null) { args.locale = webstate.loctag; } else { delete args.locale; } masterUpdate(0xFFFFFFFF); }
2216
- }
2204
+ try {
2205
+ if (localStorage != null) {
2206
+ var oldShowRealNames = localStorage.getItem('showRealNames');
2207
+ var oldUiMode = localStorage.getItem('uiMode');
2208
+ var oldSort = localStorage.getItem('sort');
2209
+ var oldLoctag = localStorage.getItem('loctag');
2210
+
2211
+ var webstate = JSON.parse(message.event.state);
2212
+ for (var i in webstate) { localStorage.setItem(i, webstate[i]); }
2213
+
2214
+ // Update the web page
2215
+ if ((webstate.deskAspectRatio != null) && (webstate.deskAspectRatio != deskAspectRatio)) { deskAspectRatio = webstate.deskAspectRatio; deskAdjust(); }
2216
+ if ((webstate.showRealNames != null) && (webstate.showRealNames != oldShowRealNames)) { showRealNames = Q('RealNameCheckBox').checked = (webstate.showRealNames == '1'); masterUpdate(6); }
2217
+ if ((webstate.uiMode != null) && (webstate.uiMode != oldUiMode)) { userInterfaceSelectMenu(parseInt(webstate.uiMode)); }
2218
+ if ((webstate.sort != null) && (webstate.sort != oldSort)) { document.getElementById('sortselect').selectedIndex = sort = parseInt(webstate.sort); masterUpdate(6); }
2219
+ if ((webstate.loctag != null) && (webstate.loctag != oldLoctag)) { if (webstate.loctag != null) { args.locale = webstate.loctag; } else { delete args.locale; } masterUpdate(0xFFFFFFFF); }
2220
+ }
2221
+ } catch (ex) {}
2222
break;
2223
}
2224
case 'servertimelinestats': { addServerTimelineStats(message.event.data); break; }
@@ -10724,9 +10729,11 @@
10729
function putstore(name, val) {
10730
try {
10731
if ((typeof (localStorage) === 'undefined') || (localStorage.getItem(name) == val)) return;
10727
- if (val == null) { localStorage.removeItem(name); } else { localStorage.setItem(name, val); } } catch (e) { }
10728
- if (name[0] != '_') {
10729
- var s = {};
10732
+ if (val == null) { localStorage.removeItem(name); } else { localStorage.setItem(name, val); }
10733
+ } catch (e) { }
10734
+ if (name[0] != '_') {
10735
+ var s = {};
10736
+ try {
10737
for (var i = 0, len = localStorage.length; i < len; ++i) {
10738
var k = localStorage.key(i);
10739
if (k[0] != '_') {
@@ -10734,9 +10741,10 @@
10741
if ((k != 'desktopsettings') && (typeof s[k] == 'string') && (s[k].length > 64)) { delete s[k]; }
10742
}
10743
}
10737
- meshserver.send({ action: 'userWebState', state: JSON.stringify(s) });
10738
- }
10744
+ } catch (ex) {}
10745
+ meshserver.send({ action: 'userWebState', state: JSON.stringify(s) });
10746
}
10747
+ }
10748
function getstore(name, val) { try { if (typeof (localStorage) === 'undefined') return val; var v = localStorage.getItem(name); if ((v == null) || (v == null)) return val; return v; } catch (e) { return val; } }
10749
function addLink(x, f) { return '<span tabindex=0 style=cursor:pointer;text-decoration:none onclick=\'' + f + '\' onkeypress=\"if (event.key==\'Enter\') {' + f + '} \">' + x + ' <img class=hoverButton src=images/link5.png></span>'; }
10750
function addLinkConditional(x, f, c) { if (c) return addLink(x, f); return x; }