mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-20 12:44:21 +00:00
60 lines
2.1 KiB
JavaScript
60 lines
2.1 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
var program = require('commander'),
|
|
proxy = require("./proxy.js"),
|
|
color = require('colorful'),
|
|
fs = require("fs"),
|
|
path = require("path"),
|
|
packageInfo = require("./package.json");
|
|
|
|
program
|
|
.version(packageInfo.version)
|
|
.option('-u, --host [value]', 'hostname for https proxy, localhost for default')
|
|
.option('-t, --type [value]', 'http|https, http for default')
|
|
.option('-p, --port [value]', 'proxy port, 8001 for default')
|
|
.option('-f, --file [value]', 'save request data to a specified file, will use in-memory db if not specified')
|
|
.option('-r, --rule [value]', 'path for rule file,')
|
|
.option('-g, --root [value]', 'generate root CA')
|
|
.option('-l, --throttle [value]', 'throttle speed in kb/s (kbyte / sec)')
|
|
.option('-i, --intercept', 'intercept(decrypt) https requests when root CA exists')
|
|
.option('-c, --clear', 'clear all the tmp certificates')
|
|
.parse(process.argv);
|
|
|
|
if(program.clear){
|
|
require("./lib/certMgr").clearCerts(function(){
|
|
console.log( color.green("all certs cleared") );
|
|
process.exit(0);
|
|
});
|
|
|
|
}else if(program.root){
|
|
require("./lib/certMgr").generateRootCA(function(){
|
|
process.exit(0);
|
|
});
|
|
}else{
|
|
var ruleModule;
|
|
|
|
if(program.rule){
|
|
var ruleFilePath = path.join(process.cwd(),program.rule);
|
|
try{
|
|
if(fs.existsSync(ruleFilePath)){
|
|
ruleModule = require(program.rule);
|
|
console.log("rule file loaded :" + ruleFilePath);
|
|
}else{
|
|
console.log(color.red("can not find rule file"));
|
|
}
|
|
}catch(e){
|
|
console.log("failed to load rule file :" + e.toString());
|
|
}
|
|
}
|
|
|
|
new proxy.proxyServer({
|
|
type : program.type,
|
|
port : program.port,
|
|
hostname : program.host,
|
|
dbFile : program.file,
|
|
throttle : program.throttle,
|
|
rule : ruleModule,
|
|
disableWebInterface : false,
|
|
interceptHttps : program.intercept
|
|
});
|
|
} |