Agent core download and reverse proxy improvements.

Ylian Saint-Hilaire committed Nov 30, 2020 at 13:20 UTC 1e27592ce4ff177374760b98b2b32fbdb66c007b
6 files changed +19 -5
agents/meshcore.js
+1 -1
@@ -2274,7 +2274,7 @@ function createMeshCore(agent) {
2274 if ((process.cwd() != '//') && fs.existsSync(process.cwd() + 'core')) { cmd.path = process.cwd() + 'core'; }
2275 }
2276 }
2277 - MeshServerLogEx(49, [cmd.path], 'Download: \"' + cmd.path + '\"', this.httprequest);
2277 + MeshServerLogEx((cmd.ask == 'coredump')?104:49, [cmd.path], 'Download: \"' + cmd.path + '\"', this.httprequest);
2278 if ((cmd.path == null) || (this.filedownload != null)) { this.write({ action: 'download', sub: 'cancel', id: this.filedownload.id }); delete this.filedownload; }
2279 this.filedownload = { id: cmd.id, path: cmd.path, ptr: 0 }
2280 try { this.filedownload.f = fs.openSync(this.filedownload.path, 'rbN'); } catch (e) { this.write({ action: 'download', sub: 'cancel', id: this.filedownload.id }); delete this.filedownload; }
views/default-mobile.handlebars
+4
@@ -31,6 +31,10 @@
31 <meta name="theme-color" content="#ffffff">
32 <title>{{{title}}}</title>
33 <style>
34 + :focus {
35 + outline: 0;
36 + }
37 +
38 a {
39 color: #036;
40 text-decoration: underline;
views/default.handlebars
+1
@@ -11086,6 +11086,7 @@
11086 101: "Added device share {0} from {1} to {2}",
11087 102: "Removed device share {0}",
11088 103: "Batch upload of {0} file(s) to folder {1}",
11089 + 104: "Automated download of agent core dump file: \"{0}\""
11090 };
11091
11092 // Highlights the device being hovered
views/mstsc.handlebars
+4
@@ -14,6 +14,10 @@
14 <script type="text/javascript" src="mstsc/client.js"></script>
15 <script type="text/javascript" src="mstsc/canvas.js"></script>
16 <style>
17 + :focus {
18 + outline: 0;
19 + }
20 +
21 body {
22 font-family:sans-serif;
23 margin: 0;
views/terms-mobile.handlebars
+4
@@ -10,6 +10,10 @@
10 <link rel="apple-touch-icon" href="/favicon-303x303.png" />
11 <title>{{{title}}} - Terms of use</title>
12 <style type="text/css">
13 + :focus {
14 + outline: 0;
15 + }
16 +
17 a {
18 color: #036;
19 text-decoration: underline;
webserver.js
+5 -4
@@ -3928,7 +3928,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
3928 if (obj.fs.existsSync(coreDumpPath) == false) { try { obj.fs.mkdirSync(coreDumpPath); } catch (ex) { } }
3929 ws.xfilepath = obj.path.join(parent.datapath, '..', 'meshcentral-coredumps', ws.xarg);
3930 ws.xid = 'coredump';
3931 - ws.send(JSON.stringify({ action: 'download', sub: 'start', ask: 'coredump', id: 'coredump' })); // Ask for a directory (test)
3931 + ws.send(JSON.stringify({ action: 'download', sub: 'start', ask: 'coredump', id: 'coredump' })); // Ask for a core dump file
3932 }
3933
3934 // When data is received from the web socket, echo it back
@@ -4853,7 +4853,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4853 obj.app.use(function (req, res, next) {
4854 // Set the real IP address of the request
4855 // If a trusted reverse-proxy is sending us the remote IP address, use it.
4856 - var ipex = '0.0.0.0', serverHost = req.headers.host;
4856 + var ipex = '0.0.0.0', xforwardedhost = req.headers.host;
4857 if (typeof req.connection.remoteAddress == 'string') { ipex = (req.connection.remoteAddress.startsWith('::ffff:')) ? req.connection.remoteAddress.substring(7) : req.connection.remoteAddress; }
4858 if (
4859 (obj.args.trustedproxy === true) ||
@@ -4872,7 +4872,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4872 }
4873
4874 // Get server host
4875 - if (req.headers['x-forwarded-host']) { serverHost = req.headers['x-forwarded-host']; }
4875 + if (req.headers['x-forwarded-host']) { xforwardedhost = req.headers['x-forwarded-host']; }
4876 } else {
4877 req.clientIp = ipex;
4878 }
@@ -4892,7 +4892,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4892 } else {
4893 // Use default security headers
4894 const geourl = (domain.geolocation ? ' *.openstreetmap.org' : '');
4895 - const selfurl = ' wss://' + serverHost;
4895 + var selfurl = ' wss://' + req.headers.host;
4896 + if ((xforwardedhost != null) && (xforwardedhost != req.headers.host)) { selfurl += ' wss://' + xforwardedhost; }
4897 const headers = {
4898 'Referrer-Policy': 'no-referrer',
4899 'X-XSS-Protection': '1; mode=block',