@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/ssh.ts DELETED
@@ -1,191 +0,0 @@
1
- /**
2
- * Project: Kebab, User: JianSuoQiYue
3
- * Date: 2019-6-8 21:34:35
4
- * Last: 2020-04-06 21:22:46, 2022-09-12 00:19:05, 2024-3-4 14:46:11
5
- */
6
-
7
- // --- 第三方 ---
8
- import * as ssh2 from 'ssh2';
9
- // --- 自己 ---
10
- import * as shell from './ssh/shell';
11
- import * as sftp from './ssh/sftp';
12
-
13
- interface IExtOptions {
14
- 'mproxy'?: {
15
- 'host': string;
16
- 'port': number;
17
- 'username': string;
18
- 'password': string;
19
- };
20
- }
21
-
22
- /** 主连接对象 */
23
- export class Connection {
24
-
25
- /** --- SSH 对象 --- */
26
- private readonly _client: ssh2.Client;
27
-
28
- /** --- 中转服务器 --- */
29
- private _mclient?: ssh2.Client;
30
-
31
- public constructor() {
32
- this._client = new ssh2.Client();
33
- }
34
-
35
- /**
36
- * --- 发起连接 ---
37
- * @param opt 选项
38
- */
39
- public connect(opt: ssh2.ConnectConfig & IExtOptions): Promise<boolean> {
40
- return new Promise((resolve) => {
41
- if (!opt.mproxy) {
42
- this._client.on('error', function() {
43
- resolve(false);
44
- }).on('ready', () => {
45
- resolve(true);
46
- }).connect(opt);
47
- return;
48
- }
49
- this._mclient = new ssh2.Client();
50
- const old = {
51
- 'host': opt.host,
52
- 'port': opt.port,
53
- 'username': opt.username,
54
- 'password': opt.password,
55
- 'privateKey': opt.privateKey
56
- };
57
- opt.host = opt.mproxy.host;
58
- opt.port = opt.mproxy.port;
59
- opt.username = opt.mproxy.username;
60
- opt.password = opt.mproxy.password;
61
- if (opt.privateKey) {
62
- delete opt.privateKey;
63
- }
64
- this._mclient.on('error', function() {
65
- resolve(false);
66
- }).on('ready', () => {
67
- if (!old.host || !old.port || !this._mclient) {
68
- resolve(false);
69
- return;
70
- }
71
- this._mclient.forwardOut('0.0.0.0', 12345, old.host, old.port, (err, stream) => {
72
- if (err) {
73
- this._mclient?.end();
74
- resolve(false);
75
- return;
76
- }
77
- this._client.on('error', () => {
78
- this._mclient?.end();
79
- resolve(false);
80
- }).on('ready', () => {
81
- resolve(true);
82
- }).on('close', () => {
83
- this._mclient?.end();
84
- }).connect({
85
- 'sock': stream,
86
- 'username': old.username,
87
- 'password': old.password,
88
- 'privateKey': old.privateKey
89
- });
90
- });
91
- }).connect(opt);
92
- });
93
- }
94
-
95
- /**
96
- * --- 断开此连接 socket ---
97
- */
98
- public disconnect(): void {
99
- this._client.end();
100
- }
101
-
102
- /**
103
- * --- 执行一个命令并获取返回值,请不要在此执行无尽命令,否则获取不到返回值 ---
104
- * @param command 命令内容
105
- */
106
- public exec(command: string): Promise<Buffer | false> {
107
- return new Promise((resolve) => {
108
- this._client.exec(command, function(err?: Error, channel?: ssh2.ClientChannel): void {
109
- if (err ?? !channel) {
110
- resolve(false);
111
- return;
112
- }
113
- let data = Buffer.from('');
114
- channel.on('close', () => {
115
- resolve(data);
116
- }).on('data', function(chunk: Buffer) {
117
- data = Buffer.concat([data, chunk], data.length + chunk.length);
118
- }).stderr.on('data', function(chunk: Buffer) {
119
- data = Buffer.concat([data, chunk], data.length + chunk.length);
120
- });
121
- });
122
- });
123
- }
124
-
125
- /**
126
- * --- 获取 Shell 执行对象 ---
127
- */
128
- public getShell(): Promise<shell.Connection | null> {
129
- return new Promise((resolve) => {
130
- this._client.shell(function(err, channel) {
131
- if (err ?? !channel) {
132
- resolve(null);
133
- return;
134
- }
135
- resolve(new shell.Connection(channel));
136
- });
137
- });
138
- }
139
-
140
- /**
141
- * --- 获取 Sftp 执行对象 ---
142
- */
143
- public getSftp(): Promise<sftp.Connection | null> {
144
- return new Promise((resolve) => {
145
- this._client.sftp((err, ssftp) => {
146
- if (err ?? !ssftp) {
147
- resolve(null);
148
- return;
149
- }
150
- (async () => {
151
- const pwdb = await this.exec('pwd');
152
- let pwd = '/';
153
- if (pwdb) {
154
- pwd = pwdb.toString().trim();
155
- if (!pwd.endsWith('/')) {
156
- pwd = pwd + '/';
157
- }
158
- }
159
- resolve(new sftp.Connection(ssftp, pwd));
160
- })().catch(function() {
161
- resolve(null);
162
- });
163
- });
164
- });
165
- }
166
-
167
- /**
168
- * --- 直接获取原生 shell stream 对象 ---
169
- */
170
- public getStream(): Promise<ssh2.ClientChannel | null> {
171
- return new Promise((resolve) => {
172
- this._client.shell(function(err, stream) {
173
- if (err) {
174
- resolve(null);
175
- }
176
- resolve(stream);
177
- });
178
- });
179
- }
180
-
181
- }
182
-
183
- /**
184
- * --- 创建一个 SSH 连接 ---
185
- * @param opt 选项
186
- */
187
- export async function get(opt: ssh2.ConnectConfig & IExtOptions): Promise<Connection | null> {
188
- const conn = new Connection();
189
- const rtn = await conn.connect(opt);
190
- return rtn ? conn : null;
191
- }