t880216t-server 1.5.20

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.
Files changed (104) hide show
  1. package/LICENSE +124 -0
  2. package/README.md +191 -0
  3. package/bin/nohost.js +178 -0
  4. package/bin/plugin.js +70 -0
  5. package/bin/util.js +93 -0
  6. package/index.js +89 -0
  7. package/lib/config.js +42 -0
  8. package/lib/index.js +205 -0
  9. package/lib/main/cgi/getSettings.js +11 -0
  10. package/lib/main/cgi/getVersion.js +12 -0
  11. package/lib/main/cgi/login.js +14 -0
  12. package/lib/main/cgi/restart.js +5 -0
  13. package/lib/main/cgi/setAdmin.js +6 -0
  14. package/lib/main/cgi/setDomain.js +13 -0
  15. package/lib/main/cgi/status.js +122 -0
  16. package/lib/main/index.js +94 -0
  17. package/lib/main/router.js +79 -0
  18. package/lib/main/storage.js +132 -0
  19. package/lib/main/util.js +138 -0
  20. package/lib/main/whistleMgr.js +56 -0
  21. package/lib/main/worker.js +52 -0
  22. package/lib/main/workerNum.js +11 -0
  23. package/lib/plugins/account/whistle.share/menu.html +171 -0
  24. package/lib/plugins/account/whistle.share/package.json +20 -0
  25. package/lib/plugins/account/whistle.storage/index.js +43 -0
  26. package/lib/plugins/account/whistle.storage/package.json +8 -0
  27. package/lib/plugins/account/whistle.storage/rules.txt +1 -0
  28. package/lib/plugins/whistle.nohost/_rules.txt +38 -0
  29. package/lib/plugins/whistle.nohost/index.js +3 -0
  30. package/lib/plugins/whistle.nohost/initial.js +9 -0
  31. package/lib/plugins/whistle.nohost/lib/accountMgr.js +750 -0
  32. package/lib/plugins/whistle.nohost/lib/envMgr.js +114 -0
  33. package/lib/plugins/whistle.nohost/lib/rulesServer.js +85 -0
  34. package/lib/plugins/whistle.nohost/lib/tunnelRulesServer.js +71 -0
  35. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/account/changePassword.js +8 -0
  36. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/activeAccount.js +9 -0
  37. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/addAccount.js +8 -0
  38. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/allAccounts.js +9 -0
  39. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/changeNotice.js +8 -0
  40. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/changePassword.js +8 -0
  41. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/enableGuest.js +5 -0
  42. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/getAuthKey.js +3 -0
  43. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/getSettings.js +22 -0
  44. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/login.js +14 -0
  45. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/move.js +9 -0
  46. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/removeAccount.js +9 -0
  47. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/setAccountRules.js +5 -0
  48. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/setAuthKey.js +5 -0
  49. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/setDefaultRules.js +5 -0
  50. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/setEntryPatterns.js +6 -0
  51. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/setJsonData.js +5 -0
  52. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/setRulesTpl.js +5 -0
  53. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/setTestRules.js +5 -0
  54. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/admin/specPattern.js +4 -0
  55. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/allowlist.js +4 -0
  56. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/entryRules.js +4 -0
  57. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/follow.js +17 -0
  58. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/getEnv.js +12 -0
  59. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/list.js +43 -0
  60. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/patterns.js +14 -0
  61. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/pluginRules.js +61 -0
  62. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/proxy.js +42 -0
  63. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/proxyNetwork.js +12 -0
  64. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/redirect.js +10 -0
  65. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/selectEnv.js +30 -0
  66. package/lib/plugins/whistle.nohost/lib/uiServer/cgi/unfollow.js +4 -0
  67. package/lib/plugins/whistle.nohost/lib/uiServer/index.js +60 -0
  68. package/lib/plugins/whistle.nohost/lib/uiServer/network.js +38 -0
  69. package/lib/plugins/whistle.nohost/lib/uiServer/openAPI.js +94 -0
  70. package/lib/plugins/whistle.nohost/lib/uiServer/router.js +85 -0
  71. package/lib/plugins/whistle.nohost/lib/util.js +230 -0
  72. package/lib/plugins/whistle.nohost/lib/whistle.js +149 -0
  73. package/lib/plugins/whistle.nohost/lib/whistleMgr.js +94 -0
  74. package/lib/plugins/whistle.nohost/package.json +7 -0
  75. package/lib/plugins/whistle.nohost/rules.txt +3 -0
  76. package/lib/service/cgi/export.js +76 -0
  77. package/lib/service/cgi/import.js +33 -0
  78. package/lib/service/cgi/util.js +35 -0
  79. package/lib/service/index.js +37 -0
  80. package/lib/service/router.js +7 -0
  81. package/lib/service/server.js +25 -0
  82. package/lib/util/address.js +55 -0
  83. package/lib/util/getPort.js +19 -0
  84. package/lib/util/login.js +55 -0
  85. package/lib/util/parseDomain.js +17 -0
  86. package/lib/whistle.js +86 -0
  87. package/package.json +135 -0
  88. package/pnpm-workspace.yaml +6 -0
  89. package/public/admin.75d42731d4aa7f7a558d3abf2a375fcb.js +2 -0
  90. package/public/admin.75d42731d4aa7f7a558d3abf2a375fcb.js.LICENSE.txt +76 -0
  91. package/public/admin.html +11 -0
  92. package/public/button.js +2 -0
  93. package/public/button.js.LICENSE.txt +31 -0
  94. package/public/capture.7bab900f27c9bb1b0e33523e994554ae.js +2 -0
  95. package/public/capture.7bab900f27c9bb1b0e33523e994554ae.js.LICENSE.txt +83 -0
  96. package/public/capture.html +11 -0
  97. package/public/eed368d0656f03932671530c3132ed61.svg +1 -0
  98. package/public/favicon.ico +0 -0
  99. package/public/network.e4814ec8c966a8a789296679619ec573.js +2 -0
  100. package/public/network.e4814ec8c966a8a789296679619ec573.js.LICENSE.txt +76 -0
  101. package/public/network.html +11 -0
  102. package/public/select.cb638be6656d02a558f2690acd59901a.js +2 -0
  103. package/public/select.cb638be6656d02a558f2690acd59901a.js.LICENSE.txt +24 -0
  104. package/public/select.html +26 -0
