1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | const program = require('commander'),
|
6 | color = require('colorful'),
|
7 | co = require('co'),
|
8 | packageInfo = require('../package.json'),
|
9 | util = require('../lib/util'),
|
10 | rootCACheck = require('./rootCACheck'),
|
11 | startServer = require('./startServer'),
|
12 | logUtil = require('../lib/log');
|
13 |
|
14 | program
|
15 | .version(packageInfo.version)
|
16 | .option('-p, --port [value]', 'proxy port, 8001 for default')
|
17 | .option('-w, --web [value]', 'web GUI port, 8002 for default')
|
18 | .option('-r, --rule [value]', 'path for rule file,')
|
19 | .option('-l, --throttle [value]', 'throttle speed in kb/s (kbyte / sec)')
|
20 | .option('-i, --intercept', 'intercept(decrypt) https requests when root CA exists')
|
21 | .option('-s, --silent', 'do not print anything into terminal')
|
22 | .option('-c, --clear', 'clear all the certificates and temp files')
|
23 | .option('--ws-intercept', 'intercept websocket')
|
24 | .option('--ignore-unauthorized-ssl', 'ignore all ssl error')
|
25 | .parse(process.argv);
|
26 |
|
27 | if (program.clear) {
|
28 | require('../lib/certMgr').clearCerts(() => {
|
29 | util.deleteFolderContentsRecursive(util.getAnyProxyPath('cache'));
|
30 | console.log(color.green('done !'));
|
31 | process.exit(0);
|
32 | });
|
33 | } else if (program.root) {
|
34 | require('../lib/certMgr').generateRootCA(() => {
|
35 | process.exit(0);
|
36 | });
|
37 | } else {
|
38 | co(function *() {
|
39 | if (program.silent) {
|
40 | logUtil.setPrintStatus(false);
|
41 | }
|
42 |
|
43 | if (program.intercept) {
|
44 | try {
|
45 | yield rootCACheck();
|
46 | } catch (e) {
|
47 | console.error(e);
|
48 | }
|
49 | }
|
50 |
|
51 | return startServer(program);
|
52 | })
|
53 | }
|
54 |
|