@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.
- package/.VSCodeCounter/2025-02-14_14-46-44/details.md +82 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/diff-details.md +15 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.csv +2 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.md +19 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.txt +22 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/results.csv +69 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/results.json +1 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/results.md +48 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/results.txt +118 -0
- package/.vscode/tasks.json +15 -0
- package/LICENSE +201 -0
- package/README.md +201 -0
- package/bin/kebab.js +2 -0
- package/eslint.config.js +22 -0
- package/index.js +19 -0
- package/index.ts +33 -0
- package/lib/buffer.js +108 -0
- package/lib/buffer.ts +152 -0
- package/lib/captcha/zcool-addict-italic.ttf +0 -0
- package/lib/captcha.js +71 -0
- package/lib/captcha.ts +63 -0
- package/lib/consistent.js +171 -0
- package/lib/consistent.ts +219 -0
- package/lib/core.js +663 -0
- package/lib/core.ts +880 -0
- package/lib/crypto.js +256 -0
- package/lib/crypto.ts +384 -0
- package/lib/db.js +521 -0
- package/lib/db.ts +719 -0
- package/lib/dns.js +321 -0
- package/lib/dns.ts +405 -0
- package/lib/fs.js +405 -0
- package/lib/fs.ts +527 -0
- package/lib/jwt.js +223 -0
- package/lib/jwt.ts +276 -0
- package/lib/kv.js +1004 -0
- package/lib/kv.ts +1489 -0
- package/lib/lan.js +99 -0
- package/lib/lan.ts +87 -0
- package/lib/net/cacert.pem +3480 -0
- package/lib/net/formdata.js +137 -0
- package/lib/net/formdata.ts +166 -0
- package/lib/net/request.js +102 -0
- package/lib/net/request.ts +150 -0
- package/lib/net/response.js +28 -0
- package/lib/net/response.ts +59 -0
- package/lib/net.js +462 -0
- package/lib/net.ts +662 -0
- package/lib/s3.js +180 -0
- package/lib/s3.ts +235 -0
- package/lib/scan.js +276 -0
- package/lib/scan.ts +364 -0
- package/lib/session.js +177 -0
- package/lib/session.ts +230 -0
- package/lib/sql.js +818 -0
- package/lib/sql.ts +1151 -0
- package/lib/ssh/sftp.js +373 -0
- package/lib/ssh/sftp.ts +508 -0
- package/lib/ssh/shell.js +109 -0
- package/lib/ssh/shell.ts +123 -0
- package/lib/ssh.js +171 -0
- package/lib/ssh.ts +191 -0
- package/lib/text/tld.json +1 -0
- package/lib/text.js +452 -0
- package/lib/text.ts +607 -0
- package/lib/time.js +216 -0
- package/lib/time.ts +254 -0
- package/lib/ws.js +373 -0
- package/lib/ws.ts +523 -0
- package/lib/zip.js +381 -0
- package/lib/zip.ts +447 -0
- package/lib/zlib.js +289 -0
- package/lib/zlib.ts +350 -0
- package/main.js +51 -0
- package/main.ts +27 -0
- package/package.json +37 -0
- package/sys/child.js +585 -0
- package/sys/child.ts +678 -0
- package/sys/cmd.js +226 -0
- package/sys/cmd.ts +225 -0
- package/sys/ctr.js +608 -0
- package/sys/ctr.ts +904 -0
- package/sys/master.js +314 -0
- package/sys/master.ts +355 -0
- package/sys/mod.js +1273 -0
- package/sys/mod.ts +1871 -0
- package/sys/route.js +922 -0
- package/sys/route.ts +1113 -0
- package/types/index.d.ts +283 -0
- package/www/example/ctr/main.js +42 -0
- package/www/example/ctr/main.ts +9 -0
- package/www/example/ctr/middle.js +57 -0
- package/www/example/ctr/middle.ts +26 -0
- package/www/example/ctr/test.js +2818 -0
- package/www/example/ctr/test.ts +3218 -0
- package/www/example/data/locale/en.test.json +8 -0
- package/www/example/data/locale/index.html +1 -0
- package/www/example/data/locale/ja.test.json +8 -0
- package/www/example/data/locale/sc.test.json +8 -0
- package/www/example/data/locale/tc.test.json +8 -0
- package/www/example/data/test.zip +0 -0
- package/www/example/kebab.json +24 -0
- package/www/example/mod/test.js +49 -0
- package/www/example/mod/test.ts +47 -0
- package/www/example/mod/testdata.js +11 -0
- package/www/example/mod/testdata.ts +30 -0
- package/www/example/route.json +6 -0
- package/www/example/view/test.ejs +11 -0
- package/www/example/ws/mproxy.js +49 -0
- package/www/example/ws/mproxy.ts +16 -0
- package/www/example/ws/rproxy.js +47 -0
- package/www/example/ws/rproxy.ts +14 -0
- package/www/example/ws/test.js +68 -0
- package/www/example/ws/test.ts +36 -0
package/lib/ws.js
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Socket = exports.EOpcode = exports.EFrameReceiveMode = void 0;
|
|
37
|
+
exports.connect = connect;
|
|
38
|
+
exports.createServer = createServer;
|
|
39
|
+
exports.mproxy = mproxy;
|
|
40
|
+
exports.rproxy = rproxy;
|
|
41
|
+
const liws = __importStar(require("@litert/websocket"));
|
|
42
|
+
const lText = __importStar(require("~/lib/text"));
|
|
43
|
+
const lNet = __importStar(require("~/lib/net"));
|
|
44
|
+
var EFrameReceiveMode;
|
|
45
|
+
(function (EFrameReceiveMode) {
|
|
46
|
+
EFrameReceiveMode[EFrameReceiveMode["STANDARD"] = 0] = "STANDARD";
|
|
47
|
+
EFrameReceiveMode[EFrameReceiveMode["LITE"] = 1] = "LITE";
|
|
48
|
+
EFrameReceiveMode[EFrameReceiveMode["SIMPLE"] = 2] = "SIMPLE";
|
|
49
|
+
})(EFrameReceiveMode || (exports.EFrameReceiveMode = EFrameReceiveMode = {}));
|
|
50
|
+
var EOpcode;
|
|
51
|
+
(function (EOpcode) {
|
|
52
|
+
EOpcode[EOpcode["CONTINUATION"] = 0] = "CONTINUATION";
|
|
53
|
+
EOpcode[EOpcode["TEXT"] = 1] = "TEXT";
|
|
54
|
+
EOpcode[EOpcode["BINARY"] = 2] = "BINARY";
|
|
55
|
+
EOpcode[EOpcode["CLOSE"] = 8] = "CLOSE";
|
|
56
|
+
EOpcode[EOpcode["PING"] = 9] = "PING";
|
|
57
|
+
EOpcode[EOpcode["PONG"] = 10] = "PONG";
|
|
58
|
+
})(EOpcode || (exports.EOpcode = EOpcode = {}));
|
|
59
|
+
const liwsServer = liws.createServer();
|
|
60
|
+
class Socket {
|
|
61
|
+
constructor(request, socket, options = {}) {
|
|
62
|
+
this._waitMsg = [];
|
|
63
|
+
this._error = null;
|
|
64
|
+
this._close = false;
|
|
65
|
+
this._on = {
|
|
66
|
+
message: (msg) => {
|
|
67
|
+
this._waitMsg.push(msg);
|
|
68
|
+
},
|
|
69
|
+
drain: () => {
|
|
70
|
+
},
|
|
71
|
+
error: (e) => {
|
|
72
|
+
this._error = e;
|
|
73
|
+
},
|
|
74
|
+
close: () => {
|
|
75
|
+
this._close = true;
|
|
76
|
+
},
|
|
77
|
+
end: () => {
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
if (!request || !socket) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this._ws = liwsServer.accept({
|
|
84
|
+
'request': request,
|
|
85
|
+
'socket': socket,
|
|
86
|
+
'headers': options.headers,
|
|
87
|
+
'timeout': options.timeout
|
|
88
|
+
});
|
|
89
|
+
this._bindEvent();
|
|
90
|
+
}
|
|
91
|
+
async connect(u, opt = {}) {
|
|
92
|
+
const uri = lText.parseUrl(u);
|
|
93
|
+
if (!uri.hostname) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const puri = opt.mproxy ? lText.parseUrl(opt.mproxy.url) : null;
|
|
97
|
+
const timeout = opt.timeout ?? 10;
|
|
98
|
+
const hosts = opt.hosts ?? {};
|
|
99
|
+
const local = opt.local;
|
|
100
|
+
const mode = opt.mode ?? EFrameReceiveMode.SIMPLE;
|
|
101
|
+
const masking = opt.masking ?? true;
|
|
102
|
+
const headers = {};
|
|
103
|
+
if (opt.headers) {
|
|
104
|
+
for (const key in opt.headers) {
|
|
105
|
+
headers[key.toLowerCase()] = opt.headers[key];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
headers['user-agent'] ??= 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36';
|
|
109
|
+
if (opt.cookie) {
|
|
110
|
+
headers['cookie'] = lNet.buildCookieQuery(opt.cookie, uri);
|
|
111
|
+
}
|
|
112
|
+
const ca = puri ?
|
|
113
|
+
puri.protocol === 'wss:' ? await lNet.getCa() : null :
|
|
114
|
+
uri.protocol === 'wss:' ? await lNet.getCa() : null;
|
|
115
|
+
if (!ca && hosts[uri.hostname]) {
|
|
116
|
+
headers['host'] = uri.hostname + (uri.port ? ':' + uri.port : '');
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const host = puri?.hostname ?? uri.hostname ?? '';
|
|
120
|
+
const port = (puri ? puri.port : uri.port) ?? 443;
|
|
121
|
+
const path = puri ? puri.path + (puri.path?.includes('?') ? '&' : '?') + lText.queryStringify({
|
|
122
|
+
'url': u,
|
|
123
|
+
'auth': opt.mproxy?.auth ?? ''
|
|
124
|
+
}) : uri.path;
|
|
125
|
+
const cli = ca ?
|
|
126
|
+
await liws.wssConnect({
|
|
127
|
+
'hostname': hosts[host] ?? host,
|
|
128
|
+
'port': port,
|
|
129
|
+
'path': path,
|
|
130
|
+
'servername': host,
|
|
131
|
+
'headers': headers,
|
|
132
|
+
'connectTimeout': timeout * 1000,
|
|
133
|
+
'frameReceiveMode': mode,
|
|
134
|
+
'localAddress': local,
|
|
135
|
+
'ca': ca
|
|
136
|
+
}) :
|
|
137
|
+
await liws.wsConnect({
|
|
138
|
+
'hostname': hosts[host] ?? host,
|
|
139
|
+
'port': port,
|
|
140
|
+
'path': path,
|
|
141
|
+
'headers': headers,
|
|
142
|
+
'connectTimeout': timeout * 1000,
|
|
143
|
+
'frameReceiveMode': mode,
|
|
144
|
+
'localAddress': local
|
|
145
|
+
});
|
|
146
|
+
cli.setMasking(masking);
|
|
147
|
+
this._ws = cli;
|
|
148
|
+
this._bindEvent();
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
_bindEvent() {
|
|
156
|
+
this._ws.on('message', (msg) => {
|
|
157
|
+
(async () => {
|
|
158
|
+
if (msg.opcode === EOpcode.CLOSE) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
let data = '';
|
|
162
|
+
if ('data' in msg) {
|
|
163
|
+
data = Buffer.concat(msg.data);
|
|
164
|
+
if (msg.opcode === EOpcode.TEXT) {
|
|
165
|
+
data = data.toString();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
data = await (msg.opcode === EOpcode.TEXT ? msg.toString() : msg.toBuffer());
|
|
170
|
+
}
|
|
171
|
+
this._on.message({
|
|
172
|
+
'opcode': msg.opcode,
|
|
173
|
+
'data': data
|
|
174
|
+
});
|
|
175
|
+
})().catch(() => {
|
|
176
|
+
});
|
|
177
|
+
}).on('drain', () => {
|
|
178
|
+
this._on.drain();
|
|
179
|
+
}).on('error', (e) => {
|
|
180
|
+
this._on.error(e);
|
|
181
|
+
}).on('end', () => {
|
|
182
|
+
this._on.end();
|
|
183
|
+
}).on('close', () => {
|
|
184
|
+
this._on.close();
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
on(event, cb) {
|
|
188
|
+
this._on[event] = cb;
|
|
189
|
+
switch (event) {
|
|
190
|
+
case 'message': {
|
|
191
|
+
for (const item of this._waitMsg) {
|
|
192
|
+
cb(item);
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case 'error': {
|
|
197
|
+
if (!this._error) {
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
cb(this._error);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
case 'end': {
|
|
204
|
+
cb();
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
default: {
|
|
208
|
+
if (!this._close) {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
cb();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
end() {
|
|
217
|
+
this._ws.end();
|
|
218
|
+
}
|
|
219
|
+
destroy() {
|
|
220
|
+
this._ws.destroy();
|
|
221
|
+
}
|
|
222
|
+
writeText(data) {
|
|
223
|
+
if (!this._ws.writable) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
return this._ws.writeText(data);
|
|
227
|
+
}
|
|
228
|
+
writeResult(data) {
|
|
229
|
+
if (!this._ws.writable) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
return this._ws.writeText(lText.stringifyResult(data));
|
|
233
|
+
}
|
|
234
|
+
writeBinary(data) {
|
|
235
|
+
if (!this._ws.writable) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
return this._ws.writeBinary(data);
|
|
239
|
+
}
|
|
240
|
+
get writable() {
|
|
241
|
+
return this._ws.writable;
|
|
242
|
+
}
|
|
243
|
+
get ended() {
|
|
244
|
+
return this._ws.ended;
|
|
245
|
+
}
|
|
246
|
+
get finished() {
|
|
247
|
+
return this._ws.finished;
|
|
248
|
+
}
|
|
249
|
+
get isServer() {
|
|
250
|
+
return this._ws.isServer;
|
|
251
|
+
}
|
|
252
|
+
ping(data) {
|
|
253
|
+
try {
|
|
254
|
+
this._ws.ping(data);
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
pong(data) {
|
|
262
|
+
try {
|
|
263
|
+
this._ws.pong(data);
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
exports.Socket = Socket;
|
|
272
|
+
function connect(u, opt = {}) {
|
|
273
|
+
const s = new Socket();
|
|
274
|
+
return s.connect(u, opt);
|
|
275
|
+
}
|
|
276
|
+
function createServer(request, socket, options = {}) {
|
|
277
|
+
return new Socket(request, socket, options);
|
|
278
|
+
}
|
|
279
|
+
function bindPipe(s1, s2) {
|
|
280
|
+
return new Promise((resolve) => {
|
|
281
|
+
s1.on('message', (msg) => {
|
|
282
|
+
switch (msg.opcode) {
|
|
283
|
+
case EOpcode.TEXT:
|
|
284
|
+
case EOpcode.BINARY: {
|
|
285
|
+
if (typeof msg.data === 'string') {
|
|
286
|
+
s2.writeText(msg.data);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
s2.writeBinary(msg.data);
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
case EOpcode.CLOSE: {
|
|
293
|
+
s2.end();
|
|
294
|
+
resolve();
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
case EOpcode.PING: {
|
|
298
|
+
s2.ping(msg.data);
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
case EOpcode.PONG: {
|
|
302
|
+
s2.pong(msg.data);
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
default: {
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}).on('close', () => {
|
|
309
|
+
resolve();
|
|
310
|
+
});
|
|
311
|
+
s2.on('message', (msg) => {
|
|
312
|
+
switch (msg.opcode) {
|
|
313
|
+
case EOpcode.TEXT:
|
|
314
|
+
case EOpcode.BINARY: {
|
|
315
|
+
if (typeof msg.data === 'string') {
|
|
316
|
+
s1.writeText(msg.data);
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
s1.writeBinary(msg.data);
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
case EOpcode.CLOSE: {
|
|
323
|
+
s1.end();
|
|
324
|
+
resolve();
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
case EOpcode.PING: {
|
|
328
|
+
s1.ping(msg.data);
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
case EOpcode.PONG: {
|
|
332
|
+
s1.pong(msg.data);
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
default: {
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}).on('close', () => {
|
|
339
|
+
resolve();
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
async function mproxy(ctr, auth, opt = {}) {
|
|
344
|
+
const req = ctr.getPrototype('_req');
|
|
345
|
+
const socket = ctr.getPrototype('_socket');
|
|
346
|
+
const get = ctr.getPrototype('_get');
|
|
347
|
+
if (get['auth'] !== auth) {
|
|
348
|
+
return 0;
|
|
349
|
+
}
|
|
350
|
+
if (!get['url']) {
|
|
351
|
+
return -1;
|
|
352
|
+
}
|
|
353
|
+
opt.headers ??= {};
|
|
354
|
+
Object.assign(opt.headers, lNet.filterProxyHeaders(req.headers));
|
|
355
|
+
const rsocket = await connect(get['url'], opt);
|
|
356
|
+
if (!rsocket) {
|
|
357
|
+
return -2;
|
|
358
|
+
}
|
|
359
|
+
await bindPipe(socket, rsocket);
|
|
360
|
+
return 1;
|
|
361
|
+
}
|
|
362
|
+
async function rproxy(ctr, url, opt = {}) {
|
|
363
|
+
const req = ctr.getPrototype('_req');
|
|
364
|
+
const socket = ctr.getPrototype('_socket');
|
|
365
|
+
opt.headers ??= {};
|
|
366
|
+
Object.assign(opt.headers, lNet.filterProxyHeaders(req.headers));
|
|
367
|
+
const rsocket = await connect(url, opt);
|
|
368
|
+
if (!rsocket) {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
await bindPipe(socket, rsocket);
|
|
372
|
+
return true;
|
|
373
|
+
}
|