bdy 1.12.8-beta → 1.12.8-dev-pipeline-run
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 +1 -1
- package/package.json +1 -1
- package/distTs/bin/cli.js +0 -5
- package/distTs/src/agent/agent.js +0 -328
- package/distTs/src/agent/linux.js +0 -124
- package/distTs/src/agent/manager.js +0 -519
- package/distTs/src/agent/osx.js +0 -146
- package/distTs/src/agent/socket/client.js +0 -178
- package/distTs/src/agent/socket/tunnel.js +0 -237
- package/distTs/src/agent/socket.js +0 -242
- package/distTs/src/agent/system.js +0 -179
- package/distTs/src/agent/wait.js +0 -23
- package/distTs/src/agent/windows.js +0 -159
- package/distTs/src/agent.js +0 -302
- package/distTs/src/api/agent.js +0 -99
- package/distTs/src/api/buddy.js +0 -139
- package/distTs/src/api/socket.js +0 -159
- package/distTs/src/cfg.js +0 -234
- package/distTs/src/command/agent/disable.js +0 -27
- package/distTs/src/command/agent/enable.js +0 -27
- package/distTs/src/command/agent/install.js +0 -117
- package/distTs/src/command/agent/restart.js +0 -27
- package/distTs/src/command/agent/run.js +0 -19
- package/distTs/src/command/agent/start.js +0 -28
- package/distTs/src/command/agent/status.js +0 -34
- package/distTs/src/command/agent/stop.js +0 -28
- package/distTs/src/command/agent/target/disable.js +0 -27
- package/distTs/src/command/agent/target/enable.js +0 -27
- package/distTs/src/command/agent/target/status.js +0 -32
- package/distTs/src/command/agent/target.js +0 -15
- package/distTs/src/command/agent/tunnel/http.js +0 -43
- package/distTs/src/command/agent/tunnel/list.js +0 -27
- package/distTs/src/command/agent/tunnel/remove.js +0 -28
- package/distTs/src/command/agent/tunnel/start.js +0 -34
- package/distTs/src/command/agent/tunnel/status.js +0 -31
- package/distTs/src/command/agent/tunnel/tcp.js +0 -43
- package/distTs/src/command/agent/tunnel/tls.js +0 -43
- package/distTs/src/command/agent/tunnel.js +0 -23
- package/distTs/src/command/agent/uninstall.js +0 -44
- package/distTs/src/command/agent/update.js +0 -38
- package/distTs/src/command/agent/version.js +0 -21
- package/distTs/src/command/agent.js +0 -35
- package/distTs/src/command/config/add/http.js +0 -25
- package/distTs/src/command/config/add/tcp.js +0 -25
- package/distTs/src/command/config/add/tls.js +0 -25
- package/distTs/src/command/config/add.js +0 -15
- package/distTs/src/command/config/get/region.js +0 -15
- package/distTs/src/command/config/get/timeout.js +0 -15
- package/distTs/src/command/config/get/token.js +0 -15
- package/distTs/src/command/config/get/tunnel.js +0 -19
- package/distTs/src/command/config/get/tunnels.js +0 -15
- package/distTs/src/command/config/get/whitelist.js +0 -15
- package/distTs/src/command/config/get.js +0 -21
- package/distTs/src/command/config/remove/tunnel.js +0 -19
- package/distTs/src/command/config/remove.js +0 -11
- package/distTs/src/command/config/set/region.js +0 -17
- package/distTs/src/command/config/set/timeout.js +0 -17
- package/distTs/src/command/config/set/token.js +0 -16
- package/distTs/src/command/config/set/whitelist.js +0 -17
- package/distTs/src/command/config/set.js +0 -17
- package/distTs/src/command/config.js +0 -17
- package/distTs/src/command/http.js +0 -30
- package/distTs/src/command/pre.js +0 -49
- package/distTs/src/command/start.js +0 -28
- package/distTs/src/command/tcp.js +0 -30
- package/distTs/src/command/tls.js +0 -30
- package/distTs/src/command/tunnel/config.js +0 -17
- package/distTs/src/command/tunnel/http.js +0 -31
- package/distTs/src/command/tunnel/start.js +0 -28
- package/distTs/src/command/tunnel/tcp.js +0 -30
- package/distTs/src/command/tunnel/tls.js +0 -30
- package/distTs/src/command/tunnel.js +0 -19
- package/distTs/src/command/ut/upload.js +0 -108
- package/distTs/src/command/ut.js +0 -12
- package/distTs/src/command/version.js +0 -13
- package/distTs/src/command/vt/close.js +0 -27
- package/distTs/src/command/vt/compare/validation.js +0 -173
- package/distTs/src/command/vt/compare.js +0 -97
- package/distTs/src/command/vt/exec.js +0 -81
- package/distTs/src/command/vt/installBrowser.js +0 -20
- package/distTs/src/command/vt/scrap.js +0 -193
- package/distTs/src/command/vt/storybook.js +0 -92
- package/distTs/src/command/vt.js +0 -22
- package/distTs/src/format.js +0 -174
- package/distTs/src/index.js +0 -34
- package/distTs/src/input.js +0 -270
- package/distTs/src/logger.js +0 -95
- package/distTs/src/output/interactive/tunnel.js +0 -860
- package/distTs/src/output/noninteractive/agent/tunnels.js +0 -43
- package/distTs/src/output/noninteractive/config/tunnel.js +0 -65
- package/distTs/src/output/noninteractive/config/tunnels.js +0 -18
- package/distTs/src/output/noninteractive/tunnel.js +0 -59
- package/distTs/src/output.js +0 -143
- package/distTs/src/server/cert.js +0 -52
- package/distTs/src/server/http1.js +0 -75
- package/distTs/src/server/http2.js +0 -78
- package/distTs/src/server/sftp.js +0 -497
- package/distTs/src/server/ssh.js +0 -446
- package/distTs/src/server/tls.js +0 -41
- package/distTs/src/ssh/client.js +0 -197
- package/distTs/src/texts.js +0 -421
- package/distTs/src/tunnel/agent.js +0 -103
- package/distTs/src/tunnel/api/agent.js +0 -100
- package/distTs/src/tunnel/api/buddy.js +0 -141
- package/distTs/src/tunnel/cfg.js +0 -243
- package/distTs/src/tunnel/compression.js +0 -44
- package/distTs/src/tunnel/dns.js +0 -53
- package/distTs/src/tunnel/html/503.html +0 -338
- package/distTs/src/tunnel/html.js +0 -33
- package/distTs/src/tunnel/http/log.js +0 -218
- package/distTs/src/tunnel/http/serve.js +0 -133
- package/distTs/src/tunnel/http/stream.js +0 -34
- package/distTs/src/tunnel/http.js +0 -508
- package/distTs/src/tunnel/identification.js +0 -103
- package/distTs/src/tunnel/latency.js +0 -83
- package/distTs/src/tunnel/output/interactive/tunnel.js +0 -867
- package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +0 -45
- package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +0 -67
- package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +0 -20
- package/distTs/src/tunnel/output/noninteractive/tunnel.js +0 -61
- package/distTs/src/tunnel/server/cert.js +0 -54
- package/distTs/src/tunnel/server/http1.js +0 -80
- package/distTs/src/tunnel/server/http2.js +0 -84
- package/distTs/src/tunnel/server/sftp.js +0 -514
- package/distTs/src/tunnel/server/ssh.js +0 -464
- package/distTs/src/tunnel/server/tls.js +0 -47
- package/distTs/src/tunnel/ssh/client.js +0 -211
- package/distTs/src/tunnel/tcp.js +0 -113
- package/distTs/src/tunnel/tunnel.js +0 -1010
- package/distTs/src/tunnel.js +0 -656
- package/distTs/src/types/ciInfo.js +0 -10
- package/distTs/src/types/options.js +0 -2
- package/distTs/src/types/plugin.js +0 -2
- package/distTs/src/types/queue.js +0 -2
- package/distTs/src/types/requests.js +0 -2
- package/distTs/src/types/resources.js +0 -2
- package/distTs/src/types/schemas.js +0 -54
- package/distTs/src/types/scrape.js +0 -2
- package/distTs/src/types/snapshots.js +0 -2
- package/distTs/src/types/storybook.js +0 -2
- package/distTs/src/types/tunnel.js +0 -141
- package/distTs/src/unitTest/ci.js +0 -108
- package/distTs/src/unitTest/requests.js +0 -72
- package/distTs/src/utils.js +0 -378
- package/distTs/src/visualTest/browser.js +0 -39
- package/distTs/src/visualTest/ci.js +0 -241
- package/distTs/src/visualTest/context.js +0 -52
- package/distTs/src/visualTest/exec.js +0 -51
- package/distTs/src/visualTest/linkUtils.js +0 -21
- package/distTs/src/visualTest/queue.js +0 -43
- package/distTs/src/visualTest/requests.js +0 -365
- package/distTs/src/visualTest/resources.js +0 -259
- package/distTs/src/visualTest/server.js +0 -109
- package/distTs/src/visualTest/snapshots.js +0 -129
- package/distTs/src/visualTest/utils/parseDom.js +0 -238
- package/distTs/src/visualTest/validation.js +0 -18
|
@@ -1,1010 +0,0 @@
|
|
|
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 (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const basic_auth_1 = __importDefault(require("basic-auth"));
|
|
30
|
-
const utils_1 = require("../utils");
|
|
31
|
-
const latency_1 = __importDefault(require("./latency"));
|
|
32
|
-
const client_1 = __importDefault(require("./ssh/client"));
|
|
33
|
-
const events_1 = __importDefault(require("events"));
|
|
34
|
-
const tcp_1 = __importDefault(require("./tcp"));
|
|
35
|
-
const tls_1 = __importDefault(require("./server/tls"));
|
|
36
|
-
const ssh_1 = __importDefault(require("./server/ssh"));
|
|
37
|
-
const logger_1 = __importDefault(require("../logger"));
|
|
38
|
-
const identification_1 = __importDefault(require("./identification"));
|
|
39
|
-
const http_1 = __importDefault(require("./http"));
|
|
40
|
-
const http2_1 = __importDefault(require("./server/http2"));
|
|
41
|
-
const http1_1 = __importDefault(require("./server/http1"));
|
|
42
|
-
const log_1 = __importDefault(require("./http/log"));
|
|
43
|
-
const format_1 = __importDefault(require("../format"));
|
|
44
|
-
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
45
|
-
const cookie = __importStar(require("cookie"));
|
|
46
|
-
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
47
|
-
const undici_1 = require("undici");
|
|
48
|
-
const texts_1 = require("../texts");
|
|
49
|
-
const dns_1 = __importDefault(require("./dns"));
|
|
50
|
-
const tunnel_1 = require("../types/tunnel");
|
|
51
|
-
const cfg_1 = __importDefault(require("./cfg"));
|
|
52
|
-
const CIPHER_ALG = 'aes-256-cbc';
|
|
53
|
-
const CIPHER_IV = Buffer.alloc(16).fill(0);
|
|
54
|
-
const COOKIE_NAME = 'jwt_token';
|
|
55
|
-
class Tunnel extends events_1.default {
|
|
56
|
-
agent;
|
|
57
|
-
id;
|
|
58
|
-
cipherKey;
|
|
59
|
-
sshHostKey;
|
|
60
|
-
type;
|
|
61
|
-
region;
|
|
62
|
-
target;
|
|
63
|
-
whitelist;
|
|
64
|
-
domain;
|
|
65
|
-
subdomain;
|
|
66
|
-
name;
|
|
67
|
-
timeout;
|
|
68
|
-
useragents;
|
|
69
|
-
headers;
|
|
70
|
-
responseHeaders;
|
|
71
|
-
terminate;
|
|
72
|
-
key;
|
|
73
|
-
cert;
|
|
74
|
-
ca;
|
|
75
|
-
host;
|
|
76
|
-
login;
|
|
77
|
-
password;
|
|
78
|
-
authType;
|
|
79
|
-
serve;
|
|
80
|
-
circuitBreaker;
|
|
81
|
-
log;
|
|
82
|
-
verify;
|
|
83
|
-
compression;
|
|
84
|
-
http2;
|
|
85
|
-
sshIp;
|
|
86
|
-
sshId;
|
|
87
|
-
sshPort;
|
|
88
|
-
sshUser;
|
|
89
|
-
sshPassword;
|
|
90
|
-
sshForwardPort;
|
|
91
|
-
sshClientUser;
|
|
92
|
-
sshClientPassword;
|
|
93
|
-
targetProto;
|
|
94
|
-
targetHost;
|
|
95
|
-
targetPort;
|
|
96
|
-
targetAuth;
|
|
97
|
-
totalConnections;
|
|
98
|
-
status;
|
|
99
|
-
connections;
|
|
100
|
-
dns;
|
|
101
|
-
regionLatency;
|
|
102
|
-
targetLatency;
|
|
103
|
-
tls;
|
|
104
|
-
httpLog;
|
|
105
|
-
identify;
|
|
106
|
-
http2server;
|
|
107
|
-
http1server;
|
|
108
|
-
sshServer;
|
|
109
|
-
ssh;
|
|
110
|
-
started;
|
|
111
|
-
constructor({ agent, id, type, target, region, timeout, domain, name, subdomain, whitelist, tlsSettings, httpSettings, sshSettings, sshHostKey, }) {
|
|
112
|
-
super();
|
|
113
|
-
if (!sshHostKey)
|
|
114
|
-
sshHostKey = (0, utils_1.createSshHostKey)();
|
|
115
|
-
this.agent = agent;
|
|
116
|
-
this.id = id;
|
|
117
|
-
this.cipherKey = node_crypto_1.default.createHash('sha512').update(this.id).digest('hex').substring(0, 32);
|
|
118
|
-
this.sshHostKey = sshHostKey;
|
|
119
|
-
this.create({
|
|
120
|
-
type,
|
|
121
|
-
target,
|
|
122
|
-
region,
|
|
123
|
-
timeout,
|
|
124
|
-
domain,
|
|
125
|
-
subdomain,
|
|
126
|
-
name,
|
|
127
|
-
whitelist,
|
|
128
|
-
tlsSettings,
|
|
129
|
-
httpSettings,
|
|
130
|
-
sshSettings,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
create({ type, target, region, timeout, domain, subdomain, name, whitelist, tlsSettings, httpSettings, sshSettings, }) {
|
|
134
|
-
this.type = type;
|
|
135
|
-
this.region = region;
|
|
136
|
-
this.target = target;
|
|
137
|
-
this.whitelist = whitelist || [];
|
|
138
|
-
this.domain = domain;
|
|
139
|
-
this.subdomain = subdomain;
|
|
140
|
-
this.name = name;
|
|
141
|
-
this.timeout = timeout || utils_1.DEFAULT_TIMEOUT;
|
|
142
|
-
this.useragents = [];
|
|
143
|
-
this.headers = [];
|
|
144
|
-
this.responseHeaders = [];
|
|
145
|
-
if (tlsSettings) {
|
|
146
|
-
this.terminate = tlsSettings.terminate;
|
|
147
|
-
this.key = tlsSettings.key;
|
|
148
|
-
this.cert = tlsSettings.cert;
|
|
149
|
-
this.ca = tlsSettings.ca;
|
|
150
|
-
}
|
|
151
|
-
if (httpSettings) {
|
|
152
|
-
this.host = httpSettings.host;
|
|
153
|
-
if (httpSettings.authType) {
|
|
154
|
-
this.authType = httpSettings.authType;
|
|
155
|
-
if (this.authType === tunnel_1.TUNNEL_HTTP_AUTH_TYPE.BASIC) {
|
|
156
|
-
this.login = httpSettings.login || '';
|
|
157
|
-
this.password = httpSettings.password || '';
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
else if (httpSettings.login || httpSettings.password) {
|
|
161
|
-
this.authType = tunnel_1.TUNNEL_HTTP_AUTH_TYPE.BASIC;
|
|
162
|
-
this.login = httpSettings.login || '';
|
|
163
|
-
this.password = httpSettings.password || '';
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
this.authType = tunnel_1.TUNNEL_HTTP_AUTH_TYPE.NONE;
|
|
167
|
-
}
|
|
168
|
-
this.ca = httpSettings.ca;
|
|
169
|
-
this.serve = httpSettings.serve;
|
|
170
|
-
this.useragents = httpSettings.userAgents || [];
|
|
171
|
-
this.headers = httpSettings.headers || [];
|
|
172
|
-
this.responseHeaders = httpSettings.responseHeaders || [];
|
|
173
|
-
this.circuitBreaker = httpSettings.circuitBreaker;
|
|
174
|
-
this.log = httpSettings.log;
|
|
175
|
-
this.verify = httpSettings.verify;
|
|
176
|
-
this.compression = httpSettings.compression;
|
|
177
|
-
this.http2 = httpSettings.http2;
|
|
178
|
-
}
|
|
179
|
-
if (sshSettings) {
|
|
180
|
-
this.sshIp = sshSettings.ip;
|
|
181
|
-
this.sshId = sshSettings.sshId;
|
|
182
|
-
this.sshPort = sshSettings.port;
|
|
183
|
-
this.sshUser = sshSettings.user;
|
|
184
|
-
this.sshPassword = sshSettings.password;
|
|
185
|
-
this.sshForwardPort = sshSettings.forwardPort;
|
|
186
|
-
this.sshClientUser = sshSettings.clientUser;
|
|
187
|
-
this.sshClientPassword = sshSettings.clientPassword;
|
|
188
|
-
}
|
|
189
|
-
this.targetProto = 'http';
|
|
190
|
-
this.targetHost = 'localhost';
|
|
191
|
-
this.targetPort = 80;
|
|
192
|
-
this.targetAuth = null;
|
|
193
|
-
if (this.type === tunnel_1.TUNNEL_TYPE.HTTP) {
|
|
194
|
-
let m = this.target.match(utils_1.TARGET_ONLY_PORT_REGEX);
|
|
195
|
-
if (m) {
|
|
196
|
-
this.targetPort = parseInt(m[0], 10);
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
m = this.target.match(utils_1.TARGET_HTTP_REGEX);
|
|
200
|
-
if (m) {
|
|
201
|
-
if (m[2])
|
|
202
|
-
this.targetProto = m[2];
|
|
203
|
-
if (m[6])
|
|
204
|
-
this.targetPort = parseInt(m[6], 10);
|
|
205
|
-
else if (this.targetProto === 'https')
|
|
206
|
-
this.targetPort = 443;
|
|
207
|
-
if (m[4])
|
|
208
|
-
this.targetHost = m[4];
|
|
209
|
-
if (m[3])
|
|
210
|
-
this.targetAuth = m[3].replace(/@$/, '');
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
else if (this.type === tunnel_1.TUNNEL_TYPE.SSH) {
|
|
215
|
-
this.targetHost = 'localhost';
|
|
216
|
-
this.targetProto = 'ssh://';
|
|
217
|
-
this.targetPort = 22;
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
const m = this.target.match(utils_1.TARGET_TCP_TLS_REGEX);
|
|
221
|
-
if (m) {
|
|
222
|
-
this.targetPort = parseInt(m[3], 10);
|
|
223
|
-
if (m[2])
|
|
224
|
-
this.targetHost = m[2];
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
this.connections = {};
|
|
228
|
-
this.totalConnections = 0;
|
|
229
|
-
this.status = tunnel_1.TUNNEL_STATUS.CLOSED;
|
|
230
|
-
this.dns = null;
|
|
231
|
-
this.regionLatency = null;
|
|
232
|
-
this.targetLatency = null;
|
|
233
|
-
this.tls = null;
|
|
234
|
-
this.httpLog = null;
|
|
235
|
-
this.identify = null;
|
|
236
|
-
this.http2server = null;
|
|
237
|
-
this.http1server = null;
|
|
238
|
-
this.sshServer = null;
|
|
239
|
-
this.ssh = null;
|
|
240
|
-
this.started = false;
|
|
241
|
-
}
|
|
242
|
-
recreate({ type, target, region, timeout, domain, subdomain, name, whitelist, tlsSettings, httpSettings, sshSettings, }) {
|
|
243
|
-
const started = this.started;
|
|
244
|
-
this.stop(false);
|
|
245
|
-
this.create({
|
|
246
|
-
type,
|
|
247
|
-
target,
|
|
248
|
-
region,
|
|
249
|
-
timeout,
|
|
250
|
-
domain,
|
|
251
|
-
subdomain,
|
|
252
|
-
name,
|
|
253
|
-
whitelist,
|
|
254
|
-
tlsSettings,
|
|
255
|
-
httpSettings,
|
|
256
|
-
sshSettings,
|
|
257
|
-
});
|
|
258
|
-
if (started)
|
|
259
|
-
this.start();
|
|
260
|
-
}
|
|
261
|
-
hasChanged(data) {
|
|
262
|
-
const tunnel = new Tunnel({
|
|
263
|
-
...data,
|
|
264
|
-
sshHostKey: this.sshHostKey,
|
|
265
|
-
});
|
|
266
|
-
if (this.type !== tunnel.type)
|
|
267
|
-
return true;
|
|
268
|
-
if (this.target !== tunnel.target)
|
|
269
|
-
return true;
|
|
270
|
-
if (this.region !== tunnel.region)
|
|
271
|
-
return true;
|
|
272
|
-
if (this.timeout !== tunnel.timeout)
|
|
273
|
-
return true;
|
|
274
|
-
if (this.domain !== tunnel.domain)
|
|
275
|
-
return true;
|
|
276
|
-
if (this.subdomain !== tunnel.subdomain)
|
|
277
|
-
return true;
|
|
278
|
-
if (this.terminate !== tunnel.terminate)
|
|
279
|
-
return true;
|
|
280
|
-
if (this.key !== tunnel.key)
|
|
281
|
-
return true;
|
|
282
|
-
if (this.cert !== tunnel.cert)
|
|
283
|
-
return true;
|
|
284
|
-
if (this.ca !== tunnel.ca)
|
|
285
|
-
return true;
|
|
286
|
-
if (this.host !== tunnel.host)
|
|
287
|
-
return true;
|
|
288
|
-
if (this.login !== tunnel.login)
|
|
289
|
-
return true;
|
|
290
|
-
if (this.password !== tunnel.password)
|
|
291
|
-
return true;
|
|
292
|
-
if (this.serve !== tunnel.serve)
|
|
293
|
-
return true;
|
|
294
|
-
if (this.circuitBreaker !== tunnel.circuitBreaker)
|
|
295
|
-
return true;
|
|
296
|
-
if (this.log !== tunnel.log)
|
|
297
|
-
return true;
|
|
298
|
-
if (this.verify !== tunnel.verify)
|
|
299
|
-
return true;
|
|
300
|
-
if (this.http2 !== tunnel.http2)
|
|
301
|
-
return true;
|
|
302
|
-
if (this.compression !== tunnel.compression)
|
|
303
|
-
return true;
|
|
304
|
-
if (this.sshIp !== tunnel.sshIp)
|
|
305
|
-
return true;
|
|
306
|
-
if (this.sshId !== tunnel.sshId)
|
|
307
|
-
return true;
|
|
308
|
-
if (this.sshPort !== tunnel.sshPort)
|
|
309
|
-
return true;
|
|
310
|
-
if (this.sshUser !== tunnel.sshUser)
|
|
311
|
-
return true;
|
|
312
|
-
if (this.sshPassword !== tunnel.sshPassword)
|
|
313
|
-
return true;
|
|
314
|
-
if (this.sshForwardPort !== tunnel.sshForwardPort)
|
|
315
|
-
return true;
|
|
316
|
-
if (this.sshClientPassword !== tunnel.sshClientPassword)
|
|
317
|
-
return true;
|
|
318
|
-
if (this.sshClientUser !== tunnel.sshClientUser)
|
|
319
|
-
return true;
|
|
320
|
-
if (this.whitelist?.length !== tunnel.whitelist?.length)
|
|
321
|
-
return true;
|
|
322
|
-
if (this.whitelist && tunnel.whitelist) {
|
|
323
|
-
this.whitelist.sort();
|
|
324
|
-
tunnel.whitelist.sort();
|
|
325
|
-
for (let i = 0; i < this.whitelist.length; i += 1) {
|
|
326
|
-
if (this.whitelist[i] !== tunnel.whitelist[i])
|
|
327
|
-
return true;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if (this.useragents?.length !== tunnel.useragents?.length)
|
|
331
|
-
return true;
|
|
332
|
-
if (this.useragents && tunnel.useragents) {
|
|
333
|
-
this.useragents.sort();
|
|
334
|
-
tunnel.useragents.sort();
|
|
335
|
-
for (let i = 0; i < this.useragents.length; i += 1) {
|
|
336
|
-
if (this.useragents[i] !== tunnel.useragents[i])
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
const sortHeaders = (a, b) => a.name.localeCompare(b.name);
|
|
341
|
-
if (this.headers?.length !== tunnel.headers?.length)
|
|
342
|
-
return true;
|
|
343
|
-
if (this.headers && tunnel.headers) {
|
|
344
|
-
this.headers.sort(sortHeaders);
|
|
345
|
-
tunnel.headers.sort(sortHeaders);
|
|
346
|
-
for (let i = 0; i < this.headers.length; i += 1) {
|
|
347
|
-
const thisH = this.headers[i];
|
|
348
|
-
const tunnelH = tunnel.headers[i];
|
|
349
|
-
if (thisH.name !== tunnelH.name)
|
|
350
|
-
return true;
|
|
351
|
-
if (thisH.value !== tunnelH.value)
|
|
352
|
-
return true;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
if (this.responseHeaders?.length !== tunnel.responseHeaders?.length)
|
|
356
|
-
return true;
|
|
357
|
-
if (this.responseHeaders && tunnel.responseHeaders) {
|
|
358
|
-
this.responseHeaders.sort(sortHeaders);
|
|
359
|
-
tunnel.responseHeaders.sort(sortHeaders);
|
|
360
|
-
for (let i = 0; i < this.responseHeaders.length; i += 1) {
|
|
361
|
-
const thisRH = this.responseHeaders[i];
|
|
362
|
-
const tunnelRH = tunnel.responseHeaders[i];
|
|
363
|
-
if (thisRH.name !== tunnelRH.name)
|
|
364
|
-
return true;
|
|
365
|
-
if (thisRH.value !== tunnelRH.value)
|
|
366
|
-
return true;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
return false;
|
|
370
|
-
}
|
|
371
|
-
async sshConnected() {
|
|
372
|
-
try {
|
|
373
|
-
logger_1.default.debug((0, texts_1.LOG_TUNNEL_CONNECTED)(this.id, this.sshForwardPort));
|
|
374
|
-
if (this.ssh && this.sshForwardPort)
|
|
375
|
-
await this.ssh.forwardIn(this.sshForwardPort);
|
|
376
|
-
this.status = tunnel_1.TUNNEL_STATUS.OPEN;
|
|
377
|
-
}
|
|
378
|
-
catch (err) {
|
|
379
|
-
// reconnect
|
|
380
|
-
logger_1.default.debug((0, texts_1.LOG_TUNNEL_FAILED)(this.id));
|
|
381
|
-
logger_1.default.debug(err);
|
|
382
|
-
if (this.ssh)
|
|
383
|
-
this.ssh.close();
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
this.emit(tunnel_1.TUNNEL_EVENT.OPEN, this);
|
|
387
|
-
}
|
|
388
|
-
sshDisconnected() {
|
|
389
|
-
if (this.status !== tunnel_1.TUNNEL_STATUS.CLOSED) {
|
|
390
|
-
logger_1.default.debug((0, texts_1.LOG_TUNNEL_DISCONNECTED)(this.id));
|
|
391
|
-
this.status = tunnel_1.TUNNEL_STATUS.CLOSED;
|
|
392
|
-
this.emit(tunnel_1.TUNNEL_EVENT.CLOSED, this);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
tunnelToTarget(stream, onClose) {
|
|
396
|
-
if (!this.totalConnections)
|
|
397
|
-
this.totalConnections = 0;
|
|
398
|
-
this.totalConnections += 1;
|
|
399
|
-
const tcp = new tcp_1.default(this.targetHost || '', this.targetPort || 0, stream);
|
|
400
|
-
if (!this.connections)
|
|
401
|
-
this.connections = {};
|
|
402
|
-
this.connections[tcp.id] = tcp;
|
|
403
|
-
tcp.on(tunnel_1.TUNNEL_EVENT_TCP.CLOSED, () => {
|
|
404
|
-
if (this.connections && this.connections[tcp.id]) {
|
|
405
|
-
this.connections[tcp.id].removeAllListeners();
|
|
406
|
-
delete this.connections[tcp.id];
|
|
407
|
-
}
|
|
408
|
-
onClose();
|
|
409
|
-
});
|
|
410
|
-
tcp.pipe();
|
|
411
|
-
}
|
|
412
|
-
httpIdentified(type) {
|
|
413
|
-
logger_1.default.info((0, texts_1.LOG_TUNNEL_IDENTIFIED)(this.id, type));
|
|
414
|
-
this.emit(tunnel_1.TUNNEL_EVENT.HTTP_IDENTIFIED, this, type);
|
|
415
|
-
}
|
|
416
|
-
httpConnectionOpen(s) {
|
|
417
|
-
if (!this.totalConnections)
|
|
418
|
-
this.totalConnections = 0;
|
|
419
|
-
if (!this.connections)
|
|
420
|
-
this.connections = {};
|
|
421
|
-
this.totalConnections += 1;
|
|
422
|
-
this.connections[s.id] = s;
|
|
423
|
-
this.emit(tunnel_1.TUNNEL_EVENT.HTTP_OPEN, this);
|
|
424
|
-
}
|
|
425
|
-
httpConnectionClosed(s) {
|
|
426
|
-
if (this.connections && this.connections[s.id]) {
|
|
427
|
-
delete this.connections[s.id];
|
|
428
|
-
}
|
|
429
|
-
this.emit(tunnel_1.TUNNEL_EVENT.HTTP_CLOSED, this);
|
|
430
|
-
}
|
|
431
|
-
async httpBasicAuth(req, res) {
|
|
432
|
-
if (this.authType === tunnel_1.TUNNEL_HTTP_AUTH_TYPE.BASIC) {
|
|
433
|
-
const user = (0, basic_auth_1.default)(req);
|
|
434
|
-
if (user && user.name === this.login && user.pass === this.password) {
|
|
435
|
-
return true;
|
|
436
|
-
}
|
|
437
|
-
const authorized = await this._checkHttpPat(req, res, false);
|
|
438
|
-
if (authorized) {
|
|
439
|
-
return true;
|
|
440
|
-
}
|
|
441
|
-
logger_1.default.debug(texts_1.LOG_TUNNEL_HTTP_WRON_AUTH);
|
|
442
|
-
this.httpEndFast(req, res, 401, 'Unauthorised', {
|
|
443
|
-
'WWW-Authenticate': 'Basic real="Buddy"',
|
|
444
|
-
});
|
|
445
|
-
return false;
|
|
446
|
-
}
|
|
447
|
-
return true;
|
|
448
|
-
}
|
|
449
|
-
async _checkHttpPat(req, res, setCookie) {
|
|
450
|
-
const user = (0, basic_auth_1.default)(req);
|
|
451
|
-
if (!user || !user.name || !user.pass)
|
|
452
|
-
return false;
|
|
453
|
-
const client = this._getHttpAuthClient();
|
|
454
|
-
try {
|
|
455
|
-
const { statusCode, body } = await client.request({
|
|
456
|
-
path: `/tunnel/auth/pat`,
|
|
457
|
-
method: 'POST',
|
|
458
|
-
headers: {
|
|
459
|
-
'content-type': 'application/json',
|
|
460
|
-
},
|
|
461
|
-
body: JSON.stringify({
|
|
462
|
-
id: this.id,
|
|
463
|
-
agentId: this.agent.id,
|
|
464
|
-
login: user.name,
|
|
465
|
-
password: user.pass,
|
|
466
|
-
})
|
|
467
|
-
});
|
|
468
|
-
if (statusCode !== 200)
|
|
469
|
-
return false;
|
|
470
|
-
const result = await body.json();
|
|
471
|
-
if (!result.success)
|
|
472
|
-
return false;
|
|
473
|
-
if (setCookie)
|
|
474
|
-
this._httpSetAuthCookie(res, result.token);
|
|
475
|
-
return true;
|
|
476
|
-
}
|
|
477
|
-
catch {
|
|
478
|
-
return false;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
_getHttpAuthClient() {
|
|
482
|
-
return new undici_1.Client(cfg_1.default.getTokenHost(), {
|
|
483
|
-
connect: {
|
|
484
|
-
rejectUnauthorized: false
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
async _httpExchangeAuthCode(code) {
|
|
489
|
-
const client = this._getHttpAuthClient();
|
|
490
|
-
try {
|
|
491
|
-
const r = await client.request({
|
|
492
|
-
path: `/external-api/auth/token?grant_type=authorization_code`,
|
|
493
|
-
method: 'POST',
|
|
494
|
-
headers: {
|
|
495
|
-
'content-type': 'application/json',
|
|
496
|
-
},
|
|
497
|
-
body: JSON.stringify({
|
|
498
|
-
code
|
|
499
|
-
})
|
|
500
|
-
});
|
|
501
|
-
const o = await r.body.json();
|
|
502
|
-
if (o.accessToken) {
|
|
503
|
-
return o.accessToken;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
catch {
|
|
507
|
-
// do nothing
|
|
508
|
-
}
|
|
509
|
-
return '';
|
|
510
|
-
}
|
|
511
|
-
_httpParseAuthToken(token) {
|
|
512
|
-
const msg = 'Invalid authorization token';
|
|
513
|
-
if (!token)
|
|
514
|
-
throw new Error(msg);
|
|
515
|
-
const data = (0, jsonwebtoken_1.decode)(token);
|
|
516
|
-
if (data === null || !data.tunnelId || !data.userId || data.aud !== 'tunnels' || data.sub !== 'tunnel_read')
|
|
517
|
-
throw new Error(msg);
|
|
518
|
-
return {
|
|
519
|
-
tunnelId: data.tunnelId,
|
|
520
|
-
userId: data.userId,
|
|
521
|
-
token
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
_httpSetAuthCookie(res, token) {
|
|
525
|
-
res.setHeader('set-cookie', cookie.serialize(COOKIE_NAME, token, {
|
|
526
|
-
maxAge: 3600,
|
|
527
|
-
path: '/',
|
|
528
|
-
secure: false,
|
|
529
|
-
httpOnly: true,
|
|
530
|
-
sameSite: 'lax'
|
|
531
|
-
}));
|
|
532
|
-
}
|
|
533
|
-
async _checkHttpAuthToken(code, token, req, res) {
|
|
534
|
-
let fromCookie = false;
|
|
535
|
-
if (code && !token) {
|
|
536
|
-
token = await this._httpExchangeAuthCode(code);
|
|
537
|
-
}
|
|
538
|
-
if (!token) {
|
|
539
|
-
const cookies = cookie.parse(req.headers.cookie || '');
|
|
540
|
-
token = cookies[COOKIE_NAME] || '';
|
|
541
|
-
fromCookie = true;
|
|
542
|
-
}
|
|
543
|
-
if (!token) {
|
|
544
|
-
return false;
|
|
545
|
-
}
|
|
546
|
-
try {
|
|
547
|
-
const data = this._httpParseAuthToken(token);
|
|
548
|
-
if (data.tunnelId !== this.id) {
|
|
549
|
-
return false;
|
|
550
|
-
}
|
|
551
|
-
if (!data.userId) {
|
|
552
|
-
return false;
|
|
553
|
-
}
|
|
554
|
-
if (fromCookie) {
|
|
555
|
-
return true;
|
|
556
|
-
}
|
|
557
|
-
this._httpSetAuthCookie(res, token);
|
|
558
|
-
return true;
|
|
559
|
-
}
|
|
560
|
-
catch {
|
|
561
|
-
return false;
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
_httpEncryptState(str) {
|
|
565
|
-
try {
|
|
566
|
-
const cipher = node_crypto_1.default.createCipheriv(CIPHER_ALG, Buffer.from(this.cipherKey), Buffer.from(CIPHER_IV));
|
|
567
|
-
let enc = cipher.update(JSON.stringify({ str }), 'utf8', 'hex');
|
|
568
|
-
enc += cipher.final('hex');
|
|
569
|
-
return enc;
|
|
570
|
-
}
|
|
571
|
-
catch {
|
|
572
|
-
// do nothing
|
|
573
|
-
}
|
|
574
|
-
return '';
|
|
575
|
-
}
|
|
576
|
-
_httpDecryptState(state) {
|
|
577
|
-
if (state) {
|
|
578
|
-
try {
|
|
579
|
-
const decipher = node_crypto_1.default.createDecipheriv(CIPHER_ALG, Buffer.from(this.cipherKey), Buffer.from(CIPHER_IV));
|
|
580
|
-
let dec = decipher.update(state, 'hex', 'utf8');
|
|
581
|
-
dec += decipher.final('utf8');
|
|
582
|
-
const url = JSON.parse(dec).str;
|
|
583
|
-
if (url) {
|
|
584
|
-
new URL(url);
|
|
585
|
-
return url;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
catch {
|
|
589
|
-
// do nothing
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
return '';
|
|
593
|
-
}
|
|
594
|
-
_redirectHttpToBuddyAuth(pathname, search, req, res) {
|
|
595
|
-
let host = this.agent.host;
|
|
596
|
-
if (/^https:\/\/\d+\.\d+\.\d+\.\d+$/.test(host)) {
|
|
597
|
-
host = 'https://app.local.io';
|
|
598
|
-
}
|
|
599
|
-
const callback = `https://${this.subdomain}.${(this.region || '').toLowerCase()}-${this.sshId}.${this.domain}`;
|
|
600
|
-
let state;
|
|
601
|
-
if (req.headers['x-forwarded-host']) {
|
|
602
|
-
if (req.headers['x-forwarded-proto'] === 'http') {
|
|
603
|
-
state = 'http://';
|
|
604
|
-
}
|
|
605
|
-
else {
|
|
606
|
-
state = 'https://';
|
|
607
|
-
}
|
|
608
|
-
state += req.headers['x-forwarded-host'];
|
|
609
|
-
}
|
|
610
|
-
else {
|
|
611
|
-
state = callback;
|
|
612
|
-
}
|
|
613
|
-
state += pathname;
|
|
614
|
-
if (search)
|
|
615
|
-
state += search;
|
|
616
|
-
const enc = this._httpEncryptState(state);
|
|
617
|
-
let url = `${host}/tunnel/auth?redirect_url=${encodeURIComponent(callback)}&id=${encodeURIComponent(this.id)}&agentId=${encodeURIComponent(this.agent.id)}&state=${encodeURIComponent(enc)}`;
|
|
618
|
-
if (/app\.local\.io/.test(host)) {
|
|
619
|
-
url += '&response_type=token';
|
|
620
|
-
}
|
|
621
|
-
this.httpEndFast(req, res, 302, 'Found', {
|
|
622
|
-
location: url,
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
async httpBuddyAuth(req, res) {
|
|
626
|
-
if (this.authType === tunnel_1.TUNNEL_HTTP_AUTH_TYPE.BUDDY) {
|
|
627
|
-
const { searchParams, pathname, search } = new URL(req.url, 'https://abc.com');
|
|
628
|
-
const code = searchParams.get('code') || '';
|
|
629
|
-
const state = searchParams.get('state') || '';
|
|
630
|
-
const token = searchParams.get('access_token') || '';
|
|
631
|
-
const url = this._httpDecryptState(state);
|
|
632
|
-
const authByToken = await this._checkHttpAuthToken(code, token, req, res);
|
|
633
|
-
if (authByToken) {
|
|
634
|
-
if (url) {
|
|
635
|
-
this.httpEndFast(req, res, 302, 'Found', {
|
|
636
|
-
location: url,
|
|
637
|
-
});
|
|
638
|
-
return false;
|
|
639
|
-
}
|
|
640
|
-
return true;
|
|
641
|
-
}
|
|
642
|
-
else if ((code || token) && url) {
|
|
643
|
-
this.httpEndFast(req, res, 404, 'Not found');
|
|
644
|
-
return false;
|
|
645
|
-
}
|
|
646
|
-
const auth = (0, basic_auth_1.default)(req);
|
|
647
|
-
if (auth) {
|
|
648
|
-
const authorized = await this._checkHttpPat(req, res, true);
|
|
649
|
-
if (authorized) {
|
|
650
|
-
return true;
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
this._redirectHttpToBuddyAuth(pathname, search, req, res);
|
|
654
|
-
return false;
|
|
655
|
-
}
|
|
656
|
-
return true;
|
|
657
|
-
}
|
|
658
|
-
httpEndFast(req, res, statusCode, msg, headers = {}) {
|
|
659
|
-
let log;
|
|
660
|
-
if (this.httpLog) {
|
|
661
|
-
log = this.httpLog.newRequest(req.method, req.headers, req.url, req.httpVersion, req);
|
|
662
|
-
}
|
|
663
|
-
if (!log) {
|
|
664
|
-
if (this.httpLog)
|
|
665
|
-
this.httpLog.newResponse(statusCode, headers);
|
|
666
|
-
res.statusCode = statusCode;
|
|
667
|
-
Object.keys(headers).forEach((k) => {
|
|
668
|
-
res.setHeader(k, headers[k]);
|
|
669
|
-
});
|
|
670
|
-
res.end(msg);
|
|
671
|
-
}
|
|
672
|
-
else {
|
|
673
|
-
req.pipe(log.requestBody);
|
|
674
|
-
log.requestBody.pipeToNothing(() => {
|
|
675
|
-
if (this.httpLog)
|
|
676
|
-
this.httpLog.newResponse(statusCode, headers, log);
|
|
677
|
-
res.statusCode = statusCode;
|
|
678
|
-
Object.keys(headers).forEach((k) => {
|
|
679
|
-
res.setHeader(k, headers[k]);
|
|
680
|
-
});
|
|
681
|
-
res.end(msg);
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
httpRateLimit(req, res) {
|
|
686
|
-
const isRateLimited = !!this.httpLog && this.httpLog.isRateLimited(req);
|
|
687
|
-
if (isRateLimited) {
|
|
688
|
-
logger_1.default.debug(texts_1.LOG_TUNNEL_HTTP_RATE_LIMIT);
|
|
689
|
-
this.httpEndFast(req, res, 429, 'Too Many Requests', {
|
|
690
|
-
'Retry-After': '60',
|
|
691
|
-
});
|
|
692
|
-
return false;
|
|
693
|
-
}
|
|
694
|
-
return true;
|
|
695
|
-
}
|
|
696
|
-
httpCircuitBreaker(req, res) {
|
|
697
|
-
const isOpen = !!this.httpLog && this.httpLog.isCircuitBreakerOpen();
|
|
698
|
-
if (isOpen) {
|
|
699
|
-
logger_1.default.debug(texts_1.LOG_TUNNEL_HTTP_CIRCUIT_BREAKER_OPEN);
|
|
700
|
-
this.httpEndFast(req, res, 504, 'Service Unavailable', {});
|
|
701
|
-
return false;
|
|
702
|
-
}
|
|
703
|
-
return true;
|
|
704
|
-
}
|
|
705
|
-
httpUserAgent(req, res) {
|
|
706
|
-
if (this.useragents && this.useragents.length > 0) {
|
|
707
|
-
const ua = req.headers['user-agent'] || '';
|
|
708
|
-
for (let i = 0; i < this.useragents.length; i += 1) {
|
|
709
|
-
const str = this.useragents[i];
|
|
710
|
-
if ((0, utils_1.isStringRegExp)(str)) {
|
|
711
|
-
try {
|
|
712
|
-
const r = new RegExp(str, 'i');
|
|
713
|
-
if (r.test(ua))
|
|
714
|
-
return true;
|
|
715
|
-
}
|
|
716
|
-
catch {
|
|
717
|
-
// do nothing
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
else if (ua.includes(str)) {
|
|
721
|
-
return true;
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
logger_1.default.debug(texts_1.LOG_TUNNEL_HTTP_WRONG_USER_AGENTS);
|
|
725
|
-
this.httpEndFast(req, res, 401, 'Unauthorised', {});
|
|
726
|
-
return false;
|
|
727
|
-
}
|
|
728
|
-
return true;
|
|
729
|
-
}
|
|
730
|
-
targetReconnected() {
|
|
731
|
-
if (this.identify)
|
|
732
|
-
this.identify.identify();
|
|
733
|
-
}
|
|
734
|
-
httpLogRequest(logRequest) {
|
|
735
|
-
this.emit(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, this, logRequest);
|
|
736
|
-
}
|
|
737
|
-
httpLogResponse(logRequest) {
|
|
738
|
-
this.emit(tunnel_1.TUNNEL_EVENT.HTTP_RESPONSE, this, logRequest);
|
|
739
|
-
}
|
|
740
|
-
retryHttpLogRequest(logRequest) {
|
|
741
|
-
if (logRequest.requestBody.tooLarge)
|
|
742
|
-
return;
|
|
743
|
-
if (logRequest.httpVersion === '2.0') {
|
|
744
|
-
if (this.http2server)
|
|
745
|
-
return this.http2server.retryRequest(logRequest);
|
|
746
|
-
}
|
|
747
|
-
if (this.http1server) {
|
|
748
|
-
return this.http1server.retryRequest(logRequest);
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
async httpRequest(req, res) {
|
|
752
|
-
const isAuth = (await this.httpBasicAuth(req, res)) &&
|
|
753
|
-
(await this.httpBuddyAuth(req, res)) &&
|
|
754
|
-
this.httpUserAgent(req, res) &&
|
|
755
|
-
this.httpRateLimit(req, res) &&
|
|
756
|
-
this.httpCircuitBreaker(req, res);
|
|
757
|
-
if (!isAuth)
|
|
758
|
-
return;
|
|
759
|
-
const http = new http_1.default({
|
|
760
|
-
req,
|
|
761
|
-
res,
|
|
762
|
-
auth: this.targetAuth,
|
|
763
|
-
proto: this.targetProto,
|
|
764
|
-
host: this.targetHost,
|
|
765
|
-
port: this.targetPort,
|
|
766
|
-
hostHeader: this.host,
|
|
767
|
-
timeout: this.timeout,
|
|
768
|
-
verify: this.verify,
|
|
769
|
-
compression: this.compression,
|
|
770
|
-
headers: this.headers,
|
|
771
|
-
serve: this.serve,
|
|
772
|
-
responseHeaders: this.responseHeaders,
|
|
773
|
-
httpIdentify: this.identify?.type,
|
|
774
|
-
httpLog: this.httpLog,
|
|
775
|
-
});
|
|
776
|
-
http.once(tunnel_1.TUNNEL_HTTP_SOCKET.CLOSED, (socket) => this.httpConnectionClosed(socket));
|
|
777
|
-
http.pipe().then();
|
|
778
|
-
}
|
|
779
|
-
tlsSocket(tlsSocket) {
|
|
780
|
-
this.tunnelToTarget(tlsSocket, () => {
|
|
781
|
-
this.emit(tunnel_1.TUNNEL_EVENT.TLS_CLOSED, this);
|
|
782
|
-
});
|
|
783
|
-
this.emit(tunnel_1.TUNNEL_EVENT.TLS_OPEN, this);
|
|
784
|
-
}
|
|
785
|
-
canStreamTcp() {
|
|
786
|
-
if (this.type === tunnel_1.TUNNEL_TYPE.TCP)
|
|
787
|
-
return true;
|
|
788
|
-
return (this.type === tunnel_1.TUNNEL_TYPE.TLS &&
|
|
789
|
-
this.terminate &&
|
|
790
|
-
[tunnel_1.TUNNEL_TERMINATE_AT.REGION, tunnel_1.TUNNEL_TERMINATE_AT.TARGET].includes(this.terminate));
|
|
791
|
-
}
|
|
792
|
-
canStreamTls() {
|
|
793
|
-
return this.type === tunnel_1.TUNNEL_TYPE.TLS;
|
|
794
|
-
}
|
|
795
|
-
canStreamSsh() {
|
|
796
|
-
return this.type === tunnel_1.TUNNEL_TYPE.SSH;
|
|
797
|
-
}
|
|
798
|
-
canStreamHttp() {
|
|
799
|
-
return this.type === tunnel_1.TUNNEL_TYPE.HTTP;
|
|
800
|
-
}
|
|
801
|
-
safeEndStream(stream) {
|
|
802
|
-
try {
|
|
803
|
-
stream.removeAllListeners();
|
|
804
|
-
stream.once('error', () => { });
|
|
805
|
-
stream.end();
|
|
806
|
-
}
|
|
807
|
-
catch {
|
|
808
|
-
// do nothing
|
|
809
|
-
}
|
|
810
|
-
setTimeout(() => {
|
|
811
|
-
try {
|
|
812
|
-
stream.destroy();
|
|
813
|
-
}
|
|
814
|
-
catch {
|
|
815
|
-
// do nothing
|
|
816
|
-
}
|
|
817
|
-
}, 1000);
|
|
818
|
-
}
|
|
819
|
-
sshStreamTcp(stream) {
|
|
820
|
-
if (!this.canStreamTcp()) {
|
|
821
|
-
this.safeEndStream(stream);
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
logger_1.default.debug((0, texts_1.LOG_TUNNEL_TCP_STREAM)(this.id));
|
|
825
|
-
this.tunnelToTarget(stream, () => {
|
|
826
|
-
this.emit(tunnel_1.TUNNEL_EVENT.TCP_CLOSED, this);
|
|
827
|
-
});
|
|
828
|
-
this.emit(tunnel_1.TUNNEL_EVENT.TCP_OPEN, this);
|
|
829
|
-
}
|
|
830
|
-
sshStreamHttp1(stream, info, ip) {
|
|
831
|
-
if (!this.canStreamHttp()) {
|
|
832
|
-
this.safeEndStream(stream);
|
|
833
|
-
return;
|
|
834
|
-
}
|
|
835
|
-
logger_1.default.debug((0, texts_1.LOG_TUNNEL_HTTP1_STREAM)(this.id));
|
|
836
|
-
if (this.http1server) {
|
|
837
|
-
this.http1server.handleSshTunnel(stream, info, ip);
|
|
838
|
-
return;
|
|
839
|
-
}
|
|
840
|
-
this.safeEndStream(stream);
|
|
841
|
-
}
|
|
842
|
-
sshStreamHttp2(stream, info, ip) {
|
|
843
|
-
if (!this.canStreamHttp()) {
|
|
844
|
-
this.safeEndStream(stream);
|
|
845
|
-
return;
|
|
846
|
-
}
|
|
847
|
-
logger_1.default.debug((0, texts_1.LOG_TUNNEL_HTTP2_STREAM)(this.id));
|
|
848
|
-
if (this.http2server) {
|
|
849
|
-
this.http2server.handleSshTunnel(stream, info, ip);
|
|
850
|
-
return;
|
|
851
|
-
}
|
|
852
|
-
this.safeEndStream(stream);
|
|
853
|
-
}
|
|
854
|
-
sshStreamSsh(stream) {
|
|
855
|
-
if (!this.canStreamSsh()) {
|
|
856
|
-
this.safeEndStream(stream);
|
|
857
|
-
return;
|
|
858
|
-
}
|
|
859
|
-
logger_1.default.debug((0, texts_1.LOG_TUNNEL_SSH_STREAM)(this.id));
|
|
860
|
-
if (this.sshServer) {
|
|
861
|
-
this.sshServer.handleSshTunnel(stream);
|
|
862
|
-
return;
|
|
863
|
-
}
|
|
864
|
-
this.safeEndStream(stream);
|
|
865
|
-
}
|
|
866
|
-
sshStreamTls(stream) {
|
|
867
|
-
if (!this.canStreamTls()) {
|
|
868
|
-
this.safeEndStream(stream);
|
|
869
|
-
return;
|
|
870
|
-
}
|
|
871
|
-
if (this.terminate === tunnel_1.TUNNEL_TERMINATE_AT.TARGET) {
|
|
872
|
-
logger_1.default.debug((0, texts_1.LOG_TUNNEL_TLS_TARGET_STREAM)(this.id));
|
|
873
|
-
this.sshStreamTcp(stream);
|
|
874
|
-
return;
|
|
875
|
-
}
|
|
876
|
-
if (this.terminate === tunnel_1.TUNNEL_TERMINATE_AT.REGION) {
|
|
877
|
-
logger_1.default.debug((0, texts_1.LOG_TUNNEL_TLS_REGION_STREAM)(this.id));
|
|
878
|
-
this.sshStreamTcp(stream);
|
|
879
|
-
return;
|
|
880
|
-
}
|
|
881
|
-
if (this.tls) {
|
|
882
|
-
logger_1.default.debug((0, texts_1.LOG_TUNNEL_TLS_AGENT_STREAM)(this.id));
|
|
883
|
-
this.tls.handleSshTunnel(stream);
|
|
884
|
-
return;
|
|
885
|
-
}
|
|
886
|
-
this.safeEndStream(stream);
|
|
887
|
-
}
|
|
888
|
-
start() {
|
|
889
|
-
if (this.started ||
|
|
890
|
-
!this.sshIp ||
|
|
891
|
-
!this.sshPort ||
|
|
892
|
-
!this.domain ||
|
|
893
|
-
!this.subdomain ||
|
|
894
|
-
!this.region ||
|
|
895
|
-
!this.sshId ||
|
|
896
|
-
!this.sshUser ||
|
|
897
|
-
!this.sshPassword)
|
|
898
|
-
return;
|
|
899
|
-
this.started = true;
|
|
900
|
-
logger_1.default.info((0, texts_1.LOG_STARTING_TUNNEL)(this.id));
|
|
901
|
-
// region latency
|
|
902
|
-
this.regionLatency = new latency_1.default(this.sshIp, this.sshPort);
|
|
903
|
-
this.regionLatency.startChecking();
|
|
904
|
-
// target latency
|
|
905
|
-
if (!this.serve && this.type !== tunnel_1.TUNNEL_TYPE.SSH) {
|
|
906
|
-
this.targetLatency = new latency_1.default(this.targetHost || '', this.targetPort || 0);
|
|
907
|
-
this.targetLatency.on(tunnel_1.TUNNEL_EVENT_LATENCY.RECONNECTED, () => this.targetReconnected());
|
|
908
|
-
this.targetLatency.startChecking();
|
|
909
|
-
}
|
|
910
|
-
// dns health
|
|
911
|
-
this.dns = new dns_1.default(this.sshIp, this.domain, this.subdomain, this.region, this.sshId);
|
|
912
|
-
this.dns.startChecking();
|
|
913
|
-
if (this.type === tunnel_1.TUNNEL_TYPE.TLS &&
|
|
914
|
-
this.terminate === tunnel_1.TUNNEL_TERMINATE_AT.AGENT) {
|
|
915
|
-
// tls
|
|
916
|
-
this.tls = new tls_1.default(this.key, this.cert, this.ca);
|
|
917
|
-
this.tls.on(tunnel_1.TUNNEL_EVENT.TLS_SOCKET, (socket) => this.tlsSocket(socket));
|
|
918
|
-
}
|
|
919
|
-
else if (this.type === tunnel_1.TUNNEL_TYPE.HTTP) {
|
|
920
|
-
// http
|
|
921
|
-
this.httpLog = new log_1.default(this.log, this.circuitBreaker);
|
|
922
|
-
this.httpLog.on(tunnel_1.TUNNEL_EVENT_HTTP.NEW_REQUEST, (logRequest) => this.httpLogRequest(logRequest));
|
|
923
|
-
this.httpLog.on(tunnel_1.TUNNEL_EVENT_HTTP.NEW_RESPONSE, (logRequest) => this.httpLogResponse(logRequest));
|
|
924
|
-
this.identify = new identification_1.default(this.targetProto || '', this.targetHost || '', this.targetPort || 0, this.http2 || !!this.serve);
|
|
925
|
-
this.identify.on(tunnel_1.TUNNEL_EVENT.IDENTIFIED, (type) => this.httpIdentified(type));
|
|
926
|
-
const host = format_1.default.entryHostEncoded(this);
|
|
927
|
-
this.http2server = new http2_1.default(host);
|
|
928
|
-
this.http2server.on(tunnel_1.TUNNEL_EVENT.HTTP_SESSION_OPEN, (session) => this.httpConnectionOpen(session));
|
|
929
|
-
this.http2server.on(tunnel_1.TUNNEL_EVENT.HTTP_SESSION_CLOSED, (session) => this.httpConnectionClosed(session));
|
|
930
|
-
this.http2server.on(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, async (req, res) => await this.httpRequest(req, res));
|
|
931
|
-
this.http1server = new http1_1.default(host);
|
|
932
|
-
this.http1server.on(tunnel_1.TUNNEL_HTTP_SOCKET.OPEN, (socket) => this.httpConnectionOpen(socket));
|
|
933
|
-
this.http1server.on(tunnel_1.TUNNEL_HTTP_SOCKET.CLOSED, (socket) => this.httpConnectionClosed(socket));
|
|
934
|
-
this.http1server.on(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, async (req, res) => await this.httpRequest(req, res));
|
|
935
|
-
}
|
|
936
|
-
else if (this.type === tunnel_1.TUNNEL_TYPE.SSH) {
|
|
937
|
-
// ssh server
|
|
938
|
-
this.sshServer = new ssh_1.default(this.agent, this.sshClientUser || '', this.sshClientPassword || '', this.sshHostKey);
|
|
939
|
-
}
|
|
940
|
-
// ssh
|
|
941
|
-
this.ssh = new client_1.default(this.sshIp, this.sshPort, this.sshUser, this.sshPassword);
|
|
942
|
-
this.ssh.on(tunnel_1.TUNNEL_SSH_EVENT.CONNECTED, () => this.sshConnected());
|
|
943
|
-
this.ssh.on(tunnel_1.TUNNEL_SSH_EVENT.DISCONNECTED, () => this.sshDisconnected());
|
|
944
|
-
this.ssh.on(tunnel_1.TUNNEL_SSH_EVENT.STREAM_TCP, (stream) => this.sshStreamTcp(stream));
|
|
945
|
-
this.ssh.on(tunnel_1.TUNNEL_SSH_EVENT.STREAM_TLS, (stream) => this.sshStreamTls(stream));
|
|
946
|
-
this.ssh.on(tunnel_1.TUNNEL_SSH_EVENT.STREAM_HTTP1, (stream, info, ip) => this.sshStreamHttp1(stream, info, ip));
|
|
947
|
-
this.ssh.on(tunnel_1.TUNNEL_SSH_EVENT.STREAM_HTTP2, (stream, info, ip) => this.sshStreamHttp2(stream, info, ip));
|
|
948
|
-
this.ssh.on(tunnel_1.TUNNEL_SSH_EVENT.STREAM_SSH, (stream) => this.sshStreamSsh(stream));
|
|
949
|
-
this.ssh.openKeepAlive();
|
|
950
|
-
}
|
|
951
|
-
stop(emitEvent = true) {
|
|
952
|
-
if (!this.started)
|
|
953
|
-
return;
|
|
954
|
-
this.started = false;
|
|
955
|
-
logger_1.default.info((0, texts_1.LOG_STOPPING_TUNNEL)(this.id));
|
|
956
|
-
if (emitEvent)
|
|
957
|
-
this.emit(tunnel_1.TUNNEL_EVENT.STOPPED, this);
|
|
958
|
-
if (this.regionLatency) {
|
|
959
|
-
this.regionLatency.removeAllListeners();
|
|
960
|
-
this.regionLatency.stopChecking();
|
|
961
|
-
this.regionLatency = null;
|
|
962
|
-
}
|
|
963
|
-
if (this.dns) {
|
|
964
|
-
this.dns.stopChecking();
|
|
965
|
-
this.dns = null;
|
|
966
|
-
}
|
|
967
|
-
if (this.targetLatency) {
|
|
968
|
-
this.targetLatency.removeAllListeners();
|
|
969
|
-
this.targetLatency.stopChecking();
|
|
970
|
-
this.targetLatency = null;
|
|
971
|
-
}
|
|
972
|
-
if (this.tls) {
|
|
973
|
-
this.tls.removeAllListeners();
|
|
974
|
-
this.tls.stop();
|
|
975
|
-
this.tls = null;
|
|
976
|
-
}
|
|
977
|
-
if (this.httpLog) {
|
|
978
|
-
this.httpLog.removeAllListeners();
|
|
979
|
-
this.httpLog.stop();
|
|
980
|
-
this.httpLog = null;
|
|
981
|
-
}
|
|
982
|
-
if (this.sshServer) {
|
|
983
|
-
this.sshServer.removeAllListeners();
|
|
984
|
-
this.sshServer.stop();
|
|
985
|
-
this.sshServer = null;
|
|
986
|
-
}
|
|
987
|
-
if (this.identify) {
|
|
988
|
-
this.identify.removeAllListeners();
|
|
989
|
-
this.identify.stop();
|
|
990
|
-
this.identify = null;
|
|
991
|
-
}
|
|
992
|
-
if (this.http2server) {
|
|
993
|
-
this.http2server.removeAllListeners();
|
|
994
|
-
this.http2server.stop();
|
|
995
|
-
this.http2server = null;
|
|
996
|
-
}
|
|
997
|
-
if (this.http1server) {
|
|
998
|
-
this.http1server.removeAllListeners();
|
|
999
|
-
this.http1server.stop();
|
|
1000
|
-
this.http1server = null;
|
|
1001
|
-
}
|
|
1002
|
-
if (this.ssh) {
|
|
1003
|
-
this.ssh.removeAllListeners();
|
|
1004
|
-
this.ssh.closeKeepAlive();
|
|
1005
|
-
this.ssh = null;
|
|
1006
|
-
}
|
|
1007
|
-
this.status = tunnel_1.TUNNEL_STATUS.CLOSED;
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
exports.default = Tunnel;
|