@maiyunnet/kebab 2.0.0

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 (114) hide show
  1. package/.VSCodeCounter/2025-02-14_14-46-44/details.md +82 -0
  2. package/.VSCodeCounter/2025-02-14_14-46-44/diff-details.md +15 -0
  3. package/.VSCodeCounter/2025-02-14_14-46-44/diff.csv +2 -0
  4. package/.VSCodeCounter/2025-02-14_14-46-44/diff.md +19 -0
  5. package/.VSCodeCounter/2025-02-14_14-46-44/diff.txt +22 -0
  6. package/.VSCodeCounter/2025-02-14_14-46-44/results.csv +69 -0
  7. package/.VSCodeCounter/2025-02-14_14-46-44/results.json +1 -0
  8. package/.VSCodeCounter/2025-02-14_14-46-44/results.md +48 -0
  9. package/.VSCodeCounter/2025-02-14_14-46-44/results.txt +118 -0
  10. package/.vscode/tasks.json +15 -0
  11. package/LICENSE +201 -0
  12. package/README.md +201 -0
  13. package/bin/kebab.js +2 -0
  14. package/eslint.config.js +22 -0
  15. package/index.js +19 -0
  16. package/index.ts +33 -0
  17. package/lib/buffer.js +108 -0
  18. package/lib/buffer.ts +152 -0
  19. package/lib/captcha/zcool-addict-italic.ttf +0 -0
  20. package/lib/captcha.js +71 -0
  21. package/lib/captcha.ts +63 -0
  22. package/lib/consistent.js +171 -0
  23. package/lib/consistent.ts +219 -0
  24. package/lib/core.js +663 -0
  25. package/lib/core.ts +880 -0
  26. package/lib/crypto.js +256 -0
  27. package/lib/crypto.ts +384 -0
  28. package/lib/db.js +521 -0
  29. package/lib/db.ts +719 -0
  30. package/lib/dns.js +321 -0
  31. package/lib/dns.ts +405 -0
  32. package/lib/fs.js +405 -0
  33. package/lib/fs.ts +527 -0
  34. package/lib/jwt.js +223 -0
  35. package/lib/jwt.ts +276 -0
  36. package/lib/kv.js +1004 -0
  37. package/lib/kv.ts +1489 -0
  38. package/lib/lan.js +99 -0
  39. package/lib/lan.ts +87 -0
  40. package/lib/net/cacert.pem +3480 -0
  41. package/lib/net/formdata.js +137 -0
  42. package/lib/net/formdata.ts +166 -0
  43. package/lib/net/request.js +102 -0
  44. package/lib/net/request.ts +150 -0
  45. package/lib/net/response.js +28 -0
  46. package/lib/net/response.ts +59 -0
  47. package/lib/net.js +462 -0
  48. package/lib/net.ts +662 -0
  49. package/lib/s3.js +180 -0
  50. package/lib/s3.ts +235 -0
  51. package/lib/scan.js +276 -0
  52. package/lib/scan.ts +364 -0
  53. package/lib/session.js +177 -0
  54. package/lib/session.ts +230 -0
  55. package/lib/sql.js +818 -0
  56. package/lib/sql.ts +1151 -0
  57. package/lib/ssh/sftp.js +373 -0
  58. package/lib/ssh/sftp.ts +508 -0
  59. package/lib/ssh/shell.js +109 -0
  60. package/lib/ssh/shell.ts +123 -0
  61. package/lib/ssh.js +171 -0
  62. package/lib/ssh.ts +191 -0
  63. package/lib/text/tld.json +1 -0
  64. package/lib/text.js +452 -0
  65. package/lib/text.ts +607 -0
  66. package/lib/time.js +216 -0
  67. package/lib/time.ts +254 -0
  68. package/lib/ws.js +373 -0
  69. package/lib/ws.ts +523 -0
  70. package/lib/zip.js +381 -0
  71. package/lib/zip.ts +447 -0
  72. package/lib/zlib.js +289 -0
  73. package/lib/zlib.ts +350 -0
  74. package/main.js +51 -0
  75. package/main.ts +27 -0
  76. package/package.json +37 -0
  77. package/sys/child.js +585 -0
  78. package/sys/child.ts +678 -0
  79. package/sys/cmd.js +226 -0
  80. package/sys/cmd.ts +225 -0
  81. package/sys/ctr.js +608 -0
  82. package/sys/ctr.ts +904 -0
  83. package/sys/master.js +314 -0
  84. package/sys/master.ts +355 -0
  85. package/sys/mod.js +1273 -0
  86. package/sys/mod.ts +1871 -0
  87. package/sys/route.js +922 -0
  88. package/sys/route.ts +1113 -0
  89. package/types/index.d.ts +283 -0
  90. package/www/example/ctr/main.js +42 -0
  91. package/www/example/ctr/main.ts +9 -0
  92. package/www/example/ctr/middle.js +57 -0
  93. package/www/example/ctr/middle.ts +26 -0
  94. package/www/example/ctr/test.js +2818 -0
  95. package/www/example/ctr/test.ts +3218 -0
  96. package/www/example/data/locale/en.test.json +8 -0
  97. package/www/example/data/locale/index.html +1 -0
  98. package/www/example/data/locale/ja.test.json +8 -0
  99. package/www/example/data/locale/sc.test.json +8 -0
  100. package/www/example/data/locale/tc.test.json +8 -0
  101. package/www/example/data/test.zip +0 -0
  102. package/www/example/kebab.json +24 -0
  103. package/www/example/mod/test.js +49 -0
  104. package/www/example/mod/test.ts +47 -0
  105. package/www/example/mod/testdata.js +11 -0
  106. package/www/example/mod/testdata.ts +30 -0
  107. package/www/example/route.json +6 -0
  108. package/www/example/view/test.ejs +11 -0
  109. package/www/example/ws/mproxy.js +49 -0
  110. package/www/example/ws/mproxy.ts +16 -0
  111. package/www/example/ws/rproxy.js +47 -0
  112. package/www/example/ws/rproxy.ts +14 -0
  113. package/www/example/ws/test.js +68 -0
  114. package/www/example/ws/test.ts +36 -0