@@ -0,0 +1,43 @@
1
+
2
+ const { Pool } = require('socketx');
3
+ const { encode } = require('simpleproto');
4
+ const crc32 = require('crc32');
5
+
6
+ const UID_RE = /^[\w.-]{1,64}$/;
7
+
8
+ exports.uiServer = (server, { data }) => {
9
+ const { storageServer } = data || '';
10
+ const len = storageServer && storageServer.length;
11
+ const rules = len ? '* whistle.storage:// includeFilter://reqH:x-whistle-nohost-storage-uid=/^[\\w.-]{1,64}$/' : '';
12
+ server.on('request', (_, res) => {
13
+ res.writeHead(200, { 'content-type': 'text/plain; charset=utf8' });
14
+ res.end(rules);
15
+ });
16
+ };
17
+
18
+ exports.resStatsServer = (server, { data }) => {
19
+ const { storageServer } = data || '';
20
+ const len = storageServer && storageServer.length;
21
+ if (!len) {
22
+ return;
23
+ }
24
+ const pool = new Pool();
25
+ storageServer.forEach((opt) => {
26
+ opt.idleTimeout = 30000;
27
+ });
28
+ server.on('request', (req) => {
29
+ req.getSession(async (s) => {
30
+ if (s) {
31
+ const uid = s.req.headers['x-whistle-nohost-storage-uid'];
32
+ if (!uid || !UID_RE.test(uid)) {
33
+ return;
34
+ }
35
+ const index = len > 1 ? (parseInt(crc32(uid), 16) % len) : 0;
36
+ try {
37
+ const socket = await pool.connect(storageServer[index]);
38
+ socket.write(encode(s));
39
+ } catch (e) {}
40
+ }
41
+ });
42
+ });
43
+ };
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "whistle.storage",
3
+ "version": "1.0.0",
4
+ "whistleConfig": {
5
+ "hideLongProtocol": true,
6
+ "hideShortProtocol": true
7
+ }
8
+ }
@@ -0,0 +1 @@
1
+ @whistle.storage
@@ -0,0 +1,38 @@
1
+
2
+ ``` whistle.nohost/inject.html
3
+
4
+ <script>
5
+ (function() {
6
+ if (typeof window === 'undefined' || !window || window.self !== window.top
7
+ || window.__whistle_nohost_from_imweb_is_inited__) {
8
+ return;
9
+ }
10
+ window.__whistle_nohost_from_imweb_is_inited__ = true;
11
+ var head = document.head || document.getElementsByTagName('head')[0] || document.documentElement;
12
+ var script = document.createElement('script');
13
+ var prefixPath = window.__WHISTLE_PATH_PREFIX__;
14
+ if (/^\/[\w./-]+$/.test(prefixPath) && prefixPath.length <= 128) {
15
+ var len = prefixPath.length - 1;
16
+ if (prefixPath[len] === '/') {
17
+ prefixPath = prefixPath.substring(0, len);
18
+ }
19
+ } else {
20
+ prefixPath = '';
21
+ }
22
+ script.defer = true;
23
+ script.charset = 'utf8';
24
+ script.src = prefixPath + '/.whistle-path.5b6af7b9884e1165/whistle.nohost/button.js';
25
+ if (head.firstChild) {
26
+ head.insertBefore(script, head.firstChild);
27
+ } else {
28
+ head.appendChild(script);
29
+ }
30
+ })();
31
+ </script>
32
+ ```
33
+
34
+ ``` whistle.nohost/none.html
35
+ <script>
36
+ window.__whistle_nohost_from_imweb_is_inited__ = true;
37
+ </script>
38
+ ```
@@ -0,0 +1,3 @@
1
+ exports.uiServer = require('./lib/uiServer');
2
+ exports.rulesServer = require('./lib/rulesServer');
3
+ exports.tunnelRulesServer = require('./lib/tunnelRulesServer');
@@ -0,0 +1,9 @@
1
+ const initAccountMgr = require('./lib/accountMgr');
2
+ const initEnvMgr = require('./lib/envMgr');
3
+ const { initPlugin } = require('./lib/util');
4
+
5
+ module.exports = (options) => {
6
+ initPlugin(options);
7
+ const accountMgr = initAccountMgr(options);
8
+ initEnvMgr(accountMgr);
9
+ };