Skip to content

Commit 53edd07

Browse files
committed
Squashed 'vendor/whistle/' changes from d70edcf1a..5ff01575d
5ff01575d Release v2.8.2 d3fd39c9a Release v2.8.2 a6506b7b7 refactor: remove wisl 126e4313f style: refine ui 08cede362 feat: use resMerge://true to deep merge a2cf4341e Release v2.8.1 4de2e6b0e refactor: refine code a4c66c8c9 refactor: refine readFile c7e256c6a refactor: refine code d4759ae79 feat: add enable://tunnelHeadersFirst 33dc5c500 style: fix trigger update plugins 6c99a5f2b refactor: refine code 89b20b15e refactor: refine code af7c1656b refactor: ensure plugin loading order 7deb348f4 refactor: refine code 75982f1e9 refactor: refine code 1af05c6b0 refactor: refine request data cache 417525ebf feat: custom response body by auth hook 69e698976 refactor: refine code 02f36d0db feat: req.setHtml & req.setUrl 87a5dd2c7 refactor: refine code 3007a7f58 chore: refine wording 32175b7b6 refactor: update starting b3ab7f8ff refactor: make sure to load plugins in order beff58ba1 refactor: refine load plugins 766593693 style: do not highlight ignore bce96263b refactor: refine code af06d9d77 refactor: ipList => idList 1c9e8aa80 Release v2.8.1 5d873002e refactor: refine code d69ddc50a refactor: refine code 8e31ad10d feat: support setting res rules through headers 8a2ab1670 refactor: use SNI first 7e70e42ca refactor: w2 status -l <=> w2 status --all d64970ded refactor: handle unhandledRejection 1d74cb296 ci: add Node17 ee0d24940 chore: add workerIndex 2a74c50b8 chore: add workerIndex ebee9cdbc refactor: refine cli 4304dfd70 Releases v2.8.0 9e2f3205a refactor: refine code 6bec8bd15 feat: cluster > headless 59742b807 refactor: refine load plugin rules b5786d657 feat: loadPluginUntil d2a6075ca feat: add cli --cluster [workers] 6bfc65022 refactor: refine code 8552a66f4 refactor: config.notAllowedDisablePlugins = true is config.disableWebUI === true 04978e0d2 Release v2.7.29 34f7588fb fix: avwo/whistle#643 09a7c63f0 refactor: refine http h2 812e1d9b4 fix: display SNI Plugin 7ec2e3805 refactor: refine code 41b5aae62 feat: add whistleStarted event 392da8428 refactor: refine code ac2438f84 refactor: update adm-zip 4a3904811 Release v2.7.28 427c40748 fix: capture data baee80b4f style: table sort d78b999f0 Release v2.7.27 6c02ace9a feat: inheritAuth 3dbee3861 Release v2.7.27 fa7e919e8 fix: setProperties 9e224012b Release v2.7.26 71c1dd0ef refactor: refine export sessions adc5c70f4 refactor: hasCertCache -> certCacheInfo 7c9ca476c refactor: refine sniCallback 5944558b1 refactor: refine sniCallback 158e6223b feat: add pluginBaseDir ee0420fcd Release v2.7.26 640bf55aa refactor: refine code d00566210 refactor: refine code 188ce0755 refactor: Cert Source -> SNI Plugin 1c5409964 style: show cert source 637d9a98d feat: resovle sni callback 20a0876d8 refactor: refine code bc8404444 refactor: allow cache certs from plugin 91da64cf6 feat: add disableCustomCerts mode d042b220f feat(plugin): add sniCallback hook 9ab031943 feat: add sniCallback protocol ad8af581c feat: disable://captureSNI & disable://captureNoSNI f32a8dc32 refactor: refine code 5b8a15536 refactor: output error stack 5b2cc59b6 feat: export require to require whistle project deps for config script d8da3308b refactor: --pluginPaths === --addon 84120885f feat: add headless mode 1994a11fa chore: refine tips e2d78abca firewall typo e43721bfa feat: allow to disable web UI 1157eb29c refactor: update hagent 4574b02d6 feat: add cli -M captureData ec3dffd83 Release v2.7.26 f0697a66e refactor: refine code 4013d70ec feat: add --config cli option f1a376249 feat: read shadowRules from local file afaa70790 refactor: refine code 2009bab53 Release v2.7.26 05a14a369 feat: support remote certificate b2289b1fa refactor: refine code ab77dcccc Release v2.7.25 3713e5191 style: add +Top button 0f3a23ddf refactor: refine code 426a1ede4 Release v2.7.25 1d4647d88 refactor: refine w2 stop d07e34134 refactor: httpsH2 === h2 53f46d13c fix: ensure resume paused stream 1027b2355 style: export getWhistleProxyServerInfo 607e88d7a style: add openInPlugins option 64c5ee830 refactor: refine code 46dc40e26 refactor: set content-type 3d9d7ec6b refactor: refine updateRules 7e3a395a3 refactor: keep client id 5a2d8b839 Release v2.7.24 0f96a7b03 refactor: proxyTunnel requires proxyHost to be valid to take effect ec9051f80 refactor: refine lineProps 323256c7f refactor: refine code a45a8d40b feat: add globalData a29537603 feat: add x-server header 5107b2488 fix: display tunnel port a49636dfb style: refine overview b8dca4e90 style: fix word spelling errors 2dbb7211d style: refine ui 0bd93bc54 refactor: refine code 2ec0bef89 README-zh_CN.md: update outdated url 6924b722f style: responsive 312e9b97b refactor: handle ERR_SSL_WRONG_VERSION_NUMBER 5631235f0 style: refine ui 481299114 feat: allow to obtain reqId in Composer 7be02aa1d style: refine ui d9d041087 style: refine ui 71e9bf348 Release v2.7.23 f142c9d76 style: add history list 092420d9a style: show compose history 7efd75812 refactor: add gzip 5b1c41e85 style: refine history list of Composer 90600039b refactor: refine code 0f1f2d1bd style: refine http methods 39502db14 feat: add proxyServer mode f6bfb909c refactor: refine code 37e090504 refactor: refine composer a48b088b3 style: add confirm dialog 78a8a2d60 style: refine update plugins button c5f36ec72 style: show plugins disabled status 772017e10 style: show the rules disabled status ad031d865 Release v2.7.22 b0790241f style: refine ui 94fa352da Release v2.7.22 6161f8f47 feat: add plugin.auth/req.setRedirect(fullUrl) cdf71a2ee refactor: refine code f57b9c616 style: refine ui 4ecc85684 refactor: refine code dfc576d8e refactor: refine frame cache 9a20b2dc5 Release v2.7.1 5ae6bf926 Release v2.7.21 4086897da style: refine ui 2f0028ff8 perf: refine code 9dc288df5 fix: requests count 8934bc069 feat: reset proxy-authorization by auth hook 88b732d34 refactor: increase cache size 1f5488cdc refactor: refine code 42f7af55c feat: http request support customParser 1068c83b5 refactor: tunnel.getFrames(cb) 5a3dff136 refactor: refine code 33cd33373 refactor: refine frames 5d005c397 feat: plugin/options.getHttpsStatus(callback) 7e5a4c68f refactor: enable://useFrames === enable://customFrames 50ac75c2a feat: allow to custom http request frames 24514094f refactor: refine ui d82587ba1 refactor: refine request event 5e6523c1d refactor: refine code 32e17e26c style: refine ui c7852d8eb feat: auto cache certs cf3b6e72d feat: plugin/options.getRootCA 17514289e style: refine context menu in left bar e51105956 Release v2.7.21 be45fd974 fix: this -> self a16a3a3b3 Release v2.7.20 81428821e fix: Cannot read property 'headers' of undefined c9f28b4b9 refactor: w2 add 98371cb0b feat: custom tunnel proxy headers for websocket 3ac56f69c feat: custom tunnel proxy headers 0546ec058 style: refine ui d5e22b12f refactor: do not use h2 in internal proxy 07b3e91da refactor: refine code 06a340b6e refactor: refine timings 76e2c2638 refactor: add gzip 710eba109 feat: get the request & response body of h2 on time 7c24c19ba feat: handle the proxy of http h2 request ac754fdde style: refine timeline 81430643a refactor: refine timeline c8a4f514b refactor: refine code 5830ea26c style: refine ui 6e4da82df refactor: refine code d05d7ad6f feat: enable://httpH2 or disable://httpH2 ecc930a8a refactor: refine code 6e362fd90 Release v2.7.19 21c45e991 refactor: refine code 9ec218aed feat: handle http h2 b82b89a6b feat: handle http2 request ab8b1b79a refactor: refine code c029ec430 feat: getHttp2Server 19f75b1b1 feat: handle unencrypted http2 request bf358d82d feat: add getCert API for plugin 45c3471c7 refactor: refine requestTime fbfe50cd7 refactor: refine resDelay fd890fbe3 fix: reqDelay & resDelay 9f625da1d fix: reqDelay for http2 request bc4f8ad3f style: refine tips fd3413efe style: add request body too long tips 10da9a7ff refactor: refine code 4e6df54dc refactor: make sure to get client ip & port faa05e254 refactor: add log 4bb04009f refactor: refine code 10cf943b4 refactor: refine code 517aff8f2 Release v2.7.18 9737f7860 feat: show ui requests info 3f187c3e9 feat: show ui requests 93d5b63d6 Release v2.7.18 f1737f648 refactor: refine code 173e57fd8 refactor: refine code f591100fb feat: allow to custom tunnel key 7343026e3 feat: allow to auth ui request 55676ca9d refactor: handle proxy request df1af46b8 refactor: refine internel proxy baf2effd8 refactor: refine code 249eec8ec feat: show login box by auth 50e54f944 feat: enable capture by auth bd24e6506 refactor: refine code aed585c4c chore: remove dockerfile 7d1f8dcf8 修复文档多余的符号 fb0a3ca24 refactor: refine resReplace c9debd092 refactor: refine resReplace c9019bd61 feat: custom static dir 9708f94c4 refactor: refine code ac6e4100d Release v2.7.17 ef072d2dd feat: replaceStatus for websocket 5b951b72b feat: replaceStatus for tunnel 497bcbbaa Release v2.7.16 b4770fe2e fix: Maximum call stack size exceeded 37934b11a refactor: refine timeout a48a250fa refactor: refine code 94d0421b5 refactor: refine code bd6d80440 refactor: refine code 85624620b style: fix js error 2e10fbf25 test: auth e37287dd8 refactor: refine code 51d52c366 feat: auth request by plugin 5af60c380 feat: add auth hook 924b9de38 style: refine disabled style 62e3f8ea2 style: refine timeline c70796c35 Release v2.7.15 ced6a8cb7 style: refine UI 83c1fc2d1 style: show req body size c4778cace style: refine UI 78bafe703 refactor: refine code c66a43927 Release v2.7.14 8e98f891a refactor: refine code 41743aad2 feat: export require 6aac921d5 refactor: refine plugin data dir 106f945ad style: refine overview a28ff46e5 style: refine overview b068cf5c9 refactor: refine code 27e6b7fd6 style: refine win.confirm 0d5b5e406 style: word-break -> break-word d99b8a9ca style: use custom confirm dialog 592e105a8 style: refine ui b1aba6faa style: custom alert 1b4eb6a99 refactor: refine code 1249fd011 refactor: refine regexp ae5a90a2b style: confirm -> win.confirm 72e254ad7 style: alert -> win.alert 02d5afaa2 style: refine code 7e304c77c feat: filter by clientPort & serverPort 246f4adff feat: add tpl var: clientPort, serverPort 30fdfaa2a feat: set req.serverPort de01141d0 Release v2.7.13 d3676b25c refactor: update hparser 04908bac1 refactor: parse ws headers a56959725 refactor: refine code dbbc1c811 style: refine preview 9593648b3 Release v2.7.12 99fd4cd53 fix: shift-1 error 660f10e63 refactor: refine code fa585e18e refactor: refine code 7ad76fe85 feat: connect(tunnelPath, cb, opts) 8e264bbbc refactor: handle replace all 5f0348e76 Release v2.7.12 64f569e16 refactor: refine code 93ef281b5 refactor: refine code fc96c96ce Release v2.7.12 2f06da812 fix: reqReplace & resReplace git-subtree-dir: vendor/whistle git-subtree-split: 5ff01575d18befa2070f973a598f6c3bc06fed64
1 parent 259900a commit 53edd07

