dispatch-proxy
Advanced tools
Comparing version 0.0.7 to 0.0.8
124
lib/index.js
@@ -1,2 +0,2 @@ | ||
var HttpDispatcher, SocksDispatcher, colog, crypto, os, print, program, | ||
var Dispatcher, HttpProxy, Logger, SocksProxy, crypto, emit, log, logger, os, print, program, _ref, | ||
__slice = [].slice; | ||
@@ -12,12 +12,18 @@ | ||
colog = require('colog'); | ||
Logger = require('./logger'); | ||
SocksDispatcher = require('./dispatcher/socks'); | ||
Dispatcher = require('./dispatcher'); | ||
HttpDispatcher = require('./dispatcher/http'); | ||
SocksProxy = require('./proxy/socks'); | ||
HttpProxy = require('./proxy/http'); | ||
logger = (_ref = new Logger({ | ||
tab: 10 | ||
}).registerStyle('default', ['grey']).registerStyle('b', ['bold']).registerStyle('s', ['green']).registerStyle('i', ['cyan']).registerStyle('e', ['red']).registerStyle('a', ['b', 'black']).registerEvent('request', '<b-i>request').registerEvent('dispatch', '<b-i>dispatch').registerEvent('connect', '<b-s>connect').registerEvent('response', '<b-s>response').registerEvent('error', '<b-e>error').registerEvent('end', '<b-i>end').registerMode('default', ['error']).registerMode('debug', true), log = _ref.log, emit = _ref.emit, _ref); | ||
program.version('0.0.1'); | ||
program.command('list').description('list all available network interfaces').action(function() { | ||
var address, addrs, family, interfaces, internal, name, opts, _i, _len, _ref, _results; | ||
var address, addrs, family, interfaces, internal, name, opts, _i, _len, _ref1, _results; | ||
interfaces = os.networkInterfaces(); | ||
@@ -27,6 +33,5 @@ _results = []; | ||
addrs = interfaces[name]; | ||
print((colog.green(name)) + '\n'); | ||
log("<green>" + name + "</green>"); | ||
for (_i = 0, _len = addrs.length; _i < _len; _i++) { | ||
_ref = addrs[_i], address = _ref.address, family = _ref.family, internal = _ref.internal; | ||
print(' ' + (colog.cyan(address))); | ||
_ref1 = addrs[_i], address = _ref1.address, family = _ref1.family, internal = _ref1.internal; | ||
opts = []; | ||
@@ -39,8 +44,5 @@ if (family) { | ||
} | ||
if (opts.length > 0) { | ||
print(" (" + (opts.join(', ')) + ")"); | ||
} | ||
print('\n'); | ||
log((" <a>" + address + "</>") + (opts.length > 0 ? " <i>(" + (opts.join(', ')) + ")</>" : '')); | ||
} | ||
_results.push(print('\n')); | ||
_results.push(log('')); | ||
} | ||
@@ -50,11 +52,14 @@ return _results; | ||
program.command('start').usage('[options] [addresses]').description('start a proxy server').option('-H, --host <h>', 'which host to accept connections from (defaults to localhost)', String).option('-p, --port <p>', 'which port to listen to for connections (defaults to 8080 for HTTP proxy, 1080 for SOCKS proxy)', Number).option('--http', 'start an http proxy server', Boolean).option('--debug', 'logs connections and errors', Boolean).action(function() { | ||
var addr, address, addresses, addrs, arg, args, debug, dispatcher, host, http, https, name, port, priority, type, _arg, _i, _j, _k, _len, _len1, _ref, _ref1; | ||
program.command('start').usage('[options] [addresses]').description('start a proxy server').option('-H, --host <h>', 'which host to accept connections from (defaults to localhost)', String).option('-p, --port <p>', 'which port to listen to for connections (defaults to 8080 for HTTP proxy, 1080 for SOCKS proxy)', Number).option('--http', 'start an http proxy server', Boolean).option('--debug', 'log debug info in the console', Boolean).action(function() { | ||
var addr, address, addresses, addrs, arg, args, debug, dispatcher, host, http, https, name, port, priority, proxy, type, _arg, _i, _j, _k, _len, _len1, _ref1, _ref2; | ||
args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), _arg = arguments[_i++]; | ||
port = _arg.port, host = _arg.host, http = _arg.http, https = _arg.https, debug = _arg.debug; | ||
if (debug) { | ||
logger.setMode('debug'); | ||
} | ||
addresses = []; | ||
if (args.length === 0) { | ||
_ref = os.networkInterfaces(); | ||
for (name in _ref) { | ||
addrs = _ref[name]; | ||
_ref1 = os.networkInterfaces(); | ||
for (name in _ref1) { | ||
addrs = _ref1[name]; | ||
for (_j = 0, _len = addrs.length; _j < _len; _j++) { | ||
@@ -73,3 +78,3 @@ addr = addrs[_j]; | ||
arg = args[_k]; | ||
_ref1 = arg.split('@'), address = _ref1[0], priority = _ref1[1]; | ||
_ref2 = arg.split('@'), address = _ref2[0], priority = _ref2[1]; | ||
priority = priority ? parseInt(priority) : 1; | ||
@@ -83,39 +88,68 @@ addresses.push({ | ||
host || (host = 'localhost'); | ||
dispatcher = new Dispatcher(addresses); | ||
if (http) { | ||
port || (port = 8080); | ||
type = 'HTTP'; | ||
dispatcher = new HttpDispatcher(addresses, port, host); | ||
proxy = new HttpProxy(dispatcher, port, host); | ||
proxy.on('request', function(_arg1) { | ||
var clientRequest, id, localAddress, serverRequest; | ||
clientRequest = _arg1.clientRequest, serverRequest = _arg1.serverRequest, localAddress = _arg1.localAddress; | ||
id = (crypto.randomBytes(3)).toString('hex'); | ||
emit('request', "[" + id + "] <a>" + clientRequest.url + "</>"); | ||
emit('dispatch', "[" + id + "] <a>" + localAddress + "</>"); | ||
serverRequest.on('response', function(serverResponse) { | ||
return emit('response', "[" + id + "] <magenta-b>" + serverResponse.statusCode + "</>"); | ||
}).on('error', function(err) { | ||
return emit('error', "[" + id + "] serverRequest\n" + err.stack); | ||
}).on('end', function() { | ||
return emit('end', "[" + id + "] serverRequest"); | ||
}); | ||
return clientRequest.on('error', function(err) { | ||
return emit('error', "[" + id + "] clientRequest\n" + err.stack); | ||
}).on('end', function() { | ||
return emit('end', "[" + id + "] clientRequest"); | ||
}); | ||
}).on('error', function(err) { | ||
return emit('error', "server\n" + err.stack, { | ||
raw: true | ||
}); | ||
}); | ||
} else { | ||
port || (port = 1080); | ||
type = 'SOCKS5'; | ||
dispatcher = new SocksDispatcher(addresses, port, host); | ||
if (debug) { | ||
dispatcher.on('connection', function(_arg1) { | ||
var client, host, id, localAddress, port, server; | ||
client = _arg1.client, server = _arg1.server, host = _arg1.host, port = _arg1.port, localAddress = _arg1.localAddress; | ||
id = (crypto.randomBytes(3)).toString('hex'); | ||
console.log("" + (colog.yellow(id)) + " - Received connection to " + (colog.cyan("" + host + ":" + port)) + ", dispatching to " + (colog.cyan("" + localAddress.address + "@" + localAddress.priority)) + "."); | ||
server.on('connect', function() { | ||
return console.log("" + (colog.green(id)) + " - Successfully connected to " + (colog.cyan("" + host + ":" + port)) + " (" + (colog.cyan("" + server.remoteAddress + ":" + server.remotePort)) + ") from " + (colog.cyan("" + server.localAddress + ":" + server.localPort)) + "."); | ||
}).on('error', function(err) { | ||
return console.log("" + (colog.red(id)) + " - serverConnection error\n" + (' ' + (err.stack.replace(/\n/g, '\n ')))); | ||
}).on('end', function() { | ||
return console.log("" + (colog.yellow(id)) + " - serverConnection ended"); | ||
}); | ||
return client.on('error', function(err) { | ||
return console.log("" + (colog.red(id)) + " - clientConnection error\n" + (' ' + (err.stack.replace(/\n/g, '\n ')))); | ||
}).on('end', function() { | ||
return console.log("" + (colog.yellow(id)) + " - clientConnection ended"); | ||
}); | ||
proxy = new SocksProxy(dispatcher, port, host); | ||
proxy.on('request', function(_arg1) { | ||
var clientConnection, host, id, localAddress, port, serverConnection; | ||
serverConnection = _arg1.serverConnection, clientConnection = _arg1.clientConnection, host = _arg1.host, port = _arg1.port, localAddress = _arg1.localAddress; | ||
id = (crypto.randomBytes(3)).toString('hex'); | ||
emit('request', "[" + id + "] <a>" + host + "</><b>:" + port + "</>"); | ||
emit('dispatch', "[" + id + "] <a>" + localAddress + "</>"); | ||
serverConnection.on('connect', function() { | ||
return emit('connect', "[" + id + "] <a>" + host + "</><b>:" + port + "</>"); | ||
}).on('error', function(err) { | ||
return console.log("" + (colog.red("server error")) + "\n" + err.stack); | ||
return emit('error', "[" + id + "] serverConnection\n" + err.stack); | ||
}).on('end', function() { | ||
return emit('end', "[" + id + "] serverConnection"); | ||
}); | ||
} | ||
return clientConnection.on('error', function(err) { | ||
return emit('error', "[" + id + "] clientConnection\n" + err.stack); | ||
}).on('end', function() { | ||
return emit('end', "[" + id + "] clientConnection"); | ||
}); | ||
}).on('error', function(err) { | ||
return emit('error', "server\n" + err.stack, { | ||
raw: true | ||
}); | ||
}).on('clientError', function(err, data) { | ||
return emit('error', "client\n" + err.message + "\nReceived:\n" + data, { | ||
raw: true | ||
}); | ||
}); | ||
} | ||
return console.log("" + type + " server started on " + (colog.green("" + host + ":" + port)) + "\nDispatching to addresses " + (((function() { | ||
var _l, _len2, _ref2, _results; | ||
return log("<bold-magenta>" + type + "</> server started on <a>" + host + "</><b>:" + port + "</>\nDispatching to addresses " + (((function() { | ||
var _l, _len2, _ref3, _results; | ||
_results = []; | ||
for (_l = 0, _len2 = addresses.length; _l < _len2; _l++) { | ||
_ref2 = addresses[_l], address = _ref2.address, priority = _ref2.priority; | ||
_results.push(colog.cyan("" + address + "@" + priority)); | ||
_ref3 = addresses[_l], address = _ref3.address, priority = _ref3.priority; | ||
_results.push("<a>" + address + "</><b>@" + priority + "</>"); | ||
} | ||
@@ -122,0 +156,0 @@ return _results; |
@@ -5,3 +5,3 @@ { | ||
"author": "Alexandre Kirszenberg <a.kirszenberg@gmail.com>", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
@@ -22,4 +22,3 @@ "repository": { | ||
"dependencies": { | ||
"commander": "2.0.0", | ||
"colog": "1.0.1" | ||
"commander": "2.0.0" | ||
}, | ||
@@ -26,0 +25,0 @@ |
@@ -49,2 +49,3 @@ dispatch-proxy | ||
--http start an http proxy server | ||
--debug log debug info in the console | ||
``` | ||
@@ -51,0 +52,0 @@ Examples |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
38920
1
15
958
65
- Removedcolog@1.0.1
- Removedcolog@1.0.1(transitive)