bdy 1.10.13-dev → 1.10.14-beta
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/distTs/package.json
CHANGED
|
@@ -635,7 +635,7 @@ class OutputInteractiveTunnel {
|
|
|
635
635
|
attr: {
|
|
636
636
|
color: COLOR_WHITE,
|
|
637
637
|
},
|
|
638
|
-
}, fillString(format_1.default.identify(this.tunnel.identify
|
|
638
|
+
}, fillString(format_1.default.identify(this.tunnel.identify?.type), ROW_LENGTH - COLUMN_LENGTH));
|
|
639
639
|
this.sprites.identify.draw({
|
|
640
640
|
dst: this.viewPort,
|
|
641
641
|
y,
|
package/distTs/src/tunnel.js
CHANGED
|
@@ -4,19 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const basic_auth_1 = __importDefault(require("basic-auth"));
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const latency_1 = __importDefault(require("./tunnel/latency"));
|
|
9
|
+
const client_1 = __importDefault(require("./ssh/client"));
|
|
10
10
|
const events_1 = __importDefault(require("events"));
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
11
|
+
const tcp_1 = __importDefault(require("./tunnel/tcp"));
|
|
12
|
+
const tls_1 = __importDefault(require("./server/tls"));
|
|
13
|
+
const ssh_1 = __importDefault(require("./server/ssh"));
|
|
14
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
15
|
+
const identification_1 = __importDefault(require("./tunnel/identification"));
|
|
16
|
+
const http_1 = __importDefault(require("./tunnel/http"));
|
|
17
|
+
const http2_1 = __importDefault(require("./server/http2"));
|
|
18
|
+
const http1_1 = __importDefault(require("./server/http1"));
|
|
19
|
+
const log_1 = __importDefault(require("./tunnel/http/log"));
|
|
20
20
|
const format_1 = __importDefault(require("./format"));
|
|
21
21
|
const texts_js_1 = require("./texts.js");
|
|
22
22
|
const dns_js_1 = __importDefault(require("./tunnel/dns.js"));
|
|
@@ -24,7 +24,7 @@ class Tunnel extends events_1.default {
|
|
|
24
24
|
constructor({ agent, id, type, target, region, timeout, domain, customDomain, name, subdomain, whitelist, tlsSettings, httpSettings, sshSettings, sshHostKey, }) {
|
|
25
25
|
super();
|
|
26
26
|
if (!sshHostKey)
|
|
27
|
-
sshHostKey = (0,
|
|
27
|
+
sshHostKey = (0, utils_1.createSshHostKey)();
|
|
28
28
|
this.agent = agent;
|
|
29
29
|
this.id = id;
|
|
30
30
|
this.sshHostKey = sshHostKey;
|
|
@@ -52,7 +52,7 @@ class Tunnel extends events_1.default {
|
|
|
52
52
|
this.customDomain = !!customDomain;
|
|
53
53
|
this.subdomain = subdomain;
|
|
54
54
|
this.name = name;
|
|
55
|
-
this.timeout = timeout ||
|
|
55
|
+
this.timeout = timeout || utils_1.DEFAULT_TIMEOUT;
|
|
56
56
|
this.useragents = [];
|
|
57
57
|
this.headers = [];
|
|
58
58
|
this.responseHeaders = [];
|
|
@@ -91,13 +91,13 @@ class Tunnel extends events_1.default {
|
|
|
91
91
|
this.targetHost = 'localhost';
|
|
92
92
|
this.targetPort = 80;
|
|
93
93
|
this.targetAuth = null;
|
|
94
|
-
if (this.type ===
|
|
95
|
-
let m = this.target.match(
|
|
94
|
+
if (this.type === utils_1.TUNNEL_HTTP) {
|
|
95
|
+
let m = this.target.match(utils_1.TARGET_ONLY_PORT_REGEX);
|
|
96
96
|
if (m) {
|
|
97
97
|
this.targetPort = parseInt(m[0], 10);
|
|
98
98
|
}
|
|
99
99
|
else {
|
|
100
|
-
m = this.target.match(
|
|
100
|
+
m = this.target.match(utils_1.TARGET_HTTP_REGEX);
|
|
101
101
|
if (m) {
|
|
102
102
|
if (m[2])
|
|
103
103
|
this.targetProto = m[2];
|
|
@@ -112,13 +112,13 @@ class Tunnel extends events_1.default {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
else if (this.type ===
|
|
115
|
+
else if (this.type === utils_1.TUNNEL_SSH) {
|
|
116
116
|
this.targetHost = 'localhost';
|
|
117
117
|
this.targetProto = 'ssh://';
|
|
118
118
|
this.targetPort = 22;
|
|
119
119
|
}
|
|
120
120
|
else {
|
|
121
|
-
const m = this.target.match(
|
|
121
|
+
const m = this.target.match(utils_1.TARGET_TCP_TLS_REGEX);
|
|
122
122
|
if (m) {
|
|
123
123
|
this.targetPort = parseInt(m[3], 10);
|
|
124
124
|
if (m[2])
|
|
@@ -127,7 +127,7 @@ class Tunnel extends events_1.default {
|
|
|
127
127
|
}
|
|
128
128
|
this.connections = {};
|
|
129
129
|
this.totalConnections = 0;
|
|
130
|
-
this.status =
|
|
130
|
+
this.status = utils_1.TUNNEL_CLOSED;
|
|
131
131
|
this.dns = null;
|
|
132
132
|
this.regionLatency = null;
|
|
133
133
|
this.targetLatency = null;
|
|
@@ -264,31 +264,31 @@ class Tunnel extends events_1.default {
|
|
|
264
264
|
}
|
|
265
265
|
async sshConnected() {
|
|
266
266
|
try {
|
|
267
|
-
|
|
267
|
+
logger_1.default.debug((0, texts_js_1.LOG_TUNNEL_CONNECTED)(this.id, this.sshForwardPort));
|
|
268
268
|
await this.ssh.forwardIn(this.sshForwardPort);
|
|
269
|
-
this.status =
|
|
269
|
+
this.status = utils_1.TUNNEL_OPEN;
|
|
270
270
|
}
|
|
271
271
|
catch (err) {
|
|
272
272
|
// reconnect
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
logger_1.default.debug((0, texts_js_1.LOG_TUNNEL_FAILED)(this.id));
|
|
274
|
+
logger_1.default.debug(err);
|
|
275
275
|
this.ssh.close();
|
|
276
276
|
return;
|
|
277
277
|
}
|
|
278
|
-
this.emit(
|
|
278
|
+
this.emit(utils_1.TUNNEL_EVENT_OPEN, this);
|
|
279
279
|
}
|
|
280
280
|
sshDisconnected() {
|
|
281
|
-
if (this.status !==
|
|
282
|
-
|
|
283
|
-
this.status =
|
|
284
|
-
this.emit(
|
|
281
|
+
if (this.status !== utils_1.TUNNEL_CLOSED) {
|
|
282
|
+
logger_1.default.debug((0, texts_js_1.LOG_TUNNEL_DISCONNECTED)(this.id));
|
|
283
|
+
this.status = utils_1.TUNNEL_CLOSED;
|
|
284
|
+
this.emit(utils_1.TUNNEL_EVENT_CLOSED, this);
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
tunnelToTarget(stream, onClose) {
|
|
288
288
|
this.totalConnections += 1;
|
|
289
|
-
const tcp = new
|
|
289
|
+
const tcp = new tcp_1.default(this.targetHost, this.targetPort, stream);
|
|
290
290
|
this.connections[tcp.id] = tcp;
|
|
291
|
-
tcp.on(
|
|
291
|
+
tcp.on(utils_1.TCP_EVENT_CLOSED, () => {
|
|
292
292
|
this.connections[tcp.id].removeAllListeners();
|
|
293
293
|
delete this.connections[tcp.id];
|
|
294
294
|
onClose();
|
|
@@ -296,23 +296,23 @@ class Tunnel extends events_1.default {
|
|
|
296
296
|
tcp.pipe();
|
|
297
297
|
}
|
|
298
298
|
httpIdentified(type) {
|
|
299
|
-
|
|
300
|
-
this.emit(
|
|
299
|
+
logger_1.default.info((0, texts_js_1.LOG_TUNNEL_IDENTIFIED)(this.id, type));
|
|
300
|
+
this.emit(utils_1.TUNNEL_EVENT_HTTP_IDENTIFIED, this, type);
|
|
301
301
|
}
|
|
302
302
|
httpConnectionOpen(s) {
|
|
303
303
|
this.totalConnections += 1;
|
|
304
304
|
this.connections[s.id] = s;
|
|
305
|
-
this.emit(
|
|
305
|
+
this.emit(utils_1.TUNNEL_EVENT_HTTP_OPEN, this);
|
|
306
306
|
}
|
|
307
307
|
httpConnectionClosed(s) {
|
|
308
308
|
delete this.connections[s.id];
|
|
309
|
-
this.emit(
|
|
309
|
+
this.emit(utils_1.TUNNEL_EVENT_HTTP_CLOSED, this);
|
|
310
310
|
}
|
|
311
311
|
httpBasicAuth(req, res) {
|
|
312
312
|
if (this.login || this.password) {
|
|
313
313
|
const user = (0, basic_auth_1.default)(req);
|
|
314
314
|
if (!user || user.name !== this.login || user.pass !== this.password) {
|
|
315
|
-
|
|
315
|
+
logger_1.default.debug(texts_js_1.LOG_TUNNEL_HTTP_WRON_AUTH);
|
|
316
316
|
this.httpEndFast(req, res, 401, 'Unauthorised', {
|
|
317
317
|
'WWW-Authenticate': 'Basic real="Buddy"',
|
|
318
318
|
});
|
|
@@ -346,7 +346,7 @@ class Tunnel extends events_1.default {
|
|
|
346
346
|
httpRateLimit(req, res) {
|
|
347
347
|
const isRateLimited = this.httpLog.isRateLimited(req);
|
|
348
348
|
if (isRateLimited) {
|
|
349
|
-
|
|
349
|
+
logger_1.default.debug(texts_js_1.LOG_TUNNEL_HTTP_RATE_LIMIT);
|
|
350
350
|
this.httpEndFast(req, res, 429, 'Too Many Requests', {
|
|
351
351
|
'Retry-After': '60',
|
|
352
352
|
});
|
|
@@ -357,7 +357,7 @@ class Tunnel extends events_1.default {
|
|
|
357
357
|
httpCircuitBreaker(req, res) {
|
|
358
358
|
const isOpen = this.httpLog.isCircuitBreakerOpen();
|
|
359
359
|
if (isOpen) {
|
|
360
|
-
|
|
360
|
+
logger_1.default.debug(texts_js_1.LOG_TUNNEL_HTTP_CIRCUIT_BREAKER_OPEN);
|
|
361
361
|
this.httpEndFast(req, res, 504, 'Service Unavailable', {});
|
|
362
362
|
return false;
|
|
363
363
|
}
|
|
@@ -368,7 +368,7 @@ class Tunnel extends events_1.default {
|
|
|
368
368
|
const ua = req.headers['user-agent'] || '';
|
|
369
369
|
for (let i = 0; i < this.useragents.length; i += 1) {
|
|
370
370
|
const str = this.useragents[i];
|
|
371
|
-
if ((0,
|
|
371
|
+
if ((0, utils_1.isStringRegExp)(str)) {
|
|
372
372
|
try {
|
|
373
373
|
const r = new RegExp(str, 'i');
|
|
374
374
|
if (r.test(ua))
|
|
@@ -382,7 +382,7 @@ class Tunnel extends events_1.default {
|
|
|
382
382
|
return true;
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
|
-
|
|
385
|
+
logger_1.default.debug(texts_js_1.LOG_TUNNEL_HTTP_WRONG_USER_AGENTS);
|
|
386
386
|
this.httpEndFast(req, res, 401, 'Unauthorised', {});
|
|
387
387
|
return false;
|
|
388
388
|
}
|
|
@@ -393,10 +393,10 @@ class Tunnel extends events_1.default {
|
|
|
393
393
|
this.identify.identify();
|
|
394
394
|
}
|
|
395
395
|
httpLogRequest(logRequest) {
|
|
396
|
-
this.emit(
|
|
396
|
+
this.emit(utils_1.TUNNEL_EVENT_HTTP_REQUEST, this, logRequest);
|
|
397
397
|
}
|
|
398
398
|
httpLogResponse(logRequest) {
|
|
399
|
-
this.emit(
|
|
399
|
+
this.emit(utils_1.TUNNEL_EVENT_HTTP_RESPONSE, this, logRequest);
|
|
400
400
|
}
|
|
401
401
|
retryHttpLogRequest(logRequest) {
|
|
402
402
|
if (logRequest.requestBody.tooLarge)
|
|
@@ -412,7 +412,7 @@ class Tunnel extends events_1.default {
|
|
|
412
412
|
this.httpCircuitBreaker(req, res);
|
|
413
413
|
if (!isAuth)
|
|
414
414
|
return;
|
|
415
|
-
const http = new
|
|
415
|
+
const http = new http_1.default({
|
|
416
416
|
req,
|
|
417
417
|
res,
|
|
418
418
|
auth: this.targetAuth,
|
|
@@ -429,29 +429,29 @@ class Tunnel extends events_1.default {
|
|
|
429
429
|
httpIdentify: this.identify.type,
|
|
430
430
|
httpLog: this.httpLog,
|
|
431
431
|
});
|
|
432
|
-
http.once(
|
|
432
|
+
http.once(utils_1.HTTP1_SOCKET_CLOSED, (socket) => this.httpConnectionClosed(socket));
|
|
433
433
|
http.pipe().then();
|
|
434
434
|
}
|
|
435
435
|
tlsSocket(tlsSocket) {
|
|
436
436
|
this.tunnelToTarget(tlsSocket, () => {
|
|
437
|
-
this.emit(
|
|
437
|
+
this.emit(utils_1.TUNNEL_EVENT_TLS_CLOSED, this);
|
|
438
438
|
});
|
|
439
|
-
this.emit(
|
|
439
|
+
this.emit(utils_1.TUNNEL_EVENT_TLS_OPEN, this);
|
|
440
440
|
}
|
|
441
441
|
canStreamTcp() {
|
|
442
|
-
if (this.type ===
|
|
442
|
+
if (this.type === utils_1.TUNNEL_TCP)
|
|
443
443
|
return true;
|
|
444
|
-
return (this.type ===
|
|
445
|
-
[
|
|
444
|
+
return (this.type === utils_1.TUNNEL_TLS &&
|
|
445
|
+
[utils_1.TLS_TERMINATE_AT_TARGET, utils_1.TLS_TERMINATE_AT_REGION].includes(this.terminate));
|
|
446
446
|
}
|
|
447
447
|
canStreamTls() {
|
|
448
|
-
return this.type ===
|
|
448
|
+
return this.type === utils_1.TUNNEL_TLS;
|
|
449
449
|
}
|
|
450
450
|
canStreamSsh() {
|
|
451
|
-
return this.type ===
|
|
451
|
+
return this.type === utils_1.TUNNEL_SSH;
|
|
452
452
|
}
|
|
453
453
|
canStreamHttp() {
|
|
454
|
-
return this.type ===
|
|
454
|
+
return this.type === utils_1.TUNNEL_HTTP;
|
|
455
455
|
}
|
|
456
456
|
safeEndStream(stream) {
|
|
457
457
|
try {
|
|
@@ -476,18 +476,18 @@ class Tunnel extends events_1.default {
|
|
|
476
476
|
this.safeEndStream(stream);
|
|
477
477
|
return;
|
|
478
478
|
}
|
|
479
|
-
|
|
479
|
+
logger_1.default.debug((0, texts_js_1.LOG_TUNNEL_TCP_STREAM)(this.id));
|
|
480
480
|
this.tunnelToTarget(stream, () => {
|
|
481
|
-
this.emit(
|
|
481
|
+
this.emit(utils_1.TUNNEL_EVENT_TCP_CLOSED, this);
|
|
482
482
|
});
|
|
483
|
-
this.emit(
|
|
483
|
+
this.emit(utils_1.TUNNEL_EVENT_TCP_OPEN, this);
|
|
484
484
|
}
|
|
485
485
|
sshStreamHttp1(stream, info, ip) {
|
|
486
486
|
if (!this.canStreamHttp()) {
|
|
487
487
|
this.safeEndStream(stream);
|
|
488
488
|
return;
|
|
489
489
|
}
|
|
490
|
-
|
|
490
|
+
logger_1.default.debug((0, texts_js_1.LOG_TUNNEL_HTTP1_STREAM)(this.id));
|
|
491
491
|
if (this.http1server) {
|
|
492
492
|
this.http1server.handleSshTunnel(stream, info, ip);
|
|
493
493
|
return;
|
|
@@ -499,7 +499,7 @@ class Tunnel extends events_1.default {
|
|
|
499
499
|
this.safeEndStream(stream);
|
|
500
500
|
return;
|
|
501
501
|
}
|
|
502
|
-
|
|
502
|
+
logger_1.default.debug((0, texts_js_1.LOG_TUNNEL_HTTP2_STREAM)(this.id));
|
|
503
503
|
if (this.http2server) {
|
|
504
504
|
this.http2server.handleSshTunnel(stream, info, ip);
|
|
505
505
|
return;
|
|
@@ -511,7 +511,7 @@ class Tunnel extends events_1.default {
|
|
|
511
511
|
this.safeEndStream(stream);
|
|
512
512
|
return;
|
|
513
513
|
}
|
|
514
|
-
|
|
514
|
+
logger_1.default.debug((0, texts_js_1.LOG_TUNNEL_SSH_STREAM)(this.id));
|
|
515
515
|
if (this.sshServer) {
|
|
516
516
|
this.sshServer.handleSshTunnel(stream);
|
|
517
517
|
return;
|
|
@@ -523,18 +523,18 @@ class Tunnel extends events_1.default {
|
|
|
523
523
|
this.safeEndStream(stream);
|
|
524
524
|
return;
|
|
525
525
|
}
|
|
526
|
-
if (this.terminate ===
|
|
527
|
-
|
|
526
|
+
if (this.terminate === utils_1.TLS_TERMINATE_AT_TARGET) {
|
|
527
|
+
logger_1.default.debug((0, texts_js_1.LOG_TUNNEL_TLS_TARGET_STREAM)(this.id));
|
|
528
528
|
this.sshStreamTcp(stream);
|
|
529
529
|
return;
|
|
530
530
|
}
|
|
531
|
-
if (this.terminate ===
|
|
532
|
-
|
|
531
|
+
if (this.terminate === utils_1.TLS_TERMINATE_AT_REGION) {
|
|
532
|
+
logger_1.default.debug((0, texts_js_1.LOG_TUNNEL_TLS_REGION_STREAM)(this.id));
|
|
533
533
|
this.sshStreamTcp(stream);
|
|
534
534
|
return;
|
|
535
535
|
}
|
|
536
536
|
if (this.tls) {
|
|
537
|
-
|
|
537
|
+
logger_1.default.debug((0, texts_js_1.LOG_TUNNEL_TLS_AGENT_STREAM)(this.id));
|
|
538
538
|
this.tls.handleSshTunnel(stream);
|
|
539
539
|
return;
|
|
540
540
|
}
|
|
@@ -544,63 +544,63 @@ class Tunnel extends events_1.default {
|
|
|
544
544
|
if (this.started)
|
|
545
545
|
return;
|
|
546
546
|
this.started = true;
|
|
547
|
-
|
|
547
|
+
logger_1.default.info((0, texts_js_1.LOG_STARTING_TUNNEL)(this.id));
|
|
548
548
|
// region latency
|
|
549
|
-
this.regionLatency = new
|
|
549
|
+
this.regionLatency = new latency_1.default(this.sshIp, this.sshPort);
|
|
550
550
|
this.regionLatency.startChecking();
|
|
551
551
|
// target latency
|
|
552
|
-
if (!this.serve && this.type !==
|
|
553
|
-
this.targetLatency = new
|
|
554
|
-
this.targetLatency.on(
|
|
552
|
+
if (!this.serve && this.type !== utils_1.TUNNEL_SSH) {
|
|
553
|
+
this.targetLatency = new latency_1.default(this.targetHost, this.targetPort);
|
|
554
|
+
this.targetLatency.on(utils_1.TUNNEL_LATENCY_EVENT_RECONNECTED, () => this.targetReconnected());
|
|
555
555
|
this.targetLatency.startChecking();
|
|
556
556
|
}
|
|
557
557
|
// dns health
|
|
558
558
|
this.dns = new dns_js_1.default(this.sshIp, this.domain, this.customDomain, this.subdomain, this.region, this.sshId);
|
|
559
559
|
this.dns.startChecking();
|
|
560
|
-
if (this.type ===
|
|
560
|
+
if (this.type === utils_1.TUNNEL_TLS && this.terminate === utils_1.TLS_TERMINATE_AT_AGENT) {
|
|
561
561
|
// tls
|
|
562
|
-
this.tls = new
|
|
563
|
-
this.tls.on(
|
|
562
|
+
this.tls = new tls_1.default(this.key, this.cert, this.ca);
|
|
563
|
+
this.tls.on(utils_1.TLS_SOCKET, (socket) => this.tlsSocket(socket));
|
|
564
564
|
}
|
|
565
|
-
else if (this.type ===
|
|
565
|
+
else if (this.type === utils_1.TUNNEL_HTTP) {
|
|
566
566
|
// http
|
|
567
|
-
this.httpLog = new
|
|
568
|
-
this.httpLog.on(
|
|
569
|
-
this.httpLog.on(
|
|
570
|
-
this.identify = new
|
|
571
|
-
this.identify.on(
|
|
567
|
+
this.httpLog = new log_1.default(this.log, this.circuitBreaker);
|
|
568
|
+
this.httpLog.on(utils_1.EVENT_TUNNEL_HTTP_NEW_REQUEST, (logRequest) => this.httpLogRequest(logRequest));
|
|
569
|
+
this.httpLog.on(utils_1.EVENT_TUNNEL_HTTP_NEW_RESPONSE, (logRequest) => this.httpLogResponse(logRequest));
|
|
570
|
+
this.identify = new identification_1.default(this.targetProto, this.targetHost, this.targetPort, this.http2 || !!this.serve);
|
|
571
|
+
this.identify.on(utils_1.EVENT_TUNNEL_IDENTIFIED, (type) => this.httpIdentified(type));
|
|
572
572
|
const host = format_1.default.entryHostEncoded(this);
|
|
573
|
-
this.http2server = new
|
|
574
|
-
this.http2server.on(
|
|
575
|
-
this.http2server.on(
|
|
576
|
-
this.http2server.on(
|
|
577
|
-
this.http1server = new
|
|
578
|
-
this.http1server.on(
|
|
579
|
-
this.http1server.on(
|
|
580
|
-
this.http1server.on(
|
|
581
|
-
}
|
|
582
|
-
else if (this.type ===
|
|
573
|
+
this.http2server = new http2_1.default(host);
|
|
574
|
+
this.http2server.on(utils_1.HTTP2_SESSION_OPEN, (session) => this.httpConnectionOpen(session));
|
|
575
|
+
this.http2server.on(utils_1.HTTP2_SESSION_CLOSED, (session) => this.httpConnectionClosed(session));
|
|
576
|
+
this.http2server.on(utils_1.HTTP2_REQUEST, (req, res) => this.httpRequest(req, res));
|
|
577
|
+
this.http1server = new http1_1.default(host);
|
|
578
|
+
this.http1server.on(utils_1.HTTP1_SOCKET_OPEN, (socket) => this.httpConnectionOpen(socket));
|
|
579
|
+
this.http1server.on(utils_1.HTTP1_SOCKET_CLOSED, (socket) => this.httpConnectionClosed(socket));
|
|
580
|
+
this.http1server.on(utils_1.HTTP1_REQUEST, (req, res) => this.httpRequest(req, res));
|
|
581
|
+
}
|
|
582
|
+
else if (this.type === utils_1.TUNNEL_SSH) {
|
|
583
583
|
// ssh server
|
|
584
|
-
this.sshServer = new
|
|
584
|
+
this.sshServer = new ssh_1.default(this.agent, this.sshClientUser, this.sshClientPassword, this.sshHostKey);
|
|
585
585
|
}
|
|
586
586
|
// ssh
|
|
587
|
-
this.ssh = new
|
|
588
|
-
this.ssh.on(
|
|
589
|
-
this.ssh.on(
|
|
590
|
-
this.ssh.on(
|
|
591
|
-
this.ssh.on(
|
|
592
|
-
this.ssh.on(
|
|
593
|
-
this.ssh.on(
|
|
594
|
-
this.ssh.on(
|
|
587
|
+
this.ssh = new client_1.default(this.sshIp, this.sshPort, this.sshUser, this.sshPassword);
|
|
588
|
+
this.ssh.on(utils_1.SSH_CLIENT_EVENT_CONNECTED, () => this.sshConnected());
|
|
589
|
+
this.ssh.on(utils_1.SSH_CLIENT_EVENT_DISCONNECTED, () => this.sshDisconnected());
|
|
590
|
+
this.ssh.on(utils_1.SSH_CLIENT_EVENT_STREAM_TCP, (stream) => this.sshStreamTcp(stream));
|
|
591
|
+
this.ssh.on(utils_1.SSH_CLIENT_EVENT_STREAM_TLS, (stream) => this.sshStreamTls(stream));
|
|
592
|
+
this.ssh.on(utils_1.SSH_CLIENT_EVENT_STREAM_HTTP1, (stream, info, ip) => this.sshStreamHttp1(stream, info, ip));
|
|
593
|
+
this.ssh.on(utils_1.SSH_CLIENT_EVENT_STREAM_HTTP2, (stream, info, ip) => this.sshStreamHttp2(stream, info, ip));
|
|
594
|
+
this.ssh.on(utils_1.SSH_CLIENT_EVENT_STREAM_SSH, (stream) => this.sshStreamSsh(stream));
|
|
595
595
|
this.ssh.openKeepAlive();
|
|
596
596
|
}
|
|
597
597
|
stop(emitEvent = true) {
|
|
598
598
|
if (!this.started)
|
|
599
599
|
return;
|
|
600
600
|
this.started = false;
|
|
601
|
-
|
|
601
|
+
logger_1.default.info((0, texts_js_1.LOG_STOPPING_TUNNEL)(this.id));
|
|
602
602
|
if (emitEvent)
|
|
603
|
-
this.emit(
|
|
603
|
+
this.emit(utils_1.TUNNEL_EVENT_STOPPED, this);
|
|
604
604
|
if (this.regionLatency) {
|
|
605
605
|
this.regionLatency.removeAllListeners();
|
|
606
606
|
this.regionLatency.stopChecking();
|
|
@@ -650,6 +650,7 @@ class Tunnel extends events_1.default {
|
|
|
650
650
|
this.ssh.closeKeepAlive();
|
|
651
651
|
this.ssh = null;
|
|
652
652
|
}
|
|
653
|
+
this.status = utils_1.TUNNEL_CLOSED;
|
|
653
654
|
}
|
|
654
655
|
}
|
|
655
656
|
exports.default = Tunnel;
|