File tree

116 files changed

+4014
-2451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+4014
-2451
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ node_js:
77
- "14"
88
- "15"
99
- "16"
10+
- "17"
1011

1112
install:
1213
- npm install

CHANGELOG.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,88 @@
1+
# v2.8.2
2+
1. feat: `resMerge://json1 resMerge://json2` 默认采用 `extend({}, json1, json2)`,新版支持通过 `resMerge://json1 resMerge://json2 resMerge://true` 开启 `extend(true, {}, json1, json2)`
3+
2. refactor: 插件规则里面的 req 和 res rules 分开执行
4+
5+
# v2.8.1
6+
1. refactor: 优化获取证书逻辑,合并多次相同请求
7+
2. refactor: 处理 `unhandledRejection` 事件
8+
3. feat: 支持通过请求头设置响应规则
9+
4. fix: sniCallback 内存泄露问题
10+
11+
# v2.8.0
12+
1. feat: 支持启动 `--cluster [workers]` 模式,通过该方式可以启动多进程模式(worker 为 Whistle headless)
13+
2. fix: 启动时绑定非 `127.0.0.1` 网卡,插件远程规则访问失败问题
14+
15+
# v2.7.29
16+
1. fix: https://github.com/avwo/whistle/issues/643
17+
18+
# v2.7.28
19+
1. fix: WebSocket 无法抓包问题
20+
21+
# v2.7.27
22+
1. fix: 插件用到 `storage.setProperties` 失效问题
23+
2. feat: 插件 `whistleConfig` 支持配置 `inheritAuth` 复用 Whistle 的登录账号
24+
25+
# v2.7.26
26+
1. feat: 支持通过插件 `sniCallback(req, options)` hook 获取远程证书
27+
2. feat: 支持通过 `--config localFile` 加载启动配置,优先级高于命令行
28+
29+
# v2.7.25
30+
1. fix: 某些情况下响应 stream pause 问题
31+
2. refactor: 优化 `w2 stop`,找不到指定实例时自动显示当前所有运行的实例
32+
3. style: 支持将 Rules 添加到最前面
33+
34+
# v2.7.24
35+
1. refactor: 优化 `lineProps://proxyHost|proxyTunnel|proxyFirst`
36+
37+
# v2.7.23
38+
1. style: 优化显示 Composer 历史记录列表
39+
2. style: 禁用 Rules、Plugins 显示小黄条提醒
40+
41+
# v2.7.22
42+
1. feat: 插件 auth 方法支持 `req.setRedirect(url);`
43+
2. perf: 优化启动速度
44+
3. fix: 修复第三方集成时,一些内部请求转发问题
45+
46+
# v2.7.21
47+
1. fix: 清除搜索框历史记录 js 报错问题
48+
2. feat: 普通 HTTP 请求也支持 `customParser`(或 `customFrames`):https://github.com/whistle-plugins/whistle.custom-parser
49+
50+
# v2.7.20
51+
1. fix: Cannot read property 'headers' of undefined
52+
53+
# v2.7.19
54+
1. feat: HTTP2 支持非 HTTPS 请求
55+
2. feat: 插件支持通过 `options.getCert(domain, (cert || '') => {})` 获取指定域名证书
56+
3. refactor: 优化 `reqDelay``resDelay` 实现
57+
# v2.7.18
58+
1. feat: 支持插件设置 `tunnelKey` 将指定的隧道代理请求头带到解开后的 http/https/ws 请求头
59+
2. feat: 插件 `auth` 方法支持处理 Whistle 的内部请求
60+
3. feat: 插件 `auth` 支持设置 `req.showLoginBox` 弹出登录框
61+
4. style: 显示 UI 请求情况
62+
5. refactor: 优化内部请求转发逻辑的实现方式
63+
64+
# v2.7.17
65+
1. feat: WebSocket 和 Tunnel 请求支持 `replaceStatus`
66+
67+
# v2.7.16
68+
1. fix: Maximum call stack size exceeded
69+
70+
# v2.7.15
71+
1. perf: 去掉 `Empty Request`,减少内存及 CPU 占用
72+
2. style: Network 的 `Body` 支持显示请求内容大小
73+
74+
# v2.7.14
75+
1. feat: 插件支持通过 `options.require` 直接引用 Whistle 里面的第三方模块或文件
76+
2. refacto: 插件在不同实例使用不同的存储目录
77+
78+
# v2.7.13
79+
1. fix: 特殊情况下 Whistle 无法展示 WebSocket 前几个请求帧问题
80+
2. feat: 支持在模板字符串里面通过 `clientPort``serverPort` 分别获取客户端和服务端端口
81+
3. refactor: `alert``confirm``prompt` 等浏览器内置的窗口改用自定义实现,防止 https://www.chromestatus.com/feature/5148698084376576
82+
83+
# v2.7.12
84+
1. fix: `reqReplace``resReplace` 可能因为拆包导致匹配不准确问题
85+
2. fix: Rules 编辑器行首字母输入 `!` 报错问题
186

