Fixed web site no localstorage, MongoDB backup with URL.

This commit is contained in:
Ylian Saint-Hilaire 2020-01-29 10:31:58 -08:00
parent e9ebb8aa20
commit 90b060016c
3 changed files with 35 additions and 25 deletions

View File

@ -1230,7 +1230,7 @@ function createMeshCore(agent) {
var bash = fs.existsSync('/bin/bash') ? '/bin/bash' : false; var bash = fs.existsSync('/bin/bash') ? '/bin/bash' : false;
var sh = fs.existsSync('/bin/sh') ? '/bin/sh' : false; var sh = fs.existsSync('/bin/sh') ? '/bin/sh' : false;
var script = false; var script = false;
if (this.httprequest.xoptions.script) if (this.httprequest.xoptions && this.httprequest.xoptions.script)
{ {
try try
{ {
@ -1244,7 +1244,7 @@ function createMeshCore(agent) {
} }
} catch (ex) { } } catch (ex) { }
} }
var python = (this.httprequest.xoptions.python && fs.existsSync('/usr/bin/python')) ? '/usr/bin/python' : false; var python = (this.httprequest.xoptions && this.httprequest.xoptions.python && fs.existsSync('/usr/bin/python')) ? '/usr/bin/python' : false;
var shell = bash || sh; var shell = bash || sh;
var env = { HISTCONTROL: 'ignoreboth', TERM: 'xterm' }; var env = { HISTCONTROL: 'ignoreboth', TERM: 'xterm' };

4
db.js
View File

