bdy 1.10.14-stage → 1.11.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distTs/bin/cli.js +1 -1
- package/distTs/package.json +1 -1
- package/distTs/src/agent/agent.js +302 -0
- package/distTs/src/agent/manager.js +41 -41
- package/distTs/src/agent/socket/client.js +159 -0
- package/distTs/src/agent/socket/tunnel.js +3 -3
- package/distTs/src/agent/wait.js +2 -2
- package/distTs/src/command/agent/disable.js +1 -1
- package/distTs/src/command/agent/enable.js +1 -1
- package/distTs/src/command/agent/install.js +45 -45
- package/distTs/src/command/agent/restart.js +8 -8
- package/distTs/src/command/agent/start.js +8 -8
- package/distTs/src/command/agent/status.js +15 -15
- package/distTs/src/command/agent/stop.js +8 -8
- package/distTs/src/command/agent/target/disable.js +1 -1
- package/distTs/src/command/agent/target/enable.js +1 -1
- package/distTs/src/command/agent/target/status.js +1 -1
- package/distTs/src/command/agent/tunnel/http.js +18 -18
- package/distTs/src/command/agent/tunnel/list.js +7 -7
- package/distTs/src/command/agent/tunnel/remove.js +9 -9
- package/distTs/src/command/agent/tunnel/start.js +14 -14
- package/distTs/src/command/agent/tunnel/status.js +11 -11
- package/distTs/src/command/agent/tunnel/tcp.js +19 -19
- package/distTs/src/command/agent/tunnel/tls.js +17 -17
- package/distTs/src/command/agent/tunnel.js +16 -16
- package/distTs/src/command/agent/uninstall.js +13 -13
- package/distTs/src/command/agent/update.js +12 -12
- package/distTs/src/command/agent/version.js +6 -6
- package/distTs/src/command/agent.js +18 -18
- package/distTs/src/command/config/add/http.js +15 -15
- package/distTs/src/command/config/add/tcp.js +15 -15
- package/distTs/src/command/config/add/tls.js +15 -15
- package/distTs/src/command/config/add.js +8 -8
- package/distTs/src/command/config/get/region.js +5 -5
- package/distTs/src/command/config/get/timeout.js +5 -5
- package/distTs/src/command/config/get/token.js +5 -5
- package/distTs/src/command/config/get/tunnel.js +9 -9
- package/distTs/src/command/config/get/tunnels.js +6 -6
- package/distTs/src/command/config/get/whitelist.js +5 -5
- package/distTs/src/command/config/get.js +14 -14
- package/distTs/src/command/config/remove/tunnel.js +9 -9
- package/distTs/src/command/config/remove.js +4 -4
- package/distTs/src/command/config/set/region.js +8 -8
- package/distTs/src/command/config/set/timeout.js +9 -9
- package/distTs/src/command/config/set/token.js +7 -7
- package/distTs/src/command/config/set/whitelist.js +8 -8
- package/distTs/src/command/config/set.js +10 -10
- package/distTs/src/command/pre.js +14 -14
- package/distTs/src/command/tunnel/config.js +17 -0
- package/distTs/src/command/tunnel/http.js +30 -0
- package/distTs/src/command/tunnel/start.js +28 -0
- package/distTs/src/command/tunnel/tcp.js +30 -0
- package/distTs/src/command/tunnel/tls.js +30 -0
- package/distTs/src/command/tunnel.js +19 -0
- package/distTs/src/command/ut/upload.js +6 -6
- package/distTs/src/command/ut.js +3 -2
- package/distTs/src/command/version.js +4 -4
- package/distTs/src/command/vt/close.js +4 -4
- package/distTs/src/command/vt/compare.js +16 -16
- package/distTs/src/command/vt/exec.js +12 -12
- package/distTs/src/command/vt/installBrowser.js +2 -2
- package/distTs/src/command/vt/scrap.js +17 -17
- package/distTs/src/command/vt/storybook.js +8 -8
- package/distTs/src/command/vt.js +5 -4
- package/distTs/src/index.js +12 -20
- package/distTs/src/input.js +38 -38
- package/distTs/src/logger.js +2 -2
- package/distTs/src/output.js +14 -14
- package/distTs/src/texts.js +5 -4
- package/distTs/src/tunnel/agent.js +3 -3
- package/distTs/src/tunnel/api/agent.js +99 -0
- package/distTs/src/tunnel/api/buddy.js +139 -0
- package/distTs/src/tunnel/cfg.js +234 -0
- package/distTs/src/tunnel/http/log.js +3 -3
- package/distTs/src/tunnel/http.js +29 -29
- package/distTs/src/tunnel/identification.js +13 -13
- package/distTs/src/tunnel/latency.js +3 -3
- package/distTs/src/tunnel/output/interactive/tunnel.js +860 -0
- package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +43 -0
- package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +65 -0
- package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +18 -0
- package/distTs/src/tunnel/output/noninteractive/tunnel.js +59 -0
- package/distTs/src/tunnel/server/cert.js +52 -0
- package/distTs/src/tunnel/server/http1.js +75 -0
- package/distTs/src/tunnel/server/http2.js +78 -0
- package/distTs/src/tunnel/server/sftp.js +497 -0
- package/distTs/src/tunnel/server/ssh.js +446 -0
- package/distTs/src/tunnel/server/tls.js +41 -0
- package/distTs/src/tunnel/ssh/client.js +197 -0
- package/distTs/src/tunnel/tcp.js +3 -3
- package/distTs/src/tunnel/tunnel.js +656 -0
- package/distTs/src/utils.js +2 -2
- package/distTs/src/visualTest/ci.js +10 -10
- package/distTs/src/visualTest/context.js +4 -4
- package/distTs/src/visualTest/requests.js +71 -71
- package/distTs/src/visualTest/resources.js +5 -5
- package/distTs/src/visualTest/server.js +9 -9
- package/distTs/src/visualTest/snapshots.js +18 -18
- package/distTs/src/visualTest/validation.js +3 -3
- package/package.json +1 -1
package/distTs/src/input.js
CHANGED
|
@@ -26,19 +26,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const
|
|
29
|
+
const output_1 = __importDefault(require("./output"));
|
|
30
30
|
const netmask_1 = __importDefault(require("netmask"));
|
|
31
31
|
const punycode_js_1 = __importDefault(require("punycode.js"));
|
|
32
32
|
const fs_1 = __importStar(require("fs"));
|
|
33
33
|
const tls_1 = __importDefault(require("tls"));
|
|
34
34
|
const crypto_1 = __importDefault(require("crypto"));
|
|
35
|
-
const
|
|
36
|
-
const
|
|
35
|
+
const utils_1 = require("./utils");
|
|
36
|
+
const texts_1 = require("./texts");
|
|
37
37
|
class Input {
|
|
38
38
|
static timeout(timeout) {
|
|
39
39
|
const t = parseInt(timeout, 10);
|
|
40
40
|
if (isNaN(t) || t <= 0 || t > 999) {
|
|
41
|
-
|
|
41
|
+
output_1.default.exitError((0, texts_1.ERR_TIMEOUT_IS_NOT_VALID)(timeout));
|
|
42
42
|
}
|
|
43
43
|
return t;
|
|
44
44
|
}
|
|
@@ -48,11 +48,11 @@ class Input {
|
|
|
48
48
|
try {
|
|
49
49
|
const info = (0, fs_1.statSync)(serve);
|
|
50
50
|
if (!info.isDirectory()) {
|
|
51
|
-
|
|
51
|
+
output_1.default.exitError((0, texts_1.ERR_PATH_IS_NOT_DIRECTORY)(serve));
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
catch {
|
|
55
|
-
|
|
55
|
+
output_1.default.exitError((0, texts_1.ERR_DIRECTORY_DOES_NOT_EXISTS)(serve));
|
|
56
56
|
}
|
|
57
57
|
return serve;
|
|
58
58
|
}
|
|
@@ -61,7 +61,7 @@ class Input {
|
|
|
61
61
|
return null;
|
|
62
62
|
const n = parseFloat(threshold);
|
|
63
63
|
if (isNaN(n) || n < 0 || n > 1) {
|
|
64
|
-
|
|
64
|
+
output_1.default.exitError((0, texts_1.ERR_CB_THRESHOLD_IS_NOT_VALID)(n));
|
|
65
65
|
}
|
|
66
66
|
return n;
|
|
67
67
|
}
|
|
@@ -83,13 +83,13 @@ class Input {
|
|
|
83
83
|
static auth(auth) {
|
|
84
84
|
const s = auth.split(':');
|
|
85
85
|
if (s.length !== 2) {
|
|
86
|
-
|
|
86
|
+
output_1.default.exitError((0, texts_1.ERR_BA_IS_NOT_VALID)(auth));
|
|
87
87
|
}
|
|
88
88
|
if (!s[0]) {
|
|
89
|
-
|
|
89
|
+
output_1.default.exitError(texts_1.ERR_BA_LOGIN_NOT_PROVIDED);
|
|
90
90
|
}
|
|
91
91
|
if (!s[1]) {
|
|
92
|
-
|
|
92
|
+
output_1.default.exitError(texts_1.ERR_BA_PASSWORD_NOT_PROVIDED);
|
|
93
93
|
}
|
|
94
94
|
return {
|
|
95
95
|
login: s[0],
|
|
@@ -100,12 +100,12 @@ class Input {
|
|
|
100
100
|
if (!useragents || !useragents.length)
|
|
101
101
|
return [];
|
|
102
102
|
useragents.forEach((ua) => {
|
|
103
|
-
if ((0,
|
|
103
|
+
if ((0, utils_1.isStringRegExp)(ua)) {
|
|
104
104
|
try {
|
|
105
105
|
new RegExp(ua);
|
|
106
106
|
}
|
|
107
107
|
catch {
|
|
108
|
-
|
|
108
|
+
output_1.default.exitError((0, texts_1.ERR_USER_AGENT_IS_NOT_VALID)(ua));
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
});
|
|
@@ -122,30 +122,30 @@ class Input {
|
|
|
122
122
|
new netmask_1.default.Netmask(wh);
|
|
123
123
|
}
|
|
124
124
|
catch {
|
|
125
|
-
|
|
125
|
+
output_1.default.exitError((0, texts_1.ERR_WHITELIST_IS_NOT_VALID)(wh));
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
return whitelist;
|
|
129
129
|
}
|
|
130
130
|
static region(region) {
|
|
131
131
|
if (!region)
|
|
132
|
-
|
|
132
|
+
output_1.default.exitError((0, texts_1.ERR_REGION_IS_NOT_VALID)(''));
|
|
133
133
|
region = region.toUpperCase();
|
|
134
|
-
if (![
|
|
135
|
-
|
|
134
|
+
if (![utils_1.REGION_EU, utils_1.REGION_US].includes(region)) {
|
|
135
|
+
output_1.default.exitError((0, texts_1.ERR_REGION_IS_NOT_VALID)(region));
|
|
136
136
|
}
|
|
137
137
|
return region;
|
|
138
138
|
}
|
|
139
139
|
static terminate(terminate) {
|
|
140
140
|
if (!terminate)
|
|
141
|
-
return
|
|
141
|
+
return utils_1.TLS_TERMINATE_AT_REGION;
|
|
142
142
|
terminate = terminate.toUpperCase();
|
|
143
143
|
if (![
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
utils_1.TLS_TERMINATE_AT_AGENT,
|
|
145
|
+
utils_1.TLS_TERMINATE_AT_REGION,
|
|
146
|
+
utils_1.TLS_TERMINATE_AT_TARGET,
|
|
147
147
|
].includes(terminate)) {
|
|
148
|
-
|
|
148
|
+
output_1.default.exitError((0, texts_1.ERR_TERMINATE_IS_NOT_VALID)(terminate));
|
|
149
149
|
}
|
|
150
150
|
return terminate;
|
|
151
151
|
}
|
|
@@ -153,7 +153,7 @@ class Input {
|
|
|
153
153
|
if (!target)
|
|
154
154
|
return '80';
|
|
155
155
|
if (target.length > 200) {
|
|
156
|
-
|
|
156
|
+
output_1.default.exitError((0, texts_1.ERR_TARGET_IS_NOT_VALID)(target));
|
|
157
157
|
}
|
|
158
158
|
target = target.toLowerCase();
|
|
159
159
|
// 80
|
|
@@ -164,22 +164,22 @@ class Input {
|
|
|
164
164
|
// http://user:pass@localhost
|
|
165
165
|
// http://user:pass@localhost:80
|
|
166
166
|
let port;
|
|
167
|
-
if ([
|
|
168
|
-
const m = target.match(
|
|
167
|
+
if ([utils_1.TUNNEL_TCP, utils_1.TUNNEL_TLS].includes(type)) {
|
|
168
|
+
const m = target.match(utils_1.TARGET_TCP_TLS_REGEX);
|
|
169
169
|
if (!m) {
|
|
170
|
-
|
|
170
|
+
output_1.default.exitError((0, texts_1.ERR_TARGET_IS_NOT_VALID)(target));
|
|
171
171
|
}
|
|
172
172
|
port = m[3];
|
|
173
173
|
}
|
|
174
174
|
else {
|
|
175
|
-
let m = target.match(
|
|
175
|
+
let m = target.match(utils_1.TARGET_ONLY_PORT_REGEX);
|
|
176
176
|
if (m) {
|
|
177
177
|
port = m[0];
|
|
178
178
|
}
|
|
179
179
|
else {
|
|
180
|
-
m = target.match(
|
|
180
|
+
m = target.match(utils_1.TARGET_HTTP_REGEX);
|
|
181
181
|
if (!m) {
|
|
182
|
-
|
|
182
|
+
output_1.default.exitError((0, texts_1.ERR_TARGET_IS_NOT_VALID)(target));
|
|
183
183
|
}
|
|
184
184
|
else {
|
|
185
185
|
let proto;
|
|
@@ -202,21 +202,21 @@ class Input {
|
|
|
202
202
|
static port(port) {
|
|
203
203
|
const p = parseInt(port, 10);
|
|
204
204
|
if (isNaN(p) || p <= 0 || p > 65535)
|
|
205
|
-
|
|
205
|
+
output_1.default.exitError((0, texts_1.ERR_PORT_IS_NOT_VALID)(port));
|
|
206
206
|
return p;
|
|
207
207
|
}
|
|
208
208
|
static type(type) {
|
|
209
209
|
if (!type)
|
|
210
|
-
return
|
|
210
|
+
return utils_1.TUNNEL_TCP;
|
|
211
211
|
type = type.toUpperCase();
|
|
212
|
-
if (![
|
|
213
|
-
|
|
212
|
+
if (![utils_1.TUNNEL_TCP, utils_1.TUNNEL_TLS, utils_1.TUNNEL_HTTP].includes(type)) {
|
|
213
|
+
output_1.default.exitError((0, texts_1.ERR_TYPE_IS_NOT_VALID)(type));
|
|
214
214
|
}
|
|
215
215
|
return type;
|
|
216
216
|
}
|
|
217
217
|
static name(name) {
|
|
218
218
|
if (name.includes('*')) {
|
|
219
|
-
|
|
219
|
+
output_1.default.exitError(texts_1.ERR_NAME_WITHOUT_ASTERISK);
|
|
220
220
|
}
|
|
221
221
|
return name;
|
|
222
222
|
}
|
|
@@ -226,13 +226,13 @@ class Input {
|
|
|
226
226
|
cert = fs_1.default.readFileSync(caPath, 'utf8');
|
|
227
227
|
}
|
|
228
228
|
catch {
|
|
229
|
-
|
|
229
|
+
output_1.default.exitError((0, texts_1.ERR_CA_PATH_IS_NOT_VALID)(caPath));
|
|
230
230
|
}
|
|
231
231
|
try {
|
|
232
232
|
new crypto_1.default.X509Certificate(cert);
|
|
233
233
|
}
|
|
234
234
|
catch {
|
|
235
|
-
|
|
235
|
+
output_1.default.exitError((0, texts_1.ERR_WRONG_CA)(caPath));
|
|
236
236
|
}
|
|
237
237
|
return cert;
|
|
238
238
|
}
|
|
@@ -243,13 +243,13 @@ class Input {
|
|
|
243
243
|
key = fs_1.default.readFileSync(keyPath, 'utf8');
|
|
244
244
|
}
|
|
245
245
|
catch {
|
|
246
|
-
|
|
246
|
+
output_1.default.exitError((0, texts_1.ERR_KEY_PATH_IS_NOT_VALID)(keyPath));
|
|
247
247
|
}
|
|
248
248
|
try {
|
|
249
249
|
cert = fs_1.default.readFileSync(certPath, 'utf8');
|
|
250
250
|
}
|
|
251
251
|
catch {
|
|
252
|
-
|
|
252
|
+
output_1.default.exitError((0, texts_1.ERR_CERT_PATH_IS_NOT_VALID)(certPath));
|
|
253
253
|
}
|
|
254
254
|
try {
|
|
255
255
|
tls_1.default.createSecureContext({
|
|
@@ -258,7 +258,7 @@ class Input {
|
|
|
258
258
|
});
|
|
259
259
|
}
|
|
260
260
|
catch {
|
|
261
|
-
|
|
261
|
+
output_1.default.exitError(texts_1.ERR_WRONG_KEY_CERT);
|
|
262
262
|
}
|
|
263
263
|
return {
|
|
264
264
|
cert,
|
package/distTs/src/logger.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const pino_1 = __importDefault(require("pino"));
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
10
|
class Logger {
|
|
11
11
|
rootPath = null;
|
|
12
12
|
logPath = null;
|
|
@@ -15,7 +15,7 @@ class Logger {
|
|
|
15
15
|
p = null;
|
|
16
16
|
ts = null;
|
|
17
17
|
constructor() {
|
|
18
|
-
this.rootPath = (0,
|
|
18
|
+
this.rootPath = (0, utils_1.getHomeDirectory)();
|
|
19
19
|
}
|
|
20
20
|
checkLogSize() {
|
|
21
21
|
try {
|
package/distTs/src/output.js
CHANGED
|
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
// @ts-ignore
|
|
7
7
|
const termkit_no_lazy_require_1 = __importDefault(require("terminal-kit/lib/termkit-no-lazy-require"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
8
|
+
const tunnel_1 = __importDefault(require("./tunnel/output/interactive/tunnel"));
|
|
9
|
+
const tunnel_2 = __importDefault(require("./tunnel/output/noninteractive/tunnel"));
|
|
10
|
+
const tunnel_3 = __importDefault(require("./tunnel/output/noninteractive/config/tunnel"));
|
|
11
|
+
const tunnels_1 = __importDefault(require("./tunnel/output/noninteractive/config/tunnels"));
|
|
12
|
+
const texts_1 = require("./texts");
|
|
13
|
+
const tunnels_2 = __importDefault(require("./tunnel/output/noninteractive/agent/tunnels"));
|
|
14
14
|
const context_1 = require("./visualTest/context");
|
|
15
15
|
const terminal = termkit_no_lazy_require_1.default.terminal;
|
|
16
16
|
class Output {
|
|
@@ -71,27 +71,27 @@ class Output {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
static agentTunnels(tunnels) {
|
|
74
|
-
const on = new
|
|
74
|
+
const on = new tunnels_2.default(terminal, tunnels);
|
|
75
75
|
on.start(this);
|
|
76
76
|
}
|
|
77
77
|
static tunnelInteractive(tunnel) {
|
|
78
78
|
this.killSpinner();
|
|
79
|
-
const oi = new
|
|
79
|
+
const oi = new tunnel_1.default(terminal, tunnel);
|
|
80
80
|
oi.start();
|
|
81
81
|
}
|
|
82
82
|
static tunnelNonInteractive(tunnel) {
|
|
83
83
|
this.killSpinner();
|
|
84
|
-
const on = new
|
|
84
|
+
const on = new tunnel_2.default(terminal, tunnel);
|
|
85
85
|
on.start();
|
|
86
86
|
}
|
|
87
87
|
static newCliVersion(version) {
|
|
88
|
-
terminal.gray((0,
|
|
88
|
+
terminal.gray((0, texts_1.TXT_NEW_CLI_VERSION)(version));
|
|
89
89
|
}
|
|
90
90
|
static newCliDockerVersion(version) {
|
|
91
|
-
terminal.gray((0,
|
|
91
|
+
terminal.gray((0, texts_1.TXT_NEW_CLI_DOCKER_VERSION)(version));
|
|
92
92
|
}
|
|
93
93
|
static newAgentVersion() {
|
|
94
|
-
terminal.gray(
|
|
94
|
+
terminal.gray(texts_1.TXT_NEW_AGENT_VERSION);
|
|
95
95
|
}
|
|
96
96
|
static tunnel(tunnel) {
|
|
97
97
|
if (terminal.isTTY)
|
|
@@ -116,11 +116,11 @@ class Output {
|
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
static configTunnels(tunnels) {
|
|
119
|
-
const on = new
|
|
119
|
+
const on = new tunnels_1.default(terminal, tunnels);
|
|
120
120
|
on.start(this);
|
|
121
121
|
}
|
|
122
122
|
static configTunnel(tunnel) {
|
|
123
|
-
const on = new
|
|
123
|
+
const on = new tunnel_3.default(terminal, tunnel);
|
|
124
124
|
on.start(this);
|
|
125
125
|
}
|
|
126
126
|
static exitError(err) {
|
package/distTs/src/texts.js
CHANGED
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ERR_CONNECTION_ERROR = exports.ERR_CONNECTION_TIMEOUT = exports.ERR_WRONG_STREAM = exports.ERR_WRONG_HANDSHAKE = exports.ERR_FETCH_VERSION = exports.ERR_SWW = exports.ERR_NOT_FOUND = exports.ERR_FAILED_TO_CONNECT_TO_AGENT = exports.ERR_TUNNEL_REMOVED = exports.ERR_TUNNELS_DISABLED = exports.ERR_AGENT_LIMIT_REACHED = exports.ERR_TUNNEL_TARGET_INVALID = exports.ERR_WORKSPACE_FLAGGED = exports.ERR_TUNNEL_LIMIT_REACHED = exports.ERR_DOMAIN_RESTRICTED = exports.ERR_AGENT_REMOVED = exports.ERR_FAILED_TO_CONNECT = exports.ERR_TUNNEL_ALREADY_EXISTS = exports.ERR_AGENT_NOT_SUPPORTED = exports.ERR_AGENT_ADMIN_RIGHTS = exports.ERR_AGENT_ENABLE = exports.ERR_SWW_AGENT_UPDATING = exports.ERR_SWW_AGENT_DISABLING = exports.ERR_SWW_AGENT_ENABLING = exports.ERR_AGENT_NOT_FOUND = exports.ERR_AGENT_NOT_RUNNING = exports.ERR_AGENT_NOT_ENABLED = exports.ERR_TUNNEL_NOT_FOUND = exports.ERR_WHITELIST_IS_NOT_VALID = exports.ERR_USER_AGENT_IS_NOT_VALID = exports.ERR_BA_IS_NOT_VALID = exports.ERR_BA_LOGIN_NOT_PROVIDED = exports.ERR_BA_PASSWORD_NOT_PROVIDED = exports.ERR_CB_THRESHOLD_IS_NOT_VALID = exports.ERR_CERT_PATH_IS_NOT_VALID = exports.ERR_KEY_PATH_IS_NOT_VALID = exports.ERR_CA_PATH_IS_NOT_VALID = exports.ERR_WRONG_CA = exports.ERR_WRONG_KEY_CERT = exports.ERR_NAME_WITHOUT_ASTERISK = exports.ERR_PORT_IS_NOT_VALID = exports.ERR_REGION_IS_NOT_VALID = exports.ERR_PATH_IS_NOT_DIRECTORY = exports.ERR_DIRECTORY_DOES_NOT_EXISTS = exports.ERR_TERMINATE_IS_NOT_VALID = exports.ERR_TIMEOUT_IS_NOT_VALID = exports.ERR_TYPE_IS_NOT_VALID = exports.ERR_TARGET_IS_NOT_VALID = exports.ERR_SAVING_AGENT_CONFIG = exports.ERR_AGENT_NOT_REGISTERED = void 0;
|
|
4
4
|
exports.TXT_AGENT_ENABLED = exports.TXT_AGENT_TARGET_DISABLED = exports.TXT_AGENT_TARGET_ENABLED = exports.TXT_AGENT_IS_DISABLED = exports.TXT_AGENT_IS_ENABLED_AND_HAVE_TROUBLES = exports.TXT_AGENT_IS_ENABLED_AND_INITIALIZING = exports.TXT_AGENT_IS_ENABLED_AND_STOPPED = exports.TXT_AGENT_IS_ENABLED_AND_STARTED = exports.TXT_AGENT_RESTARTED = exports.TXT_AGENT_STARTED = exports.TXT_AGENT_STOPPED = exports.WARN_BROWSER_VERSION = exports.ERR_NO_SNAPSHOTS_TO_SEND = exports.ERR_INVALID_SNAPSHOT = exports.ERR_GETTING_COMMIT_DETAILS = exports.ERR_GETTING_BASE_COMMIT = exports.ERR_HEAD_BRANCH_NOT_DEFINED = exports.ERR_BASE_BRANCH_NOT_DEFINED = exports.ERR_INVALID_COMMIT_HASH = exports.ERR_GETTING_COMMIT_HASH = exports.ERR_INVALID_BRANCH_NAME = exports.ERR_GETTING_BRANCH_NAME = exports.ERR_MISSING_HEAD_COMMIT_IN_FILE = exports.ERR_READING_FILE_WITH_HEAD_COMMIT = exports.ERR_MISSING_FILE_WITH_HEAD_COMMIT = exports.ERR_GITHUB_EVENT_PATH_NOT_FOUND = exports.ERR_TEST_EXECUTION = exports.ERR_INVALID_JSON = exports.ERR_INVALID_DOWNLOAD_RESPONSE = exports.ERR_INVALID_SCRAP_RESPONSE = exports.ERR_INVALID_COMPARE_LINKS_RESPONSE = exports.ERR_INVALID_STORYBOOK_RESPONSE = exports.ERR_INVALID_DEFAULT_SETTINGS_RESPONSE = exports.ERR_INVALID_CLOSE_SESSION_RESPONSE = exports.ERR_INVALID_SNAPSHOTS_RESPONSE = exports.ERR_INVALID_SNAPSHOT_RESPONSE = exports.ERR_MISSING_URLS = exports.ERR_RESOURCE_NOT_FOUND = exports.ERR_MISSING_EXEC_COMMAND = exports.ERR_PARSING_STORIES = exports.ERR_UNSUPPORTED_STORYBOOK = exports.ERR_MISSING_STORYBOOK_INDEX_FILE = exports.ERR_WRONG_STORYBOOK_DIRECTORY = exports.ERR_MISSING_BUILD_ID = exports.ERR_MISSING_UT_TOKEN = exports.ERR_MISSING_VT_TOKEN = exports.ERR_CONFIG_CORRUPTED = exports.ERR_WRONG_TOKEN = exports.ERR_TOKEN_NOT_PROVIDED = exports.ERR_CANT_CREATE_DIR_IN_HOME = void 0;
|
|
5
5
|
exports.DESC_COMMAND_AGENT_VERSION = exports.DESC_COMMAND_AGENT_UPDATE = exports.DESC_COMMAND_AGENT_TARGET = exports.DESC_COMMAND_AGENT_TUNNEL = exports.DESC_COMMAND_AGENT_STOP = exports.DESC_COMMAND_AGENT_TARGET_DISABLE = exports.DESC_COMMAND_AGENT_TARGET_ENABLE = exports.DESC_COMMAND_AGENT_TARGET_STATUS = exports.DESC_COMMAND_AGENT_STATUS = exports.DESC_COMMAND_AGENT_RESTART = exports.DESC_COMMAND_AGENT_ENABLE = exports.DESC_COMMAND_AGENT_DISABLE = exports.DESC_COMMAND_AGENT_START = exports.DESC_COMMAND_AGENT_INSTALL = exports.DESC_COMMAND_AGENT_UNINSTALL = exports.DESC_COMMAND_AGENT_TUNNEL_REMOVE = exports.DESC_COMMAND_AGENT_TUNNEL_STATUS = exports.DESC_COMMAND_AGENT_TUNNEL_LIST = exports.DESC_COMMAND_CONFIG_SET = exports.DESC_COMMAND_CONFIG_REMOVE = exports.DESC_COMMAND_CONFIG_GET = exports.DESC_COMMAND_CONFIG_ADD = exports.DESC_COMMAND_CONFIG_SET_WHITELIST = exports.DESC_COMMAND_CONFIG_SET_TOKEN = exports.DESC_COMMAND_CONFIG_SET_TIMEOUT = exports.DESC_COMMAND_CONFIG_SET_REGION = exports.DESC_COMMAND_CONFIG_REMOVE_TUNNEL = exports.DESC_COMMAND_CONFIG_GET_WHITELIST = exports.DESC_COMMAND_CONFIG_GET_TUNNELS = exports.DESC_COMMAND_CONFIG_GET_TUNNEL = exports.DESC_COMMAND_CONFIG_GET_TOKEN = exports.DESC_COMMAND_CONFIG_GET_TIMEOUT = exports.DESC_COMMAND_CONFIG_GET_REGION = exports.DESC_COMMAND_CONFIG_ADD_TLS = exports.DESC_COMMAND_CONFIG_ADD_TCP = exports.DESC_COMMAND_CONFIG_ADD_HTTP = exports.AGENT_FETCH_RETRY = exports.NO_TUNNELS_STARTED = exports.TXT_TUNNEL_ADDED = exports.TXT_TUNNEL_REMOVED = exports.TXT_REGION_SAVED = exports.TXT_TIMEOUT_SAVED = exports.TXT_TOKEN_REMOVED = exports.TXT_TOKEN_SAVED = exports.TXT_WHITELIST_SAVED = exports.TXT_TUNNEL_STOPPED = exports.TXT_TUNNEL_STARTED = exports.TXT_AGENT_DISABLED = exports.TXT_AGENT_ALREADY_ENABLED = exports.TXT_AGENT_UPDATED = void 0;
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.DEBUG_WAIT_FOR_IDLE_TIMEOUT = exports.DEBUG_WAIT_FOR_IDLE = exports.DEBUG_RESOURCE_DISCOVERY_TIMEOUT = exports.DEBUG_AUTO_WIDTH = exports.DEBUG_AUTO_SCROLL = exports.DEBUG_RESOURCE_SCRAPPING_URL = exports.DEBUG_SNAPSHOT_PROCESSING = exports.DEBUG_SNAPSHOTS_PROCESSING = exports.DEBUG_EXEC_COMMAND = exports.DEBUG_EXEC_TEST_COMMAND = exports.LOG_INSTALLED_BROWSER = exports.LOG_SESSION_LINK = exports.LOG_SENDING_DATA = exports.LOG_SENDING_REQUEST = exports.LOG_PROCESSING_SNAPSHOTS = exports.LOG_RUNNING_EXEC_COMMAND = void 0;
|
|
6
|
+
exports.OPTION_TLS_CA = exports.OPTION_TLS_CERT = exports.OPTION_TLS_KEY = exports.OPTION_HTTP_CIRCUIT_BREAKER = exports.OPTION_HTTP_COMPRESSION = exports.OPTION_HTTP_2 = exports.OPTION_HTTP_VERIFY = exports.OPTION_HTTP_LOG = exports.OPTION_HTTP_AUTH = exports.OPTION_HTTP_HOST = exports.OPTION_FORCE = exports.OPTION_TOKEN = exports.OPTION_TIMEOUT = exports.OPTION_FOLLOW = exports.OPTION_SERVE = exports.OPTION_HEADER_USER_AGENT = exports.OPTION_RESPONSE_HEADER = exports.OPTION_HEADER = exports.OPTION_WHITELIST = exports.OPTION_DEFAULT_REGION = exports.OPTION_REGION = exports.TXT_CI_INFO = exports.TXT_STORIES_AMOUNT = exports.TXT_OPENING_TUNNEL = exports.TXT_UPDATING_AGENT = exports.TXT_ENABLING_AGENT = exports.TXT_DISABLING_AGENT = exports.TXT_NEW_AGENT_VERSION = exports.TXT_NEW_CLI_VERSION = exports.TXT_NEW_CLI_DOCKER_VERSION = exports.OPTION_UPLOAD_DRY_RUN = exports.OPTION_UPLOAD_REPORT_FORMAT = exports.OPTION_UPLOAD_REPORT_GLOB = exports.DESC_COMMAND_UT_UPLOAD = exports.DESC_COMMAND_UT = exports.DESC_COMMAND_VT_INSTALL_BROWSER = exports.DESC_COMMAND_VT_EXEC = exports.DESC_COMMAND_VT_SCRAP = exports.DESC_COMMAND_VT_COMPARE = exports.DESC_COMMAND_VT_STORYBOOK = exports.DESC_COMMAND_VT_CLOSE = exports.DESC_COMMAND_VT = exports.DESC_PROGRAM = exports.DESC_COMMAND_TLS = exports.DESC_COMMAND_TCP = exports.DESC_COMMAND_START = exports.DESC_COMMAND_TUNNEL = exports.DESC_COMMAND_AGENT = exports.DESC_COMMAND_HTTP = exports.DESC_COMMAND_CONFIG = void 0;
|
|
7
|
+
exports.LOG_AGENT_SYSTEM_DIR = exports.LOG_ERROR_SAVING_AGENT_LOCAL_CONFIG = exports.LOG_ERROR_SAVING_AGENT_SYSTEM_CONFIG = exports.LOG_ERROR_SAVING_AGENT_CONFIG = exports.LOG_SAVING_AGENT_LOCAL_CONFIG = exports.LOG_SAVING_AGENT_SYSTEM_CONFIG = exports.LOG_SAVING_AGENT_CONFIG = exports.LOG_REGISTERING_AGENT = exports.OPTION_SCRAP_OUTPUT_DIR = exports.OPTION_SCRAP_DELAY = exports.OPTION_SCRAP_DARK_MODE = exports.OPTION_SCRAP_WAIT_FOR_ELEMENT = exports.OPTION_SCRAP_DEVICE_PIXEL_RATIO = exports.OPTION_SCRAP_VIEWPORT = exports.OPTION_SCRAP_BROWSER = exports.OPTION_SCRAP_XPATH_SELECTOR = exports.OPTION_SCRAP_CSS_SELECTOR = exports.OPTION_SCRAP_FULL_PAGE = exports.OPTION_SCRAP_QUALITY = exports.OPTION_SCRAP_OUTPUT_TYPE = exports.OPTION_SCRAP_FOLLOW = exports.OPTION_SCRAP_URL = exports.OPTION_COMPARE_WAIT_FOR = exports.OPTION_COMPARE_DELAY = exports.OPTION_COMPARE_HEADER = exports.OPTION_COMPARE_COOKIE = exports.OPTION_COMPARE_IGNORE = exports.OPTION_COMPARE_IGNORE_URLS = exports.OPTION_COMPARE_DRY_RUN = exports.OPTION_COMPARE_URLS_FILE = exports.OPTION_COMPARE_SITEMAP = exports.OPTION_COMPARE_URLS = exports.OPTION_COMPARE_RESPECT_ROBOTS = exports.OPTION_COMPARE_FOLLOW = exports.OPTION_EXEC_PARALLEL = exports.OPTION_EXEC_ONE_BY_ONE = exports.OPTION_EXEC_SKIP_DISCOVERY = exports.OPTION_EXEC_COMMAND = exports.OPTION_AGENT_DEBUG = exports.OPTION_AGENT_PORT = exports.OPTION_AGENT_TARGET = exports.OPTION_PASS = exports.OPTION_USER = exports.OPTION_AGENT_TOKEN = exports.OPTION_AGENT_START = exports.OPTION_AGENT_ID = exports.OPTION_ID = exports.OPTION_NAME = exports.OPTION_TARGET = exports.OPTION_TLS_TERMINATE = void 0;
|
|
8
|
+
exports.LOG_TUNNEL_TLS_AGENT_STREAM = exports.LOG_TUNNEL_TLS_REGION_STREAM = exports.LOG_TUNNEL_TLS_TARGET_STREAM = exports.LOG_TUNNEL_HTTP2_STREAM = exports.LOG_TUNNEL_HTTP1_STREAM = exports.LOG_TUNNEL_TCP_STREAM = exports.LOG_TUNNEL_HTTP_WRONG_USER_AGENTS = exports.LOG_TUNNEL_HTTP_CIRCUIT_BREAKER_OPEN = exports.LOG_TUNNEL_HTTP_RATE_LIMIT = exports.LOG_TUNNEL_HTTP_WRON_AUTH = exports.LOG_TUNNEL_IDENTIFIED = exports.LOG_TUNNEL_DISCONNECTED = exports.LOG_TUNNEL_FAILED = exports.LOG_TUNNEL_CONNECTED = exports.LOG_AGENT_STARTED = exports.LOG_AGENT_SERVER_STARTED = exports.LOG_ERROR_STARTING_AGENT_SERVER = exports.LOG_REQUEST = exports.LOG_SSH_CONNECTION = exports.LOG_WRONG_STREAM = exports.LOG_DETECTED_STREAM = exports.LOG_HTTP2_REQUEST = exports.LOG_HTTP2_CONNECTION = exports.LOG_HTTP1_REQUEST = exports.LOG_HTTP1_CONNECTION = exports.LOG_ERROR = exports.LOG_STOPPING_TUNNEL = exports.LOG_STARTING_TUNNEL = exports.LOG_ENABLING_AGENT_TARGET = exports.LOG_DISABLING_AGENT_TARGET = exports.LOG_REMOVING_TUNNEL = exports.LOG_TUNNEL_REGISTERED = exports.LOG_ERROR_WHILE_REFRESHING_AGENT = exports.LOG_REGISTERING_TUNNEL = exports.LOG_GETTING_AGENT = exports.LOG_UNREGISTERING_AGENT = exports.LOG_REGION_DETECTED = exports.LOG_AGENT_REGISTERED = exports.LOG_SOCKET_DISCONNECTED = exports.LOG_SOCKET_CONNECTED = exports.LOG_AGENT_NSSM_CLEARING = exports.LOG_AGENT_NSSM_EXTRACTING = exports.LOG_AGENT_NSSM_DOWNLOADING = exports.LOG_AGENT_ENABLED = exports.LOG_AGENT_STARTING_SYSTEM = exports.LOG_AGENT_STOPPING_SYSTEM = exports.LOG_AGENT_ENABLING_SYSTEM = exports.LOG_AGENT_SYSTEM_SERVICE_CONFIG = exports.LOG_AGENT_EXTRACTING_ARCHIVE = exports.LOG_AGENT_DOWNLOADING_ARCHIVE = void 0;
|
|
9
|
+
exports.DEBUG_WAIT_FOR_IDLE_TIMEOUT = exports.DEBUG_WAIT_FOR_IDLE = exports.DEBUG_RESOURCE_DISCOVERY_TIMEOUT = exports.DEBUG_AUTO_WIDTH = exports.DEBUG_AUTO_SCROLL = exports.DEBUG_RESOURCE_SCRAPPING_URL = exports.DEBUG_SNAPSHOT_PROCESSING = exports.DEBUG_SNAPSHOTS_PROCESSING = exports.DEBUG_EXEC_COMMAND = exports.DEBUG_EXEC_TEST_COMMAND = exports.LOG_INSTALLED_BROWSER = exports.LOG_SESSION_LINK = exports.LOG_SENDING_DATA = exports.LOG_SENDING_REQUEST = exports.LOG_PROCESSING_SNAPSHOTS = exports.LOG_RUNNING_EXEC_COMMAND = exports.LOG_TUNNEL_SSH_STREAM = void 0;
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
exports.ERR_AGENT_NOT_REGISTERED = 'Agent not registered. Exiting.';
|
|
12
12
|
exports.ERR_SAVING_AGENT_CONFIG = 'Failed saving agent config. Exiting.';
|
|
@@ -192,6 +192,7 @@ exports.DESC_COMMAND_AGENT_VERSION = 'Show the currently installed version';
|
|
|
192
192
|
exports.DESC_COMMAND_CONFIG = 'The config command gives a quick way to create or update configuration file.';
|
|
193
193
|
exports.DESC_COMMAND_HTTP = 'Starts a tunnel listening for HTTP/HTTPS traffic with a specific hostname.';
|
|
194
194
|
exports.DESC_COMMAND_AGENT = 'The agent command manages installation and execution of bdy as an operating system service on Windows, OS X and Linux systems';
|
|
195
|
+
exports.DESC_COMMAND_TUNNEL = 'The tunnel command manages tunnels configuration';
|
|
195
196
|
exports.DESC_COMMAND_START = 'Starts tunnel from the configuration file.';
|
|
196
197
|
exports.DESC_COMMAND_TCP = 'Starts a tunnel which forwards all TCP traffic on a public port to a local address. This is extremely useful for exposing services that run non-HTTP traffic (ssh, sip, rdp, game servers, etc).';
|
|
197
198
|
exports.DESC_COMMAND_TLS = 'Starts a tunnel listening for TLS traffic on port 443 with a specific hostname.';
|
|
@@ -7,7 +7,7 @@ const http_1 = __importDefault(require("http"));
|
|
|
7
7
|
const https_1 = __importDefault(require("https"));
|
|
8
8
|
const http2_1 = __importDefault(require("http2"));
|
|
9
9
|
const uuid_1 = require("uuid");
|
|
10
|
-
const
|
|
10
|
+
const texts_1 = require("../texts");
|
|
11
11
|
const CONNECTION_TIMEOUT = 5000;
|
|
12
12
|
const STREAM_LIMIT = 10;
|
|
13
13
|
class TunnelAgent {
|
|
@@ -35,7 +35,7 @@ class TunnelAgent {
|
|
|
35
35
|
return new Promise((resolve, reject) => {
|
|
36
36
|
const ts = setTimeout(() => {
|
|
37
37
|
TunnelAgent.deleteClient(authority, client, id);
|
|
38
|
-
reject(new Error(
|
|
38
|
+
reject(new Error(texts_1.ERR_CONNECTION_TIMEOUT));
|
|
39
39
|
}, CONNECTION_TIMEOUT);
|
|
40
40
|
const client = http2_1.default.connect(authority, {
|
|
41
41
|
rejectUnauthorized: verify,
|
|
@@ -52,7 +52,7 @@ class TunnelAgent {
|
|
|
52
52
|
client.once('error', () => {
|
|
53
53
|
clearTimeout(ts);
|
|
54
54
|
TunnelAgent.deleteClient(authority, client, id);
|
|
55
|
-
reject(new Error(
|
|
55
|
+
reject(new Error(texts_1.ERR_CONNECTION_ERROR));
|
|
56
56
|
});
|
|
57
57
|
client.once('connect', () => {
|
|
58
58
|
clearTimeout(ts);
|
|
@@ -0,0 +1,99 @@
|
|
|
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 logger_1 = __importDefault(require("../../logger"));
|
|
7
|
+
const texts_1 = require("../../texts");
|
|
8
|
+
const ws_1 = require("ws");
|
|
9
|
+
const TIMEOUT = 120000;
|
|
10
|
+
const openSocket = (port, path) => {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const ws = new ws_1.WebSocket(`ws://localhost:${port}${path}`);
|
|
13
|
+
ws.on('error', () => {
|
|
14
|
+
reject(new Error(texts_1.ERR_FAILED_TO_CONNECT_TO_AGENT));
|
|
15
|
+
});
|
|
16
|
+
ws.on('open', () => {
|
|
17
|
+
resolve(ws);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const makeRequest = async (port, path, body) => {
|
|
22
|
+
const c = new AbortController();
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
c.abort();
|
|
25
|
+
}, TIMEOUT);
|
|
26
|
+
const response = await fetch(`http://localhost:${port}${path}`, {
|
|
27
|
+
body: body ? JSON.stringify(body) : null,
|
|
28
|
+
headers: { 'Content-Type': 'application/json' },
|
|
29
|
+
method: 'POST',
|
|
30
|
+
signal: c.signal,
|
|
31
|
+
});
|
|
32
|
+
if (response.status === 404) {
|
|
33
|
+
throw new Error(texts_1.ERR_NOT_FOUND);
|
|
34
|
+
}
|
|
35
|
+
if (response.status === 400) {
|
|
36
|
+
const data = await response.json();
|
|
37
|
+
throw new Error(data.message);
|
|
38
|
+
}
|
|
39
|
+
if (response.status !== 200) {
|
|
40
|
+
throw new Error(texts_1.ERR_SWW);
|
|
41
|
+
}
|
|
42
|
+
let data;
|
|
43
|
+
try {
|
|
44
|
+
data = await response.json();
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
logger_1.default.error(texts_1.LOG_ERROR);
|
|
48
|
+
logger_1.default.error(err);
|
|
49
|
+
throw new Error(texts_1.ERR_FAILED_TO_CONNECT_TO_AGENT);
|
|
50
|
+
}
|
|
51
|
+
return data;
|
|
52
|
+
};
|
|
53
|
+
class ApiAgent {
|
|
54
|
+
constructor(port) {
|
|
55
|
+
this.port = port;
|
|
56
|
+
}
|
|
57
|
+
async fetchStatus() {
|
|
58
|
+
return makeRequest(this.port, '/status');
|
|
59
|
+
}
|
|
60
|
+
async addTunnel(data) {
|
|
61
|
+
return makeRequest(this.port, '/tunnel/add', data);
|
|
62
|
+
}
|
|
63
|
+
async fetchTunnels() {
|
|
64
|
+
return makeRequest(this.port, '/tunnels');
|
|
65
|
+
}
|
|
66
|
+
async fetchAgentTarget() {
|
|
67
|
+
return makeRequest(this.port, '/target');
|
|
68
|
+
}
|
|
69
|
+
async enableAgentTarget() {
|
|
70
|
+
return makeRequest(this.port, '/target/enable');
|
|
71
|
+
}
|
|
72
|
+
async disableAgentTarget() {
|
|
73
|
+
return makeRequest(this.port, '/target/disable');
|
|
74
|
+
}
|
|
75
|
+
async stopTunnel(id) {
|
|
76
|
+
return makeRequest(this.port, '/tunnel/stop', {
|
|
77
|
+
id,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async startAgent() {
|
|
81
|
+
return makeRequest(this.port, '/agent/start');
|
|
82
|
+
}
|
|
83
|
+
async disableAgent() {
|
|
84
|
+
return makeRequest(this.port, '/agent/disable');
|
|
85
|
+
}
|
|
86
|
+
async enableAgent() {
|
|
87
|
+
return makeRequest(this.port, '/agent/enable');
|
|
88
|
+
}
|
|
89
|
+
async restartAgent() {
|
|
90
|
+
return makeRequest(this.port, '/agent/restart');
|
|
91
|
+
}
|
|
92
|
+
async stopAgent() {
|
|
93
|
+
return makeRequest(this.port, '/agent/stop');
|
|
94
|
+
}
|
|
95
|
+
async socketTunnel(id) {
|
|
96
|
+
return openSocket(this.port, `/tunnel?id=${encodeURIComponent(id)}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.default = ApiAgent;
|
|
@@ -0,0 +1,139 @@
|
|
|
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 tunnel_1 = __importDefault(require("../tunnel"));
|
|
8
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
9
|
+
const agent_1 = __importDefault(require("../../agent/agent"));
|
|
10
|
+
const utils_1 = require("../../utils");
|
|
11
|
+
const texts_1 = require("../../texts");
|
|
12
|
+
const TIMEOUT = 120000;
|
|
13
|
+
const nodeFetch = (url, opts) => {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
import('node-fetch')
|
|
16
|
+
.then(({ default: fetch }) => {
|
|
17
|
+
fetch(url, opts).then(resolve).catch(reject);
|
|
18
|
+
})
|
|
19
|
+
.catch(reject);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const makeRequest = async (host, path, body, method = 'POST', respAsJson = true, timeout = TIMEOUT) => {
|
|
23
|
+
let data;
|
|
24
|
+
try {
|
|
25
|
+
const c = new AbortController();
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
c.abort();
|
|
28
|
+
}, timeout);
|
|
29
|
+
const response = await nodeFetch(`${host}${path}`, {
|
|
30
|
+
body: body ? JSON.stringify(body) : null,
|
|
31
|
+
headers: body ? { 'Content-Type': 'application/json' } : null,
|
|
32
|
+
method,
|
|
33
|
+
signal: c.signal,
|
|
34
|
+
agent: new https_1.Agent({
|
|
35
|
+
rejectUnauthorized: false,
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
if (respAsJson)
|
|
39
|
+
data = await response.json();
|
|
40
|
+
else
|
|
41
|
+
data = await response.text();
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
throw new utils_1.ApiErrorFailedToConnect(host);
|
|
45
|
+
}
|
|
46
|
+
if (respAsJson) {
|
|
47
|
+
if (data.code !== 200) {
|
|
48
|
+
throw (0, utils_1.apiErrorCodeToClass)(data.result.code, host);
|
|
49
|
+
}
|
|
50
|
+
return data.result;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return data;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
class ApiBuddyClass {
|
|
57
|
+
async register(service, target, host, token, onDefaultRegion) {
|
|
58
|
+
const version = (0, utils_1.getVersion)();
|
|
59
|
+
const hostname = (0, utils_1.getHostname)();
|
|
60
|
+
const platform = (0, utils_1.getPlatform)();
|
|
61
|
+
logger_1.default.info(texts_1.LOG_REGISTERING_AGENT);
|
|
62
|
+
const r = await makeRequest(host, '/tunnel/agent/add', {
|
|
63
|
+
token,
|
|
64
|
+
version,
|
|
65
|
+
hostname,
|
|
66
|
+
platform,
|
|
67
|
+
service,
|
|
68
|
+
target,
|
|
69
|
+
});
|
|
70
|
+
logger_1.default.info((0, texts_1.LOG_AGENT_REGISTERED)(r.id));
|
|
71
|
+
logger_1.default.info((0, texts_1.LOG_REGION_DETECTED)(r.region));
|
|
72
|
+
if (onDefaultRegion)
|
|
73
|
+
onDefaultRegion(r.region);
|
|
74
|
+
return new agent_1.default(r.id, host, r.token, service, target, this, false);
|
|
75
|
+
}
|
|
76
|
+
async unregister(id, host, token) {
|
|
77
|
+
logger_1.default.info(texts_1.LOG_UNREGISTERING_AGENT);
|
|
78
|
+
await makeRequest(host, '/tunnel/agent/remove', {
|
|
79
|
+
token,
|
|
80
|
+
id,
|
|
81
|
+
});
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
async fetchAgent(id, host, token) {
|
|
85
|
+
logger_1.default.info(texts_1.LOG_GETTING_AGENT);
|
|
86
|
+
const r = await makeRequest(host, '/tunnel/agent/fetch', {
|
|
87
|
+
token,
|
|
88
|
+
id,
|
|
89
|
+
});
|
|
90
|
+
return new agent_1.default(r.id, host, token, !!r.service, !!r.target, this, !!r.disabled);
|
|
91
|
+
}
|
|
92
|
+
async fetchAgentKeys(id, host, token) {
|
|
93
|
+
return await makeRequest(host, '/tunnel/agent/fetch/keys', {
|
|
94
|
+
token,
|
|
95
|
+
id,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
async disableTarget(agentId, host, token) {
|
|
99
|
+
logger_1.default.info(texts_1.LOG_DISABLING_AGENT_TARGET);
|
|
100
|
+
await makeRequest(host, '/tunnel/agent/target/disable', {
|
|
101
|
+
agentId,
|
|
102
|
+
token,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
async enableTarget(agentId, host, token) {
|
|
106
|
+
logger_1.default.info(texts_1.LOG_ENABLING_AGENT_TARGET);
|
|
107
|
+
await makeRequest(host, '/tunnel/agent/target/enable', {
|
|
108
|
+
agentId,
|
|
109
|
+
token,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async addTunnel(agentId, host, token, prepared, sshHostKey) {
|
|
113
|
+
logger_1.default.info(texts_1.LOG_REGISTERING_TUNNEL);
|
|
114
|
+
const config = await makeRequest(host, '/tunnel/add', {
|
|
115
|
+
...prepared,
|
|
116
|
+
token,
|
|
117
|
+
agentId,
|
|
118
|
+
});
|
|
119
|
+
logger_1.default.info((0, texts_1.LOG_TUNNEL_REGISTERED)(config.id));
|
|
120
|
+
return new tunnel_1.default({
|
|
121
|
+
...config,
|
|
122
|
+
sshHostKey,
|
|
123
|
+
agent: { id: agentId, host, token },
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async removeTunnel(agentId, tunnelId, host, token) {
|
|
127
|
+
logger_1.default.info(texts_1.LOG_REMOVING_TUNNEL);
|
|
128
|
+
await makeRequest(host, '/tunnel/remove', {
|
|
129
|
+
agentId,
|
|
130
|
+
tunnelId,
|
|
131
|
+
token,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async fetchMyIp() {
|
|
135
|
+
return makeRequest('https://es.buddy.works', '/ip', null, 'GET', false);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const ApiBuddy = new ApiBuddyClass();
|
|
139
|
+
exports.default = ApiBuddy;
|