xshell 1.0.64 → 1.0.65
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/package.json +1 -1
- package/server.d.ts +4 -1
- package/server.js +35 -32
package/package.json
CHANGED
package/server.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
/// <reference types="node" resolution-mode="require"/>
|
|
4
|
-
|
|
4
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
5
|
+
import { type Server as HttpServer, type IncomingHttpHeaders, type IncomingMessage } from 'http';
|
|
5
6
|
import { type Http2SecureServer, type IncomingHttpHeaders as IncomingHttp2Headers } from 'http2';
|
|
7
|
+
import { type Duplex } from 'stream';
|
|
6
8
|
import type { WebSocketServer } from 'ws';
|
|
7
9
|
import type { default as Koa, Context, Next } from 'koa';
|
|
8
10
|
declare module 'koa' {
|
|
@@ -70,6 +72,7 @@ export declare class Server {
|
|
|
70
72
|
on_error(error: Error & {
|
|
71
73
|
code?: string;
|
|
72
74
|
}, ctx?: Context): void;
|
|
75
|
+
on_upgrade(request: IncomingMessage, socket: Duplex, head: Buffer): void;
|
|
73
76
|
/** 可被子类重写添加额外的中间件,在 start 时被调用 */
|
|
74
77
|
init_app(app: Koa): Promise<void>;
|
|
75
78
|
entry(ctx: Context, next: Next): Promise<void>;
|
package/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createServer as http_create_server } from 'http';
|
|
1
|
+
import { createServer as http_create_server, } from 'http';
|
|
2
2
|
import { createSecureServer as http2_create_server } from 'http2';
|
|
3
3
|
import { createSecureContext } from 'tls';
|
|
4
4
|
import zlib from 'zlib';
|
|
@@ -128,37 +128,9 @@ export class Server {
|
|
|
128
128
|
this.remote.handle(new Uint8Array(data), ws);
|
|
129
129
|
});
|
|
130
130
|
});
|
|
131
|
-
this.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const ip = request.socket.remoteAddress.replace(/^::ffff:/, '');
|
|
135
|
-
console.log(
|
|
136
|
-
// 时间
|
|
137
|
-
`${new Date().to_time_str()} ` +
|
|
138
|
-
// ip(位置)
|
|
139
|
-
(ip || '').limit(60) + ' ' +
|
|
140
|
-
// ua
|
|
141
|
-
this.format_ua(headers).limit(56) + ' ' +
|
|
142
|
-
// https/2.0
|
|
143
|
-
`${this.colors ? 'websocket'.limit(10).magenta : 'websocket'.limit(10)} ` +
|
|
144
|
-
// method
|
|
145
|
-
''.limit(6) + ' ' +
|
|
146
|
-
// host
|
|
147
|
-
`${host.limit(24)} ` +
|
|
148
|
-
// path
|
|
149
|
-
(this.colors ? url.yellow : url));
|
|
150
|
-
switch (url) {
|
|
151
|
-
case '/':
|
|
152
|
-
this.websocket_server.handleUpgrade(request, socket, head, ws => {
|
|
153
|
-
ws.binaryType = 'arraybuffer';
|
|
154
|
-
this.websocket_server.emit('connection', ws, request);
|
|
155
|
-
});
|
|
156
|
-
return;
|
|
157
|
-
default:
|
|
158
|
-
console.log(`${' '.repeat(13)} connect 404: ${url}`.red);
|
|
159
|
-
socket.destroy();
|
|
160
|
-
}
|
|
161
|
-
});
|
|
131
|
+
const on_upgrade = this.on_upgrade.bind(this);
|
|
132
|
+
this.http_server.on('upgrade', on_upgrade);
|
|
133
|
+
this.http2_server?.on('upgrade', on_upgrade);
|
|
162
134
|
// 将输出到 stdout, stderr 的内容 copy 一份通过 websocket 发到 web shell
|
|
163
135
|
if (this.stdio_subscribable) {
|
|
164
136
|
this.remote.funcs = {
|
|
@@ -246,6 +218,37 @@ export class Server {
|
|
|
246
218
|
console.log(ctx);
|
|
247
219
|
}
|
|
248
220
|
}
|
|
221
|
+
on_upgrade(request, socket, head) {
|
|
222
|
+
// url 只有路径部分
|
|
223
|
+
const { url, headers, headers: { host = '' }, } = request;
|
|
224
|
+
const ip = request.socket.remoteAddress.replace(/^::ffff:/, '');
|
|
225
|
+
console.log(
|
|
226
|
+
// 时间
|
|
227
|
+
`${new Date().to_time_str()} ` +
|
|
228
|
+
// ip(位置)
|
|
229
|
+
(ip || '').limit(60) + ' ' +
|
|
230
|
+
// ua
|
|
231
|
+
this.format_ua(headers).limit(56) + ' ' +
|
|
232
|
+
// https/2.0
|
|
233
|
+
`${this.colors ? 'websocket'.limit(10).magenta : 'websocket'.limit(10)} ` +
|
|
234
|
+
// method
|
|
235
|
+
''.limit(6) + ' ' +
|
|
236
|
+
// host
|
|
237
|
+
`${host.limit(24)} ` +
|
|
238
|
+
// path
|
|
239
|
+
(this.colors ? url.yellow : url));
|
|
240
|
+
switch (url) {
|
|
241
|
+
case '/':
|
|
242
|
+
this.websocket_server.handleUpgrade(request, socket, head, ws => {
|
|
243
|
+
ws.binaryType = 'arraybuffer';
|
|
244
|
+
this.websocket_server.emit('connection', ws, request);
|
|
245
|
+
});
|
|
246
|
+
return;
|
|
247
|
+
default:
|
|
248
|
+
console.log(`${' '.repeat(13)} connect 404: ${url}`.red);
|
|
249
|
+
socket.destroy();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
249
252
|
/** 可被子类重写添加额外的中间件,在 start 时被调用 */
|
|
250
253
|
async init_app(app) {
|
|
251
254
|
}
|