whistle 2.9.103 → 2.9.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/util.js CHANGED
@@ -8,6 +8,7 @@ var config = require('../lib/config');
8
8
  var common = require('../lib/util/common');
9
9
  var colors = require('colors/safe');
10
10
  var path = require('path');
11
+ var extend = require('extend');
11
12
  var createHmac = require('crypto').createHmac;
12
13
 
13
14
  var joinIpPort = common.joinIpPort;
@@ -72,7 +73,7 @@ function showKillError() {
72
73
  exports.showKillError = showKillError;
73
74
 
74
75
  function showUsage(isRunning, options, restart) {
75
- options = formatOptions(options);
76
+ var rcConf;
76
77
  if (isRunning) {
77
78
  if (restart) {
78
79
  showKillError();
@@ -80,10 +81,20 @@ function showUsage(isRunning, options, restart) {
80
81
  warn('[!] ' + config.appName + '@' + config.version + ' is running');
81
82
  }
82
83
  } else {
84
+ rcConf = common.readWhistleRc(options);
85
+ if (rcConf) {
86
+ var rcStr = JSON.stringify(rcConf);
87
+ if (rcStr.length > 30) {
88
+ rcStr = rcStr.substring(0, 27) + '...';
89
+ }
90
+ info('[i] Load configuration from ~/.whistlerc: ' + rcStr);
91
+ }
83
92
  info('[i] ' + config.appName + '@' + config.version + (restart ? ' restarted' : ' started'));
84
93
  }
94
+ options = options ? extend({}, rcConf, options) : rcConf;
95
+ options = formatOptions(options);
85
96
  var port = /^\d+$/.test(options.port) && options.port > 0 ? options.port : config.port;
86
- var list = options.host && typeof options.host === 'string' ? [options.host] : getIpList();
97
+ var list = common.isString(options.host) ? [options.host] : getIpList();
87
98
  var oneIp = list.length === 1;
88
99
  var index = 0;
89
100
  if (!oneIp) {
package/bin/whistle.js CHANGED
@@ -169,6 +169,7 @@ program
169
169
  .option('--init [bypass]', 'auto configure proxy and install Root CA')
170
170
  .option('--cluster [workers]', 'start cluster with worker count (default: CPU cores)', String, undefined)
171
171
  .option('--config [config]', 'load startup config from file', String, undefined)
172
+ .option('--rcPath [rcPath]', 'load configuration from file (default: ~/.whistlerc)', String, undefined)
172
173
  .option('--dnsServer [dnsServer]', 'set custom DNS servers', String, undefined)
173
174
  .option('--socksPort [socksPort]', 'set SOCKSv5 server port', String, undefined)
174
175
  .option('--httpPort [httpPort]', 'set HTTP server port', String, undefined)
@@ -57,6 +57,7 @@ module.exports = function(req, res) {
57
57
  disabledPlugins: !config.notAllowedDisablePlugins && properties.get('disabledPlugins') || {},
58
58
  allowMultipleChoice: properties.get('allowMultipleChoice'),
59
59
  backRulesFirst: properties.get('backRulesFirst'),
60
+ enabledCount: rules.getEnabledRules().length,
60
61
  disabledAllPlugins: !config.notAllowedDisablePlugins && properties.get('disabledAllPlugins'),
61
62
  disabledAllRules: !config.notAllowedDisableRules && properties.get('disabledAllRules'),
62
63
  interceptHttpsConnects: properties.isEnableCapture(),
@@ -27,7 +27,7 @@ module.exports = function(req, res) {
27
27
  if (err) {
28
28
  res.type('text').status(500).send(err.stack || err);
29
29
  } else {
30
- req.url = '/cgi-bin/sessions/get-temp-file?filename=' + encodeURIComponent(url);
30
+ req.url = '/cgi-bin/temp/get?filename=' + encodeURIComponent(url);
31
31
  util.transformReq(req, res, options.port);
32
32
  }
33
33
  });
@@ -0,0 +1,10 @@
1
+ var rules = require('../../../../lib/rules/util').rules;
2
+ var util = require('../util');
3
+
4
+ module.exports = function(req, res) {
5
+ util.sendGzip(req, res, {
6
+ ec: 0,
7
+ mflag: rules.getMFlag(),
8
+ list: rules.getEnabledRules()
9
+ });
10
+ };
@@ -26,5 +26,6 @@ module.exports = function(req, res) {
26
26
  } else {
27
27
  filename = 'rules_' + util.formatDate() + '.txt';
28
28
  }
29
- res.attachment(filename).send(JSON.stringify(result, null, ' '));
29
+ res.attachment(filename);
30
+ util.sendGzipText(req, res, null, JSON.stringify(result, null, ' '));
30
31
  };
@@ -1,14 +1,14 @@
1
1
  var get = require('./index');
2
- var getReqData = require('../util').getReqData;
3
2
  var addRules = require('../../../../lib/rules/util').addRules;
3
+ var util = require('../util');
4
4
 
5
5
  module.exports = function(req, res) {
6
- getReqData(req, function(err, result) {
6
+ util.getReqData(req, function(err, result) {
7
7
  if (err) {
8
8
  res.status(200).json({ ec: 2, em: err.message });
9
9
  } else {
10
10
  addRules(result.data, result.replace, req.query.clientId);
11
- res.json(get());
11
+ util.sendGzip(req, res, get());
12
12
  }
13
13
  });
14
14
  };
@@ -4,6 +4,7 @@ var properties = require('../../../../lib/rules/util').properties;
4
4
  module.exports = function get() {
5
5
  return {
6
6
  ec: 0,
7
+ enabledCount: rules.getEnabledRules().length,
7
8
  defaultRulesIsDisabled: rules.defaultRulesIsDisabled(),
8
9
  defaultRules: rules.getDefault(),
9
10
  allowMultipleChoice: properties.get('allowMultipleChoice'),
@@ -1,5 +1,6 @@
1
1
  var get = require('./index');
2
+ var util = require('../util');
2
3
 
3
4
  module.exports = function(req, res) {
4
- res.json(get());
5
+ util.sendGzip(req, res, get());
5
6
  };
@@ -1,7 +1,8 @@
1
1
  var recycleBin = require('../../../../../lib/rules/util').rules.recycleBin;
2
+ var util = require('../../util');
2
3
 
3
4
  module.exports = function(req, res) {
4
- res.json({
5
+ util.sendGzip(req, res, {
5
6
  ec: 0,
6
7
  list: recycleBin.list()
7
8
  });
@@ -2,8 +2,10 @@ var gzip = require('zlib').gzip;
2
2
  var util = require('../../../lib/util');
3
3
  var config = require('../../../lib/config');
4
4
  var proc = require('../../../lib/util/process');
5
- var properties = require('../../../lib/rules/util').properties;
5
+ var rulesUtil = require('../../../lib/rules/util');
6
6
 
7
+ var properties = rulesUtil.properties;
8
+ var rules = rulesUtil.rules;
7
9
  var PID = process.pid;
8
10
  var MAX_OBJECT_SIZE = 1024 * 1024 * 6;
9
11
  var index = 0;
@@ -31,6 +33,7 @@ exports.getServerInfo = function(req) {
31
33
  ipv6Only: config.ipv6Only,
32
34
  dcc: config.disableCustomCerts,
33
35
  dns: dnsOverHttps || config.dnsServer,
36
+ rulesMFlag: rules.getMFlag(),
34
37
  doh: doh,
35
38
  bip: config.host,
36
39
  df: config.dnsOptional,
@@ -151,6 +154,19 @@ function sendError(res, err) {
151
154
 
152
155
  exports.sendError = sendError;
153
156
 
157
+ function sendGzipData(res, headers, buffer) {
158
+ if (headers) {
159
+ headers['Content-Encoding'] = 'gzip';
160
+ headers['Content-Length'] = buffer.length;
161
+ res.writeHead(200, headers);
162
+ res.end(buffer);
163
+ } else {
164
+ res.setHeader('Content-Encoding', 'gzip');
165
+ res.setHeader('Content-Length', buffer.length);
166
+ res.send(buffer);
167
+ }
168
+ }
169
+
154
170
  exports.sendGzip = function(req, res, data) {
155
171
  if (!util.canGzip(req)) {
156
172
  return res.json(data);
@@ -164,11 +180,25 @@ exports.sendGzip = function(req, res, data) {
164
180
  }
165
181
  return;
166
182
  }
167
- res.writeHead(200, {
168
- 'Content-Type': 'application/json; charset=utf-8',
169
- 'Content-Encoding': 'gzip',
170
- 'Content-Length': result.length
171
- });
172
- res.end(result);
183
+ sendGzipData(res, {
184
+ 'Content-Type': 'application/json; charset=utf-8'
185
+ }, result);
186
+ });
187
+ };
188
+
189
+ exports.sendGzipText = function(req, res, headers, text, gzipText) {
190
+ if (!text || !util.canGzip(req)) {
191
+ headers && res.writeHead(200, headers);
192
+ return headers ? res.end(text) : res.send(text);
193
+ }
194
+ if (gzipText) {
195
+ return sendGzipData(res, headers, gzipText);
196
+ }
197
+ gzip(text, function(err, result) {
198
+ if (err) {
199
+ headers && res.writeHead(200, headers);
200
+ return headers ? res.end(text) : res.send(text);
201
+ }
202
+ sendGzipData(res, headers, result);
173
203
  });
174
204
  };
@@ -1,14 +1,14 @@
1
1
  var get = require('./index');
2
- var getReqData = require('../util').getReqData;
2
+ var util = require('../util');
3
3
  var addValues = require('../../../../lib/rules/util').addValues;
4
4
 
5
5
  module.exports = function(req, res) {
6
- getReqData(req, function(err, result) {
6
+ util.getReqData(req, function(err, result) {
7
7
  if (err) {
8
8
  res.status(200).json({ ec: 2, em: err.message });
9
9
  } else {
10
10
  addValues(result.data, result.replace, req.query.clientId);
11
- res.json(get());
11
+ util.sendGzip(req, res, get());
12
12
  }
13
13
  });
14
14
  };
@@ -1,5 +1,6 @@
1
1
  var get = require('./index');
2
+ var util = require('../util');
2
3
 
3
4
  module.exports = function(req, res) {
4
- res.json(get());
5
+ util.sendGzip(req, res, get());
5
6
  };
@@ -1,7 +1,8 @@
1
1
  var recycleBin = require('../../../../../lib/rules/util').values.recycleBin;
2
+ var util = require('../../util');
2
3
 
3
4
  module.exports = function(req, res) {
4
- res.json({
5
+ util.sendGzip(req, res, {
5
6
  ec: 0,
6
7
  list: recycleBin.list()
7
8
  });
@@ -8,6 +8,6 @@
8
8
  </head>
9
9
  <body style="overscroll-behavior-x: none;">
10
10
  <div id="container" class="main"></div>
11
- <script src="js/index.js?v=2.9.103"></script>
11
+ <script src="js/index.js?v=2.9.104"></script>
12
12
  </body>
13
13
  </html>