whistle 2.9.7 → 2.9.10
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/assets/menu.html +3 -0
- package/assets/tab.html +4 -1
- package/bin/plugin.js +51 -20
- package/bin/util.js +7 -2
- package/biz/webui/cgi-bin/util.js +1 -1
- package/biz/webui/htdocs/index.html +1 -1
- package/biz/webui/htdocs/js/index.js +12 -12
- package/index.d.ts +1 -0
- package/lib/config.js +11 -7
- package/lib/https/index.js +43 -67
- package/lib/init.js +1 -20
- package/lib/plugins/get-plugins-sync.js +10 -5
- package/lib/plugins/get-plugins.js +5 -6
- package/lib/plugins/index.js +1 -1
- package/lib/plugins/load-plugin.js +4 -0
- package/lib/plugins/module-paths.js +3 -4
- package/lib/rules/protocols.js +1 -0
- package/lib/rules/rules.js +87 -25
- package/lib/upgrade.js +2 -2
- package/lib/util/common.js +11 -0
- package/lib/util/index.js +115 -3
- package/lib/util/perf.js +11 -2
- package/package.json +1 -1
package/assets/menu.html
CHANGED
|
@@ -170,6 +170,9 @@
|
|
|
170
170
|
whistleBridge.getServerInfo = options.getServerInfo;
|
|
171
171
|
whistleBridge.alert = options.alert;
|
|
172
172
|
whistleBridge.confirm = options.confirm;
|
|
173
|
+
whistleBridge.syncData = options.syncData;
|
|
174
|
+
whistleBridge.syncRules = options.syncRules;
|
|
175
|
+
whistleBridge.syncValues = options.syncValues;
|
|
173
176
|
};
|
|
174
177
|
window.parent.onPluginContextMenuReady(window);
|
|
175
178
|
} catch (e) {}
|
package/assets/tab.html
CHANGED
|
@@ -296,7 +296,10 @@
|
|
|
296
296
|
whistleBridge.getServerInfo = options.getServerInfo;
|
|
297
297
|
whistleBridge.alert = options.alert;
|
|
298
298
|
whistleBridge.confirm = options.confirm;
|
|
299
|
-
|
|
299
|
+
whistleBridge.syncData = options.syncData;
|
|
300
|
+
whistleBridge.syncRules = options.syncRules;
|
|
301
|
+
whistleBridge.syncValues = options.syncValues;
|
|
302
|
+
}, window);
|
|
300
303
|
} catch (e) {}
|
|
301
304
|
window.whistleBridge = whistleBridge;
|
|
302
305
|
})();
|
package/bin/plugin.js
CHANGED
|
@@ -3,23 +3,31 @@ var cp = require('child_process');
|
|
|
3
3
|
var fs = require('fs');
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var fse = require('fs-extra2');
|
|
6
|
-
var
|
|
6
|
+
var getHash = require('./util').getHash;
|
|
7
|
+
var commonUtil = require('../lib/util/common');
|
|
7
8
|
|
|
9
|
+
var getWhistlePath = commonUtil.getWhistlePath;
|
|
10
|
+
var REMOTE_URL_RE = commonUtil.REMOTE_URL_RE;
|
|
8
11
|
var CMD_SUFFIX = process.platform === 'win32' ? '.cmd' : '';
|
|
9
|
-
var WHISTLE_PLUGIN_RE = /^((?:@[\w-]+\/)?whistle\.[a-z\d_-]+)(?:\@([\w.^~*-]*))?$/;
|
|
10
|
-
var PLUGIN_PATH = path.join(getWhistlePath(), 'plugins');
|
|
11
12
|
var CUSTOM_PLUGIN_PATH = path.join(getWhistlePath(), 'custom_plugins');
|
|
12
13
|
var PACKAGE_JSON = '{"repository":"https://github.com/avwo/whistle","license":"MIT"}';
|
|
13
14
|
var LICENSE = 'Copyright (c) 2019 avwo';
|
|
14
15
|
var RESP_URL = 'https://github.com/avwo/whistle';
|
|
16
|
+
var WHISTLE_PLUGIN_RE = /^((?:@[\w-]+\/)?whistle\.[a-z\d_-]+)(?:\@([\w.^~*-]*))?$/;
|
|
15
17
|
|
|
16
18
|
function getInstallPath(name, dir) {
|
|
17
19
|
return path.join(dir || CUSTOM_PLUGIN_PATH, name);
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
function getPlugins(argv) {
|
|
21
|
-
return argv.filter(function(name) {
|
|
22
|
-
|
|
22
|
+
function getPlugins(argv, isInstall) {
|
|
23
|
+
return argv.filter(function(name, i) {
|
|
24
|
+
if (WHISTLE_PLUGIN_RE.test(name)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (argv[i - 1] === '--registry') {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return isInstall && REMOTE_URL_RE.test(name);
|
|
23
31
|
});
|
|
24
32
|
}
|
|
25
33
|
|
|
@@ -29,11 +37,6 @@ function removeDir(installPath) {
|
|
|
29
37
|
}
|
|
30
38
|
}
|
|
31
39
|
|
|
32
|
-
function removeOldPlugin(name) {
|
|
33
|
-
removeDir(path.join(PLUGIN_PATH, 'node_modules', name));
|
|
34
|
-
removeDir(path.join(PLUGIN_PATH, 'node_modules', getTempName(name)));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
40
|
function getTempName(name) {
|
|
38
41
|
if (name.indexOf('/') === -1) {
|
|
39
42
|
return '.' + name;
|
|
@@ -59,11 +62,28 @@ function getInstallDir(argv) {
|
|
|
59
62
|
return result;
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
function getPluginNameFormDeps(deps) {
|
|
66
|
+
var keys = Object.keys(deps);
|
|
67
|
+
for (var i = 0, len = keys.length; i < len; i++) {
|
|
68
|
+
if (WHISTLE_PLUGIN_RE.test(keys[i])) {
|
|
69
|
+
return RegExp.$1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getPkgName(name) {
|
|
75
|
+
if (/[/\\](whistle\.[a-z\d_-]+)(?:\.git)?$/.test(name)) {
|
|
76
|
+
return RegExp.$1;
|
|
77
|
+
}
|
|
78
|
+
return getHash(name);
|
|
79
|
+
}
|
|
80
|
+
|
|
62
81
|
function install(cmd, name, argv, ver, pluginsCache, callback) {
|
|
63
|
-
|
|
64
|
-
var
|
|
82
|
+
var result = getInstallDir(argv.slice());
|
|
83
|
+
var isPkg = WHISTLE_PLUGIN_RE.test(name);
|
|
84
|
+
var pkgName = isPkg ? name : getPkgName(name);
|
|
85
|
+
var installPath = getInstallPath(getTempName(pkgName), result.dir);
|
|
65
86
|
argv = result.argv;
|
|
66
|
-
var installPath = getInstallPath(getTempName(name), result.dir);
|
|
67
87
|
fse.ensureDirSync(installPath);
|
|
68
88
|
fse.emptyDirSync(installPath);
|
|
69
89
|
var pkgJson = PACKAGE_JSON;
|
|
@@ -74,7 +94,7 @@ function install(cmd, name, argv, ver, pluginsCache, callback) {
|
|
|
74
94
|
fs.writeFileSync(path.join(installPath, 'LICENSE'), LICENSE);
|
|
75
95
|
fs.writeFileSync(path.join(installPath, 'README.md'), RESP_URL);
|
|
76
96
|
argv.unshift('install', name);
|
|
77
|
-
pluginsCache[
|
|
97
|
+
pluginsCache[pkgName] = 1;
|
|
78
98
|
cp.spawn(cmd, argv, {
|
|
79
99
|
stdio: 'inherit',
|
|
80
100
|
cwd: installPath
|
|
@@ -83,11 +103,22 @@ function install(cmd, name, argv, ver, pluginsCache, callback) {
|
|
|
83
103
|
removeDir(installPath);
|
|
84
104
|
callback();
|
|
85
105
|
} else {
|
|
106
|
+
if (!isPkg) {
|
|
107
|
+
var deps = fse.readJsonSync(path.join(installPath, 'package.json')).dependencies;
|
|
108
|
+
name = deps && getPluginNameFormDeps(deps);
|
|
109
|
+
}
|
|
110
|
+
if (!name) {
|
|
111
|
+
try {
|
|
112
|
+
removeDir(installPath);
|
|
113
|
+
} catch (e) {}
|
|
114
|
+
return callback();
|
|
115
|
+
}
|
|
86
116
|
var realPath = getInstallPath(name, result.dir);
|
|
87
117
|
removeDir(realPath);
|
|
88
118
|
try {
|
|
89
119
|
fs.renameSync(installPath, realPath);
|
|
90
120
|
} catch (e) {
|
|
121
|
+
fse.ensureDirSync(realPath);
|
|
91
122
|
fse.copySync(installPath, realPath);
|
|
92
123
|
try {
|
|
93
124
|
removeDir(installPath);
|
|
@@ -125,7 +156,8 @@ function installPlugins(cmd, plugins, argv, pluginsCache, deep) {
|
|
|
125
156
|
var list = pkg.whistleConfig && (pkg.whistleConfig.peerPluginList || pkg.whistleConfig.peerPlugins);
|
|
126
157
|
if (Array.isArray(list) && list.length < 16) {
|
|
127
158
|
list.forEach(function(name) {
|
|
128
|
-
|
|
159
|
+
name = typeof name === 'string' ? name.trim() : null;
|
|
160
|
+
if (name && (WHISTLE_PLUGIN_RE.test(name) || REMOTE_URL_RE.test(name))) {
|
|
129
161
|
name = RegExp.$1;
|
|
130
162
|
if (peerPlugins.indexOf(name) === -1) {
|
|
131
163
|
peerPlugins.push(name);
|
|
@@ -142,11 +174,11 @@ function installPlugins(cmd, plugins, argv, pluginsCache, deep) {
|
|
|
142
174
|
}
|
|
143
175
|
};
|
|
144
176
|
plugins.forEach(function(name) {
|
|
145
|
-
|
|
177
|
+
var isPkg = WHISTLE_PLUGIN_RE.test(name);
|
|
178
|
+
if (isPkg || REMOTE_URL_RE.test(name)) {
|
|
146
179
|
++count;
|
|
147
180
|
name = RegExp.$1;
|
|
148
181
|
var ver = RegExp.$2;
|
|
149
|
-
removeOldPlugin(name);
|
|
150
182
|
install(cmd, name, argv, ver, pluginsCache, callback);
|
|
151
183
|
}
|
|
152
184
|
});
|
|
@@ -155,7 +187,7 @@ function installPlugins(cmd, plugins, argv, pluginsCache, deep) {
|
|
|
155
187
|
exports.getWhistlePath = getWhistlePath;
|
|
156
188
|
|
|
157
189
|
exports.install = function(cmd, argv) {
|
|
158
|
-
var plugins = getPlugins(argv);
|
|
190
|
+
var plugins = getPlugins(argv, true);
|
|
159
191
|
if (!plugins.length) {
|
|
160
192
|
return;
|
|
161
193
|
}
|
|
@@ -174,7 +206,6 @@ exports.uninstall = function(plugins) {
|
|
|
174
206
|
getPlugins(plugins).forEach(function(name) {
|
|
175
207
|
if (WHISTLE_PLUGIN_RE.test(name)) {
|
|
176
208
|
name = RegExp.$1;
|
|
177
|
-
!result.dir && removeOldPlugin(name);
|
|
178
209
|
removeDir(getInstallPath(name, result.dir));
|
|
179
210
|
}
|
|
180
211
|
});
|
package/bin/util.js
CHANGED
|
@@ -6,6 +6,7 @@ var fse = require('fs-extra2');
|
|
|
6
6
|
var config = require('../lib/config');
|
|
7
7
|
var colors = require('colors/safe');
|
|
8
8
|
var path = require('path');
|
|
9
|
+
var createHmac = require('crypto').createHmac;
|
|
9
10
|
/*eslint no-console: "off"*/
|
|
10
11
|
var CHECK_RUNNING_CMD = process.platform === 'win32' ?
|
|
11
12
|
'tasklist /fi "PID eq %s" | findstr /i "node.exe"'
|
|
@@ -26,7 +27,7 @@ function getIpList() {
|
|
|
26
27
|
var ifaces = os.networkInterfaces();
|
|
27
28
|
Object.keys(ifaces).forEach(function(ifname) {
|
|
28
29
|
ifaces[ifname].forEach(function (iface) {
|
|
29
|
-
if (iface.family == 'IPv4') {
|
|
30
|
+
if (iface.family == 'IPv4' || iface.family === 4) {
|
|
30
31
|
ipList.push(iface.address);
|
|
31
32
|
}
|
|
32
33
|
});
|
|
@@ -141,4 +142,8 @@ function readConfigList() {
|
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
exports.readConfig = readConfig;
|
|
144
|
-
exports.readConfigList = readConfigList;
|
|
145
|
+
exports.readConfigList = readConfigList;
|
|
146
|
+
exports.getHash = function(str) {
|
|
147
|
+
var hmac = createHmac('sha256', 'a secret');
|
|
148
|
+
return hmac.update(str).digest('hex');
|
|
149
|
+
};
|
|
@@ -65,7 +65,7 @@ exports.getServerInfo = function(req) {
|
|
|
65
65
|
if (iface.internal) {
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
-
info[iface.family == 'IPv4' ? 'ipv4' : 'ipv6'].push(iface.address);
|
|
68
|
+
info[iface.family == 'IPv4' || iface.family === 4 ? 'ipv4' : 'ipv6'].push(iface.address);
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
71
|
|