bdy 1.12.8-dev → 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,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const https_1 = require("https");
|
|
7
|
-
const events_1 = __importDefault(require("events"));
|
|
8
|
-
const logger_1 = __importDefault(require("../../logger"));
|
|
9
|
-
const texts_1 = require("../../texts");
|
|
10
|
-
const utils_1 = require("../../utils");
|
|
11
|
-
const socket_io_client_1 = require("socket.io-client");
|
|
12
|
-
const tunnel_1 = require("../../types/tunnel");
|
|
13
|
-
const MAX_REQUESTS_SYNC_WINDOW = 30000;
|
|
14
|
-
const MAX_REQUESTS_SYNC_IN_WINDOW = 100;
|
|
15
|
-
class AgentSocketClient extends events_1.default {
|
|
16
|
-
socket;
|
|
17
|
-
id;
|
|
18
|
-
token;
|
|
19
|
-
hostname;
|
|
20
|
-
platform;
|
|
21
|
-
version;
|
|
22
|
-
connected;
|
|
23
|
-
lastUpdate;
|
|
24
|
-
tunnelRequests;
|
|
25
|
-
fetch(activate = true, action = null, disabled = null, resetFirstHeard = false, tunnels) {
|
|
26
|
-
if (!this.socket)
|
|
27
|
-
return;
|
|
28
|
-
this.socket.emit('fetchTunnelAgent', {
|
|
29
|
-
id: this.id,
|
|
30
|
-
token: this.token,
|
|
31
|
-
hostname: this.hostname,
|
|
32
|
-
platform: this.platform,
|
|
33
|
-
version: this.version,
|
|
34
|
-
activate,
|
|
35
|
-
action,
|
|
36
|
-
disabled,
|
|
37
|
-
resetFirstHeard,
|
|
38
|
-
tunnels,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
update(activate, tunnels, force = false) {
|
|
42
|
-
if (!this.socket)
|
|
43
|
-
return;
|
|
44
|
-
const now = Date.now();
|
|
45
|
-
// nie robimy update jak byl mniej niz 5s temu
|
|
46
|
-
if (!force && this.lastUpdate && now - this.lastUpdate < 5000)
|
|
47
|
-
return;
|
|
48
|
-
this.lastUpdate = now;
|
|
49
|
-
this.socket.emit('updateTunnelAgent', {
|
|
50
|
-
id: this.id,
|
|
51
|
-
token: this.token,
|
|
52
|
-
hostname: this.hostname,
|
|
53
|
-
platform: this.platform,
|
|
54
|
-
version: this.version,
|
|
55
|
-
activate,
|
|
56
|
-
tunnels,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
emitRequest(tunnelId, logRequest) {
|
|
60
|
-
if (!this.socket)
|
|
61
|
-
return;
|
|
62
|
-
this.socket.emit('tunnelRequest', {
|
|
63
|
-
id: this.id,
|
|
64
|
-
token: this.token,
|
|
65
|
-
tunnelId,
|
|
66
|
-
request: logRequest.toSocket(),
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
request(tunnelId, logRequest) {
|
|
70
|
-
if (this.tunnelRequests > MAX_REQUESTS_SYNC_IN_WINDOW)
|
|
71
|
-
return;
|
|
72
|
-
this.tunnelRequests += 1;
|
|
73
|
-
logRequest.once(tunnel_1.TUNNEL_EVENT_HTTP.NEW_RESPONSE_END, () => {
|
|
74
|
-
this.emitRequest(tunnelId, logRequest);
|
|
75
|
-
});
|
|
76
|
-
this.emitRequest(tunnelId, logRequest);
|
|
77
|
-
}
|
|
78
|
-
onSyncAgent(data, action) {
|
|
79
|
-
this.emit(tunnel_1.TUNNEL_SOCKET_EVENT.AGENT, data, action);
|
|
80
|
-
}
|
|
81
|
-
onSyncTunnel(data, action) {
|
|
82
|
-
this.emit(tunnel_1.TUNNEL_SOCKET_EVENT.TUNNEL, data, action);
|
|
83
|
-
}
|
|
84
|
-
onSync(data) {
|
|
85
|
-
try {
|
|
86
|
-
const json = JSON.parse(data);
|
|
87
|
-
if (json.payloadType === 'TunnelAgentFront')
|
|
88
|
-
this.onSyncAgent(json.payload, json.action);
|
|
89
|
-
else if (json.payloadType === 'TunnelFront')
|
|
90
|
-
this.onSyncTunnel(json.payload, json.action);
|
|
91
|
-
}
|
|
92
|
-
catch {
|
|
93
|
-
// do nothing
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
connect(atOnce) {
|
|
97
|
-
logger_1.default.debug('socket connect');
|
|
98
|
-
if (atOnce && this.socket && !this.socket.connected) {
|
|
99
|
-
this.socket.connect();
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
setTimeout(() => {
|
|
103
|
-
if (this.socket && !this.socket.connected)
|
|
104
|
-
this.socket.connect();
|
|
105
|
-
}, 3000);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
destroy() {
|
|
109
|
-
if (this.socket) {
|
|
110
|
-
this.socket.removeAllListeners();
|
|
111
|
-
this.socket.disconnect();
|
|
112
|
-
this.socket = null;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
constructor(host, id, token) {
|
|
116
|
-
super();
|
|
117
|
-
this.id = id;
|
|
118
|
-
this.token = token;
|
|
119
|
-
this.connected = false;
|
|
120
|
-
this.hostname = (0, utils_1.getHostname)();
|
|
121
|
-
this.platform = (0, utils_1.getPlatform)();
|
|
122
|
-
this.version = (0, utils_1.getVersion)();
|
|
123
|
-
this.lastUpdate = null;
|
|
124
|
-
this.tunnelRequests = 0;
|
|
125
|
-
setInterval(() => {
|
|
126
|
-
this.tunnelRequests = 0;
|
|
127
|
-
}, MAX_REQUESTS_SYNC_WINDOW);
|
|
128
|
-
this.socket = (0, socket_io_client_1.io)(host, {
|
|
129
|
-
forceNew: true,
|
|
130
|
-
autoConnect: false,
|
|
131
|
-
autoUnref: true,
|
|
132
|
-
forceBase64: true,
|
|
133
|
-
transports: ['websocket'],
|
|
134
|
-
reconnection: false,
|
|
135
|
-
rejectUnauthorized: false,
|
|
136
|
-
// @ts-ignore
|
|
137
|
-
agent: new https_1.Agent({
|
|
138
|
-
rejectUnauthorized: false,
|
|
139
|
-
}),
|
|
140
|
-
maxHttpBufferSize: 3e6,
|
|
141
|
-
extraHeaders: {
|
|
142
|
-
cookie: 'a=b',
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
this.socket.on('connect', () => {
|
|
146
|
-
if (!this.socket)
|
|
147
|
-
return;
|
|
148
|
-
this.connected = true;
|
|
149
|
-
logger_1.default.info(texts_1.LOG_SOCKET_CONNECTED);
|
|
150
|
-
this.emit(tunnel_1.TUNNEL_SOCKET_EVENT.CONNECTED);
|
|
151
|
-
this.socket.emit('joinTunnelAgent', {
|
|
152
|
-
id: this.id,
|
|
153
|
-
token: this.token,
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
this.socket.on('disconnect', () => {
|
|
157
|
-
this.connected = false;
|
|
158
|
-
logger_1.default.info(texts_1.LOG_SOCKET_DISCONNECTED);
|
|
159
|
-
this.emit(tunnel_1.TUNNEL_SOCKET_EVENT.DISCONNECTED);
|
|
160
|
-
this.connect();
|
|
161
|
-
});
|
|
162
|
-
this.socket.on('connect_error', () => {
|
|
163
|
-
logger_1.default.debug('socket error');
|
|
164
|
-
this.connect();
|
|
165
|
-
});
|
|
166
|
-
this.socket.on('fetchTunnelAgentSuccess', (data) => {
|
|
167
|
-
logger_1.default.debug('Socket fetch success');
|
|
168
|
-
this.emit(tunnel_1.TUNNEL_SOCKET_EVENT.FETCH_SUCCESS, data);
|
|
169
|
-
});
|
|
170
|
-
this.socket.on('fetchTunnelAgentFailed', (code) => {
|
|
171
|
-
logger_1.default.debug('Socket fetch failed');
|
|
172
|
-
this.emit(tunnel_1.TUNNEL_SOCKET_EVENT.FETCH_FAILED, (0, utils_1.apiErrorCodeToClass)(code, host));
|
|
173
|
-
});
|
|
174
|
-
this.socket.on('sync', (data) => this.onSync(data));
|
|
175
|
-
this.connect(true);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
exports.default = AgentSocketClient;
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const texts_1 = require("../../texts");
|
|
7
|
-
const events_1 = __importDefault(require("events"));
|
|
8
|
-
const utils_1 = require("../../utils");
|
|
9
|
-
const tunnel_1 = require("../../types/tunnel");
|
|
10
|
-
class AgentSocketTunnel extends events_1.default {
|
|
11
|
-
id;
|
|
12
|
-
closed;
|
|
13
|
-
ready;
|
|
14
|
-
socket;
|
|
15
|
-
httpLog;
|
|
16
|
-
regionLatency;
|
|
17
|
-
targetLatency;
|
|
18
|
-
identify;
|
|
19
|
-
sshForwardPort;
|
|
20
|
-
domain;
|
|
21
|
-
sshId;
|
|
22
|
-
subdomain;
|
|
23
|
-
terminate;
|
|
24
|
-
target;
|
|
25
|
-
type;
|
|
26
|
-
region;
|
|
27
|
-
status;
|
|
28
|
-
log;
|
|
29
|
-
serve;
|
|
30
|
-
totalConnections;
|
|
31
|
-
connections;
|
|
32
|
-
dns;
|
|
33
|
-
constructor(socket, id) {
|
|
34
|
-
super();
|
|
35
|
-
this.id = id;
|
|
36
|
-
this.ready = false;
|
|
37
|
-
this.closed = false;
|
|
38
|
-
this.socket = socket;
|
|
39
|
-
this.socket.on('close', () => this.onClose());
|
|
40
|
-
this.socket.on('message', (msg) => this.onMessage(msg));
|
|
41
|
-
this.socket.send(JSON.stringify({
|
|
42
|
-
message: tunnel_1.TUNNEL_SOCKET_MESSAGE.READY,
|
|
43
|
-
}));
|
|
44
|
-
}
|
|
45
|
-
close() {
|
|
46
|
-
if (this.socket) {
|
|
47
|
-
this.socket.close();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
onTunnelRequests(data) {
|
|
51
|
-
this.httpLog = {
|
|
52
|
-
requests: data.requests.map((r) => {
|
|
53
|
-
r.requestBody = {
|
|
54
|
-
data: Buffer.from(r.requestBody.data, 'base64'),
|
|
55
|
-
tooLarge: r.requestBody.tooLarge,
|
|
56
|
-
realLength: r.requestBody.realLength,
|
|
57
|
-
};
|
|
58
|
-
r.responseBody = {
|
|
59
|
-
data: Buffer.from(r.responseBody.data, 'base64'),
|
|
60
|
-
tooLarge: r.responseBody.tooLarge,
|
|
61
|
-
realLength: r.responseBody.realLength,
|
|
62
|
-
};
|
|
63
|
-
return r;
|
|
64
|
-
}),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
onTunnelData(data) {
|
|
68
|
-
if (data.regionLatency)
|
|
69
|
-
this.regionLatency = data.regionLatency;
|
|
70
|
-
if (data.targetLatency)
|
|
71
|
-
this.targetLatency = data.targetLatency;
|
|
72
|
-
if (data.identify)
|
|
73
|
-
this.identify = data.identify;
|
|
74
|
-
if (data.dns)
|
|
75
|
-
this.dns = data.dns;
|
|
76
|
-
if (data.connections)
|
|
77
|
-
this.connections = data.connections;
|
|
78
|
-
this.totalConnections = data.totalConnections;
|
|
79
|
-
this.serve = data.serve;
|
|
80
|
-
this.log = data.log;
|
|
81
|
-
this.status = data.status;
|
|
82
|
-
this.region = data.region;
|
|
83
|
-
this.type = data.type;
|
|
84
|
-
this.target = data.target;
|
|
85
|
-
this.terminate = data.terminate;
|
|
86
|
-
this.id = data.id;
|
|
87
|
-
this.subdomain = data.subdomain;
|
|
88
|
-
this.sshId = data.sshId;
|
|
89
|
-
this.domain = data.domain;
|
|
90
|
-
this.sshForwardPort = data.sshForwardPort;
|
|
91
|
-
}
|
|
92
|
-
upsertHttpLog(data) {
|
|
93
|
-
if (!this.httpLog || !this.httpLog.requests || !this.log)
|
|
94
|
-
return;
|
|
95
|
-
/**
|
|
96
|
-
* @type {object}
|
|
97
|
-
*/
|
|
98
|
-
const r = this.httpLog.requests.find((r) => r.id === data.id);
|
|
99
|
-
if (!r) {
|
|
100
|
-
data.requestBody = {
|
|
101
|
-
data: Buffer.from(data.requestBody.data, 'base64'),
|
|
102
|
-
tooLarge: data.requestBody.tooLarge,
|
|
103
|
-
realLength: data.requestBody.realLength,
|
|
104
|
-
};
|
|
105
|
-
data.responseBody = {
|
|
106
|
-
data: Buffer.from(data.responseBody.data, 'base64'),
|
|
107
|
-
tooLarge: data.responseBody.tooLarge,
|
|
108
|
-
realLength: data.responseBody.realLength,
|
|
109
|
-
};
|
|
110
|
-
this.httpLog.requests.unshift(data);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
r.finished = data.finished;
|
|
114
|
-
r.time = data.time;
|
|
115
|
-
r.httpVersion = data.httpVersion;
|
|
116
|
-
r.requestBody = {
|
|
117
|
-
data: Buffer.from(data.requestBody.data, 'base64'),
|
|
118
|
-
tooLarge: data.requestBody.tooLarge,
|
|
119
|
-
realLength: data.requestBody.realLength,
|
|
120
|
-
};
|
|
121
|
-
r.responseBody = {
|
|
122
|
-
data: Buffer.from(data.responseBody.data, 'base64'),
|
|
123
|
-
tooLarge: data.responseBody.tooLarge,
|
|
124
|
-
realLength: data.responseBody.realLength,
|
|
125
|
-
};
|
|
126
|
-
r.headers = data.headers;
|
|
127
|
-
r.status = data.status;
|
|
128
|
-
r.url = data.url;
|
|
129
|
-
r.method = data.method;
|
|
130
|
-
}
|
|
131
|
-
if (this.httpLog.requests.length > utils_1.TUNNEL_HTTP_LOG_MAX_REQUESTS)
|
|
132
|
-
this.httpLog.requests.pop();
|
|
133
|
-
}
|
|
134
|
-
onMessage(msg) {
|
|
135
|
-
try {
|
|
136
|
-
const json = JSON.parse(msg.toString('utf8'));
|
|
137
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL) {
|
|
138
|
-
this.onTunnelData(json);
|
|
139
|
-
this.ready = true;
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_REQUESTS) {
|
|
143
|
-
this.onTunnelRequests(json);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_OPEN) {
|
|
147
|
-
this.emit(tunnel_1.TUNNEL_EVENT.OPEN, json);
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_CLOSED) {
|
|
151
|
-
this.emit(tunnel_1.TUNNEL_EVENT.CLOSED, json);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TCP_OPEN) {
|
|
155
|
-
this.emit(tunnel_1.TUNNEL_EVENT.TCP_OPEN, json);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TCP_CLOSED) {
|
|
159
|
-
this.emit(tunnel_1.TUNNEL_EVENT.TCP_CLOSED, json);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TLS_OPEN) {
|
|
163
|
-
this.emit(tunnel_1.TUNNEL_EVENT.TLS_OPEN, json);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TLS_CLOSED) {
|
|
167
|
-
this.emit(tunnel_1.TUNNEL_EVENT.TLS_CLOSED, json);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_IDENTIFIED) {
|
|
171
|
-
this.emit(tunnel_1.TUNNEL_EVENT.HTTP_IDENTIFIED, json, json.identify);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_REQUEST) {
|
|
175
|
-
this.upsertHttpLog(json.logRequest);
|
|
176
|
-
this.emit(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, json, json.logRequest);
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_RESPONSE) {
|
|
180
|
-
this.upsertHttpLog(json.logRequest);
|
|
181
|
-
this.emit(tunnel_1.TUNNEL_EVENT.HTTP_RESPONSE, json, json.logRequest);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_STOPPED) {
|
|
185
|
-
this.emit(tunnel_1.TUNNEL_EVENT.STOPPED, json);
|
|
186
|
-
this.close();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
catch {
|
|
190
|
-
this.close();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
onClose() {
|
|
194
|
-
this.emit(tunnel_1.TUNNEL_EVENT.STOPPED);
|
|
195
|
-
if (this.socket) {
|
|
196
|
-
try {
|
|
197
|
-
this.socket.removeAllListeners();
|
|
198
|
-
this.socket.close();
|
|
199
|
-
}
|
|
200
|
-
catch {
|
|
201
|
-
// do nothing
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
this.closed = true;
|
|
205
|
-
this.socket = null;
|
|
206
|
-
}
|
|
207
|
-
retryHttpLogRequest(logRequest) {
|
|
208
|
-
if (this.socket) {
|
|
209
|
-
this.socket.send(JSON.stringify({
|
|
210
|
-
message: tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_RETRY,
|
|
211
|
-
logRequest,
|
|
212
|
-
}));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
waitForReady() {
|
|
216
|
-
return new Promise((resolve, reject) => {
|
|
217
|
-
const ts1 = setInterval(() => {
|
|
218
|
-
if (this.ready) {
|
|
219
|
-
clearInterval(ts1);
|
|
220
|
-
clearTimeout(ts2);
|
|
221
|
-
resolve();
|
|
222
|
-
}
|
|
223
|
-
else if (this.closed) {
|
|
224
|
-
clearInterval(ts1);
|
|
225
|
-
clearTimeout(ts2);
|
|
226
|
-
reject(new Error((0, texts_1.ERR_TUNNEL_NOT_FOUND)(this.id)));
|
|
227
|
-
}
|
|
228
|
-
}, 100);
|
|
229
|
-
const ts2 = setTimeout(() => {
|
|
230
|
-
clearInterval(ts1);
|
|
231
|
-
clearTimeout(ts2);
|
|
232
|
-
reject(new Error((0, texts_1.ERR_TUNNEL_NOT_FOUND)(this.id)));
|
|
233
|
-
}, 3000);
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
exports.default = AgentSocketTunnel;
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tunnel_1 = require("../types/tunnel");
|
|
4
|
-
class AgentSocket {
|
|
5
|
-
tunnel;
|
|
6
|
-
socket;
|
|
7
|
-
ready;
|
|
8
|
-
ts;
|
|
9
|
-
boundEventStopped;
|
|
10
|
-
boundEventOpen;
|
|
11
|
-
boundEventClosed;
|
|
12
|
-
boundEventTcpOpen;
|
|
13
|
-
boundEventTcpClosed;
|
|
14
|
-
boundEventTlsOpen;
|
|
15
|
-
boundEventTlsClosed;
|
|
16
|
-
boundEventHttpIdentified;
|
|
17
|
-
boundEventHttpRequest;
|
|
18
|
-
boundEventHttpResponse;
|
|
19
|
-
constructor(socket, tunnel) {
|
|
20
|
-
this.tunnel = tunnel;
|
|
21
|
-
this.socket = socket;
|
|
22
|
-
this.ready = false;
|
|
23
|
-
this.socket.on('close', () => this.close());
|
|
24
|
-
this.socket.on('message', (msg) => this.onMessage(msg));
|
|
25
|
-
this.boundEventStopped = (t) => this.tunnelStopped(t);
|
|
26
|
-
this.boundEventOpen = (t) => this.tunnelOpen(t);
|
|
27
|
-
this.boundEventClosed = (t) => this.tunnelClosed(t);
|
|
28
|
-
this.boundEventTcpOpen = (t) => this.tunnelTcpOpen(t);
|
|
29
|
-
this.boundEventTcpClosed = (t) => this.tunnelTcpClosed(t);
|
|
30
|
-
this.boundEventTlsOpen = (t) => this.tunnelTlsOpen(t);
|
|
31
|
-
this.boundEventTlsClosed = (t) => this.tunnelTlsClosed(t);
|
|
32
|
-
this.boundEventHttpIdentified = (t, type) => this.tunnelHttpIdentified(t, type);
|
|
33
|
-
this.boundEventHttpRequest = (t, logRequest) => this.tunnelHttpRequest(t, logRequest);
|
|
34
|
-
this.boundEventHttpResponse = (t, logRequest) => this.tunnelHttpResponse(t, logRequest);
|
|
35
|
-
this.tunnel.on(tunnel_1.TUNNEL_EVENT.STOPPED, this.boundEventStopped);
|
|
36
|
-
this.tunnel.on(tunnel_1.TUNNEL_EVENT.OPEN, this.boundEventOpen);
|
|
37
|
-
this.tunnel.on(tunnel_1.TUNNEL_EVENT.CLOSED, this.boundEventClosed);
|
|
38
|
-
this.tunnel.on(tunnel_1.TUNNEL_EVENT.TCP_OPEN, this.boundEventTcpOpen);
|
|
39
|
-
this.tunnel.on(tunnel_1.TUNNEL_EVENT.TCP_CLOSED, this.boundEventTcpClosed);
|
|
40
|
-
this.tunnel.on(tunnel_1.TUNNEL_EVENT.TLS_OPEN, this.boundEventTlsOpen);
|
|
41
|
-
this.tunnel.on(tunnel_1.TUNNEL_EVENT.TLS_CLOSED, this.boundEventTlsClosed);
|
|
42
|
-
this.tunnel.on(tunnel_1.TUNNEL_EVENT.HTTP_IDENTIFIED, this.boundEventHttpIdentified);
|
|
43
|
-
this.tunnel.on(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, this.boundEventHttpRequest);
|
|
44
|
-
this.tunnel.on(tunnel_1.TUNNEL_EVENT.HTTP_RESPONSE, this.boundEventHttpResponse);
|
|
45
|
-
}
|
|
46
|
-
onMessage(message) {
|
|
47
|
-
try {
|
|
48
|
-
const json = JSON.parse(message.toString('utf8'));
|
|
49
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.READY) {
|
|
50
|
-
this.ready = true;
|
|
51
|
-
this.ts = setInterval(() => {
|
|
52
|
-
this.sendTunnel();
|
|
53
|
-
}, 100);
|
|
54
|
-
this.sendTunnel();
|
|
55
|
-
this.sendRequests();
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_RETRY &&
|
|
59
|
-
this.ready) {
|
|
60
|
-
this.retryHttpRequest(json.logRequest);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// do nothing
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
retryHttpRequest(logRequest) {
|
|
68
|
-
if (!this.tunnel)
|
|
69
|
-
return;
|
|
70
|
-
this.tunnel.retryHttpLogRequest(logRequest);
|
|
71
|
-
}
|
|
72
|
-
send(message, data = {}) {
|
|
73
|
-
if (this.socket && this.ready) {
|
|
74
|
-
this.socket.send(JSON.stringify({
|
|
75
|
-
message,
|
|
76
|
-
...data,
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
sendEvent(message, t, data = {}) {
|
|
81
|
-
this.send(message, {
|
|
82
|
-
type: t.type,
|
|
83
|
-
serve: t.serve,
|
|
84
|
-
target: t.target,
|
|
85
|
-
subdomain: t.subdomain,
|
|
86
|
-
domain: t.domain,
|
|
87
|
-
sshId: t.sshId,
|
|
88
|
-
sshForwardPort: t.sshForwardPort,
|
|
89
|
-
...data,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
tunnelOpen(t) {
|
|
93
|
-
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_OPEN, t);
|
|
94
|
-
}
|
|
95
|
-
tunnelClosed(t) {
|
|
96
|
-
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_CLOSED, t);
|
|
97
|
-
}
|
|
98
|
-
tunnelTcpOpen(t) {
|
|
99
|
-
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TCP_OPEN, t);
|
|
100
|
-
}
|
|
101
|
-
tunnelTcpClosed(t) {
|
|
102
|
-
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TCP_CLOSED, t);
|
|
103
|
-
}
|
|
104
|
-
tunnelTlsOpen(t) {
|
|
105
|
-
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TLS_OPEN, t);
|
|
106
|
-
}
|
|
107
|
-
tunnelTlsClosed(t) {
|
|
108
|
-
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TLS_CLOSED, t);
|
|
109
|
-
}
|
|
110
|
-
tunnelHttpIdentified(t, type) {
|
|
111
|
-
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_IDENTIFIED, t, {
|
|
112
|
-
identify: type,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
logRequestToSocket(logRequest) {
|
|
116
|
-
return {
|
|
117
|
-
id: logRequest.id,
|
|
118
|
-
finished: logRequest.finished,
|
|
119
|
-
time: logRequest.time,
|
|
120
|
-
httpVersion: logRequest.httpVersion,
|
|
121
|
-
requestBody: {
|
|
122
|
-
data: logRequest.requestBody.data.toString('base64'),
|
|
123
|
-
tooLarge: logRequest.requestBody.tooLarge,
|
|
124
|
-
realLength: logRequest.requestBody.realLength,
|
|
125
|
-
},
|
|
126
|
-
responseBody: {
|
|
127
|
-
data: logRequest.responseBody.data.toString('base64'),
|
|
128
|
-
tooLarge: logRequest.responseBody.tooLarge,
|
|
129
|
-
realLength: logRequest.responseBody.realLength,
|
|
130
|
-
},
|
|
131
|
-
headers: logRequest.headers,
|
|
132
|
-
status: logRequest.status,
|
|
133
|
-
url: logRequest.url,
|
|
134
|
-
method: logRequest.method,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
tunnelHttpRequest(t, logRequest) {
|
|
138
|
-
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_REQUEST, t, {
|
|
139
|
-
logRequest: this.logRequestToSocket(logRequest),
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
tunnelHttpResponse(t, logRequest) {
|
|
143
|
-
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_RESPONSE, t, {
|
|
144
|
-
logRequest: this.logRequestToSocket(logRequest),
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
tunnelStopped(t) {
|
|
148
|
-
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_STOPPED, t);
|
|
149
|
-
this.close();
|
|
150
|
-
}
|
|
151
|
-
sendRequests() {
|
|
152
|
-
let requests = [];
|
|
153
|
-
if (this.tunnel?.httpLog) {
|
|
154
|
-
requests = this.tunnel.httpLog.requests.map((lr) => this.logRequestToSocket(lr));
|
|
155
|
-
}
|
|
156
|
-
this.send(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_REQUESTS, {
|
|
157
|
-
requests,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
sendTunnel() {
|
|
161
|
-
const connections = {};
|
|
162
|
-
Object.keys(this.tunnel?.connections || {}).forEach((id) => {
|
|
163
|
-
connections[id] = true;
|
|
164
|
-
});
|
|
165
|
-
const regionLatency = {
|
|
166
|
-
latency: -1,
|
|
167
|
-
};
|
|
168
|
-
if (this.tunnel?.regionLatency) {
|
|
169
|
-
regionLatency.latency = this.tunnel.regionLatency.latency;
|
|
170
|
-
}
|
|
171
|
-
const targetLatency = {
|
|
172
|
-
latency: -1,
|
|
173
|
-
};
|
|
174
|
-
if (this.tunnel?.targetLatency) {
|
|
175
|
-
targetLatency.latency = this.tunnel.targetLatency.latency;
|
|
176
|
-
}
|
|
177
|
-
let identify = null;
|
|
178
|
-
if (this.tunnel?.identify) {
|
|
179
|
-
identify = {
|
|
180
|
-
type: this.tunnel.identify.type,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
const dns = {
|
|
184
|
-
checking: false,
|
|
185
|
-
valid: false,
|
|
186
|
-
};
|
|
187
|
-
if (this.tunnel?.dns) {
|
|
188
|
-
dns.checking = this.tunnel.dns.checking;
|
|
189
|
-
dns.valid = this.tunnel.dns.valid;
|
|
190
|
-
}
|
|
191
|
-
this.send(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL, {
|
|
192
|
-
regionLatency,
|
|
193
|
-
targetLatency,
|
|
194
|
-
connections,
|
|
195
|
-
identify,
|
|
196
|
-
dns,
|
|
197
|
-
totalConnections: this.tunnel?.totalConnections,
|
|
198
|
-
serve: this.tunnel?.serve,
|
|
199
|
-
log: this.tunnel?.log,
|
|
200
|
-
status: this.tunnel?.status,
|
|
201
|
-
region: this.tunnel?.region,
|
|
202
|
-
type: this.tunnel?.type,
|
|
203
|
-
target: this.tunnel?.target,
|
|
204
|
-
terminate: this.tunnel?.terminate,
|
|
205
|
-
id: this.tunnel?.id,
|
|
206
|
-
subdomain: this.tunnel?.subdomain,
|
|
207
|
-
domain: this.tunnel?.domain,
|
|
208
|
-
sshId: this.tunnel?.sshId,
|
|
209
|
-
sshForwardPort: this.tunnel?.sshForwardPort,
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
close() {
|
|
213
|
-
if (this.ts) {
|
|
214
|
-
clearInterval(this.ts);
|
|
215
|
-
}
|
|
216
|
-
this.ts = null;
|
|
217
|
-
if (this.socket) {
|
|
218
|
-
try {
|
|
219
|
-
this.socket.removeAllListeners();
|
|
220
|
-
this.socket.close();
|
|
221
|
-
}
|
|
222
|
-
catch {
|
|
223
|
-
// do nothing
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
this.socket = null;
|
|
227
|
-
if (this.tunnel) {
|
|
228
|
-
this.tunnel.removeListener(tunnel_1.TUNNEL_EVENT.OPEN, this.boundEventOpen);
|
|
229
|
-
this.tunnel.removeListener(tunnel_1.TUNNEL_EVENT.CLOSED, this.boundEventClosed);
|
|
230
|
-
this.tunnel.removeListener(tunnel_1.TUNNEL_EVENT.TCP_OPEN, this.boundEventTcpOpen);
|
|
231
|
-
this.tunnel.removeListener(tunnel_1.TUNNEL_EVENT.TCP_CLOSED, this.boundEventTcpClosed);
|
|
232
|
-
this.tunnel.removeListener(tunnel_1.TUNNEL_EVENT.HTTP_IDENTIFIED, this.boundEventHttpIdentified);
|
|
233
|
-
this.tunnel.removeListener(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, this.boundEventHttpRequest);
|
|
234
|
-
this.tunnel.removeListener(tunnel_1.TUNNEL_EVENT.HTTP_RESPONSE, this.boundEventHttpResponse);
|
|
235
|
-
this.tunnel.removeListener(tunnel_1.TUNNEL_EVENT.TLS_OPEN, this.boundEventTlsOpen);
|
|
236
|
-
this.tunnel.removeListener(tunnel_1.TUNNEL_EVENT.TLS_CLOSED, this.boundEventTlsClosed);
|
|
237
|
-
this.tunnel.removeListener(tunnel_1.TUNNEL_EVENT.STOPPED, this.boundEventStopped);
|
|
238
|
-
}
|
|
239
|
-
this.tunnel = null;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
exports.default = AgentSocket;
|