whistle 2.9.101 → 2.9.102
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/ca/cli.js +1 -1
- package/bin/use.js +3 -18
- package/bin/util.js +23 -5
- package/bin/whistle.js +43 -11
- package/biz/webui/cgi-bin/check-update.js +4 -24
- package/biz/webui/cgi-bin/plugins/disable-all-plugins.js +1 -3
- package/biz/webui/cgi-bin/rules/disable-all-rules.js +1 -3
- package/biz/webui/htdocs/index.html +1 -1
- package/biz/webui/htdocs/js/index.js +18 -18
- package/biz/webui/lib/index.js +1 -1
- package/lib/config.js +1 -0
- package/lib/handlers/file-proxy.js +1 -1
- package/lib/https/h2.js +9 -10
- package/lib/https/index.js +3 -3
- package/lib/inspectors/req.js +5 -5
- package/lib/inspectors/res.js +2 -2
- package/lib/plugins/index.js +5 -0
- package/lib/rules/rules.js +1 -1
- package/lib/rules/storage.js +1 -0
- package/lib/rules/util.js +31 -3
- package/lib/tunnel.js +2 -2
- package/lib/util/common.js +49 -0
- package/lib/util/index.js +72 -22
- package/package.json +2 -2
package/bin/ca/cli.js
CHANGED
|
@@ -29,7 +29,7 @@ function install(addr, useDefault) {
|
|
|
29
29
|
addr.needRawData = true;
|
|
30
30
|
addr.maxLength = MAX_LEN;
|
|
31
31
|
addr.headers = {
|
|
32
|
-
'user-agent': '
|
|
32
|
+
'user-agent': config.appName + '/' + config.version
|
|
33
33
|
};
|
|
34
34
|
httpMgr.request(addr, function(err, body, res) {
|
|
35
35
|
if (err) {
|
package/bin/use.js
CHANGED
|
@@ -14,7 +14,7 @@ var warn = util.warn;
|
|
|
14
14
|
var info = util.info;
|
|
15
15
|
var readConfig = util.readConfig;
|
|
16
16
|
var MAX_RULES_LEN = 1024 * 256;
|
|
17
|
-
var DEFAULT_OPTIONS =
|
|
17
|
+
var DEFAULT_OPTIONS = util.DEFAULT_OPTIONS;
|
|
18
18
|
var options;
|
|
19
19
|
|
|
20
20
|
function showStartWhistleTips(storage, isClient) {
|
|
@@ -60,21 +60,6 @@ function existsPlugin(name) {
|
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
function getBody(res, callback) {
|
|
64
|
-
var resBody = '';
|
|
65
|
-
res.setEncoding('utf8');
|
|
66
|
-
res.on('data', function(data) {
|
|
67
|
-
resBody += data;
|
|
68
|
-
});
|
|
69
|
-
res.on('end', function() {
|
|
70
|
-
if (res.statusCode != 200) {
|
|
71
|
-
callback(resBody || 'response ' + res.statusCode + ' error');
|
|
72
|
-
} else {
|
|
73
|
-
callback(null, JSON.parse(resBody));
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
63
|
var reqOptions;
|
|
79
64
|
function request(body, callback) {
|
|
80
65
|
if (!reqOptions) {
|
|
@@ -92,7 +77,7 @@ function request(body, callback) {
|
|
|
92
77
|
}
|
|
93
78
|
}
|
|
94
79
|
var req = http.request(reqOptions, function(res) {
|
|
95
|
-
getBody(res, function(err, data) {
|
|
80
|
+
util.getBody(res, function(err, data) {
|
|
96
81
|
if (err) {
|
|
97
82
|
throw err;
|
|
98
83
|
}
|
|
@@ -116,7 +101,7 @@ function checkDefault(running, storage, isClient, callback) {
|
|
|
116
101
|
};
|
|
117
102
|
var req = http.get('http://' + DEFAULT_OPTIONS.host + ':' + DEFAULT_OPTIONS.port + '/cgi-bin/status', function(res) {
|
|
118
103
|
res.on('error', execCallback);
|
|
119
|
-
getBody(res, function(err, data) {
|
|
104
|
+
util.getBody(res, function(err, data) {
|
|
120
105
|
if (err || !data || data.name !== pkg.name || data.storage !== storage) {
|
|
121
106
|
return execCallback(true);
|
|
122
107
|
}
|
package/bin/util.js
CHANGED
|
@@ -11,8 +11,10 @@ var path = require('path');
|
|
|
11
11
|
var createHmac = require('crypto').createHmac;
|
|
12
12
|
|
|
13
13
|
var joinIpPort = common.joinIpPort;
|
|
14
|
+
var DEFAULT_OPTIONS = { host: '127.0.0.1', port: 8899 };
|
|
14
15
|
|
|
15
16
|
exports.joinIpPort = joinIpPort;
|
|
17
|
+
exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
|
|
16
18
|
/*eslint no-console: "off"*/
|
|
17
19
|
var CHECK_RUNNING_CMD = process.platform === 'win32' ?
|
|
18
20
|
'tasklist /fi "PID eq %s" | findstr /i "node.exe"'
|
|
@@ -63,7 +65,7 @@ exports.warn = warn;
|
|
|
63
65
|
exports.info = info;
|
|
64
66
|
|
|
65
67
|
function showKillError() {
|
|
66
|
-
error('[!] Cannot kill ' + config.
|
|
68
|
+
error('[!] Cannot kill ' + config.appName + ' owned by root');
|
|
67
69
|
info('[i] Try to run command ' + (isWin ? 'as an administrator' : 'with sudo'));
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -75,10 +77,10 @@ function showUsage(isRunning, options, restart) {
|
|
|
75
77
|
if (restart) {
|
|
76
78
|
showKillError();
|
|
77
79
|
} else {
|
|
78
|
-
warn('[!] ' + config.
|
|
80
|
+
warn('[!] ' + config.appName + '@' + config.version + ' is running');
|
|
79
81
|
}
|
|
80
82
|
} else {
|
|
81
|
-
info('[i] ' + config.
|
|
83
|
+
info('[i] ' + config.appName + '@' + config.version + (restart ? ' restarted' : ' started'));
|
|
82
84
|
}
|
|
83
85
|
var port = /^\d+$/.test(options.port) && options.port > 0 ? options.port : config.port;
|
|
84
86
|
var list = options.host && typeof options.host === 'string' ? [options.host] : getIpList();
|
|
@@ -92,8 +94,8 @@ function showUsage(isRunning, options, restart) {
|
|
|
92
94
|
warn(' Note: If none are accessible, check your firewall settings');
|
|
93
95
|
warn(' For help, see ' + colors.bold('https://github.com/avwo/whistle'));
|
|
94
96
|
}
|
|
95
|
-
info('[i] ' + (++index) + '.
|
|
96
|
-
info('[i] ' + (++index) + '.
|
|
97
|
+
info('[i] ' + (++index) + '. Set your device\'s HTTP PROXY to ' + colors.bold((oneIp ? 'IP(' + list[0] + ')' : 'the working IP') + ' & PORT(' + port + ')'));
|
|
98
|
+
info('[i] ' + (++index) + '. Open ' + colors.bold('Chrome') + ' and visit ' + colors.bold('http://' + (options.localUIHost || config.localUIHost) + '/') + ' to begin');
|
|
97
99
|
|
|
98
100
|
var bypass = program.init;
|
|
99
101
|
if (bypass == null) {
|
|
@@ -171,3 +173,19 @@ exports.getDefaultPort = function () {
|
|
|
171
173
|
var port = conf && conf.port;
|
|
172
174
|
return port > 0 ? port : 8899;
|
|
173
175
|
};
|
|
176
|
+
|
|
177
|
+
function getBody(res, callback) {
|
|
178
|
+
var resBody;
|
|
179
|
+
res.on('data', function(data) {
|
|
180
|
+
resBody = resBody ? Buffer.concat([resBody, data]) : data;
|
|
181
|
+
});
|
|
182
|
+
res.on('end', function() {
|
|
183
|
+
if (res.statusCode != 200) {
|
|
184
|
+
callback(resBody || 'response ' + res.statusCode + ' error');
|
|
185
|
+
} else {
|
|
186
|
+
callback(null, JSON.parse(resBody + ''));
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
exports.getBody = getBody;
|
package/bin/whistle.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/*eslint no-console: "off"*/
|
|
3
3
|
var program = require('starting');
|
|
4
4
|
var path = require('path');
|
|
5
|
+
var http = require('http');
|
|
5
6
|
var config = require('../lib/config');
|
|
6
7
|
var useRules = require('./use');
|
|
7
8
|
var showStatus = require('./status');
|
|
@@ -9,19 +10,51 @@ var util = require('./util');
|
|
|
9
10
|
var plugin = require('./plugin');
|
|
10
11
|
var setProxy = require('./proxy');
|
|
11
12
|
var installCA = require('./ca/cli');
|
|
13
|
+
var colors = require('colors');
|
|
12
14
|
|
|
13
15
|
var error = util.error;
|
|
14
16
|
var info = util.info;
|
|
17
|
+
var OPTIONS = util.DEFAULT_OPTIONS;
|
|
15
18
|
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
function getLatestVersion(options, cb, index) {
|
|
20
|
+
var done;
|
|
21
|
+
var handleCb = function(err, data) {
|
|
22
|
+
if (done) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
index = index || 0;
|
|
26
|
+
if (index < 5 && (err || !data)) {
|
|
27
|
+
return setTimeout(function() {
|
|
28
|
+
getLatestVersion(options, cb, index + 1);
|
|
29
|
+
}, 300);
|
|
30
|
+
}
|
|
31
|
+
done = true;
|
|
32
|
+
cb(data && data.hasNewVersion ? data.latestVersion : '');
|
|
33
|
+
};
|
|
34
|
+
options = options || OPTIONS;
|
|
35
|
+
var req = http.get('http://' + util.joinIpPort(options.host || OPTIONS.host, options.port || OPTIONS.port) + '/cgi-bin/check-update', function(res) {
|
|
36
|
+
res.on('error', handleCb);
|
|
37
|
+
util.getBody(res, handleCb);
|
|
38
|
+
});
|
|
39
|
+
req.on('error', handleCb);
|
|
40
|
+
req.end();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function handleEnd(err, options, restart, run) {
|
|
44
|
+
var result = util.showUsage(err, options, restart);
|
|
45
|
+
getLatestVersion(options, function(latestVersion) {
|
|
46
|
+
if (latestVersion) {
|
|
47
|
+
error('[!] A new version is available (v' + latestVersion + '). Run \'' + colors.bold('npm i -g ' + config.name) + '\' to update');
|
|
48
|
+
}
|
|
49
|
+
run && console.log('Press [Ctrl+C] to stop ' + config.appName + '...');
|
|
50
|
+
});
|
|
51
|
+
if (!result) {
|
|
19
52
|
return;
|
|
20
53
|
}
|
|
21
|
-
var host = util.joinIpPort(
|
|
54
|
+
var host = util.joinIpPort(result.host, result.port);
|
|
22
55
|
var argv = [host];
|
|
23
|
-
if (
|
|
24
|
-
argv.push('-x',
|
|
56
|
+
if (result.bypass) {
|
|
57
|
+
argv.push('-x', result.bypass);
|
|
25
58
|
}
|
|
26
59
|
setProxy(argv);
|
|
27
60
|
installCA([host]);
|
|
@@ -35,10 +68,10 @@ function showStartupInfo(err, options, debugMode, restart) {
|
|
|
35
68
|
options = util.formatOptions(options);
|
|
36
69
|
var port = options.port || config.port;
|
|
37
70
|
error('[!] Failed to bind proxy port ' + (options.host ? util.joinIpPort(options.host, port) : port) + ': Port already in use');
|
|
38
|
-
info('[i] ' + config.
|
|
71
|
+
info('[i] ' + config.appName + ' may already be running. Try: ' + (debugMode ? 'w2 stop' : 'w2 restart') + ' to ' + (debugMode ? 'stop' : 'restart') + ' ' + config.appName);
|
|
39
72
|
info(' or use a different port with: ' + (debugMode ? '`w2 run -p newPort`\n' : '`w2 start -p newPort`\n'));
|
|
40
73
|
} else if (err.code == 'EACCES' || err.code == 'EPERM') {
|
|
41
|
-
error('[!] Permission denied: Cannot start ' + config.
|
|
74
|
+
error('[!] Permission denied: Cannot start ' + config.appName + ' as root');
|
|
42
75
|
info('[i] Try running with sudo\n');
|
|
43
76
|
}
|
|
44
77
|
|
|
@@ -70,8 +103,7 @@ program.setConfig({
|
|
|
70
103
|
showStartupInfo(err, options, true);
|
|
71
104
|
return;
|
|
72
105
|
}
|
|
73
|
-
handleEnd(false, options);
|
|
74
|
-
console.log('Press [Ctrl+C] to stop ' + config.name + '...');
|
|
106
|
+
handleEnd(false, options, false, true);
|
|
75
107
|
},
|
|
76
108
|
startCallback: showStartupInfo,
|
|
77
109
|
restartCallback: function(err, options) {
|
|
@@ -79,7 +111,7 @@ program.setConfig({
|
|
|
79
111
|
},
|
|
80
112
|
stopCallback: function(err) {
|
|
81
113
|
if (err === true) {
|
|
82
|
-
info('[i] ' + config.
|
|
114
|
+
info('[i] ' + config.appName + ' killed');
|
|
83
115
|
} else if (err) {
|
|
84
116
|
if (err.code === 'EPERM') {
|
|
85
117
|
util.showKillError();
|
|
@@ -1,38 +1,18 @@
|
|
|
1
1
|
var properties = require('../../../lib/rules/util').properties;
|
|
2
2
|
var config = require('../../../lib/config');
|
|
3
|
-
|
|
4
|
-
function compare(v1, v2) {
|
|
5
|
-
if (typeof v1 != 'string') {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
if (typeof v2 != 'string') {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
v1 = v1.split('.');
|
|
12
|
-
v2 = v2.split('.');
|
|
13
|
-
var v1Major = parseInt(v1[0], 10) || 0;
|
|
14
|
-
var v2Major = parseInt(v2[0], 10) || 0;
|
|
15
|
-
|
|
16
|
-
if (v1Major < v2Major) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (v1Major > v2Major) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return parseInt(v1[1], 10) > parseInt(v2[1], 10);
|
|
25
|
-
}
|
|
3
|
+
var common = require('../../../lib/util/common');
|
|
26
4
|
|
|
27
5
|
module.exports = function(req, res) {
|
|
28
6
|
var version = config.version;
|
|
29
7
|
var doNotShowAgainVersion = properties.get('doNotShowAgainVersion');
|
|
30
8
|
var latestVersion = properties.getLatestVersion('latestVersion');
|
|
9
|
+
var hasNewVersion = common.compareVersion(latestVersion, version);
|
|
31
10
|
|
|
32
11
|
res.json({
|
|
33
12
|
ec: 0,
|
|
34
13
|
em: 'success',
|
|
35
|
-
showUpdate: !config.disableUpdateTips &&
|
|
14
|
+
showUpdate: !config.disableUpdateTips && hasNewVersion > 1 && common.compareVersion(latestVersion, doNotShowAgainVersion) > 1,
|
|
15
|
+
hasNewVersion: hasNewVersion > 0,
|
|
36
16
|
version: config.version,
|
|
37
17
|
latestVersion: latestVersion
|
|
38
18
|
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
var properties = require('../../../../lib/rules/util').properties;
|
|
2
1
|
var pluginMgr = require('../../lib/proxy').pluginMgr;
|
|
3
2
|
|
|
4
3
|
module.exports = function(req, res) {
|
|
5
|
-
|
|
6
|
-
pluginMgr.updateRules();
|
|
4
|
+
pluginMgr.disableAllPlugins(req.body.disabledAllPlugins == 1);
|
|
7
5
|
res.json({ec: 0, em: 'success'});
|
|
8
6
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
var properties = require('../../../../lib/rules/util').properties;
|
|
2
1
|
var rules = require('../../../../lib/rules/util').rules;
|
|
3
2
|
|
|
4
3
|
module.exports = function(req, res) {
|
|
5
|
-
|
|
6
|
-
rules.parseRules();
|
|
4
|
+
rules.disableAllRules(req.body.disabledAllRules == 1);
|
|
7
5
|
res.json({ec: 0, em: 'success'});
|
|
8
6
|
};
|
|
9
7
|
|