@maiyunnet/kebab 2.0.2 → 2.0.4

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 (49) hide show
  1. package/index.js +1 -1
  2. package/lib/sql.js +1 -3
  3. package/lib/text.js +5 -1
  4. package/package.json +1 -1
  5. package/tsconfig.json +1 -1
  6. package/index.ts +0 -33
  7. package/lib/buffer.ts +0 -152
  8. package/lib/captcha.ts +0 -63
  9. package/lib/consistent.ts +0 -219
  10. package/lib/core.ts +0 -880
  11. package/lib/crypto.ts +0 -384
  12. package/lib/db.ts +0 -719
  13. package/lib/dns.ts +0 -405
  14. package/lib/fs.ts +0 -527
  15. package/lib/jwt.ts +0 -276
  16. package/lib/kv.ts +0 -1489
  17. package/lib/lan.ts +0 -87
  18. package/lib/net/formdata.ts +0 -166
  19. package/lib/net/request.ts +0 -150
  20. package/lib/net/response.ts +0 -59
  21. package/lib/net.ts +0 -662
  22. package/lib/s3.ts +0 -235
  23. package/lib/scan.ts +0 -364
  24. package/lib/session.ts +0 -230
  25. package/lib/sql.ts +0 -1151
  26. package/lib/ssh/sftp.ts +0 -508
  27. package/lib/ssh/shell.ts +0 -123
  28. package/lib/ssh.ts +0 -191
  29. package/lib/text.ts +0 -615
  30. package/lib/time.ts +0 -254
  31. package/lib/ws.ts +0 -523
  32. package/lib/zip.ts +0 -447
  33. package/lib/zlib.ts +0 -350
  34. package/main.ts +0 -27
  35. package/sys/child.ts +0 -678
  36. package/sys/cmd.ts +0 -225
  37. package/sys/ctr.ts +0 -904
  38. package/sys/master.ts +0 -355
  39. package/sys/mod.ts +0 -1871
  40. package/sys/route.ts +0 -1113
  41. package/types/index.d.ts +0 -283
  42. package/www/example/ctr/main.ts +0 -9
  43. package/www/example/ctr/middle.ts +0 -26
  44. package/www/example/ctr/test.ts +0 -3218
  45. package/www/example/mod/test.ts +0 -47
  46. package/www/example/mod/testdata.ts +0 -30
  47. package/www/example/ws/mproxy.ts +0 -16
  48. package/www/example/ws/rproxy.ts +0 -14
  49. package/www/example/ws/test.ts +0 -36
package/lib/dns.ts DELETED
@@ -1,405 +0,0 @@
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
- }