pangoliner
Version:
pangoliner is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet. As of now, it supports tcp & udp, as well as http and https protocols, where requests can be forwarded to internal services by domain name.
63 lines (57 loc) • 2.11 kB
JavaScript
const program = require('commander');
const { ActiveServer } = require('../index');
const { ClientServer } = require('../index');
program
// 版本信息
.version('0.0.4', '-v, --version')
// 用法说明
.usage('<file ...> [options]')
// 选择名 选项描述 默认值
// 选项 可以带有一个参数 可以通过 program.copy 获取该选项信息
// 如果没有参数 该值为 true
.option('-s, --server', 'run as a server')
.option('-p, --port <port>', 'listen the local port')
.option('-c, --client', 'run as a client')
.option('-h, --host <host>', 'connect the host')
.option('-b, --binds <binds>', 'bind local port to remote')
.option('-e, --encrypt <encrypt>', 'which encrypt algorithm to use, the list is aes-128-cbc, aes-192-cbc, aes-256-cbc')
.option('-k, --key <key>', 'the encrypt key')
.option('-iv, --iv <iv>', 'the encrypt iv')
.parse(process.argv);
function resolve(program) {
// 没有匹配任何选项的参数会被放到数组 args 中
console.log(program);
const { server, client, port, host, binds, slash, args, encrypt, key, iv } = program._optionValues;
console.log(`server: ${server}, port: ${port}, args: ${JSON.stringify(args)}, binds: ${JSON.stringify(binds)}`);
if (server === true) {
(new ActiveServer({port: port || 27, encrypt, key, iv})).start();
}
if (client === true) {
// pangoliner -c -h 10.9.2.233 -p 29 -b www:80:8080;ftp:21:21
// const { binds } = program._optionValues;
console.log(`binds: ${binds}`);
const bindsArgs = {};
binds.split(',').map(item => {
const args = item.split(':');
if (args.length !== 3) {
throw `the argument of the binding port is incorrect. Error: ${args}`
}
bindsArgs[args[0]] = {
local_port: args[1],
remote_port: args[2]
}
});
console.log(`bindsArgs:${JSON.stringify(bindsArgs)}`);
const client = new ClientServer({
host: host,
port: port || 27,
binds: bindsArgs,
encrypt,
key,
iv
});
client.init();
}
}
resolve(program);