287
# v2.7.11
388
1. feat: 插件 hook 支持 `async-await`

Dockerfile

Lines changed: 0 additions & 7 deletions
This file was deleted.

README-zh_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ w2 restart
182182
更多匹配模式参考:[匹配模式](https://avwo.github.io/whistle/pattern.html)
183183
5. 调试远程页面
184184

185-
利用whistle提供的[weinre](rules/weinre.html)和[log](rules/log.html)两个协议,可以实现修改远程页面DOM结构及自动捕获页面js错误及console打印的信息,还可以在页面顶部或js文件底部注入指定的脚步调试页面信息。
185+
利用whistle提供的[weinre](http://wproxy.org/whistle/webui/weinre.html)和[log](http://wproxy.org/whistle/webui/log.html)两个协议,可以实现修改远程页面DOM结构及自动捕获页面js错误及console打印的信息,还可以在页面顶部或js文件底部注入指定的脚步调试页面信息。
186186

187-
使用whistle的功能前,先把要相应的系统代理或浏览器代理指向whistle,如何设置可以参考:[安装启动](install.html)
187+
使用whistle的功能前,先把要相应的系统代理或浏览器代理指向whistle,如何设置可以参考:[安装启动](http://wproxy.org/whistle/install.html)
188188

189189
weinre:
190190

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ For more details, please visit [install and start](https://avwo.github.io/whistl
199199

200200
3. in mobiles, configure the proxy of current Wi-Fi in `Setting`
201201

202-
PS: The mobile may failed to use network after configuration because the fireworks of the PC has forbidden remote visit to the whistle's port. you can try to close the fireworks or configure white list :[ http://jingyan.baidu.com/article/870c6fc317cae7b03ee4be48.html]( http://jingyan.baidu.com/article/870c6fc317cae7b03ee4be48.html)
202+
PS: The mobile may failed to use network after configuration because the firewall of the PC has forbidden remote visit to the whistle's port. you can try to close the firewall or configure white list :[ http://jingyan.baidu.com/article/870c6fc317cae7b03ee4be48.html]( http://jingyan.baidu.com/article/870c6fc317cae7b03ee4be48.html)
203203

204204
For more details, please vsit [install and start](https://avwo.github.io/whistle/install.html)
205205

assets/fiddler/meta.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
<SessionFlag N="x-ttlb" V="${ttlb}" />
1818
<SessionFlag N="x-hostip" V="${hostip}" />
1919
<SessionFlag N="x-clientport" V="${clientport}" />
20+
<SessionFlag N="x-serverport" V="${serverport}" />
2021
</SessionFlags>
2122
</Session>

bin/status.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
var Q = require('q');
2+
23
var util = require('./util');
34
var pkg = require('../package.json');
4-
5+
var colors = require('colors/safe');
56
var isRunning = util.isRunning;
67
var showUsage = util.showUsage;
78
var readConfig = util.readConfig;
89
var readConfigList = util.readConfigList;
9-
var error = util.error;
10+
var warn = util.warn;
1011
var info = util.info;
1112

12-
function showAll() {
13+
function showAll(byStop) {
1314
var list = readConfigList().map(function(config) {
1415
var deferred = Q.defer();
1516
isRunning(config.pid, function(running) {
@@ -23,16 +24,18 @@ function showAll() {
2324
});
2425
var len = confList.length;
2526
if (!len) {
26-
error('No running whistle.');
27+
warn('[!] No running whistle.');
2728
} else {
28-
var tips = ['All running whistle:'];
29+
var tips = [byStop ? '[i] Other running whistle:' : '[i] All running whistle:'];
2930
confList.forEach(function(conf, i) {
3031
++i;
3132
var options = conf.options;
3233
tips.push(' ' + i + '. port: ' + (options.port || pkg.port)
3334
+ (options.host ? ', host: ' + options.host : '')
34-
+ (options.storage ? ', storage: ' + options.storage : ''));
35+
+ (options.storage ? ', storage: ' + options.storage : '')
36+
+ (byStop ? colors.red(' (stop cmd: ' + (options.storage ? 'w2 stop -S ' + options.storage : 'w2 stop') + ')') : ''));
3537
});
38+
byStop && warn('[!] This whistle is not running.');
3639
info(tips.join('\n'));
3740
}
3841
});
@@ -58,4 +61,6 @@ module.exports = function(all, storage) {
5861
}
5962
}
6063
showAll();
61-
};
64+
};
65+
66+
module.exports.showAll = showAll;

bin/use.js

Lines changed: 85 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var warn = util.warn;
1111
var info = util.info;
1212
var readConfig = util.readConfig;
1313
var MAX_RULES_LEN = 1024 * 16;
14+
var DEFAULT_OPTIONS = { host: '127.0.0.1', port: 8899 };
1415
var options;
1516

1617
function showStartWhistleTips(storage) {
@@ -48,6 +49,21 @@ function existsPlugin(name) {
4849
return false;
4950
}
5051

52+
function getBody(res, callback) {
53+
var resBody = '';
54+
res.setEncoding('utf8');
55+
res.on('data', function(data) {
56+
resBody += data;
57+
});
58+
res.on('end', function() {
59+
if (res.statusCode != 200) {
60+
callback(resBody || 'response ' + res.statusCode + ' error');
61+
} else {
62+
callback(null, JSON.parse(resBody));
63+
}
64+
});
65+
}
66+
5167
var reqOptions;
5268
function request(body, callback) {
5369
if (!reqOptions) {
@@ -62,23 +78,40 @@ function request(body, callback) {
6278
}
6379
}
6480
var req = http.request(reqOptions, function(res) {
65-
res.setEncoding('utf8');
66-
var resBody = '';
67-
res.on('data', function(data) {
68-
resBody += data;
69-
});
70-
res.on('end', function() {
71-
if (res.statusCode != 200) {
72-
throw resBody || 'response ' + res.statusCode + ' error';
81+
getBody(res, function(err, data) {
82+
if (err) {
83+
throw err;
7384
}
74-
callback(JSON.parse(resBody));
85+
callback(data);
7586
});
7687
});
7788
// 不处理错误,直接抛出终止进程
7889
req.end(body);
7990
}
8091

92+
function checkDefault(running, storage, callback) {
93+
if (running) {
94+
return callback();
95+
}
96+
var execCallback = function(err) {
97+
callback && callback(err);
98+
callback = null;
99+
};
100+
var req = http.get('http://' + DEFAULT_OPTIONS.host + ':' + DEFAULT_OPTIONS.port + '/cgi-bin/status', function(res) {
101+
res.on('error', execCallback);
102+
getBody(res, function(err, data) {
103+
if (err || !data || data.name !== pkg.name || data.storage !== storage) {
104+
return execCallback(true);
105+
}
106+
callback(null, DEFAULT_OPTIONS.port);
107+
});
108+
});
109+
req.on('error', execCallback);
110+
req.end();
111+
}
112+
81113
module.exports = function(filepath, storage, force) {
114+
storage = storage || '';
82115
var config = readConfig(storage) || '';
83116
options = config.options;
84117
var pid = options && config.pid;
@@ -87,46 +120,52 @@ module.exports = function(filepath, storage, force) {
87120
conf.addon = addon && typeof addon === 'string' ? addon.split(/[|,]/) : null;
88121
conf.noGlobalPlugins = options && options.noGlobalPlugins;
89122
isRunning(pid, function(running) {
90-
if (!running) {
91-
return showStartWhistleTips(storage);
92-
}
93-
filepath = path.resolve(filepath || '.whistle.js');
94-
var port = options.port = options.port > 0 ? options.port : pkg.port;
95-
handleRules(filepath, function(result) {
96-
if (!result) {
97-
error('The name and rules cannot be empty.');
98-
return;
99-
}
100-
var name = getString(result.name);
101-
if (!name || name.length > 64) {
102-
error('The name cannot be empty and the length cannot exceed 64 characters.');
103-
return;
104-
}
105-
var rules = getString(result.rules);
106-
if (rules.length > MAX_RULES_LEN) {
107-
error('The rules cannot be empty and the size cannot exceed 16k.');
108-
return;
123+
checkDefault(running, storage, function(err, port) {
124+
if (err) {
125+
return showStartWhistleTips(storage);
109126
}
110-
var setRules = function() {
111-
var body = [
112-
'name=' + encodeURIComponent(name),
113-
'rules=' + encodeURIComponent(rules)
114-
].join('&');
115-
request(body, function() {
116-
info('Setting whistle[' + (options.host || '127.0.0.1') + ':' + port + '] rules successful.');
117-
});
118-
};
119-
if (force) {
120-
return setRules();
127+
filepath = path.resolve(filepath || '.whistle.js');
128+
if (port) {
129+
options = DEFAULT_OPTIONS;
130+
} else {
131+
port = options.port = options.port > 0 ? options.port : pkg.port;
121132
}
122-
request('name=' + encodeURIComponent(name) + '&enable=1&top=1', function(data) {
123-
if (data.rules) {
124-
info('Successfully enabled.');
125-
warn('Warning: The rule already exists, to override the content, add CLI option --force.');
133+
handleRules(filepath, function(result) {
134+
if (!result) {
135+
error('The name and rules cannot be empty.');
136+
return;
137+
}
138+
var name = getString(result.name);
139+
if (!name || name.length > 64) {
140+
error('The name cannot be empty and the length cannot exceed 64 characters.');
126141
return;
127142
}
128-
setRules();
129-
});
130-
}, port);
143+
var rules = getString(result.rules);
144+
if (rules.length > MAX_RULES_LEN) {
145+
error('The rules cannot be empty and the size cannot exceed 16k.');
146+
return;
147+
}
148+
var setRules = function() {
149+
var body = [
150+
'name=' + encodeURIComponent(name),
151+
'rules=' + encodeURIComponent(rules)
152+
].join('&');
153+
request(body, function() {
154+
info('Setting whistle[' + (options.host || '127.0.0.1') + ':' + port + '] rules successful.');
155+
});
156+
};
157+
if (force) {
158+
return setRules();
159+
}
160+
request('name=' + encodeURIComponent(name) + '&enable=1&top=1', function(data) {
161+
if (data.rules) {
162+
info('Successfully enabled.');
163+
warn('Warning: The rule already exists, to override the content, add CLI option --force.');
164+
return;
165+
}
166+
setRules();
167+
});
168+
}, port);
169+
});
131170
});
132171
};

bin/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function showUsage(isRunning, options, restart) {
8181

8282
warn(' Note: If all the above URLs are unable to access, check the firewall settings');
8383
warn(' For help see ' + colors.bold('https://github.com/avwo/whistle'));
84-
info('[i] 2. configure your device to use ' + config.name + ' as its HTTP and HTTPS proxy on ' + colors.bold('IP:') + port);
84+
info('[i] 2. set the HTTP proxy on your device with ' + colors.bold((list.length === 1 ? 'IP(' + list[0] + ')' : 'the above IP') + ' & PORT(' + port + ')'));
8585
info('[i] 3. use ' + colors.bold('Chrome') + ' to visit ' + colors.bold('http://' + (options.localUIHost || config.localUIHost) + '/') + ' to get started');
8686

8787
if (parseInt(process.version.slice(1), 10) < 6) {

0 commit comments

Comments
 (0)