@ -973,6 +973,7 @@ module.exports.CreateDB = function (parent, func) {
if (parent.config.settings.autobackup && parent.config.settings.autobackup.backuppath) { backupPath = parent.config.settings.autobackup.backuppath; } if (parent.config.settings.autobackup && parent.config.settings.autobackup.backuppath) { backupPath = parent.config.settings.autobackup.backuppath; }
try { parent.fs.mkdirSync(backupPath); } catch (e) { } try { parent.fs.mkdirSync(backupPath); } catch (e) { }
const dbname = (parent.args.mongodbname) ? (parent.args.mongodbname) : 'meshcentral'; const dbname = (parent.args.mongodbname) ? (parent.args.mongodbname) : 'meshcentral';
const dburl = parent.args.mongodb;
const currentDate = new Date(); const currentDate = new Date();
const fileSuffix = currentDate.getFullYear() + '-' + padNumber(currentDate.getMonth() + 1, 2) + '-' + padNumber(currentDate.getDate(), 2) + '-' + padNumber(currentDate.getHours(), 2) + '-' + padNumber(currentDate.getMinutes(), 2); const fileSuffix = currentDate.getFullYear() + '-' + padNumber(currentDate.getMonth() + 1, 2) + '-' + padNumber(currentDate.getDate(), 2) + '-' + padNumber(currentDate.getHours(), 2) + '-' + padNumber(currentDate.getMinutes(), 2);
const newAutoBackupFile = 'meshcentral-autobackup-' + fileSuffix; const newAutoBackupFile = 'meshcentral-autobackup-' + fileSuffix;
@ -985,7 +986,8 @@ module.exports.CreateDB = function (parent, func) {
var mongoDumpPath = 'mongodump'; var mongoDumpPath = 'mongodump';
if (parent.config.settings.autobackup && parent.config.settings.autobackup.mongodumppath) { mongoDumpPath = parent.config.settings.autobackup.mongodumppath; } if (parent.config.settings.autobackup && parent.config.settings.autobackup.mongodumppath) { mongoDumpPath = parent.config.settings.autobackup.mongodumppath; }
const child_process = require('child_process'); const child_process = require('child_process');
const cmd = '\"' + mongoDumpPath + '\" --db \"' + dbname + '\" --archive=\"' + newBackupPath + '.archive\"'; const cmd = '\"' + mongoDumpPath + '\" --db=\"' + dbname + '\" --archive=\"' + newBackupPath + '.archive\"';
if (dburl) { cmd = '\"' + mongoDumpPath + '\" --url=\"' + dburl + '\" --db=\"' + dbname + '\" --archive=\"' + newBackupPath + '.archive\"'; }
var backupProcess = child_process.exec(cmd, { cwd: backupPath }, function (error, stdout, stderr) { var backupProcess = child_process.exec(cmd, { cwd: backupPath }, function (error, stdout, stderr) {
try { try {
backupProcess = null; backupProcess = null;

View File

@ -1114,7 +1114,7 @@
var webState = '{{{webstate}}}'; var webState = '{{{webstate}}}';
if (webState != '') { webState = JSON.parse(decodeURIComponent(webState)); } if (webState != '') { webState = JSON.parse(decodeURIComponent(webState)); }
for (var i in webState) { localStorage.setItem(i, webState[i]); } for (var i in webState) { localStorage.setItem(i, webState[i]); }
if (!webState.loctag) { delete localStorage.removeItem('loctag'); } if (!webState.loctag) { try { delete localStorage.removeItem('loctag'); } catch (ex) { } }
var args; var args;
var autoReconnect = true; var autoReconnect = true;
@ -1221,6 +1221,7 @@
// Setup logout control // Setup logout control
var logoutControl = ''; var logoutControl = '';
if (logoutControls)
if (logoutControls.name != null) { logoutControl = format("Welcome {0}.", logoutControls.name); } if (logoutControls.name != null) { logoutControl = format("Welcome {0}.", logoutControls.name); }
if (logoutControls.logoutUrl != null) { logoutControl += format(' <a href=\"' + logoutControls.logoutUrl + '\" style="color:white">' + "Logout" + '</a>'); } if (logoutControls.logoutUrl != null) { logoutControl += format(' <a href=\"' + logoutControls.logoutUrl + '\" style="color:white">' + "Logout" + '</a>'); }
if (args.hide & 1) { QH('logoutControlSpan2', logoutControl); } else { QH('logoutControlSpan', logoutControl); } if (args.hide & 1) { QH('logoutControlSpan2', logoutControl); } else { QH('logoutControlSpan', logoutControl); }
@ -1274,9 +1275,11 @@
setInterval(updateDeviceTimeline, 120000); // Check every 2 minutes setInterval(updateDeviceTimeline, 120000); // Check every 2 minutes
// Load desktop settings // Load desktop settings
var t = localStorage.getItem('desktopsettings'); var t = null;
try { t = localStorage.getItem('desktopsettings'); } catch (ex) {}
if (t != null) { desktopsettings = JSON.parse(t); } if (t != null) { desktopsettings = JSON.parse(t); }
t = localStorage.getItem('multidesktopsettings'); t = null;
try { t = localStorage.getItem('multidesktopsettings'); } catch (ex) {}
if (t != null) { multidesktopsettings = JSON.parse(t); } if (t != null) { multidesktopsettings = JSON.parse(t); }
applyDesktopSettings(); applyDesktopSettings();
@ -2198,22 +2201,24 @@
switch (message.event.action) { switch (message.event.action) {
case 'userWebState': { case 'userWebState': {
// New user web state, update the web page as needed // New user web state, update the web page as needed
if (localStorage != null) { try {
var oldShowRealNames = localStorage.getItem('showRealNames'); if (localStorage != null) {
var oldUiMode = localStorage.getItem('uiMode'); var oldShowRealNames = localStorage.getItem('showRealNames');
var oldSort = localStorage.getItem('sort'); var oldUiMode = localStorage.getItem('uiMode');
var oldLoctag = localStorage.getItem('loctag'); var oldSort = localStorage.getItem('sort');
var oldLoctag = localStorage.getItem('loctag');
var webstate = JSON.parse(message.event.state); var webstate = JSON.parse(message.event.state);
for (var i in webstate) { localStorage.setItem(i, webstate[i]); } for (var i in webstate) { localStorage.setItem(i, webstate[i]); }
// Update the web page // Update the web page
if ((webstate.deskAspectRatio != null) && (webstate.deskAspectRatio != deskAspectRatio)) { deskAspectRatio = webstate.deskAspectRatio; deskAdjust(); } if ((webstate.deskAspectRatio != null) && (webstate.deskAspectRatio != deskAspectRatio)) { deskAspectRatio = webstate.deskAspectRatio; deskAdjust(); }
if ((webstate.showRealNames != null) && (webstate.showRealNames != oldShowRealNames)) { showRealNames = Q('RealNameCheckBox').checked = (webstate.showRealNames == '1'); masterUpdate(6); } if ((webstate.showRealNames != null) && (webstate.showRealNames != oldShowRealNames)) { showRealNames = Q('RealNameCheckBox').checked = (webstate.showRealNames == '1'); masterUpdate(6); }
if ((webstate.uiMode != null) && (webstate.uiMode != oldUiMode)) { userInterfaceSelectMenu(parseInt(webstate.uiMode)); } if ((webstate.uiMode != null) && (webstate.uiMode != oldUiMode)) { userInterfaceSelectMenu(parseInt(webstate.uiMode)); }
if ((webstate.sort != null) && (webstate.sort != oldSort)) { document.getElementById('sortselect').selectedIndex = sort = parseInt(webstate.sort); masterUpdate(6); } if ((webstate.sort != null) && (webstate.sort != oldSort)) { document.getElementById('sortselect').selectedIndex = sort = parseInt(webstate.sort); masterUpdate(6); }
if ((webstate.loctag != null) && (webstate.loctag != oldLoctag)) { if (webstate.loctag != null) { args.locale = webstate.loctag; } else { delete args.locale; } masterUpdate(0xFFFFFFFF); } if ((webstate.loctag != null) && (webstate.loctag != oldLoctag)) { if (webstate.loctag != null) { args.locale = webstate.loctag; } else { delete args.locale; } masterUpdate(0xFFFFFFFF); }
} }
} catch (ex) {}
break; break;
} }
case 'servertimelinestats': { addServerTimelineStats(message.event.data); break; } case 'servertimelinestats': { addServerTimelineStats(message.event.data); break; }
@ -10724,9 +10729,11 @@
function putstore(name, val) { function putstore(name, val) {
try { try {
if ((typeof (localStorage) === 'undefined') || (localStorage.getItem(name) == val)) return; if ((typeof (localStorage) === 'undefined') || (localStorage.getItem(name) == val)) return;
if (val == null) { localStorage.removeItem(name); } else { localStorage.setItem(name, val); } } catch (e) { } if (val == null) { localStorage.removeItem(name); } else { localStorage.setItem(name, val); }
if (name[0] != '_') { } catch (e) { }
var s = {}; if (name[0] != '_') {
var s = {};
try {
for (var i = 0, len = localStorage.length; i < len; ++i) { for (var i = 0, len = localStorage.length; i < len; ++i) {
var k = localStorage.key(i); var k = localStorage.key(i);
if (k[0] != '_') { if (k[0] != '_') {
@ -10734,9 +10741,10 @@
if ((k != 'desktopsettings') && (typeof s[k] == 'string') && (s[k].length > 64)) { delete s[k]; } if ((k != 'desktopsettings') && (typeof s[k] == 'string') && (s[k].length > 64)) { delete s[k]; }
} }
} }
meshserver.send({ action: 'userWebState', state: JSON.stringify(s) }); } catch (ex) {}
} meshserver.send({ action: 'userWebState', state: JSON.stringify(s) });
} }
}
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; } } 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; } }
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>'; } 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>'; }
function addLinkConditional(x, f, c) { if (c) return addLink(x, f); return x; } function addLinkConditional(x, f, c) { if (c) return addLink(x, f); return x; }