@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/lib/dns.ts ADDED
@@ -0,0 +1,405 @@
1
+ /**
2
+ * Project: Kebab, User: JianSuoQiYue
3
+ * Date: 2019-6-19
4
+ * Last: 2022-09-12 20:58:07, 2024-2-21 17:55:54, 2025-6-13 19:08:56
5
+ */
6
+
7
+ // --- 库和定义 ---
8
+ import * as net from '~/lib/net';
9
+ import * as core from '~/lib/core';
10
+ import * as text from '~/lib/text';
11
+ import * as crypto from '~/lib/crypto';
12
+ import * as response from '~/lib/net/response';
13
+ import * as ctr from '~/sys/ctr';
14
+
15
+ /**
16
+ * 0.DNSPod:https://www.dnspod.cn/docs/index.html(腾讯云也请使用 DNSPod 的 API)
17
+ * 1.阿里云:https://help.aliyun.com/document_detail/29745.html
18
+ */
19
+
20
+ /** --- 服务商定义 --- */
21
+ export enum ESERVICE {
22
+ 'DNSPOD',
23
+ 'ALIBABA'
24
+ }
25
+
26
+ /** --- 选项 --- */
27
+ export interface IOptions {
28
+ /** --- 服务商 ---- */
29
+ 'service': ESERVICE;
30
+ /** --- 密钥键 --- */
31
+ 'secretId'?: string;
32
+ /** --- 密钥值 --- */
33
+ 'secretKey'?: string;
34
+ }
35
+
36
+ /**
37
+ * --- 获取域名列表的返回对象 ---
38
+ */
39
+ export interface IDomainList {
40
+ 'total': number;
41
+ 'list': Array<{
42
+ 'id': string;
43
+ 'name': string;
44
+ 'count': number;
45
+ 'punyCode': string;
46
+ }>;
47
+ }
48
+
49
+ /**
50
+ * --- 添加记录的返回对象 ---
51
+ */
52
+ export interface IAddDomainRecord {
53
+ 'success': boolean;
54
+ 'id': string;
55
+ }
56
+
57
+ /**
58
+ * --- 记录值类型 ---
59
+ */
60
+ export const RECORD_TYPE = {
61
+ 'A': 'A',
62
+ 'NS': 'NS',
63
+ 'MX': 'MX',
64
+ 'TXT': 'TXT',
65
+ 'CNAME': 'CNAME',
66
+ 'SRV': 'SRV',
67
+ 'AAAA': 'AAAA'
68
+ };
69
+
70
+ /**
71
+ * --- 记录值线路 ---
72
+ */
73
+ export enum ERecordLine {
74
+ 'DEFAULT',
75
+ 'TELECOM',
76
+ 'UNICOM',
77
+ 'MOBILE',
78
+ 'EDU',
79
+ 'OVERSEA'
80
+ }
81
+
82
+ const recordLine = {
83
+ [ESERVICE.DNSPOD]: [
84
+ '默认',
85
+ '电信',
86
+ '联通',
87
+ '移动',
88
+ '教育网',
89
+ '境外'
90
+ ],
91
+ [ESERVICE.ALIBABA]: [
92
+ 'default',
93
+ 'telecom',
94
+ 'unicom',
95
+ 'mobile',
96
+ 'edu',
97
+ 'oversea'
98
+ ]
99
+ };
100
+
101
+ export class Dns {
102
+
103
+ /** --- 当前选项 --- */
104
+ private readonly _opt: IOptions;
105
+
106
+ public constructor(ctr: ctr.Ctr, opt: IOptions) {
107
+ const config = ctr.getPrototype('_config');
108
+ opt.secretId ??= config.dns?.[ESERVICE[opt.service]].sid;
109
+ opt.secretKey ??= config.dns?.[ESERVICE[opt.service]].skey;
110
+ this._opt = opt;
111
+ }
112
+
113
+ /**
114
+ * --- 最终发送 ---
115
+ * @param obj 要发送的信息
116
+ */
117
+ private async _send(obj: Record<string, string | number | undefined>): Promise<response.Response> {
118
+ for (const key in obj) {
119
+ if (obj[key] === null || obj[key] === undefined) {
120
+ delete obj[key];
121
+ }
122
+ }
123
+ switch (this._opt.service) {
124
+ // --- DNSPod ---
125
+ case ESERVICE.DNSPOD: {
126
+ const data = Object.assign({
127
+ 'login_token': (this._opt.secretId ?? '') + '.' + (this._opt.secretKey ?? ''),
128
+ 'format': 'json'
129
+ }, obj);
130
+ const path = data['_path'] as string;
131
+ delete data['_path'];
132
+ return net.post('https://dnsapi.cn/' + path, data); // 境外 api 会自动调度到香港服务器
133
+ }
134
+ // --- 阿里云 ---
135
+ case ESERVICE.ALIBABA: {
136
+ const getData = core.objectSort(Object.assign({
137
+ 'Format': 'JSON',
138
+ 'Version': '2015-01-09',
139
+ 'AccessKeyId': this._opt.secretId,
140
+ 'SignatureMethod': 'HMAC-SHA1',
141
+ 'Timestamp': (new Date()).toISOString(),
142
+ 'SignatureVersion': '1.0',
143
+ 'SignatureNonce': core.rand(1000000000, 9999999999)
144
+ }, obj));
145
+ const urlRight = text.queryStringify(getData);
146
+ const signature = crypto.hashHmac('sha1', `GET&${encodeURIComponent('/')}&${encodeURIComponent(urlRight)}`, (this._opt.secretKey ?? '') + '&', 'base64');
147
+ return net.get(`https://alidns.aliyuncs.com/?${urlRight}&Signature=${encodeURIComponent(signature)}`); // 境外 api 会自动调度到新加坡服务器
148
+ }
149
+ }
150
+ return new response.Response(null);
151
+ }
152
+
153
+ /**
154
+ * --- 获取域名列表 ---
155
+ * @param opt 参数
156
+ */
157
+ public async getDomainList(opt: {
158
+ 'offset'?: number;
159
+ 'length'?: number;
160
+ }): Promise<IDomainList | null> {
161
+ switch (this._opt.service) {
162
+ // --- DNSPod ---
163
+ case ESERVICE.DNSPOD: {
164
+ const rtn = await this._send({
165
+ '_path': 'Domain.List',
166
+ 'offset': opt.offset ?? 0,
167
+ 'length': opt.length ?? 20
168
+ });
169
+ const res = await rtn.getContent();
170
+ if (!res) {
171
+ return res;
172
+ }
173
+ const json = text.parseJson(res.toString());
174
+ const r: IDomainList = {
175
+ 'total': json.info.domain_total,
176
+ 'list': []
177
+ };
178
+ for (const item of json.domains) {
179
+ r.list.push({
180
+ 'id': item.id.toString(),
181
+ 'name': item.name,
182
+ 'count': parseInt(item.records),
183
+ 'punyCode': item.punycode
184
+ });
185
+ }
186
+ return r;
187
+ }
188
+ // --- 阿里云 ---
189
+ case ESERVICE.ALIBABA: {
190
+ const length = opt.length ?? 20;
191
+ const rtn = await this._send({
192
+ 'Action': 'DescribeDomains',
193
+ 'PageNumber': opt.offset !== undefined ? opt.offset / length + 1 : 1,
194
+ 'PageSize': length
195
+ });
196
+ const res = await rtn.getContent();
197
+ if (!res) {
198
+ return res;
199
+ }
200
+ const json = text.parseJson(res.toString());
201
+ const r: IDomainList = {
202
+ 'total': json.TotalCount,
203
+ 'list': []
204
+ };
205
+ for (const item of json.Domains.Domain) {
206
+ r.list.push({
207
+ 'id': item.DomainId,
208
+ 'name': item.DomainName,
209
+ 'count': item.RecordCount,
210
+ 'punyCode': item.PunyCode
211
+ });
212
+ }
213
+ return r;
214
+ }
215
+ }
216
+ return null;
217
+ }
218
+
219
+ /**
220
+ * --- 添加记录 ---
221
+ * @param opt 参数
222
+ */
223
+ public async addDomainRecord(opt: {
224
+ 'domain': string;
225
+ 'sub': string;
226
+ 'type': string;
227
+ 'value': string;
228
+ 'line'?: number;
229
+ 'ttl'?: number;
230
+ 'mx'?: number;
231
+ }): Promise<IAddDomainRecord | null> {
232
+ const line = opt.line ?? ERecordLine.DEFAULT;
233
+ const ttl = opt.ttl ?? 600;
234
+ switch (this._opt.service) {
235
+ // --- DNSPod ---
236
+ case ESERVICE.DNSPOD: {
237
+ const rtn = await this._send({
238
+ '_path': 'Record.Create',
239
+ 'domain': opt.domain,
240
+ 'sub_domain': opt.sub,
241
+ 'record_type': opt.type,
242
+ 'record_line': recordLine[ESERVICE.DNSPOD][line],
243
+ 'value': opt.value,
244
+ 'ttl': ttl,
245
+ 'mx': opt.mx
246
+ });
247
+ const res = await rtn.getContent();
248
+ if (!res) {
249
+ return res;
250
+ }
251
+ const json = text.parseJson(res.toString());
252
+ const r: IAddDomainRecord = {
253
+ 'success': json.record?.id ? true : false,
254
+ 'id': json.record?.id ?? ''
255
+ };
256
+ return r;
257
+ }
258
+ // --- 阿里云 ---
259
+ case ESERVICE.ALIBABA: {
260
+ const rtn = await this._send({
261
+ 'Action': 'AddDomainRecord',
262
+ 'DomainName': opt.domain,
263
+ 'RR': opt.sub,
264
+ 'Type': opt.type,
265
+ 'Line': recordLine[ESERVICE.ALIBABA][line],
266
+ 'Value': opt.value,
267
+ 'TTL': ttl,
268
+ 'Priority': opt.mx
269
+ });
270
+ const res = await rtn.getContent();
271
+ if (!res) {
272
+ return res;
273
+ }
274
+ const json = text.parseJson(res.toString());
275
+ const r: IAddDomainRecord = {
276
+ 'success': json.RecordId !== undefined ? true : false,
277
+ 'id': json.RecordId ?? ''
278
+ };
279
+ return r;
280
+ }
281
+ }
282
+ return null;
283
+ }
284
+
285
+ /**
286
+ * --- 修改记录 ---
287
+ * @param opt 参数
288
+ */
289
+ public async updateDomainRecord(opt: {
290
+ 'domain': string;
291
+ 'record': string;
292
+ 'sub': string;
293
+ 'type': string;
294
+ 'value': string;
295
+ 'line'?: number;
296
+ 'ttl'?: number;
297
+ 'mx'?: number;
298
+ }): Promise<IAddDomainRecord | null> {
299
+ const line = opt.line ?? ERecordLine.DEFAULT;
300
+ const ttl = opt.ttl ?? 600;
301
+ switch (this._opt.service) {
302
+ // --- DNSPod ---
303
+ case ESERVICE.DNSPOD: {
304
+ // --- DNSPod 必须传 domain ---
305
+ const rtn = await this._send({
306
+ '_path': 'Record.Modify',
307
+ 'domain': opt.domain,
308
+ 'record_id': opt.record,
309
+ 'sub_domain': opt.sub,
310
+ 'record_type': opt.type,
311
+ 'record_line': recordLine[ESERVICE.DNSPOD][line],
312
+ 'value': opt.value,
313
+ 'ttl': ttl,
314
+ 'mx': opt.mx
315
+ });
316
+ const res = await rtn.getContent();
317
+ if (!res) {
318
+ return res;
319
+ }
320
+ const json = text.parseJson(res.toString());
321
+ const r: IAddDomainRecord = {
322
+ 'success': json.record?.id ? true : false,
323
+ 'id': json.record?.id ?? ''
324
+ };
325
+ return r;
326
+ }
327
+ // --- 阿里云 ---
328
+ case ESERVICE.ALIBABA: {
329
+ const rtn = await this._send({
330
+ 'Action': 'UpdateDomainRecord',
331
+ 'RecordId': opt.record,
332
+ 'RR': opt.sub,
333
+ 'Type': opt.type,
334
+ 'Line': recordLine[ESERVICE.ALIBABA][line],
335
+ 'Value': opt.value,
336
+ 'TTL': ttl,
337
+ 'Priority': opt.mx
338
+ });
339
+ const res = await rtn.getContent();
340
+ if (!res) {
341
+ return res;
342
+ }
343
+ const json = text.parseJson(res.toString());
344
+ const r: IAddDomainRecord = {
345
+ 'success': json.RecordId !== undefined ? true : false,
346
+ 'id': json.RecordId ?? ''
347
+ };
348
+ return r;
349
+ }
350
+ }
351
+ return null;
352
+ }
353
+
354
+ /**
355
+ * --- 删除记录 ---
356
+ * @param opt 参数
357
+ */
358
+ public async deleteDomainRecord(opt: {
359
+ 'domain': string;
360
+ 'id': string;
361
+ }): Promise<{ 'success': boolean; } | null> {
362
+ switch (this._opt.service) {
363
+ // --- DNSPod ---
364
+ case ESERVICE.DNSPOD: {
365
+ const rtn = await this._send({
366
+ '_path': 'Record.Remove',
367
+ 'domain': opt.domain,
368
+ 'record_id': opt.id
369
+ });
370
+ const res = await rtn.getContent();
371
+ if (!res) {
372
+ return res;
373
+ }
374
+ const json = text.parseJson(res.toString());
375
+ return {
376
+ 'success': json.status.code === '1' ? true : false
377
+ };
378
+ }
379
+ // --- 阿里云 ---
380
+ case ESERVICE.ALIBABA: {
381
+ const rtn = await this._send({
382
+ 'Action': 'DeleteDomainRecord',
383
+ 'RecordId': opt.id
384
+ });
385
+ const res = await rtn.getContent();
386
+ if (!res) {
387
+ return res;
388
+ }
389
+ const json = text.parseJson(res.toString());
390
+ return {
391
+ 'success': json.Code === undefined ? true : false
392
+ };
393
+ }
394
+ }
395
+ return null;
396
+ }
397
+ }
398
+
399
+ /**
400
+ * --- 创建一个第三方 Dns 对象 ---
401
+ * @param opt 选项
402
+ */
403
+ export function get(ctr: ctr.Ctr, opt: IOptions): Dns {
404
+ return new Dns(ctr, opt);
405
+ }