bdy 1.11.0-dev → 1.12.0-dev
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 +16 -5
- package/distTs/src/agent/agent.js +62 -36
- package/distTs/src/agent/linux.js +9 -4
- package/distTs/src/agent/manager.js +61 -42
- package/distTs/src/agent/osx.js +12 -5
- package/distTs/src/agent/socket/client.js +26 -7
- package/distTs/src/agent/socket/tunnel.js +56 -32
- package/distTs/src/agent/socket.js +83 -63
- package/distTs/src/agent/system.js +3 -1
- package/distTs/src/agent/windows.js +6 -6
- package/distTs/src/command/agent/install.js +4 -4
- package/distTs/src/command/agent/run.js +2 -2
- package/distTs/src/command/agent/status.js +6 -7
- package/distTs/src/command/agent/tunnel/http.js +4 -5
- package/distTs/src/command/agent/tunnel/tcp.js +3 -3
- package/distTs/src/command/agent/tunnel/tls.js +3 -3
- package/distTs/src/command/config/add/http.js +3 -3
- package/distTs/src/command/config/add/tcp.js +3 -3
- package/distTs/src/command/config/add/tls.js +3 -3
- package/distTs/src/command/config/get/region.js +1 -1
- package/distTs/src/command/pre.js +1 -1
- package/distTs/src/command/tunnel/http.js +2 -1
- package/distTs/src/command/tunnel/tcp.js +3 -3
- package/distTs/src/command/tunnel/tls.js +4 -4
- package/distTs/src/format.js +14 -15
- package/distTs/src/index.js +1 -1
- package/distTs/src/input.js +13 -12
- package/distTs/src/logger.js +12 -13
- package/distTs/src/tunnel/agent.js +3 -1
- package/distTs/src/tunnel/api/agent.js +1 -0
- package/distTs/src/tunnel/api/buddy.js +2 -0
- package/distTs/src/tunnel/cfg.js +6 -2
- package/distTs/src/tunnel/compression.js +17 -14
- package/distTs/src/tunnel/dns.js +20 -29
- package/distTs/src/tunnel/html.js +2 -0
- package/distTs/src/tunnel/http/log.js +30 -8
- package/distTs/src/tunnel/http/serve.js +3 -2
- package/distTs/src/tunnel/http/stream.js +5 -1
- package/distTs/src/tunnel/http.js +67 -26
- package/distTs/src/tunnel/identification.js +21 -14
- package/distTs/src/tunnel/latency.js +19 -11
- package/distTs/src/tunnel/output/interactive/tunnel.js +16 -9
- package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +4 -2
- package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +6 -4
- package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +2 -0
- package/distTs/src/tunnel/output/noninteractive/tunnel.js +13 -11
- package/distTs/src/tunnel/server/cert.js +2 -0
- package/distTs/src/tunnel/server/http1.js +15 -10
- package/distTs/src/tunnel/server/http2.js +18 -12
- package/distTs/src/tunnel/server/sftp.js +32 -15
- package/distTs/src/tunnel/server/ssh.js +49 -31
- package/distTs/src/tunnel/server/tls.js +11 -5
- package/distTs/src/tunnel/ssh/client.js +45 -31
- package/distTs/src/tunnel/tcp.js +61 -42
- package/distTs/src/tunnel/tunnel.js +196 -112
- package/distTs/src/types/tunnel.js +135 -0
- package/distTs/src/utils.js +2 -87
- package/package.json +16 -5
|
@@ -9,10 +9,22 @@ const logger_1 = __importDefault(require("../../logger"));
|
|
|
9
9
|
const texts_1 = require("../../texts");
|
|
10
10
|
const utils_1 = require("../../utils");
|
|
11
11
|
const socket_io_client_1 = require("socket.io-client");
|
|
12
|
+
const tunnel_1 = require("../../types/tunnel");
|
|
12
13
|
const MAX_REQUESTS_SYNC_WINDOW = 30000;
|
|
13
14
|
const MAX_REQUESTS_SYNC_IN_WINDOW = 100;
|
|
14
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;
|
|
15
25
|
fetch(activate = true, action = null, disabled = null, resetFirstHeard = false, tunnels) {
|
|
26
|
+
if (!this.socket)
|
|
27
|
+
return;
|
|
16
28
|
this.socket.emit('fetchTunnelAgent', {
|
|
17
29
|
id: this.id,
|
|
18
30
|
token: this.token,
|
|
@@ -27,6 +39,8 @@ class AgentSocketClient extends events_1.default {
|
|
|
27
39
|
});
|
|
28
40
|
}
|
|
29
41
|
update(activate, tunnels, force = false) {
|
|
42
|
+
if (!this.socket)
|
|
43
|
+
return;
|
|
30
44
|
const now = Date.now();
|
|
31
45
|
// nie robimy update jak byl mniej niz 5s temu
|
|
32
46
|
if (!force && this.lastUpdate && now - this.lastUpdate < 5000)
|
|
@@ -43,6 +57,8 @@ class AgentSocketClient extends events_1.default {
|
|
|
43
57
|
});
|
|
44
58
|
}
|
|
45
59
|
emitRequest(tunnelId, logRequest) {
|
|
60
|
+
if (!this.socket)
|
|
61
|
+
return;
|
|
46
62
|
this.socket.emit('tunnelRequest', {
|
|
47
63
|
id: this.id,
|
|
48
64
|
token: this.token,
|
|
@@ -54,16 +70,16 @@ class AgentSocketClient extends events_1.default {
|
|
|
54
70
|
if (this.tunnelRequests > MAX_REQUESTS_SYNC_IN_WINDOW)
|
|
55
71
|
return;
|
|
56
72
|
this.tunnelRequests += 1;
|
|
57
|
-
logRequest.once(
|
|
73
|
+
logRequest.once(tunnel_1.TUNNEL_EVENT_HTTP.NEW_RESPONSE_END, () => {
|
|
58
74
|
this.emitRequest(tunnelId, logRequest);
|
|
59
75
|
});
|
|
60
76
|
this.emitRequest(tunnelId, logRequest);
|
|
61
77
|
}
|
|
62
78
|
onSyncAgent(data, action) {
|
|
63
|
-
this.emit(
|
|
79
|
+
this.emit(tunnel_1.TUNNEL_SOCKET_EVENT.AGENT, data, action);
|
|
64
80
|
}
|
|
65
81
|
onSyncTunnel(data, action) {
|
|
66
|
-
this.emit(
|
|
82
|
+
this.emit(tunnel_1.TUNNEL_SOCKET_EVENT.TUNNEL, data, action);
|
|
67
83
|
}
|
|
68
84
|
onSync(data) {
|
|
69
85
|
try {
|
|
@@ -117,6 +133,7 @@ class AgentSocketClient extends events_1.default {
|
|
|
117
133
|
transports: ['websocket'],
|
|
118
134
|
reconnection: false,
|
|
119
135
|
rejectUnauthorized: false,
|
|
136
|
+
// @ts-ignore
|
|
120
137
|
agent: new https_1.Agent({
|
|
121
138
|
rejectUnauthorized: false,
|
|
122
139
|
}),
|
|
@@ -126,9 +143,11 @@ class AgentSocketClient extends events_1.default {
|
|
|
126
143
|
},
|
|
127
144
|
});
|
|
128
145
|
this.socket.on('connect', () => {
|
|
146
|
+
if (!this.socket)
|
|
147
|
+
return;
|
|
129
148
|
this.connected = true;
|
|
130
149
|
logger_1.default.info(texts_1.LOG_SOCKET_CONNECTED);
|
|
131
|
-
this.emit(
|
|
150
|
+
this.emit(tunnel_1.TUNNEL_SOCKET_EVENT.CONNECTED);
|
|
132
151
|
this.socket.emit('joinTunnelAgent', {
|
|
133
152
|
id: this.id,
|
|
134
153
|
token: this.token,
|
|
@@ -137,7 +156,7 @@ class AgentSocketClient extends events_1.default {
|
|
|
137
156
|
this.socket.on('disconnect', () => {
|
|
138
157
|
this.connected = false;
|
|
139
158
|
logger_1.default.info(texts_1.LOG_SOCKET_DISCONNECTED);
|
|
140
|
-
this.emit(
|
|
159
|
+
this.emit(tunnel_1.TUNNEL_SOCKET_EVENT.DISCONNECTED);
|
|
141
160
|
this.connect();
|
|
142
161
|
});
|
|
143
162
|
this.socket.on('connect_error', () => {
|
|
@@ -146,11 +165,11 @@ class AgentSocketClient extends events_1.default {
|
|
|
146
165
|
});
|
|
147
166
|
this.socket.on('fetchTunnelAgentSuccess', (data) => {
|
|
148
167
|
logger_1.default.debug('Socket fetch success');
|
|
149
|
-
this.emit(
|
|
168
|
+
this.emit(tunnel_1.TUNNEL_SOCKET_EVENT.FETCH_SUCCESS, data);
|
|
150
169
|
});
|
|
151
170
|
this.socket.on('fetchTunnelAgentFailed', (code) => {
|
|
152
171
|
logger_1.default.debug('Socket fetch failed');
|
|
153
|
-
this.emit(
|
|
172
|
+
this.emit(tunnel_1.TUNNEL_SOCKET_EVENT.FETCH_FAILED, (0, utils_1.apiErrorCodeToClass)(code, host));
|
|
154
173
|
});
|
|
155
174
|
this.socket.on('sync', (data) => this.onSync(data));
|
|
156
175
|
this.connect(true);
|
|
@@ -6,7 +6,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const texts_1 = require("../../texts");
|
|
7
7
|
const events_1 = __importDefault(require("events"));
|
|
8
8
|
const utils_1 = require("../../utils");
|
|
9
|
+
const tunnel_1 = require("../../types/tunnel");
|
|
9
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;
|
|
10
33
|
constructor(socket, id) {
|
|
11
34
|
super();
|
|
12
35
|
this.id = id;
|
|
@@ -16,7 +39,7 @@ class AgentSocketTunnel extends events_1.default {
|
|
|
16
39
|
this.socket.on('close', () => this.onClose());
|
|
17
40
|
this.socket.on('message', (msg) => this.onMessage(msg));
|
|
18
41
|
this.socket.send(JSON.stringify({
|
|
19
|
-
message:
|
|
42
|
+
message: tunnel_1.TUNNEL_SOCKET_MESSAGE.READY,
|
|
20
43
|
}));
|
|
21
44
|
}
|
|
22
45
|
close() {
|
|
@@ -64,7 +87,6 @@ class AgentSocketTunnel extends events_1.default {
|
|
|
64
87
|
this.subdomain = data.subdomain;
|
|
65
88
|
this.sshId = data.sshId;
|
|
66
89
|
this.domain = data.domain;
|
|
67
|
-
this.customDomain = data.customDomain;
|
|
68
90
|
this.sshForwardPort = data.sshForwardPort;
|
|
69
91
|
}
|
|
70
92
|
upsertHttpLog(data) {
|
|
@@ -112,55 +134,55 @@ class AgentSocketTunnel extends events_1.default {
|
|
|
112
134
|
onMessage(msg) {
|
|
113
135
|
try {
|
|
114
136
|
const json = JSON.parse(msg.toString('utf8'));
|
|
115
|
-
if (json.message ===
|
|
137
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL) {
|
|
116
138
|
this.onTunnelData(json);
|
|
117
139
|
this.ready = true;
|
|
118
140
|
return;
|
|
119
141
|
}
|
|
120
|
-
if (json.message ===
|
|
142
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_REQUESTS) {
|
|
121
143
|
this.onTunnelRequests(json);
|
|
122
144
|
return;
|
|
123
145
|
}
|
|
124
|
-
if (json.message ===
|
|
125
|
-
this.emit(
|
|
146
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_OPEN) {
|
|
147
|
+
this.emit(tunnel_1.TUNNEL_EVENT.OPEN, json);
|
|
126
148
|
return;
|
|
127
149
|
}
|
|
128
|
-
if (json.message ===
|
|
129
|
-
this.emit(
|
|
150
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_CLOSED) {
|
|
151
|
+
this.emit(tunnel_1.TUNNEL_EVENT.CLOSED, json);
|
|
130
152
|
return;
|
|
131
153
|
}
|
|
132
|
-
if (json.message ===
|
|
133
|
-
this.emit(
|
|
154
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TCP_OPEN) {
|
|
155
|
+
this.emit(tunnel_1.TUNNEL_EVENT.TCP_OPEN, json);
|
|
134
156
|
return;
|
|
135
157
|
}
|
|
136
|
-
if (json.message ===
|
|
137
|
-
this.emit(
|
|
158
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TCP_CLOSED) {
|
|
159
|
+
this.emit(tunnel_1.TUNNEL_EVENT.TCP_CLOSED, json);
|
|
138
160
|
return;
|
|
139
161
|
}
|
|
140
|
-
if (json.message ===
|
|
141
|
-
this.emit(
|
|
162
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TLS_OPEN) {
|
|
163
|
+
this.emit(tunnel_1.TUNNEL_EVENT.TLS_OPEN, json);
|
|
142
164
|
return;
|
|
143
165
|
}
|
|
144
|
-
if (json.message ===
|
|
145
|
-
this.emit(
|
|
166
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TLS_CLOSED) {
|
|
167
|
+
this.emit(tunnel_1.TUNNEL_EVENT.TLS_CLOSED, json);
|
|
146
168
|
return;
|
|
147
169
|
}
|
|
148
|
-
if (json.message ===
|
|
149
|
-
this.emit(
|
|
170
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_IDENTIFIED) {
|
|
171
|
+
this.emit(tunnel_1.TUNNEL_EVENT.HTTP_IDENTIFIED, json, json.identify);
|
|
150
172
|
return;
|
|
151
173
|
}
|
|
152
|
-
if (json.message ===
|
|
174
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_REQUEST) {
|
|
153
175
|
this.upsertHttpLog(json.logRequest);
|
|
154
|
-
this.emit(
|
|
176
|
+
this.emit(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, json, json.logRequest);
|
|
155
177
|
return;
|
|
156
178
|
}
|
|
157
|
-
if (json.message ===
|
|
179
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_RESPONSE) {
|
|
158
180
|
this.upsertHttpLog(json.logRequest);
|
|
159
|
-
this.emit(
|
|
181
|
+
this.emit(tunnel_1.TUNNEL_EVENT.HTTP_RESPONSE, json, json.logRequest);
|
|
160
182
|
return;
|
|
161
183
|
}
|
|
162
|
-
if (json.message ===
|
|
163
|
-
this.emit(
|
|
184
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_STOPPED) {
|
|
185
|
+
this.emit(tunnel_1.TUNNEL_EVENT.STOPPED, json);
|
|
164
186
|
this.close();
|
|
165
187
|
}
|
|
166
188
|
}
|
|
@@ -169,13 +191,15 @@ class AgentSocketTunnel extends events_1.default {
|
|
|
169
191
|
}
|
|
170
192
|
}
|
|
171
193
|
onClose() {
|
|
172
|
-
this.emit(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
+
}
|
|
179
203
|
}
|
|
180
204
|
this.closed = true;
|
|
181
205
|
this.socket = null;
|
|
@@ -183,7 +207,7 @@ class AgentSocketTunnel extends events_1.default {
|
|
|
183
207
|
retryHttpLogRequest(logRequest) {
|
|
184
208
|
if (this.socket) {
|
|
185
209
|
this.socket.send(JSON.stringify({
|
|
186
|
-
message:
|
|
210
|
+
message: tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_RETRY,
|
|
187
211
|
logRequest,
|
|
188
212
|
}));
|
|
189
213
|
}
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const tunnel_1 = require("../types/tunnel");
|
|
4
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;
|
|
5
19
|
constructor(socket, tunnel) {
|
|
6
20
|
this.tunnel = tunnel;
|
|
7
21
|
this.socket = socket;
|
|
@@ -18,21 +32,21 @@ class AgentSocket {
|
|
|
18
32
|
this.boundEventHttpIdentified = (t, type) => this.tunnelHttpIdentified(t, type);
|
|
19
33
|
this.boundEventHttpRequest = (t, logRequest) => this.tunnelHttpRequest(t, logRequest);
|
|
20
34
|
this.boundEventHttpResponse = (t, logRequest) => this.tunnelHttpResponse(t, logRequest);
|
|
21
|
-
this.tunnel.on(
|
|
22
|
-
this.tunnel.on(
|
|
23
|
-
this.tunnel.on(
|
|
24
|
-
this.tunnel.on(
|
|
25
|
-
this.tunnel.on(
|
|
26
|
-
this.tunnel.on(
|
|
27
|
-
this.tunnel.on(
|
|
28
|
-
this.tunnel.on(
|
|
29
|
-
this.tunnel.on(
|
|
30
|
-
this.tunnel.on(
|
|
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);
|
|
31
45
|
}
|
|
32
46
|
onMessage(message) {
|
|
33
47
|
try {
|
|
34
48
|
const json = JSON.parse(message.toString('utf8'));
|
|
35
|
-
if (json.message ===
|
|
49
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.READY) {
|
|
36
50
|
this.ready = true;
|
|
37
51
|
this.ts = setInterval(() => {
|
|
38
52
|
this.sendTunnel();
|
|
@@ -41,7 +55,7 @@ class AgentSocket {
|
|
|
41
55
|
this.sendRequests();
|
|
42
56
|
return;
|
|
43
57
|
}
|
|
44
|
-
if (json.message ===
|
|
58
|
+
if (json.message === tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_RETRY &&
|
|
45
59
|
this.ready) {
|
|
46
60
|
this.retryHttpRequest(json.logRequest);
|
|
47
61
|
}
|
|
@@ -51,6 +65,8 @@ class AgentSocket {
|
|
|
51
65
|
}
|
|
52
66
|
}
|
|
53
67
|
retryHttpRequest(logRequest) {
|
|
68
|
+
if (!this.tunnel)
|
|
69
|
+
return;
|
|
54
70
|
this.tunnel.retryHttpLogRequest(logRequest);
|
|
55
71
|
}
|
|
56
72
|
send(message, data = {}) {
|
|
@@ -68,32 +84,31 @@ class AgentSocket {
|
|
|
68
84
|
target: t.target,
|
|
69
85
|
subdomain: t.subdomain,
|
|
70
86
|
domain: t.domain,
|
|
71
|
-
customDomain: t.customDomain,
|
|
72
87
|
sshId: t.sshId,
|
|
73
88
|
sshForwardPort: t.sshForwardPort,
|
|
74
89
|
...data,
|
|
75
90
|
});
|
|
76
91
|
}
|
|
77
92
|
tunnelOpen(t) {
|
|
78
|
-
this.sendEvent(
|
|
93
|
+
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_OPEN, t);
|
|
79
94
|
}
|
|
80
95
|
tunnelClosed(t) {
|
|
81
|
-
this.sendEvent(
|
|
96
|
+
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_CLOSED, t);
|
|
82
97
|
}
|
|
83
98
|
tunnelTcpOpen(t) {
|
|
84
|
-
this.sendEvent(
|
|
99
|
+
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TCP_OPEN, t);
|
|
85
100
|
}
|
|
86
101
|
tunnelTcpClosed(t) {
|
|
87
|
-
this.sendEvent(
|
|
102
|
+
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TCP_CLOSED, t);
|
|
88
103
|
}
|
|
89
104
|
tunnelTlsOpen(t) {
|
|
90
|
-
this.sendEvent(
|
|
105
|
+
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TLS_OPEN, t);
|
|
91
106
|
}
|
|
92
107
|
tunnelTlsClosed(t) {
|
|
93
|
-
this.sendEvent(
|
|
108
|
+
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_TLS_CLOSED, t);
|
|
94
109
|
}
|
|
95
110
|
tunnelHttpIdentified(t, type) {
|
|
96
|
-
this.sendEvent(
|
|
111
|
+
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_IDENTIFIED, t, {
|
|
97
112
|
identify: type,
|
|
98
113
|
});
|
|
99
114
|
}
|
|
@@ -120,47 +135,47 @@ class AgentSocket {
|
|
|
120
135
|
};
|
|
121
136
|
}
|
|
122
137
|
tunnelHttpRequest(t, logRequest) {
|
|
123
|
-
this.sendEvent(
|
|
138
|
+
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_REQUEST, t, {
|
|
124
139
|
logRequest: this.logRequestToSocket(logRequest),
|
|
125
140
|
});
|
|
126
141
|
}
|
|
127
142
|
tunnelHttpResponse(t, logRequest) {
|
|
128
|
-
this.sendEvent(
|
|
143
|
+
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_RESPONSE, t, {
|
|
129
144
|
logRequest: this.logRequestToSocket(logRequest),
|
|
130
145
|
});
|
|
131
146
|
}
|
|
132
147
|
tunnelStopped(t) {
|
|
133
|
-
this.sendEvent(
|
|
148
|
+
this.sendEvent(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_STOPPED, t);
|
|
134
149
|
this.close();
|
|
135
150
|
}
|
|
136
151
|
sendRequests() {
|
|
137
152
|
let requests = [];
|
|
138
|
-
if (this.tunnel
|
|
153
|
+
if (this.tunnel?.httpLog) {
|
|
139
154
|
requests = this.tunnel.httpLog.requests.map((lr) => this.logRequestToSocket(lr));
|
|
140
155
|
}
|
|
141
|
-
this.send(
|
|
156
|
+
this.send(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL_HTTP_REQUESTS, {
|
|
142
157
|
requests,
|
|
143
158
|
});
|
|
144
159
|
}
|
|
145
160
|
sendTunnel() {
|
|
146
161
|
const connections = {};
|
|
147
|
-
Object.keys(this.tunnel
|
|
162
|
+
Object.keys(this.tunnel?.connections || {}).forEach((id) => {
|
|
148
163
|
connections[id] = true;
|
|
149
164
|
});
|
|
150
165
|
const regionLatency = {
|
|
151
166
|
latency: -1,
|
|
152
167
|
};
|
|
153
|
-
if (this.tunnel
|
|
168
|
+
if (this.tunnel?.regionLatency) {
|
|
154
169
|
regionLatency.latency = this.tunnel.regionLatency.latency;
|
|
155
170
|
}
|
|
156
171
|
const targetLatency = {
|
|
157
172
|
latency: -1,
|
|
158
173
|
};
|
|
159
|
-
if (this.tunnel
|
|
174
|
+
if (this.tunnel?.targetLatency) {
|
|
160
175
|
targetLatency.latency = this.tunnel.targetLatency.latency;
|
|
161
176
|
}
|
|
162
177
|
let identify = null;
|
|
163
|
-
if (this.tunnel
|
|
178
|
+
if (this.tunnel?.identify) {
|
|
164
179
|
identify = {
|
|
165
180
|
type: this.tunnel.identify.type,
|
|
166
181
|
};
|
|
@@ -169,53 +184,58 @@ class AgentSocket {
|
|
|
169
184
|
checking: false,
|
|
170
185
|
valid: false,
|
|
171
186
|
};
|
|
172
|
-
if (this.tunnel
|
|
187
|
+
if (this.tunnel?.dns) {
|
|
173
188
|
dns.checking = this.tunnel.dns.checking;
|
|
174
189
|
dns.valid = this.tunnel.dns.valid;
|
|
175
190
|
}
|
|
176
|
-
this.send(
|
|
191
|
+
this.send(tunnel_1.TUNNEL_SOCKET_MESSAGE.TUNNEL, {
|
|
177
192
|
regionLatency,
|
|
178
193
|
targetLatency,
|
|
179
194
|
connections,
|
|
180
195
|
identify,
|
|
181
196
|
dns,
|
|
182
|
-
totalConnections: this.tunnel
|
|
183
|
-
serve: this.tunnel
|
|
184
|
-
log: this.tunnel
|
|
185
|
-
status: this.tunnel
|
|
186
|
-
region: this.tunnel
|
|
187
|
-
type: this.tunnel
|
|
188
|
-
target: this.tunnel
|
|
189
|
-
terminate: this.tunnel
|
|
190
|
-
id: this.tunnel
|
|
191
|
-
subdomain: this.tunnel
|
|
192
|
-
domain: this.tunnel
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
sshForwardPort: this.tunnel.sshForwardPort,
|
|
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,
|
|
196
210
|
});
|
|
197
211
|
}
|
|
198
212
|
close() {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
this.socket.removeAllListeners();
|
|
202
|
-
this.socket.close();
|
|
203
|
-
}
|
|
204
|
-
catch {
|
|
205
|
-
// do nothing
|
|
213
|
+
if (this.ts) {
|
|
214
|
+
clearInterval(this.ts);
|
|
206
215
|
}
|
|
207
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
|
+
}
|
|
208
226
|
this.socket = null;
|
|
209
|
-
this.tunnel
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
+
}
|
|
219
239
|
this.tunnel = null;
|
|
220
240
|
}
|
|
221
241
|
}
|
|
@@ -15,7 +15,8 @@ class AgentSystem {
|
|
|
15
15
|
return Promise.resolve(false);
|
|
16
16
|
}
|
|
17
17
|
// extend
|
|
18
|
-
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
+
enable(id, host, token, port, start, user, pass, debug) {
|
|
19
20
|
return Promise.reject();
|
|
20
21
|
}
|
|
21
22
|
// extend
|
|
@@ -54,6 +55,7 @@ class AgentSystem {
|
|
|
54
55
|
}
|
|
55
56
|
extractArchive(source, dest) {
|
|
56
57
|
return new Promise((resolve, reject) => {
|
|
58
|
+
// @ts-ignore
|
|
57
59
|
import('@xhmikosr/decompress')
|
|
58
60
|
.then(({ default: decompress }) => {
|
|
59
61
|
decompress(source, dest)
|
|
@@ -137,21 +137,21 @@ class AgentWindows extends system_1.default {
|
|
|
137
137
|
}
|
|
138
138
|
nssm(cmd) {
|
|
139
139
|
return new Promise((resolve, reject) => {
|
|
140
|
-
(0, child_process_1.exec)(`${this.getNssmBinaryPath()} ${cmd}`, (err
|
|
140
|
+
(0, child_process_1.exec)(`${this.getNssmBinaryPath()} ${cmd}`, (err) => {
|
|
141
141
|
if (!err)
|
|
142
|
-
resolve(
|
|
142
|
+
resolve();
|
|
143
143
|
else
|
|
144
|
-
reject(err
|
|
144
|
+
reject(err);
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
147
|
}
|
|
148
148
|
sc(cmd) {
|
|
149
149
|
return new Promise((resolve, reject) => {
|
|
150
|
-
(0, child_process_1.exec)(`sc ${cmd}`, (err
|
|
150
|
+
(0, child_process_1.exec)(`sc ${cmd}`, (err) => {
|
|
151
151
|
if (!err)
|
|
152
|
-
resolve(
|
|
152
|
+
resolve();
|
|
153
153
|
else
|
|
154
|
-
reject(err
|
|
154
|
+
reject(err);
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
157
|
}
|
|
@@ -61,10 +61,10 @@ commandAgentInstall.action(async (options) => {
|
|
|
61
61
|
if (isEnabled) {
|
|
62
62
|
output_1.default.exitSuccess(texts_1.TXT_AGENT_ALREADY_ENABLED);
|
|
63
63
|
}
|
|
64
|
-
let id;
|
|
65
|
-
let token;
|
|
64
|
+
let id = '';
|
|
65
|
+
let token = '';
|
|
66
66
|
let agent;
|
|
67
|
-
|
|
67
|
+
const port = input_1.default.port(options.port);
|
|
68
68
|
const target = !!options.target;
|
|
69
69
|
if (options.id && options.token) {
|
|
70
70
|
// if id & token passed set as it is
|
|
@@ -81,7 +81,7 @@ commandAgentInstall.action(async (options) => {
|
|
|
81
81
|
// set global token if passed
|
|
82
82
|
cfg_1.default.setToken(options.token);
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
const host = cfg_1.default.getTokenHost();
|
|
85
85
|
if (!agent) {
|
|
86
86
|
agent = await buddy_1.default.register(true, target, host, cfg_1.default.getToken(), (region) => {
|
|
87
87
|
cfg_1.default.setRegionIfNotSet(region);
|
|
@@ -14,6 +14,6 @@ commandAgentRun.option('--port <port>');
|
|
|
14
14
|
commandAgentRun.option('--start <start>');
|
|
15
15
|
commandAgentRun.action(async (options) => {
|
|
16
16
|
logger_1.default.changeRootPath(manager_1.default.system.getAgentConfigDir());
|
|
17
|
-
manager_1.default.start(options.id, options.host, options.token, options.port, String(options.start) === 'true');
|
|
17
|
+
manager_1.default.start(options.id, options.host, options.token, parseInt(options.port, 10), String(options.start) === 'true');
|
|
18
18
|
});
|
|
19
|
-
|
|
19
|
+
exports.default = commandAgentRun;
|
|
@@ -7,24 +7,23 @@ const output_1 = __importDefault(require("../../output"));
|
|
|
7
7
|
const texts_1 = require("../../texts");
|
|
8
8
|
const utils_1 = require("../../utils");
|
|
9
9
|
const manager_1 = __importDefault(require("../../agent/manager"));
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const commandAgentStatus = (0, utils_2.newCommand)('status', texts_1.DESC_COMMAND_AGENT_STATUS);
|
|
10
|
+
const tunnel_1 = require("../../types/tunnel");
|
|
11
|
+
const commandAgentStatus = (0, utils_1.newCommand)('status', texts_1.DESC_COMMAND_AGENT_STATUS);
|
|
13
12
|
commandAgentStatus.action(async () => {
|
|
14
13
|
const isEnabled = await manager_1.default.system.isEnabled();
|
|
15
14
|
if (!isEnabled) {
|
|
16
15
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_ENABLED);
|
|
17
16
|
}
|
|
18
17
|
if (!commandAgentStatus.agentStatus) {
|
|
19
|
-
output_1.default.exitError(
|
|
18
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
20
19
|
}
|
|
21
|
-
if (commandAgentStatus.agentStatus.status ===
|
|
20
|
+
if (commandAgentStatus.agentStatus.status === tunnel_1.TUNNEL_AGENT_STATUS.INITIALIZING) {
|
|
22
21
|
output_1.default.exitError(texts_1.TXT_AGENT_IS_ENABLED_AND_INITIALIZING);
|
|
23
22
|
}
|
|
24
|
-
if (commandAgentStatus.agentStatus.status ===
|
|
23
|
+
if (commandAgentStatus.agentStatus.status === tunnel_1.TUNNEL_AGENT_STATUS.FETCH_FAILED) {
|
|
25
24
|
output_1.default.exitError(texts_1.TXT_AGENT_IS_ENABLED_AND_HAVE_TROUBLES);
|
|
26
25
|
}
|
|
27
|
-
if (commandAgentStatus.agentStatus.status !==
|
|
26
|
+
if (commandAgentStatus.agentStatus.status !== tunnel_1.TUNNEL_AGENT_STATUS.ENABLED) {
|
|
28
27
|
output_1.default.exitError(texts_1.TXT_AGENT_IS_DISABLED);
|
|
29
28
|
}
|
|
30
29
|
if (commandAgentStatus.agentStatus.started) {
|
|
@@ -8,20 +8,19 @@ const output_1 = __importDefault(require("../../../output"));
|
|
|
8
8
|
const cfg_1 = __importDefault(require("../../../tunnel/cfg"));
|
|
9
9
|
const texts_1 = require("../../../texts");
|
|
10
10
|
const tunnel_1 = __importDefault(require("../../../agent/socket/tunnel"));
|
|
11
|
-
const texts_2 = require("../../../texts");
|
|
12
11
|
const manager_1 = __importDefault(require("../../../agent/manager"));
|
|
13
|
-
const utils_2 = require("../../../utils");
|
|
14
12
|
const agent_1 = __importDefault(require("../../../tunnel/api/agent"));
|
|
15
|
-
const
|
|
13
|
+
const tunnel_2 = require("../../../types/tunnel");
|
|
14
|
+
const commandAgentTunnelHttp = (0, utils_1.getBasicCommandHttp)();
|
|
16
15
|
commandAgentTunnelHttp.description(texts_1.DESC_COMMAND_HTTP);
|
|
17
|
-
commandAgentTunnelHttp.option('-f, --follow',
|
|
16
|
+
commandAgentTunnelHttp.option('-f, --follow', texts_1.OPTION_FOLLOW);
|
|
18
17
|
commandAgentTunnelHttp.argument('[protocol://host:port]', texts_1.OPTION_TARGET);
|
|
19
18
|
commandAgentTunnelHttp.action(async (target, options) => {
|
|
20
19
|
const isEnabled = await manager_1.default.system.isEnabled();
|
|
21
20
|
if (!isEnabled) {
|
|
22
21
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_ENABLED);
|
|
23
22
|
}
|
|
24
|
-
const prepared = await cfg_1.default.prepareTunnel(
|
|
23
|
+
const prepared = await cfg_1.default.prepareTunnel(tunnel_2.TUNNEL_TYPE.HTTP, target, options, true);
|
|
25
24
|
try {
|
|
26
25
|
await output_1.default.spinner(texts_1.TXT_OPENING_TUNNEL);
|
|
27
26
|
const json = manager_1.default.system.loadSystemConfig();
|