mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-20 04:04:22 +00:00
56 lines
1.6 KiB
JavaScript
Executable File
56 lines
1.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
'use strict';
|
|
|
|
const program = require('commander'),
|
|
color = require('colorful'),
|
|
co = require('co'),
|
|
packageInfo = require('../package.json'),
|
|
util = require('../dist/util').default,
|
|
rootCACheck = require('./rootCaCheck'),
|
|
startServer = require('./startServer'),
|
|
certMgr = require('../dist/certMgr').default,
|
|
logUtil = require('../dist/log');
|
|
|
|
program
|
|
.version(packageInfo.version)
|
|
.option('-p, --port [value]', 'proxy port, 8001 for default')
|
|
.option('-w, --web [value]', 'web GUI port, 8002 for default')
|
|
.option('-r, --rule [value]', 'path for rule file,')
|
|
.option('-l, --throttle [value]', 'throttle speed in kb/s (kbyte / sec)')
|
|
.option('-i, --intercept', 'intercept(decrypt) https requests when root CA exists')
|
|
.option('-s, --silent', 'do not print anything into terminal')
|
|
.option('-c, --clear', 'clear all the certificates and temp files')
|
|
.option('--ws-intercept', 'intercept websocket')
|
|
.option('--ignore-unauthorized-ssl', 'ignore all ssl error')
|
|
.parse(process.argv);
|
|
|
|
if (program.clear) {
|
|
certMgr.clearCerts(() => {
|
|
util.deleteFolderContentsRecursive(util.getAnyProxyPath('cache'));
|
|
console.log(color.green('done !'));
|
|
process.exit(0);
|
|
});
|
|
} else if (program.root) {
|
|
certMgr.generateRootCA(() => {
|
|
process.exit(0);
|
|
});
|
|
} else {
|
|
co(function *() {
|
|
if (program.silent) {
|
|
logUtil.setPrintStatus(false);
|
|
}
|
|
|
|
if (program.intercept) {
|
|
try {
|
|
yield rootCACheck();
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
return startServer(program);
|
|
})
|
|
}
|
|
|