@maiyunnet/kebab 2.0.3 → 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.
- package/index.js +1 -1
- package/package.json +1 -1
- package/tsconfig.json +1 -1
- package/index.ts +0 -33
- package/lib/buffer.ts +0 -152
- package/lib/captcha.ts +0 -63
- package/lib/consistent.ts +0 -219
- package/lib/core.ts +0 -880
- package/lib/crypto.ts +0 -384
- package/lib/db.ts +0 -719
- package/lib/dns.ts +0 -405
- package/lib/fs.ts +0 -527
- package/lib/jwt.ts +0 -276
- package/lib/kv.ts +0 -1489
- package/lib/lan.ts +0 -87
- package/lib/net/formdata.ts +0 -166
- package/lib/net/request.ts +0 -150
- package/lib/net/response.ts +0 -59
- package/lib/net.ts +0 -662
- package/lib/s3.ts +0 -235
- package/lib/scan.ts +0 -364
- package/lib/session.ts +0 -230
- package/lib/sql.ts +0 -1149
- package/lib/ssh/sftp.ts +0 -508
- package/lib/ssh/shell.ts +0 -123
- package/lib/ssh.ts +0 -191
- package/lib/text.ts +0 -626
- package/lib/time.ts +0 -254
- package/lib/ws.ts +0 -523
- package/lib/zip.ts +0 -447
- package/lib/zlib.ts +0 -350
- package/main.ts +0 -27
- package/sys/child.ts +0 -678
- package/sys/cmd.ts +0 -225
- package/sys/ctr.ts +0 -904
- package/sys/master.ts +0 -355
- package/sys/mod.ts +0 -1871
- package/sys/route.ts +0 -1113
- package/types/index.d.ts +0 -283
- package/www/example/ctr/main.ts +0 -9
- package/www/example/ctr/middle.ts +0 -26
- package/www/example/ctr/test.ts +0 -3218
- package/www/example/mod/test.ts +0 -47
- package/www/example/mod/testdata.ts +0 -30
- package/www/example/ws/mproxy.ts +0 -16
- package/www/example/ws/rproxy.ts +0 -14
- package/www/example/ws/test.ts +0 -36
package/lib/lan.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import * as os from 'os';
|
|
2
|
-
import * as lCore from '~/lib/core';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* --- 获取当前网卡的 IP、MAC 信息 ---
|
|
6
|
-
*/
|
|
7
|
-
export async function card(): Promise<Array<{
|
|
8
|
-
'name': string;
|
|
9
|
-
'mac': string;
|
|
10
|
-
'iPv4': string;
|
|
11
|
-
'iPv6': string;
|
|
12
|
-
}>> {
|
|
13
|
-
const result: Array<{
|
|
14
|
-
'name': string;
|
|
15
|
-
'mac': string;
|
|
16
|
-
'iPv4': string;
|
|
17
|
-
'iPv6': string;
|
|
18
|
-
}> = [];
|
|
19
|
-
let i = 0;
|
|
20
|
-
while (i < 5) {
|
|
21
|
-
const nifs = os.networkInterfaces();
|
|
22
|
-
if (!Object.keys(nifs).length) {
|
|
23
|
-
++i;
|
|
24
|
-
await lCore.sleep(50);
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
for (const name in nifs) {
|
|
28
|
-
/** --- 当前网卡 --- */
|
|
29
|
-
const card = nifs[name];
|
|
30
|
-
if (!card) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (card[0].internal) {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
const item = {
|
|
37
|
-
'name': name,
|
|
38
|
-
'mac': '',
|
|
39
|
-
'iPv4': '',
|
|
40
|
-
'iPv6': ''
|
|
41
|
-
};
|
|
42
|
-
for (const it of card) {
|
|
43
|
-
if (!item.mac) {
|
|
44
|
-
item.mac = it.mac;
|
|
45
|
-
}
|
|
46
|
-
if (it.family === 'IPv4') {
|
|
47
|
-
item.iPv4 = it.address;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
item.iPv6 = it.address;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
result.push(item);
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* --- 扫描发生关联的局域网 IP ---
|
|
62
|
-
*/
|
|
63
|
-
export async function scan(): Promise<Array<{
|
|
64
|
-
'mac': string;
|
|
65
|
-
'iPv4': string;
|
|
66
|
-
}>> {
|
|
67
|
-
const result: Array<{
|
|
68
|
-
'mac': string;
|
|
69
|
-
'iPv4': string;
|
|
70
|
-
}> = [];
|
|
71
|
-
const res = await lCore.exec('arp -a');
|
|
72
|
-
if (!res) {
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
const lines = res.replace(/\r\n/g, '\n').replace(/\r/g, '\n').split('\n');
|
|
76
|
-
for (const line of lines) {
|
|
77
|
-
const match = /([0-9.]{5,}).+?([a-zA-Z0-9:-]{5,})/.exec(line);
|
|
78
|
-
if (!match) {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
result.push({
|
|
82
|
-
'iPv4': match[1],
|
|
83
|
-
'mac': match[2].replace(/-/g, ':')
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
}
|
package/lib/net/formdata.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Project: Kebab, User: JianSuoQiYue
|
|
3
|
-
* Date: 2020-04-07 23:45:03
|
|
4
|
-
* Last: 2020-04-07 23:45:07, 2022-09-10 01:35:25
|
|
5
|
-
*/
|
|
6
|
-
import * as stream from 'stream';
|
|
7
|
-
import * as mime from '@litert/mime';
|
|
8
|
-
import * as core from '~/lib/core';
|
|
9
|
-
import * as fs from '~/lib/fs';
|
|
10
|
-
|
|
11
|
-
/** --- Item 对象 --- */
|
|
12
|
-
export interface IItem {
|
|
13
|
-
/** --- key 键 --- */
|
|
14
|
-
'key': string;
|
|
15
|
-
'isFile': boolean;
|
|
16
|
-
'isString': boolean;
|
|
17
|
-
/** --- 值或者文件名 --- */
|
|
18
|
-
'value': string;
|
|
19
|
-
'path': string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class FormData extends stream.Readable {
|
|
23
|
-
|
|
24
|
-
/** --- read 调用次数 --- */
|
|
25
|
-
private _num: number = 0;
|
|
26
|
-
|
|
27
|
-
/** --- 要编译的数据 --- */
|
|
28
|
-
private readonly _data: IItem[] = [];
|
|
29
|
-
|
|
30
|
-
/** --- 分隔符 --- */
|
|
31
|
-
private readonly _boundary: string = '----Kebab' + core.random(29, core.RANDOM_LUN);
|
|
32
|
-
|
|
33
|
-
/** --- 正在读取文件吗 --- */
|
|
34
|
-
private _fileReading: boolean = false;
|
|
35
|
-
|
|
36
|
-
/** --- 是否已经结束 --- */
|
|
37
|
-
private _close: boolean = false;
|
|
38
|
-
|
|
39
|
-
/** --- 总字节长度 --- */
|
|
40
|
-
private _length: number = 4 + this._boundary.length;
|
|
41
|
-
|
|
42
|
-
/** --- 已发送字节长度 --- */
|
|
43
|
-
private _sent: number = 0;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* --- 添加字符串 ---
|
|
47
|
-
* @param key 键
|
|
48
|
-
* @param val 值
|
|
49
|
-
*/
|
|
50
|
-
public putString(key: string, val: string): void {
|
|
51
|
-
this._data.push({
|
|
52
|
-
'key': key,
|
|
53
|
-
'isFile': false,
|
|
54
|
-
'isString': true,
|
|
55
|
-
'value': val,
|
|
56
|
-
'path': ''
|
|
57
|
-
});
|
|
58
|
-
this._length += this._boundary.length + 49 + Buffer.byteLength(key) + Buffer.byteLength(val);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* --- 添加文件 ---
|
|
63
|
-
* @param key 键
|
|
64
|
-
* @param path 路径
|
|
65
|
-
* @param fname 可选,文件名
|
|
66
|
-
*/
|
|
67
|
-
public async putFile(key: string, path: string, fname?: string): Promise<boolean> {
|
|
68
|
-
path = path.replace(/\\/g, '/');
|
|
69
|
-
const stat = await fs.stats(path);
|
|
70
|
-
if (!stat) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
if (!fname) {
|
|
74
|
-
const lio = path.lastIndexOf('/');
|
|
75
|
-
fname = lio === -1 ? path : path.slice(lio + 1);
|
|
76
|
-
}
|
|
77
|
-
this._data.push({
|
|
78
|
-
'key': key,
|
|
79
|
-
'isFile': true,
|
|
80
|
-
'isString': false,
|
|
81
|
-
'value': fname,
|
|
82
|
-
'path': path
|
|
83
|
-
});
|
|
84
|
-
this._length += this._boundary.length +
|
|
85
|
-
76 + Buffer.byteLength(key) + Buffer.byteLength(fname) +
|
|
86
|
-
mime.getMime(fname).length + stat.size + 2;
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* --- 获取 boundary ---
|
|
92
|
-
*/
|
|
93
|
-
public getBoundary(): string {
|
|
94
|
-
return this._boundary;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* --- 获取总字节长度 ---
|
|
99
|
-
*/
|
|
100
|
-
public getLength(): number {
|
|
101
|
-
return this._length;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* --- 获取已发送的字节长度 ---
|
|
106
|
-
*/
|
|
107
|
-
public getSent(): number {
|
|
108
|
-
return this._sent;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* --- 间隔读取(on data 或 pipe 触发)---
|
|
113
|
-
*/
|
|
114
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
115
|
-
public _read(): void {
|
|
116
|
-
if (this._close) {
|
|
117
|
-
// --- 结束了 ---
|
|
118
|
-
this.push(null);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
// --- 文件读取中 ---
|
|
122
|
-
if (this._fileReading) {
|
|
123
|
-
// --- 等待下面 fileReadable 的 on data 或 end 事件 ---
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
// --- 获取当前 item ---
|
|
127
|
-
const item = this._data[this._num];
|
|
128
|
-
if (!item) {
|
|
129
|
-
this._close = true;
|
|
130
|
-
const push = `--${this._boundary}--`;
|
|
131
|
-
this._sent += Buffer.byteLength(push);
|
|
132
|
-
this.push(push);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
if (item.isString) {
|
|
136
|
-
// --- 字段 ---
|
|
137
|
-
const push = `--${this._boundary}\r\nContent-Disposition: form-data; name="${item.key}"\r\n\r\n${item.value}\r\n`;
|
|
138
|
-
this._sent += Buffer.byteLength(push);
|
|
139
|
-
this.push(push);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
// --- 文件 ---
|
|
143
|
-
const push = `--${this._boundary}\r\nContent-Disposition: form-data; name="${item.key}"; filename="${item.value}"\r\nContent-Type: ${mime.getMime(item.value)}\r\n\r\n`;
|
|
144
|
-
this._sent += Buffer.byteLength(push);
|
|
145
|
-
this.push(push);
|
|
146
|
-
// --- 创建流 ---
|
|
147
|
-
this._fileReading = true;
|
|
148
|
-
const fileReadable = fs.createReadStream(item.path);
|
|
149
|
-
fileReadable.on('data', (chunk): void => {
|
|
150
|
-
if (!(chunk instanceof Buffer)) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
this._sent += chunk.byteLength;
|
|
154
|
-
this.push(chunk);
|
|
155
|
-
});
|
|
156
|
-
fileReadable.on('end', () => {
|
|
157
|
-
this._fileReading = false;
|
|
158
|
-
const push = '\r\n';
|
|
159
|
-
this._sent += Buffer.byteLength(push);
|
|
160
|
-
this.push(push);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
++this._num;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
}
|
package/lib/net/request.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Project: Kebab, User: JianSuoQiYue
|
|
3
|
-
* Date: 2020-4-9 20:02:39
|
|
4
|
-
* Last: 2020-4-9 20:47:58, 2022-09-10 01:35:34
|
|
5
|
-
*/
|
|
6
|
-
import * as stream from 'stream';
|
|
7
|
-
import * as net from '~/lib/net';
|
|
8
|
-
import * as response from './response';
|
|
9
|
-
import * as types from '~/types';
|
|
10
|
-
|
|
11
|
-
export class Request {
|
|
12
|
-
|
|
13
|
-
/** --- get 或 post 的数据 --- */
|
|
14
|
-
private _data: Record<string, any> | Buffer | string | stream.Readable | undefined = undefined;
|
|
15
|
-
|
|
16
|
-
/** --- 访问的 URL --- */
|
|
17
|
-
private readonly _url: string = '';
|
|
18
|
-
|
|
19
|
-
/** --- 要传递的参数 --- */
|
|
20
|
-
private _opt: net.IRequestOptions = {};
|
|
21
|
-
|
|
22
|
-
public constructor(url: string) {
|
|
23
|
-
this._url = url;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* --- 设置 get 或 post 的数据 ---
|
|
28
|
-
* @param data 数据
|
|
29
|
-
*/
|
|
30
|
-
public data(data: Record<string, any> | Buffer | string | stream.Readable): this {
|
|
31
|
-
this._data = data;
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* --- 设置 get 或 post 请求 ---
|
|
37
|
-
* @param method
|
|
38
|
-
*/
|
|
39
|
-
public method(method: 'GET' | 'POST'): this {
|
|
40
|
-
this._opt['method'] = method;
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* --- method get 方法别名 ---
|
|
46
|
-
*/
|
|
47
|
-
public get(): this {
|
|
48
|
-
return this.method('GET');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* --- method post 方法别名 ---
|
|
53
|
-
*/
|
|
54
|
-
public post(): this {
|
|
55
|
-
return this.method('POST');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* --- 设置提交模式,json 还是普通 form ---
|
|
60
|
-
* @param type
|
|
61
|
-
*/
|
|
62
|
-
public type(type: 'form' | 'json'): this {
|
|
63
|
-
this._opt['type'] = type;
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* --- type json 方法别名 ---
|
|
69
|
-
*/
|
|
70
|
-
public json(): this {
|
|
71
|
-
return this.type('json');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* --- 设置请求有效期 ---
|
|
76
|
-
* @param timeout 秒
|
|
77
|
-
*/
|
|
78
|
-
public timeout(timeout: number): this {
|
|
79
|
-
this._opt['timeout'] = timeout;
|
|
80
|
-
return this;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* --- 设置是否跟随请求方的 location,留空为跟随,不设置为不跟随 ---
|
|
85
|
-
* @param follow
|
|
86
|
-
*/
|
|
87
|
-
public follow(follow: number = 5): this {
|
|
88
|
-
this._opt['follow'] = follow;
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* --- 设置域名 -> ip的对应键值,就像电脑里的 hosts 一样 ---
|
|
94
|
-
* @param hosts
|
|
95
|
-
*/
|
|
96
|
-
public hosts(hosts: Record<string, string>): this {
|
|
97
|
-
this._opt['hosts'] = hosts;
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* --- 设置后将直接保存到本地文件,不会返回,save 为本地实体路径 ---
|
|
103
|
-
* @param save
|
|
104
|
-
*/
|
|
105
|
-
public save(save: string): this {
|
|
106
|
-
this._opt['save'] = save;
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* --- 设置使用的本地网卡 IP ---
|
|
112
|
-
* @param addr
|
|
113
|
-
*/
|
|
114
|
-
public local(addr: string): this {
|
|
115
|
-
this._opt['local'] = addr;
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* --- 批量设置提交的 headers ---
|
|
121
|
-
* @param headers
|
|
122
|
-
*/
|
|
123
|
-
public headers(headers: types.THttpHeaders): this {
|
|
124
|
-
this._opt['headers'] = headers;
|
|
125
|
-
return this;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* --- 设置单条 header ---
|
|
130
|
-
* @param name
|
|
131
|
-
* @param val
|
|
132
|
-
*/
|
|
133
|
-
public setHeader(name: string, val: string): this {
|
|
134
|
-
if (!this._opt['headers']) {
|
|
135
|
-
this._opt['headers'] = {};
|
|
136
|
-
}
|
|
137
|
-
this._opt['headers'][name] = val;
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* --- 发起请求 ---
|
|
143
|
-
* @param cookie
|
|
144
|
-
*/
|
|
145
|
-
public async request(cookie?: Record<string, types.ICookie>): Promise<response.Response> {
|
|
146
|
-
this._opt.cookie = cookie;
|
|
147
|
-
return net.request(this._url, this._data, this._opt);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
}
|
package/lib/net/response.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Project: Kebab, User: JianSuoQiYue
|
|
3
|
-
* Date: 2020-4-9 15:33:06
|
|
4
|
-
* Last: 2020-4-12 11:12:03, 2022-09-10 12:43:23, 2022-12-25 15:12:57, 2023-9-26 14:20:41
|
|
5
|
-
*/
|
|
6
|
-
import * as hc from '@litert/http-client';
|
|
7
|
-
import * as nStream from 'stream';
|
|
8
|
-
import * as types from '~/types';
|
|
9
|
-
|
|
10
|
-
export class Response {
|
|
11
|
-
|
|
12
|
-
/** --- httpClient 请求对象 --- */
|
|
13
|
-
private readonly _req: hc.IResponse | null = null;
|
|
14
|
-
|
|
15
|
-
/** --- 返回的 headers --- */
|
|
16
|
-
public headers: types.THttpHeaders | null = null;
|
|
17
|
-
|
|
18
|
-
public error: Error | null = null;
|
|
19
|
-
|
|
20
|
-
/** --- 用户自定义的 content 内容 --- */
|
|
21
|
-
private _content: Buffer | null = null;
|
|
22
|
-
|
|
23
|
-
public constructor(req: hc.IResponse | null) {
|
|
24
|
-
this._req = req;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* --- 读取所有内容到内存 ---
|
|
29
|
-
*/
|
|
30
|
-
public async getContent(): Promise<Buffer | null> {
|
|
31
|
-
if (this._content) {
|
|
32
|
-
return this._content;
|
|
33
|
-
}
|
|
34
|
-
return this._req ? this._req.getBuffer() : null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* --- 用户自定义的 content 内容 ---
|
|
39
|
-
* @param v 内容值
|
|
40
|
-
*/
|
|
41
|
-
public setContent(v: string | Buffer): void {
|
|
42
|
-
this._content = typeof v === 'string' ? Buffer.from(v) : v;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* --- 获取响应读取流对象 ---
|
|
47
|
-
*/
|
|
48
|
-
public getStream(): nStream.Readable {
|
|
49
|
-
return this._req!.getStream();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* --- 获取原生响应读取流对象 ---
|
|
54
|
-
*/
|
|
55
|
-
public getRawStream(): nStream.Readable {
|
|
56
|
-
return this._req!.getRawStream();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
}
|