package/sys/cmd.js ADDED
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const http = __importStar(require("http"));
37
+ const lFs = __importStar(require("~/lib/fs"));
38
+ const lText = __importStar(require("~/lib/text"));
39
+ const lTime = __importStar(require("~/lib/time"));
40
+ const lCore = __importStar(require("~/lib/core"));
41
+ const lCrypto = __importStar(require("~/lib/crypto"));
42
+ const kebab = __importStar(require("~/index"));
43
+ const cmds = process.argv.slice(2);
44
+ async function initDir(paths) {
45
+ for (const path of paths) {
46
+ if (await lFs.isDir(path)) {
47
+ continue;
48
+ }
49
+ lCore.display('KEBAB', 'CREATE', 'DIR', path);
50
+ if (!await lFs.mkdir(path)) {
51
+ lCore.display('KEBAB', 'CREATE', 'DIR', path, '[FAILED]');
52
+ return false;
53
+ }
54
+ lCore.display('KEBAB', 'CREATE', 'FILE', path + 'lock.txt');
55
+ if (!await lFs.putContent(path + 'lock.txt', 'Kebab')) {
56
+ lCore.display('KEBAB', 'CREATE', 'FILE', path + 'lock.txt', '[FAILED]');
57
+ return false;
58
+ }
59
+ }
60
+ return true;
61
+ }
62
+ async function run() {
63
+ if (cmds[0] === 'init' || cmds[0] === 'update') {
64
+ if (!await initDir([
65
+ kebab.CERT_CWD + 'default/',
66
+ kebab.VHOST_CWD,
67
+ kebab.FTMP_CWD,
68
+ kebab.IND_CWD,
69
+ kebab.LIB_CWD,
70
+ kebab.LOG_CWD,
71
+ kebab.WWW_CWD,
72
+ kebab.MOD_CWD,
73
+ ])) {
74
+ return;
75
+ }
76
+ if (!await lFs.isFile(kebab.CONF_CWD + 'cert.json')) {
77
+ lCore.display('KEBAB', 'CREATE', 'FILE', kebab.CONF_CWD + 'cert.json');
78
+ if (!await lFs.putContent(kebab.CONF_CWD + 'cert.json', lText.stringifyJson([
79
+ {
80
+ 'cert': 'default/xxx.cer',
81
+ 'key': 'default/xxx.key'
82
+ }
83
+ ], 4))) {
84
+ lCore.display('KEBAB', 'CREATE', 'FILE', kebab.CONF_CWD + 'cert.json', '[FAILED]');
85
+ return;
86
+ }
87
+ }
88
+ let config = {};
89
+ if (await lFs.isFile(kebab.CONF_CWD + 'config.json')) {
90
+ config = lText.parseJson((await lFs.getContent(kebab.CONF_CWD + 'config.json'))?.toString() ?? '{}');
91
+ }
92
+ else {
93
+ lCore.display('KEBAB', 'CREATE', 'FILE', kebab.CONF_CWD + 'config.json');
94
+ }
95
+ config.httpPort ??= 8080;
96
+ config.httpsPort ??= 4333;
97
+ config.rpcPort ??= 10630;
98
+ config.rpcSecret ??= 'MUSTCHANGE';
99
+ config.debug ??= true;
100
+ config.max ??= 64;
101
+ config.set ??= {};
102
+ config.set.timezone ??= 8;
103
+ config.set.mustHttps ??= false;
104
+ config.set.cacheTtl ??= 0;
105
+ config.set.staticVer ??= '20200314174905';
106
+ config.set.staticPath ??= '';
107
+ config.db ??= {};
108
+ config.db.host ??= '127.0.0.1';
109
+ config.db.port ??= 3306;
110
+ config.db.charset ??= 'utf8mb4';
111
+ config.db.name ??= 'maiyun';
112
+ config.db.user ??= 'root';
113
+ config.db.pwd ??= 'DashAdmin';
114
+ config.jwt ??= {};
115
+ config.jwt.name ??= 'KE_JWT';
116
+ config.jwt.ttl ??= 172800;
117
+ config.jwt.ssl ??= false;
118
+ config.jwt.secret ??= 'MUSTCHANGE';
119
+ config.jwt.auth ??= false;
120
+ config.dns ??= {};
121
+ config.dns['DNSPOD'] ??= {};
122
+ config.dns['DNSPOD'].sid ??= '';
123
+ config.dns['DNSPOD'].skey ??= '';
124
+ config.dns['CF'] ??= {};
125
+ config.dns['CF'].sid ??= '';
126
+ config.dns['CF'].skey ??= '';
127
+ config.kv ??= {};
128
+ config.kv.host ??= '127.0.0.1';
129
+ config.kv.port ??= 6379;
130
+ config.kv.index ??= 0;
131
+ config.kv.pre ??= 'm_';
132
+ config.kv.user ??= '';
133
+ config.kv.pwd ??= '';
134
+ config.session ??= {};
135
+ config.session.name ??= 'KE_SESSION';
136
+ config.session.ttl ??= 172800;
137
+ config.session.ssl ??= false;
138
+ config.sql ??= {};
139
+ config.sql.pre ??= 'm_';
140
+ config.s3 ??= {};
141
+ config.s3['CF'] ??= {};
142
+ config.s3['CF'].account = '';
143
+ config.s3['CF'].sid = '';
144
+ config.s3['CF'].skey = '';
145
+ config.s3['CF'].region = 'auto';
146
+ config.s3['CF'].bucket = '';
147
+ config.s3['TENCENT'] ??= {};
148
+ config.s3['TENCENT'].sid = '';
149
+ config.s3['TENCENT'].skey = '';
150
+ config.s3['TENCENT'].region = '';
151
+ config.s3['TENCENT'].bucket = '';
152
+ if (!await lFs.putContent(kebab.CONF_CWD + 'config.json', lText.stringifyJson(config, 4))) {
153
+ lCore.display('KEBAB', 'CREATE', 'FILE', kebab.CONF_CWD + 'config.json', '[FAILED]');
154
+ return;
155
+ }
156
+ if (cmds[0] === 'init') {
157
+ if (!await lFs.isFile(kebab.VHOST_CWD + 'default.json')) {
158
+ lCore.display('KEBAB', 'CREATE', 'FILE', kebab.VHOST_CWD + 'default.json');
159
+ if (!await lFs.putContent(kebab.VHOST_CWD + 'default.json', lText.stringifyJson([
160
+ {
161
+ 'name': 'example',
162
+ 'domains': ['*'],
163
+ 'root': '${example}',
164
+ 'remark': '',
165
+ },
166
+ {
167
+ 'name': 'default',
168
+ 'domains': ['www.maiyun.net'],
169
+ 'root': 'default/',
170
+ 'remark': '',
171
+ },
172
+ ], 4))) {
173
+ lCore.display('KEBAB', 'CREATE', 'FILE', kebab.VHOST_CWD + 'default.json', '[FAILED]');
174
+ return;
175
+ }
176
+ }
177
+ }
178
+ lCore.display('DONE');
179
+ process.exit();
180
+ }
181
+ const configContent = await lFs.getContent(kebab.CONF_CWD + 'config.json', 'utf8');
182
+ if (!configContent) {
183
+ throw `File '${kebab.CONF_CWD}config.json' not found.`;
184
+ }
185
+ const config = lText.parseJson(configContent);
186
+ for (const key in config) {
187
+ lCore.globalConfig[key] = config[key];
188
+ }
189
+ if (cmds[0] === '--ind' || cmds[0] === '-i') {
190
+ if (!await lFs.isFile(kebab.IND_CWD + cmds[1] + '/index.js')) {
191
+ lCore.display('CMD ERROR', 'IND FILE "' + cmds[1] + '" NOT FOUND.');
192
+ return;
193
+ }
194
+ Promise.resolve(`${'../ind/' + cmds[1] + '/index'}`).then(s => __importStar(require(s))).catch((e) => {
195
+ lCore.display('CMD ERROR', 'E', e);
196
+ });
197
+ }
198
+ else {
199
+ const time = lTime.stamp();
200
+ http.request({
201
+ 'hostname': '127.0.0.1',
202
+ 'port': config.rpcPort,
203
+ 'path': '/' + lCrypto.aesEncrypt(lText.stringifyJson({
204
+ 'action': cmds[0],
205
+ 'time': time
206
+ }), lCore.globalConfig.rpcSecret)
207
+ }, function (res) {
208
+ res.on('data', function (chunk) {
209
+ const str = chunk.toString();
210
+ if (str === 'Done') {
211
+ lCore.display(`Command ${cmds[0]} has been sent.`);
212
+ }
213
+ else {
214
+ lCore.display('Returns an information exception: ' + str);
215
+ }
216
+ process.exit();
217
+ });
218
+ }).on('error', function () {
219
+ lCore.display('RPC Server Error.');
220
+ }).end();
221
+ }
222
+ }
223
+ run().catch(function (e) {
224
+ lCore.display('[cmd] ------ [Process fatal Error] ------');
225
+ lCore.display(e);
226
+ });
package/sys/cmd.ts ADDED
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Project: Kebab, User: JianSuoQiYue
3
+ * Date: 2020-3-7 23:51:15
4
+ * Last: 2020-3-7 23:51:18, 2022-07-22 14:14:09, 2022-9-27 14:52:19, 2023-5-23 21:42:46, 2024-7-2 15:12:28
5
+ */
6
+ import * as http from 'http';
7
+ import * as lFs from '~/lib/fs';
8
+ import * as lText from '~/lib/text';
9
+ import * as lTime from '~/lib/time';
10
+ import * as lCore from '~/lib/core';
11
+ import * as lCrypto from '~/lib/crypto';
12
+ import * as kebab from '~/index';
13
+
14
+ /** --- 解析命令 --- */
15
+ const cmds = process.argv.slice(2);
16
+
17
+ /** --- 批量创建目录 --- */
18
+ async function initDir(paths: string[]): Promise<boolean> {
19
+ for (const path of paths) {
20
+ if (await lFs.isDir(path)) {
21
+ continue;
22
+ }
23
+ lCore.display('KEBAB', 'CREATE', 'DIR', path);
24
+ if (!await lFs.mkdir(path)) {
25
+ lCore.display('KEBAB', 'CREATE', 'DIR', path, '[FAILED]');
26
+ return false;
27
+ }
28
+ lCore.display('KEBAB', 'CREATE', 'FILE', path + 'lock.txt');
29
+ if (!await lFs.putContent(path + 'lock.txt', 'Kebab')) {
30
+ lCore.display('KEBAB', 'CREATE', 'FILE', path + 'lock.txt', '[FAILED]');
31
+ return false;
32
+ }
33
+ }
34
+ return true;
35
+ }
36
+
37
+ /** --- cmd 解析 --- */
38
+ async function run(): Promise<void> {
39
+ if (cmds[0] === 'init' || cmds[0] === 'update') {
40
+ // --- 初始化、更新 ---
41
+ if (!await initDir([
42
+ kebab.CERT_CWD + 'default/',
43
+ kebab.VHOST_CWD,
44
+ kebab.FTMP_CWD,
45
+ kebab.IND_CWD,
46
+ kebab.LIB_CWD,
47
+ kebab.LOG_CWD,
48
+ kebab.WWW_CWD,
49
+ kebab.MOD_CWD,
50
+ ])) {
51
+ return;
52
+ }
53
+ // --- /conf/cert.json ---
54
+ if (!await lFs.isFile(kebab.CONF_CWD + 'cert.json')) {
55
+ lCore.display('KEBAB', 'CREATE', 'FILE', kebab.CONF_CWD + 'cert.json');
56
+ if (!await lFs.putContent(kebab.CONF_CWD + 'cert.json', lText.stringifyJson([
57
+ {
58
+ 'cert': 'default/xxx.cer',
59
+ 'key': 'default/xxx.key'
60
+ }
61
+ ], 4))) {
62
+ lCore.display('KEBAB', 'CREATE', 'FILE', kebab.CONF_CWD + 'cert.json', '[FAILED]');
63
+ return;
64
+ }
65
+ }
66
+ // --- /conf/config.json ---
67
+ let config: any = {};
68
+ if (await lFs.isFile(kebab.CONF_CWD + 'config.json')) {
69
+ config = lText.parseJson((await lFs.getContent(kebab.CONF_CWD + 'config.json'))?.toString() ?? '{}');
70
+ }
71
+ else {
72
+ lCore.display('KEBAB', 'CREATE', 'FILE', kebab.CONF_CWD + 'config.json');
73
+ }
74
+ // --- 修复 config ---
75
+ config.httpPort ??= 8080;
76
+ config.httpsPort ??= 4333;
77
+ config.rpcPort ??= 10630;
78
+ config.rpcSecret ??= 'MUSTCHANGE';
79
+ config.debug ??= true;
80
+ config.max ??= 64;
81
+ // --- config - set ---
82
+ config.set ??= {};
83
+ config.set.timezone ??= 8;
84
+ config.set.mustHttps ??= false;
85
+ config.set.cacheTtl ??= 0;
86
+ config.set.staticVer ??= '20200314174905';
87
+ config.set.staticPath ??= '';
88
+ // --- config - db ---
89
+ config.db ??= {};
90
+ config.db.host ??= '127.0.0.1';
91
+ config.db.port ??= 3306;
92
+ config.db.charset ??= 'utf8mb4';
93
+ config.db.name ??= 'maiyun';
94
+ config.db.user ??= 'root';
95
+ config.db.pwd ??= 'DashAdmin';
96
+ // --- config - jwt ---
97
+ config.jwt ??= {};
98
+ config.jwt.name ??= 'KE_JWT';
99
+ config.jwt.ttl ??= 172800;
100
+ config.jwt.ssl ??= false;
101
+ config.jwt.secret ??= 'MUSTCHANGE';
102
+ config.jwt.auth ??= false;
103
+ // --- config - dns ---
104
+ config.dns ??= {};
105
+ config.dns['DNSPOD'] ??= {};
106
+ config.dns['DNSPOD'].sid ??= '';
107
+ config.dns['DNSPOD'].skey ??= '';
108
+ config.dns['CF'] ??= {};
109
+ config.dns['CF'].sid ??= '';
110
+ config.dns['CF'].skey ??= '';
111
+ // --- config - kv ---
112
+ config.kv ??= {};
113
+ config.kv.host ??= '127.0.0.1';
114
+ config.kv.port ??= 6379;
115
+ config.kv.index ??= 0;
116
+ config.kv.pre ??= 'm_';
117
+ config.kv.user ??= '';
118
+ config.kv.pwd ??= '';
119
+ // --- config - session ---
120
+ config.session ??= {};
121
+ config.session.name ??= 'KE_SESSION';
122
+ config.session.ttl ??= 172800;
123
+ config.session.ssl ??= false;
124
+ // --- config - sql ---
125
+ config.sql ??= {};
126
+ config.sql.pre ??= 'm_';
127
+ // --- config - s3 ---
128
+ config.s3 ??= {};
129
+ config.s3['CF'] ??= {};
130
+ config.s3['CF'].account = '';
131
+ config.s3['CF'].sid = '';
132
+ config.s3['CF'].skey = '';
133
+ config.s3['CF'].region = 'auto';
134
+ config.s3['CF'].bucket = '';
135
+ config.s3['TENCENT'] ??= {};
136
+ config.s3['TENCENT'].sid = '';
137
+ config.s3['TENCENT'].skey = '';
138
+ config.s3['TENCENT'].region = '';
139
+ config.s3['TENCENT'].bucket = '';
140
+ // --- 保存 config.json ---
141
+ if (!await lFs.putContent(kebab.CONF_CWD + 'config.json', lText.stringifyJson(config, 4))) {
142
+ lCore.display('KEBAB', 'CREATE', 'FILE', kebab.CONF_CWD + 'config.json', '[FAILED]');
143
+ return;
144
+ }
145
+ // --- 只在初始化时 ---
146
+ if (cmds[0] === 'init') {
147
+ // --- /conf/vhost/default.json ---
148
+ if (!await lFs.isFile(kebab.VHOST_CWD + 'default.json')) {
149
+ lCore.display('KEBAB', 'CREATE', 'FILE', kebab.VHOST_CWD + 'default.json');
150
+ if (!await lFs.putContent(kebab.VHOST_CWD + 'default.json', lText.stringifyJson([
151
+ {
152
+ 'name': 'example',
153
+ 'domains': ['*'],
154
+ 'root': '${example}',
155
+ 'remark': '',
156
+ },
157
+ {
158
+ 'name': 'default',
159
+ 'domains': ['www.maiyun.net'],
160
+ 'root': 'default/',
161
+ 'remark': '',
162
+ },
163
+ ], 4))) {
164
+ lCore.display('KEBAB', 'CREATE', 'FILE', kebab.VHOST_CWD + 'default.json', '[FAILED]');
165
+ return;
166
+ }
167
+ }
168
+ }
169
+ lCore.display('DONE');
170
+ process.exit();
171
+ }
172
+
173
+ // --- 读取配置文件 ---
174
+ const configContent = await lFs.getContent(kebab.CONF_CWD + 'config.json', 'utf8');
175
+ if (!configContent) {
176
+ throw `File '${kebab.CONF_CWD}config.json' not found.`;
177
+ }
178
+ /** --- 系统 config.json --- */
179
+ const config = lText.parseJson(configContent);
180
+ for (const key in config) {
181
+ lCore.globalConfig[key] = config[key];
182
+ }
183
+
184
+ if (cmds[0] === '--ind' || cmds[0] === '-i') {
185
+ // --- 运行独立文件,如 node ./index --ind gps ---
186
+ if (!await lFs.isFile(kebab.IND_CWD + cmds[1] + '/index.js')) {
187
+ lCore.display('CMD ERROR', 'IND FILE "' + cmds[1] + '" NOT FOUND.');
188
+ return;
189
+ }
190
+ // --- 载入独立文件入口 ---
191
+ import('../ind/' + cmds[1] + '/index').catch((e) => {
192
+ lCore.display('CMD ERROR', 'E', e);
193
+ });
194
+ }
195
+ else {
196
+ // --- 其他,如 node ./index reload 或 restart ---
197
+ const time = lTime.stamp();
198
+ http.request({
199
+ 'hostname': '127.0.0.1',
200
+ 'port': config.rpcPort,
201
+ 'path': '/' + lCrypto.aesEncrypt(lText.stringifyJson({
202
+ 'action': cmds[0],
203
+ 'time': time
204
+ }), lCore.globalConfig.rpcSecret)
205
+ }, function(res: http.IncomingMessage) {
206
+ res.on('data', function(chunk: Buffer) {
207
+ const str = chunk.toString();
208
+ if (str === 'Done') {
209
+ lCore.display(`Command ${cmds[0]} has been sent.`);
210
+ }
211
+ else {
212
+ lCore.display('Returns an information exception: ' + str);
213
+ }
214
+ process.exit();
215
+ });
216
+ }).on('error', function() {
217
+ lCore.display('RPC Server Error.');
218
+ }).end();
219
+ }
220
+ }
221
+
222
+ run().catch(function(e): void {
223
+ lCore.display('[cmd] ------ [Process fatal Error] ------');
224
+ lCore.display(e);
225
+ });