Added relayAliasPort setting to support relay port behind reverse proxies, #4222
Ylian Saint-Hilaire committed
Jul 4, 2022 at 20:20 UTC
18f4fe9c3aa304f77f085a717100f1248d4c6348
4 files changed
+22
-14
meshcentral-config-schema.json
+6
-5
@@ -86,13 +86,14 @@
86
"statsevents": { "type": "integer", "default": 2592000, "description": "Amount of time in seconds that server statistics are kept in the database." }
87
}
88
},
89
- "port": { "type": "integer", "minimum": 1, "maximum": 65535, "default": 443 },
89
+ "port": { "type": "integer", "minimum": 1, "maximum": 65535, "default": 443, "description": "Ths port of the main HTTPS server." },
90
"portBind": { "type": "string", "description": "When set, bind the HTTPS main port to a specific network address." },
91
- "aliasPort": { "type": "integer", "minimum": 1, "maximum": 65535, "default": null },
92
- "redirPort": { "type": "integer", "minimum": 1, "maximum": 65535, "default": 80 },
91
+ "aliasPort": { "type": "integer", "minimum": 1, "maximum": 65535, "default": null, "description": "The actual main port as seen externally on the Internet, this setting is often used when a reverse-proxy is used." },
92
+ "redirPort": { "type": "integer", "minimum": 0, "maximum": 65535, "default": 80, "description": "This is a HTTP web server port that mostly redirects users to the HTTPS port but does provide some other servces, 0 will turn this port off." },
93
"redirPortBind": { "type": "string", "description": "When set, bind the HTTP redirection port to a specific network address." },
94
- "redirAliasPort": { "type": "integer", "minimum": 1, "maximum": 65535 },
95
- "relayPort": { "type": "integer", "minimum": 1, "maximum": 65535, "default": null, "description": "When set, a web relay web server is bound to this port and will allow user access to remote web sites." },
94
+ "redirAliasPort": { "type": "integer", "minimum": 1, "maximum": 65535, "description": "The actual redirection port as seen externally on the Internet, this setting is often used when a reverse-proxy is used." },
95
+ "relayPort": { "type": "integer", "minimum": 0, "maximum": 65535, "default": 0, "description": "When set, a web relay web server is bound to this port and will allow user access to remote web sites." },
96
+ "relayAliasPort": { "type": "integer", "minimum": 1, "maximum": 65535, "default": null, "description": "The actual relay port as seen externally on the Internet, this setting is often used when a reverse-proxy is used." },
97
"relayDNS": { "type": "string", "default": null, "description": "When set, relayPort valie is ignored. Set this to a DNS name the points to this server. When the server is accessed using the DNS name, the main web server port is used as a web relay port." },
98
"agentPort": { "type": "integer", "minimum": 1, "maximum": 65535, "description": "When set, enabled a new HTTPS server port that only accepts agent connections." },
99
"agentPortBind": { "type": "string", "description": "When set, binds the agent port to a specific network interface." },
sample-config-advanced.json
+1
@@ -30,6 +30,7 @@
30
"_redirPortBind": "127.0.0.1",
31
"_redirAliasPort": 80,
32
"_relayPort": 453,
33
+ "_relayAliasPort": 463,
34
"_relayDNS": "relay.myserver.mydomain.com",
35
"_agentPort": 1234,
36
"_agentPortBind": "127.0.0.1",
webrelayserver.js
+5
-5
@@ -239,18 +239,18 @@ module.exports.CreateWebRelayServer = function (parent, db, args, certificates,
239
if (port == 0 || port == 65535) { return; }
240
if (obj.tlsServer != null) {
241
if (args.lanonly == true) {
242
- obj.tcpServer = obj.tlsServer.listen(port, addr, function () { console.log('MeshCentral HTTPS relay server running on port ' + port + ((args.aliasport != null) ? (', alias port ' + args.aliasport) : '') + '.'); });
242
+ obj.tcpServer = obj.tlsServer.listen(port, addr, function () { console.log('MeshCentral HTTPS relay server running on port ' + port + ((typeof args.relayaliasport == 'number') ? (', alias port ' + args.relayaliasport) : '') + '.'); });
243
} else {
244
- obj.tcpServer = obj.tlsServer.listen(port, addr, function () { console.log('MeshCentral HTTPS relay server running on ' + certificates.CommonName + ':' + port + ((args.aliasport != null) ? (', alias port ' + args.aliasport) : '') + '.'); });
244
+ obj.tcpServer = obj.tlsServer.listen(port, addr, function () { console.log('MeshCentral HTTPS relay server running on ' + certificates.CommonName + ':' + port + ((typeof args.relayaliasport == 'number') ? (', alias port ' + args.relayaliasport) : '') + '.'); });
245
obj.parent.updateServerState('servername', certificates.CommonName);
246
}
247
if (obj.parent.authlog) { obj.parent.authLog('https', 'Web relay server listening on ' + ((addr != null) ? addr : '0.0.0.0') + ' port ' + port + '.'); }
248
obj.parent.updateServerState('https-relay-port', port);
249
- if (args.aliasport != null) { obj.parent.updateServerState('https-relay-aliasport', args.aliasport); }
249
+ if (typeof args.relayaliasport == 'number') { obj.parent.updateServerState('https-relay-aliasport', args.relayaliasport); }
250
} else {
251
- obj.tcpServer = obj.app.listen(port, addr, function () { console.log('MeshCentral HTTP relay server running on port ' + port + ((args.aliasport != null) ? (', alias port ' + args.aliasport) : '') + '.'); });
251
+ obj.tcpServer = obj.app.listen(port, addr, function () { console.log('MeshCentral HTTP relay server running on port ' + port + ((typeof args.relayaliasport == 'number') ? (', alias port ' + args.relayaliasport) : '') + '.'); });
252
obj.parent.updateServerState('http-relay-port', port);
253
- if (args.aliasport != null) { obj.parent.updateServerState('http-relay-aliasport', args.aliasport); }
253
+ if (typeof args.relayaliasport == 'number') { obj.parent.updateServerState('http-relay-aliasport', args.relayaliasport); }
254
}
255
obj.port = port;
256
}
webserver.js
+10
-4
@@ -2864,7 +2864,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
2864
webstate: encodeURIComponent(webstate).replace(/'/g, '%27'),
2865
amtscanoptions: amtscanoptions,
2866
pluginHandler: (parent.pluginHandler == null) ? 'null' : parent.pluginHandler.prepExports(),
2867
- webRelayPort: ((typeof args.relaydns == 'string') ? args.port : ((parent.webrelayserver != null) ? parent.webrelayserver.port : 0)),
2867
+ webRelayPort: ((typeof args.relaydns == 'string') ? args.port : ((parent.webrelayserver != null) ? ((typeof args.relayaliasport == 'number') ? args.relayaliasport : parent.webrelayserver.port) : 0)),
2868
webRelayDns: ((typeof args.relaydns == 'string') ? args.relaydns : '')
2869
}, dbGetFunc.req, domain), user);
2870
}
@@ -7128,16 +7128,22 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
7128
obj.args.port = port;
7129
if (obj.tlsServer != null) {
7130
if (obj.args.lanonly == true) {
7131
- obj.tcpServer = obj.tlsServer.listen(port, addr, function () { console.log('MeshCentral HTTPS server running on port ' + port + ((args.aliasport != null) ? (', alias port ' + args.aliasport) : '') + '.'); });
7131
+ obj.tcpServer = obj.tlsServer.listen(port, addr, function () { console.log('MeshCentral HTTPS server running on port ' + port + ((typeof args.aliasport == 'number') ? (', alias port ' + args.aliasport) : '') + '.'); });
7132
} else {
7133
- obj.tcpServer = obj.tlsServer.listen(port, addr, function () { console.log('MeshCentral HTTPS server running on ' + certificates.CommonName + ':' + port + ((args.aliasport != null) ? (', alias port ' + args.aliasport) : '') + '.'); });
7133
+ obj.tcpServer = obj.tlsServer.listen(port, addr, function () {
7134
+ console.log('MeshCentral HTTPS server running on ' + certificates.CommonName + ':' + port + ((typeof args.aliasport == 'number') ? (', alias port ' + args.aliasport) : '') + '.');
7135
+ if (typeof args.relaydns == 'string') { console.log('MeshCentral HTTPS relay server running on ' + args.relaydns + ':' + port + ((typeof args.aliasport == 'number') ? (', alias port ' + args.aliasport) : '') + '.'); }
7136
+ });
7137
obj.parent.updateServerState('servername', certificates.CommonName);
7138
}
7139
if (obj.parent.authlog) { obj.parent.authLog('https', 'Server listening on ' + ((addr != null) ? addr : '0.0.0.0') + ' port ' + port + '.'); }
7140
obj.parent.updateServerState('https-port', port);
7141
if (args.aliasport != null) { obj.parent.updateServerState('https-aliasport', args.aliasport); }
7142
} else {
7140
- obj.tcpServer = obj.app.listen(port, addr, function () { console.log('MeshCentral HTTP server running on port ' + port + ((args.aliasport != null) ? (', alias port ' + args.aliasport) : '') + '.'); });
7143
+ obj.tcpServer = obj.app.listen(port, addr, function () {
7144
+ console.log('MeshCentral HTTP server running on port ' + port + ((typeof args.aliasport == 'number') ? (', alias port ' + args.aliasport) : '') + '.');
7145
+ if (typeof args.relaydns == 'string') { console.log('MeshCentral HTTP relay server running on ' + args.relaydns + ':' + port + ((typeof args.aliasport == 'number') ? (', alias port ' + args.aliasport) : '') + '.'); }
7146
+ });
7147
obj.parent.updateServerState('http-port', port);
7148
if (args.aliasport != null) { obj.parent.updateServerState('http-aliasport', args.aliasport); }
7149
}