Improved IP blocking, improved relay tunnel error in meshcore.js
Ylian Saint-Hilaire committed
Jan 10, 2020 at 11:19 UTC
b907100d8b53e71caf40bc3270b3fe4016b3995b
3 files changed
+17
-12
agents/meshcore.js
+2
-2
@@ -629,7 +629,7 @@ function createMeshCore(agent) {
629
//sendConsoleText('TUNNEL: ' + JSON.stringify(data));
630
var tunnel = http.request(woptions);
631
tunnel.upgrade = onTunnelUpgrade;
632
- tunnel.on('error', function (e) { sendConsoleText("ERROR: " + JSON.stringify(e)); });
632
+ tunnel.on('error', function (e) { sendConsoleText("ERROR: Unable to connect relay tunnel to: " + this.url + ", " + JSON.stringify(e)); });
633
tunnel.sessionid = data.sessionid;
634
tunnel.rights = data.rights;
635
tunnel.consent = data.consent;
@@ -2428,7 +2428,7 @@ function createMeshCore(agent) {
2428
} catch (e) { response = 'Invalid HTTP websocket request'; }
2429
if (httprequest != null) {
2430
httprequest.upgrade = onWebSocketUpgrade;
2431
- httprequest.on('error', function (e) { sendConsoleText('ERROR: ' + JSON.stringify(e)); });
2431
+ httprequest.on('error', function (e) { sendConsoleText("ERROR: Unable to connect to: " + this.url + ", " + JSON.stringify(e)); });
2432
2433
var index = 1;
2434
while (consoleWebSockets[index]) { index++; }
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.4.7-f",
3
+ "version": "0.4.7-h",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",
webserver.js
+14
-9
@@ -85,6 +85,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
85
obj.dnsDomains = {};
86
obj.relaySessionCount = 0;
87
obj.relaySessionErrorCount = 0;
88
+ obj.blockedUsers = 0;
89
+ obj.blockedAgents = 0;
90
obj.renderPages = null;
91
obj.renderLanguages = [];
92
@@ -247,7 +249,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
249
sessionsCount: Object.keys(obj.sessionsCount).length,
250
wsrelays: Object.keys(obj.wsrelays).length,
251
wsPeerRelays: Object.keys(obj.wsPeerRelays).length,
250
- tlsSessionStore: Object.keys(tlsSessionStore).length
252
+ tlsSessionStore: Object.keys(tlsSessionStore).length,
253
+ blockedUsers: obj.blockedUsers,
254
+ blockedAgents: obj.blockedAgents
255
};
256
}
257
@@ -453,6 +457,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
457
var ip;
458
if (req.connection) { // HTTP(S) request
459
ip = req.ip;
460
+
461
if (ip) { for (var i = 0; i < ipList.length; i++) { if (require('ipcheck').match(ip, ipList[i])) { if (closeIfThis === true) { res.sendStatus(401); } return true; } } }
462
if (closeIfThis === false) { res.sendStatus(401); }
463
} else if (req._socket) { // WebSocket request
@@ -472,21 +477,21 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
477
478
// Check if the source IP address is allowed, return domain if allowed
479
function checkUserIpAddress(req, res) {
475
- if ((obj.userBlockedIp != null) && (checkIpAddressEx(req, res, obj.userBlockedIp, true) == true)) { return null; }
476
- if ((obj.userAllowedIp != null) && (checkIpAddressEx(req, res, obj.userAllowedIp, false) == false)) { return null; }
480
+ if ((parent.config.settings.userblockedip != null) && (checkIpAddressEx(req, res, parent.config.settings.userblockedip, true) == true)) { obj.blockedUsers++; return null; }
481
+ if ((parent.config.settings.userallowedip != null) && (checkIpAddressEx(req, res, parent.config.settings.userallowedip, false) == false)) { obj.blockedUsers++; return null; }
482
const domain = (req.url ? getDomain(req) : getDomain(res));
478
- if ((domain.userblockedip != null) && (checkIpAddressEx(req, res, domain.userblockedip, true) == true)) { return null; }
479
- if ((domain.userallowedip != null) && (checkIpAddressEx(req, res, domain.userallowedip, false) == false)) { return null; }
483
+ if ((domain.userblockedip != null) && (checkIpAddressEx(req, res, domain.userblockedip, true) == true)) { obj.blockedUsers++; return null; }
484
+ if ((domain.userallowedip != null) && (checkIpAddressEx(req, res, domain.userallowedip, false) == false)) { obj.blockedUsers++; return null; }
485
return domain;
486
}
487
488
// Check if the source IP address is allowed, return domain if allowed
489
function checkAgentIpAddress(req, res) {
485
- if ((obj.agentBlockedIp != null) && (checkIpAddressEx(req, res, obj.agentBlockedIp, null) == true)) { return null; }
486
- if ((obj.agentAllowedIp != null) && (checkIpAddressEx(req, res, obj.agentAllowedIp, null) == false)) { return null; }
490
+ if ((parent.config.settings.agentblockedip != null) && (checkIpAddressEx(req, res, parent.config.settings.agentblockedip, true) == true)) { obj.blockedAgents++; return null; }
491
+ if ((parent.config.settings.agentallowedip != null) && (checkIpAddressEx(req, res, parent.config.settings.agentallowedip, false) == false)) { obj.blockedAgents++; return null; }
492
const domain = (req.url ? getDomain(req) : getDomain(res));
488
- if ((domain.agentblockedip != null) && (checkIpAddressEx(req, res, domain.agentblockedip, null) == true)) { return null; }
489
- if ((domain.agentallowedip != null) && (checkIpAddressEx(req, res, domain.agentallowedip, null) == false)) { return null; }
493
+ if ((domain.agentblockedip != null) && (checkIpAddressEx(req, res, domain.agentblockedip, null) == true)) { obj.blockedAgents++; return null; }
494
+ if ((domain.agentallowedip != null) && (checkIpAddressEx(req, res, domain.agentallowedip, null) == false)) { obj.blockedAgents++; return null; }
495
return domain;
496
}
497