Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Use Path header from client if it matches a hostname and port in modo…
Browse files Browse the repository at this point in the history
…pts.ini [web] allowed_ftelnet_targets list.
  • Loading branch information
echicken committed Jun 30, 2017
1 parent c8368b4 commit 1419a92
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions mods/websocket-telnet-service.js
@@ -1,5 +1,6 @@
load('sbbsdefs.js');
load('websocket-proxy.js');
load('modopts.js');

function log_err(msg) {
log(LOG_DEBUG, msg);
Expand Down Expand Up @@ -235,8 +236,21 @@ try {
}

var wss = new WebSocketProxy(client);
log(LOG_DEBUG, 'WSTS Connecting to ' + telnet_addr + ':' + ini.TelnetPort);
var telnet = new TelnetClient(telnet_addr, ini.TelnetPort);
var wsspath = wss.headers.Path.split('/');
if (wsspath.length < 3 || isNaN(parseInt(wsspath[2]))) {
var telnet = new TelnetClient(telnet_addr, ini.TelnetPort);
} else {
var _settings = get_mod_options('web');
if (typeof _settings.allowed_ftelnet_targets !== 'string') {
throw 'Client supplied Path but no allowed_ftelnet_targets supplied in modopts.ini [web] section.';
}
var targets = _settings.allowed_ftelnet_targets.split(',');
if (!targets.some(function (e) { var target = e.split(':'); return target[0] === wsspath[1] && target[1] === wsspath[2]; })) {
throw 'Client supplied Path is not in allowed_ftelnet_targets list.';
}
log('Using client-supplied target ' + wsspath[1] + ':' + wsspath[2]);
var telnet = new TelnetClient(wsspath[1], parseInt(wsspath[2]));
}

while (client.socket.is_connected && telnet.connected) {

Expand Down Expand Up @@ -265,4 +279,4 @@ try {

client.socket.close();

}
}

0 comments on commit 1419a92

Please sign in to comment.