forked from coolaj86/telebit.js
		
	bug in v10.3, use v10.2
This commit is contained in:
		
							parent
							
								
									34cee2dbac
								
							
						
					
					
						commit
						a942587b80
					
				| @ -63,11 +63,17 @@ module.exports.assign = function (state, tun, cb) { | |||||||
|   function trySsh(tun, cb) { |   function trySsh(tun, cb) { | ||||||
|     // https://security.stackexchange.com/questions/43231/plausibly-deniable-ssh-does-it-make-sense?rq=1
 |     // https://security.stackexchange.com/questions/43231/plausibly-deniable-ssh-does-it-make-sense?rq=1
 | ||||||
|     // https://tools.ietf.org/html/rfc4253#section-4.2
 |     // https://tools.ietf.org/html/rfc4253#section-4.2
 | ||||||
|     if (false === state.config.ssh_auto || 'SSH-2.0-' !== tun.data.slice(0, 8).toString()) { |     var sshPort; | ||||||
|  |     if (-1 !== ['true', 'enable', 'auto', 'on'].indexOf(state.config.sshAuto)) { | ||||||
|  |       sshPort = 22; | ||||||
|  |     } else { | ||||||
|  |       sshPort = parseInt(state.config.sshAuto, 10); | ||||||
|  |     } | ||||||
|  |     if (!sshPort || 'SSH-2.0-' !== tun.data.slice(0, 8).toString()) { | ||||||
|       cb(null, false); |       cb(null, false); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     cb(null, getNetConn(state.config.sshPort || 22)); |     cb(null, getNetConn(sshPort)); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   var handlers = {}; |   var handlers = {}; | ||||||
| @ -224,6 +230,7 @@ module.exports.assign = function (state, tun, cb) { | |||||||
|     }); |     }); | ||||||
|     return conn; |     return conn; | ||||||
|   } |   } | ||||||
|  |   var handlerservers = {}; | ||||||
|   function invokeHandler(conf, tlsSocket, tun, id) { |   function invokeHandler(conf, tlsSocket, tun, id) { | ||||||
|     var conn; |     var conn; | ||||||
|     if (parseInt(conf.handler, 10)) { |     if (parseInt(conf.handler, 10)) { | ||||||
| @ -239,6 +246,18 @@ module.exports.assign = function (state, tun, cb) { | |||||||
|     var handlerpath = conf.handler; |     var handlerpath = conf.handler; | ||||||
|     var homedir = os.homedir(); |     var homedir = os.homedir(); | ||||||
|     var localshare = path.join(homedir, '.local/share/telebit/apps'); |     var localshare = path.join(homedir, '.local/share/telebit/apps'); | ||||||
|  |     var http = require('http'); | ||||||
|  | 
 | ||||||
|  |     // 1. No modification handlerpath may be an aboslute path
 | ||||||
|  |     // 2. it may be relative to a user home directory
 | ||||||
|  |     // 3. it may be relative to a user local/share
 | ||||||
|  | 
 | ||||||
|  |     tlsSocket._tun = tun; | ||||||
|  |     tlsSocket._id = id; | ||||||
|  |     if (handlerservers[conf.handler]) { | ||||||
|  |       handlerservers[conf.handler].emit('connection', tlsSocket); | ||||||
|  |       return; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     if (/^~/.test(handlerpath)) { |     if (/^~/.test(handlerpath)) { | ||||||
|       handlerpath = path.join(homedir, handlerpath.replace(/^~(\/?)/, '')); |       handlerpath = path.join(homedir, handlerpath.replace(/^~(\/?)/, '')); | ||||||
| @ -247,20 +266,27 @@ module.exports.assign = function (state, tun, cb) { | |||||||
|     try { |     try { | ||||||
|       handler = require(handlerpath); |       handler = require(handlerpath); | ||||||
|       console.info("Handling '" + handle + ":" + id + "' with '" + handlerpath + "'"); |       console.info("Handling '" + handle + ":" + id + "' with '" + handlerpath + "'"); | ||||||
|       handler(tlsSocket, tun, id); |  | ||||||
|     } catch(e1) { |     } catch(e1) { | ||||||
|       try { |       try { | ||||||
|         handler = require(path.join(localshare, handlerpath)); |         handler = require(path.join(localshare, handlerpath)); | ||||||
|         console.info("Handling '" + handle + ":" + id + "' with '" + handlerpath + "'"); |         console.info("Handling '" + handle + ":" + id + "' with '" + handlerpath + "'"); | ||||||
|         handler(tlsSocket, tun, id); |  | ||||||
|       } catch(e2) { |       } catch(e2) { | ||||||
|         console.error("Failed to load '" + handlerpath + "':", e1.message); |         console.error("Failed to load '" + handlerpath + "':", e1.message); | ||||||
|         console.error("Failed to load '" + path.join(localshare, handlerpath) + "':", e2.message); |         console.error("Failed to load '" + path.join(localshare, handlerpath) + "':", e2.message); | ||||||
|         console.warn("Using default handler for '" + handle + ":" + id + "'"); |         console.warn("Using default handler for '" + handle + ":" + id + "'"); | ||||||
|  |         handler = null; | ||||||
|  |         // fallthru
 | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (handler) { | ||||||
|  |       handlerservers[conf.handler] = http.createServer(handler); | ||||||
|  |       handlerservers[conf.handler].emit('connection', tlsSocket); | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     handlers.https(tlsSocket, tun, id); |     handlers.https(tlsSocket, tun, id); | ||||||
|   } |   } | ||||||
|     } |  | ||||||
|   } |  | ||||||
| 
 | 
 | ||||||
|   function terminateTls(tun, cb) { |   function terminateTls(tun, cb) { | ||||||
|     var socketPair = require('socket-pair'); |     var socketPair = require('socket-pair'); | ||||||
|  | |||||||
| @ -82,7 +82,7 @@ fi | |||||||
| 
 | 
 | ||||||
| echo "Installing $my_name to '$TELEBIT_PATH'" | echo "Installing $my_name to '$TELEBIT_PATH'" | ||||||
| # v10.2+ has much needed networking fixes, but breaks ursa. v9.x has severe networking bugs. v8.x has working ursa, but requires tls workarounds" | # v10.2+ has much needed networking fixes, but breaks ursa. v9.x has severe networking bugs. v8.x has working ursa, but requires tls workarounds" | ||||||
| NODEJS_VER="${NODEJS_VER:-v10.3}" | NODEJS_VER="${NODEJS_VER:-v10.2}" | ||||||
| export NODEJS_VER | export NODEJS_VER | ||||||
| export NODE_PATH="$TELEBIT_PATH/lib/node_modules" | export NODE_PATH="$TELEBIT_PATH/lib/node_modules" | ||||||
| export NPM_CONFIG_PREFIX="$TELEBIT_PATH" | export NPM_CONFIG_PREFIX="$TELEBIT_PATH" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user