forked from coolaj86/telebit.js
		
	cleanup
This commit is contained in:
		
							parent
							
								
									ef751e5b32
								
							
						
					
					
						commit
						7a08220838
					
				| @ -55,17 +55,6 @@ module.exports.print = function (config) { | ||||
| module.exports.assign = function (state, tun, cb) { | ||||
|   var net = state.net || require('net'); | ||||
| 
 | ||||
|   if (!tun.name && !tun.serviceport) { | ||||
|     console.log('tun:\n',tun); | ||||
|     //console.warn(tun.data.toString());
 | ||||
|     cb(new Error("No routing information for ':tun_id'. Missing both 'name' and 'serviceport'.")); | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (!state.config.servernames) { | ||||
|     state.config.servernames = {}; | ||||
|   } | ||||
| 
 | ||||
|   var handlers = {}; | ||||
|   handlers.http = function (socket) { | ||||
|     if (!state.greenlock) { | ||||
| @ -109,13 +98,6 @@ module.exports.assign = function (state, tun, cb) { | ||||
|     return conn; | ||||
|   } | ||||
| 
 | ||||
|   if ('http' === tun.service || 'https' === tun.service) { | ||||
|     if (!tun.name) { | ||||
|       cb(new Error("No routing information for ':tun_id'. Service '" + tun.service + "' is missing 'name'.")); | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   function redirectHttp(cb) { | ||||
|     var socketPair = require('socket-pair'); | ||||
|     var conn = socketPair.create(function (err, other) { | ||||
| @ -127,31 +109,6 @@ module.exports.assign = function (state, tun, cb) { | ||||
|     return conn; | ||||
|   } | ||||
| 
 | ||||
|   var handled; | ||||
| 
 | ||||
|   if ('http' === tun.service) { | ||||
|     // TODO match *.example.com
 | ||||
|     handled = Object.keys(state.config.servernames).some(function (sn) { | ||||
|       if (sn !== tun.name) { return; } | ||||
| 
 | ||||
|       console.log('Found config match for PLAIN', tun.name); | ||||
|       if (!state.config.servernames[sn]) { return; } | ||||
| 
 | ||||
|       if (false === state.config.servernames[sn].terminate) { | ||||
|         cb(new Error("insecure http not supported yet")); | ||||
|         return true; | ||||
|       } | ||||
| 
 | ||||
|       console.log('Redirecting HTPTP for', tun.name); | ||||
|       redirectHttp(cb); | ||||
|       return true; | ||||
|     }); | ||||
|     if (!handled) { | ||||
|       redirectHttp(cb); | ||||
|     } | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   function defineProps(other, tun) { | ||||
|     Object.defineProperty(other, 'remoteFamily', { | ||||
|       enumerable: false, | ||||
| @ -233,6 +190,50 @@ module.exports.assign = function (state, tun, cb) { | ||||
|     return conn; | ||||
|   } | ||||
| 
 | ||||
|   var handled; | ||||
| 
 | ||||
|   if (!tun.name && !tun.serviceport) { | ||||
|     console.log('tun:\n',tun); | ||||
|     //console.warn(tun.data.toString());
 | ||||
|     cb(new Error("No routing information for ':tun_id'. Missing both 'name' and 'serviceport'.")); | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (!state.config.servernames) { | ||||
|     state.config.servernames = {}; | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
|   if ('http' === tun.service || 'https' === tun.service) { | ||||
|     if (!tun.name) { | ||||
|       cb(new Error("No routing information for ':tun_id'. Service '" + tun.service + "' is missing 'name'.")); | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   if ('http' === tun.service) { | ||||
|     // TODO match *.example.com
 | ||||
|     handled = Object.keys(state.config.servernames).some(function (sn) { | ||||
|       if (sn !== tun.name) { return; } | ||||
| 
 | ||||
|       console.log('Found config match for PLAIN', tun.name); | ||||
|       if (!state.config.servernames[sn]) { return; } | ||||
| 
 | ||||
|       if (false === state.config.servernames[sn].terminate) { | ||||
|         cb(new Error("insecure http not supported yet")); | ||||
|         return true; | ||||
|       } | ||||
| 
 | ||||
|       console.log('Redirecting HTPTP for', tun.name); | ||||
|       redirectHttp(cb); | ||||
|       return true; | ||||
|     }); | ||||
|     if (!handled) { | ||||
|       redirectHttp(cb); | ||||
|     } | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if ('https' === tun.service) { | ||||
|     // TODO match *.example.com
 | ||||
|     handled = Object.keys(state.config.servernames).some(function (sn) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user