@maiyunnet/kebab 2.0.3 → 2.0.5

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 (89) hide show
  1. package/index.d.ts +14 -0
  2. package/index.js +1 -1
  3. package/lib/buffer.d.ts +25 -0
  4. package/lib/captcha.d.ts +12 -0
  5. package/lib/consistent.d.ts +20 -0
  6. package/lib/core.d.ts +85 -0
  7. package/lib/crypto.d.ts +47 -0
  8. package/lib/db.d.ts +88 -0
  9. package/lib/dns.d.ts +75 -0
  10. package/lib/fs.d.ts +49 -0
  11. package/lib/jwt.d.ts +30 -0
  12. package/lib/kv.d.ts +111 -0
  13. package/lib/lan.d.ts +10 -0
  14. package/lib/net/formdata.d.ts +23 -0
  15. package/lib/net/request.d.ts +23 -0
  16. package/lib/net/response.d.ts +14 -0
  17. package/lib/net.d.ts +65 -0
  18. package/lib/s3.d.ts +35 -0
  19. package/lib/scan.d.ts +31 -0
  20. package/lib/session.d.ts +22 -0
  21. package/lib/sql.d.ts +57 -0
  22. package/lib/ssh/sftp.d.ts +40 -0
  23. package/lib/ssh/shell.d.ts +13 -0
  24. package/lib/ssh.d.ts +24 -0
  25. package/lib/text.d.ts +40 -0
  26. package/lib/time.d.ts +22 -0
  27. package/lib/ws.d.ts +87 -0
  28. package/lib/zip.d.ts +40 -0
  29. package/lib/zlib.d.ts +25 -0
  30. package/main.d.ts +1 -0
  31. package/package.json +1 -1
  32. package/sys/child.d.ts +1 -0
  33. package/sys/cmd.d.ts +1 -0
  34. package/sys/ctr.d.ts +96 -0
  35. package/sys/master.d.ts +1 -0
  36. package/sys/mod.d.ts +205 -0
  37. package/sys/route.d.ts +31 -0
  38. package/tsconfig.json +1 -1
  39. package/www/example/ctr/main.d.ts +4 -0
  40. package/www/example/ctr/middle.d.ts +6 -0
  41. package/www/example/ctr/test.d.ts +94 -0
  42. package/www/example/mod/test.d.ts +20 -0
  43. package/www/example/mod/testdata.d.ts +9 -0
  44. package/www/example/ws/mproxy.d.ts +4 -0
  45. package/www/example/ws/rproxy.d.ts +4 -0
  46. package/www/example/ws/test.d.ts +7 -0
  47. package/index.ts +0 -33
  48. package/lib/buffer.ts +0 -152
  49. package/lib/captcha.ts +0 -63
  50. package/lib/consistent.ts +0 -219
  51. package/lib/core.ts +0 -880
  52. package/lib/crypto.ts +0 -384
  53. package/lib/db.ts +0 -719
  54. package/lib/dns.ts +0 -405
  55. package/lib/fs.ts +0 -527
  56. package/lib/jwt.ts +0 -276
  57. package/lib/kv.ts +0 -1489
  58. package/lib/lan.ts +0 -87
  59. package/lib/net/formdata.ts +0 -166
  60. package/lib/net/request.ts +0 -150
  61. package/lib/net/response.ts +0 -59
  62. package/lib/net.ts +0 -662
  63. package/lib/s3.ts +0 -235
  64. package/lib/scan.ts +0 -364
  65. package/lib/session.ts +0 -230
  66. package/lib/sql.ts +0 -1149
  67. package/lib/ssh/sftp.ts +0 -508
  68. package/lib/ssh/shell.ts +0 -123
  69. package/lib/ssh.ts +0 -191
  70. package/lib/text.ts +0 -626
  71. package/lib/time.ts +0 -254
  72. package/lib/ws.ts +0 -523
  73. package/lib/zip.ts +0 -447
  74. package/lib/zlib.ts +0 -350
  75. package/main.ts +0 -27
  76. package/sys/child.ts +0 -678
  77. package/sys/cmd.ts +0 -225
  78. package/sys/ctr.ts +0 -904
  79. package/sys/master.ts +0 -355
  80. package/sys/mod.ts +0 -1871
  81. package/sys/route.ts +0 -1113
  82. package/www/example/ctr/main.ts +0 -9
  83. package/www/example/ctr/middle.ts +0 -26
  84. package/www/example/ctr/test.ts +0 -3218
  85. package/www/example/mod/test.ts +0 -47
  86. package/www/example/mod/testdata.ts +0 -30
  87. package/www/example/ws/mproxy.ts +0 -16
  88. package/www/example/ws/rproxy.ts +0 -14
  89. package/www/example/ws/test.ts +0 -36
package/sys/cmd.ts DELETED
@@ -1,225 +0,0 @@
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
- });