bdy 1.8.3-dev → 1.8.4-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/bin/cli.js +5 -0
- package/distTs/src/agent/linux.js +119 -0
- package/distTs/src/agent/manager.js +395 -0
- package/distTs/src/agent/osx.js +139 -0
- package/distTs/src/agent/socket/tunnel.js +212 -0
- package/distTs/src/agent/socket.js +220 -0
- package/distTs/src/agent/system.js +177 -0
- package/distTs/src/agent/wait.js +23 -0
- package/distTs/src/agent/windows.js +159 -0
- package/distTs/src/agent.js +237 -0
- package/distTs/src/api/agent.js +84 -0
- package/distTs/src/api/buddy.js +117 -0
- package/distTs/src/api/socket.js +133 -0
- package/distTs/src/cfg.js +238 -0
- package/distTs/src/command/agent/install.js +106 -0
- package/distTs/src/command/agent/restart.js +27 -0
- package/distTs/src/command/agent/run.js +19 -0
- package/distTs/src/command/agent/start.js +28 -0
- package/distTs/src/command/agent/status.js +35 -0
- package/distTs/src/command/agent/stop.js +28 -0
- package/distTs/src/command/agent/tunnel/http.js +44 -0
- package/distTs/src/command/agent/tunnel/list.js +27 -0
- package/distTs/src/command/agent/tunnel/remove.js +28 -0
- package/distTs/src/command/agent/tunnel/start.js +34 -0
- package/distTs/src/command/agent/tunnel/status.js +31 -0
- package/distTs/src/command/agent/tunnel/tcp.js +43 -0
- package/distTs/src/command/agent/tunnel/tls.js +43 -0
- package/distTs/src/command/agent/tunnel.js +23 -0
- package/distTs/src/command/agent/uninstall.js +38 -0
- package/distTs/src/command/agent/update.js +38 -0
- package/distTs/src/command/agent/version.js +21 -0
- package/distTs/src/command/agent.js +29 -0
- package/distTs/src/command/config/add/http.js +25 -0
- package/distTs/src/command/config/add/tcp.js +25 -0
- package/distTs/src/command/config/add/tls.js +25 -0
- package/distTs/src/command/config/add.js +15 -0
- package/distTs/src/command/config/get/region.js +15 -0
- package/distTs/src/command/config/get/timeout.js +15 -0
- package/distTs/src/command/config/get/token.js +15 -0
- package/distTs/src/command/config/get/tunnel.js +19 -0
- package/distTs/src/command/config/get/tunnels.js +15 -0
- package/distTs/src/command/config/get/whitelist.js +15 -0
- package/distTs/src/command/config/get.js +21 -0
- package/distTs/src/command/config/remove/tunnel.js +19 -0
- package/distTs/src/command/config/remove.js +11 -0
- package/distTs/src/command/config/set/region.js +17 -0
- package/distTs/src/command/config/set/timeout.js +17 -0
- package/distTs/src/command/config/set/token.js +16 -0
- package/distTs/src/command/config/set/whitelist.js +17 -0
- package/distTs/src/command/config/set.js +17 -0
- package/distTs/src/command/config.js +17 -0
- package/distTs/src/command/http.js +30 -0
- package/distTs/src/command/pre.js +49 -0
- package/distTs/src/command/start.js +28 -0
- package/distTs/src/command/tcp.js +30 -0
- package/distTs/src/command/tls.js +30 -0
- package/distTs/src/command/version.js +13 -0
- package/distTs/src/command/vt/close.js +28 -0
- package/distTs/src/command/vt/exec.js +79 -0
- package/distTs/src/command/vt/storybook.js +90 -0
- package/distTs/src/command/vt.js +15 -0
- package/distTs/src/format.js +172 -0
- package/distTs/src/index.js +40 -0
- package/distTs/src/input.js +286 -0
- package/distTs/src/logger.js +93 -0
- package/distTs/src/output/interactive/tunnel.js +860 -0
- package/distTs/src/output/noninteractive/agent/tunnels.js +43 -0
- package/distTs/src/output/noninteractive/config/tunnel.js +67 -0
- package/distTs/src/output/noninteractive/config/tunnels.js +18 -0
- package/distTs/src/output/noninteractive/tunnel.js +59 -0
- package/distTs/src/output.js +138 -0
- package/distTs/src/server/cert.js +52 -0
- package/distTs/src/server/http1.js +74 -0
- package/distTs/src/server/http2.js +74 -0
- package/distTs/src/server/sftp.js +487 -0
- package/distTs/src/server/ssh.js +112 -0
- package/distTs/src/server/tls.js +41 -0
- package/distTs/src/ssh/client.js +191 -0
- package/distTs/src/texts.js +345 -0
- package/distTs/src/tunnel/agent.js +100 -0
- package/distTs/src/tunnel/compression.js +41 -0
- package/distTs/src/tunnel/dns.js +54 -0
- package/distTs/src/tunnel/html.js +30 -0
- package/distTs/src/tunnel/http/log.js +196 -0
- package/distTs/src/tunnel/http/serve.js +132 -0
- package/distTs/src/tunnel/http/stream.js +45 -0
- package/distTs/src/tunnel/http.js +405 -0
- package/distTs/src/tunnel/identification.js +96 -0
- package/distTs/src/tunnel/latency.js +71 -0
- package/distTs/src/tunnel/tcp.js +92 -0
- package/distTs/src/tunnel.js +647 -0
- package/distTs/src/types/ciInfo.js +10 -0
- package/distTs/src/types/options.js +2 -0
- package/distTs/src/types/plugin.js +2 -0
- package/distTs/src/types/queue.js +2 -0
- package/distTs/src/types/requests.js +2 -0
- package/distTs/src/types/resources.js +2 -0
- package/distTs/src/types/snapshots.js +2 -0
- package/distTs/src/types/storybook.js +2 -0
- package/distTs/src/utils.js +437 -0
- package/distTs/src/visualTest/browser.js +32 -0
- package/distTs/src/visualTest/ci.js +206 -0
- package/distTs/src/visualTest/context.js +44 -0
- package/distTs/src/visualTest/exec.js +51 -0
- package/distTs/src/visualTest/queue.js +43 -0
- package/distTs/src/visualTest/requests.js +197 -0
- package/distTs/src/visualTest/resources.js +195 -0
- package/distTs/src/visualTest/server.js +33 -0
- package/distTs/src/visualTest/snapshots.js +109 -0
- package/distTs/src/visualTest/utils/parseDom.js +238 -0
- package/distTs/src/visualTest/validation.js +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1,133 @@
|
|
|
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_js_1 = __importDefault(require("../logger.js"));
|
|
9
|
+
const texts_1 = require("../texts");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
const socket_io_client_1 = require("socket.io-client");
|
|
12
|
+
const MAX_REQUESTS_SYNC_WINDOW = 30000;
|
|
13
|
+
const MAX_REQUESTS_SYNC_IN_WINDOW = 100;
|
|
14
|
+
class ApiSocketClass extends events_1.default {
|
|
15
|
+
fetch(activate = true, action = null, resetFirstHeard = false, tunnels) {
|
|
16
|
+
this.socket.emit('fetchTunnelAgent', {
|
|
17
|
+
id: this.id,
|
|
18
|
+
token: this.token,
|
|
19
|
+
hostname: this.hostname,
|
|
20
|
+
platform: this.platform,
|
|
21
|
+
version: this.version,
|
|
22
|
+
activate,
|
|
23
|
+
action,
|
|
24
|
+
resetFirstHeard,
|
|
25
|
+
tunnels,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
update(activate, tunnels, force = false) {
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
// nie robimy update jak byl mniej niz 5s temu
|
|
31
|
+
if (!force && this.lastUpdate && now - this.lastUpdate < 5000)
|
|
32
|
+
return;
|
|
33
|
+
this.lastUpdate = now;
|
|
34
|
+
this.socket.emit('updateTunnelAgent', {
|
|
35
|
+
id: this.id,
|
|
36
|
+
token: this.token,
|
|
37
|
+
hostname: this.hostname,
|
|
38
|
+
platform: this.platform,
|
|
39
|
+
version: this.version,
|
|
40
|
+
activate,
|
|
41
|
+
tunnels,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
emitRequest(tunnelId, logRequest) {
|
|
45
|
+
this.socket.emit('tunnelRequest', {
|
|
46
|
+
id: this.id,
|
|
47
|
+
token: this.token,
|
|
48
|
+
tunnelId,
|
|
49
|
+
request: logRequest.toSocket(),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
request(tunnelId, logRequest) {
|
|
53
|
+
if (this.tunnelRequests > MAX_REQUESTS_SYNC_IN_WINDOW)
|
|
54
|
+
return;
|
|
55
|
+
this.tunnelRequests += 1;
|
|
56
|
+
logRequest.once(utils_1.EVENT_TUNNEL_HTTP_NEW_RESPONSE_END, () => {
|
|
57
|
+
this.emitRequest(tunnelId, logRequest);
|
|
58
|
+
});
|
|
59
|
+
this.emitRequest(tunnelId, logRequest);
|
|
60
|
+
}
|
|
61
|
+
onSyncAgent(data, action) {
|
|
62
|
+
this.emit(utils_1.SOCKET_IO_EVENT_AGENT, data, action);
|
|
63
|
+
}
|
|
64
|
+
onSyncTunnel(data, action) {
|
|
65
|
+
this.emit(utils_1.SOCKET_IO_EVENT_TUNNEL, data, action);
|
|
66
|
+
}
|
|
67
|
+
onSync(data) {
|
|
68
|
+
try {
|
|
69
|
+
const json = JSON.parse(data);
|
|
70
|
+
if (json.payloadType === 'TunnelAgentFront')
|
|
71
|
+
this.onSyncAgent(json.payload, json.action);
|
|
72
|
+
else if (json.payloadType === 'TunnelFront')
|
|
73
|
+
this.onSyncTunnel(json.payload, json.action);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// do nothing
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
constructor(host, id, token) {
|
|
80
|
+
super();
|
|
81
|
+
this.id = id;
|
|
82
|
+
this.token = token;
|
|
83
|
+
this.connected = false;
|
|
84
|
+
this.hostname = (0, utils_1.getHostname)();
|
|
85
|
+
this.platform = (0, utils_1.getPlatform)();
|
|
86
|
+
this.version = (0, utils_1.getVersion)();
|
|
87
|
+
this.lastUpdate = null;
|
|
88
|
+
this.tunnelRequests = 0;
|
|
89
|
+
setInterval(() => {
|
|
90
|
+
this.tunnelRequests = 0;
|
|
91
|
+
}, MAX_REQUESTS_SYNC_WINDOW);
|
|
92
|
+
this.socket = (0, socket_io_client_1.io)(host, {
|
|
93
|
+
forceNew: true,
|
|
94
|
+
autoConnect: true,
|
|
95
|
+
autoUnref: true,
|
|
96
|
+
forceBase64: true,
|
|
97
|
+
transports: ['websocket'],
|
|
98
|
+
reconnection: true,
|
|
99
|
+
rejectUnauthorized: false,
|
|
100
|
+
agent: new https_1.Agent({
|
|
101
|
+
rejectUnauthorized: false,
|
|
102
|
+
}),
|
|
103
|
+
maxHttpBufferSize: 3e6,
|
|
104
|
+
extraHeaders: {
|
|
105
|
+
cookie: 'a=b',
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
this.socket.on('connect', () => {
|
|
109
|
+
this.connected = true;
|
|
110
|
+
logger_js_1.default.info(texts_1.LOG_SOCKET_CONNECTED);
|
|
111
|
+
this.emit(utils_1.SOCKET_IO_EVENT_CONNECTED);
|
|
112
|
+
this.socket.emit('joinTunnelAgent', {
|
|
113
|
+
id: this.id,
|
|
114
|
+
token: this.token,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
this.socket.on('disconnect', () => {
|
|
118
|
+
this.connected = false;
|
|
119
|
+
logger_js_1.default.info(texts_1.LOG_SOCKET_DISCONNECTED);
|
|
120
|
+
this.emit(utils_1.SOCKET_IO_EVENT_DISCONNECTED);
|
|
121
|
+
});
|
|
122
|
+
this.socket.on('fetchTunnelAgentSuccess', (data) => {
|
|
123
|
+
logger_js_1.default.debug('Socket fetch success');
|
|
124
|
+
this.emit(utils_1.SOCKET_IO_EVENT_FETCH_SUCCESS, data);
|
|
125
|
+
});
|
|
126
|
+
this.socket.on('fetchTunnelAgentFailed', (code) => {
|
|
127
|
+
logger_js_1.default.debug('Socket fetch failed');
|
|
128
|
+
this.emit(utils_1.SOCKET_IO_EVENT_FETCH_FAILED, (0, utils_1.apiErrorCodeToClass)(code, host));
|
|
129
|
+
});
|
|
130
|
+
this.socket.on('sync', (data) => this.onSync(data));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.default = ApiSocketClass;
|
|
@@ -0,0 +1,238 @@
|
|
|
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 path_1 = require("path");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
9
|
+
const utils_js_1 = require("./utils.js");
|
|
10
|
+
const input_js_1 = __importDefault(require("./input.js"));
|
|
11
|
+
const texts_js_1 = require("./texts.js");
|
|
12
|
+
class Cfg {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.dir = (0, utils_js_1.getHomeDirectory)();
|
|
15
|
+
this.file = (0, path_1.resolve)(this.dir, 'cfg.json');
|
|
16
|
+
this.json = {};
|
|
17
|
+
this.load();
|
|
18
|
+
}
|
|
19
|
+
createDir() {
|
|
20
|
+
try {
|
|
21
|
+
(0, fs_1.mkdirSync)(this.dir, {
|
|
22
|
+
recursive: true,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
throw new Error((0, texts_js_1.ERR_CANT_CREATE_DIR_IN_HOME)('.bdy'));
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
(0, fs_1.chmodSync)(this.dir, 0o777);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// do nothing
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
createEmptyFile() {
|
|
36
|
+
try {
|
|
37
|
+
(0, fs_1.writeFileSync)(this.file, '{}', 'utf-8');
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
throw new Error((0, texts_js_1.ERR_CANT_CREATE_DIR_IN_HOME)('.bdy/cfg.json'));
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
(0, fs_1.chmodSync)(this.file, 0o666);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// do nothing
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
ensureDir() {
|
|
50
|
+
try {
|
|
51
|
+
(0, fs_1.statSync)(this.dir);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
this.createDir();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
ensureFile() {
|
|
58
|
+
this.ensureDir();
|
|
59
|
+
try {
|
|
60
|
+
(0, fs_1.statSync)(this.file);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
this.createEmptyFile();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
ensureTunnels() {
|
|
67
|
+
if (!this.json.tunnels)
|
|
68
|
+
this.json.tunnels = {};
|
|
69
|
+
}
|
|
70
|
+
async prepareTunnel(tunnelType, target, options, useDefaults) {
|
|
71
|
+
const type = input_js_1.default.type(tunnelType);
|
|
72
|
+
const tunnel = {
|
|
73
|
+
type,
|
|
74
|
+
target: input_js_1.default.target(target, type),
|
|
75
|
+
};
|
|
76
|
+
if (options.region !== undefined)
|
|
77
|
+
tunnel.region = input_js_1.default.region(options.region);
|
|
78
|
+
else if (useDefaults)
|
|
79
|
+
tunnel.region = this.getRegion();
|
|
80
|
+
if (options.whitelist !== undefined)
|
|
81
|
+
tunnel.whitelist = input_js_1.default.whitelist(options.whitelist);
|
|
82
|
+
else if (useDefaults)
|
|
83
|
+
tunnel.whitelist = this.getWhitelist();
|
|
84
|
+
if (options.timeout !== undefined)
|
|
85
|
+
tunnel.timeout = input_js_1.default.timeout(options.timeout);
|
|
86
|
+
else if (useDefaults)
|
|
87
|
+
tunnel.timeout = this.getTimeout();
|
|
88
|
+
if (options.domain !== undefined)
|
|
89
|
+
tunnel.domain = input_js_1.default.domain(options.domain);
|
|
90
|
+
if (options.subdomain !== undefined)
|
|
91
|
+
tunnel.subdomain = input_js_1.default.subdomain(options.subdomain);
|
|
92
|
+
if (type === utils_js_1.TUNNEL_HTTP) {
|
|
93
|
+
if (options.host !== undefined)
|
|
94
|
+
tunnel.host = options.host;
|
|
95
|
+
if (options.auth !== undefined) {
|
|
96
|
+
const { password, login } = input_js_1.default.auth(options.auth);
|
|
97
|
+
tunnel.login = login;
|
|
98
|
+
tunnel.password = password;
|
|
99
|
+
}
|
|
100
|
+
if (options.ca !== undefined)
|
|
101
|
+
tunnel.ca = input_js_1.default.ca(options.ca);
|
|
102
|
+
if (options.serve !== undefined)
|
|
103
|
+
tunnel.serve = input_js_1.default.serve(options.serve);
|
|
104
|
+
if (options.useragent !== undefined)
|
|
105
|
+
tunnel.useragents = input_js_1.default.useragents(options.useragent);
|
|
106
|
+
if (options.header !== undefined)
|
|
107
|
+
tunnel.headers = input_js_1.default.headers(options.header);
|
|
108
|
+
if (options.responseHeader !== undefined)
|
|
109
|
+
tunnel.responseHeaders = input_js_1.default.headers(options.responseHeader);
|
|
110
|
+
if (options.circuitBreaker !== undefined)
|
|
111
|
+
tunnel.circuitBreaker = input_js_1.default.circuitBreaker(options.circuitBreaker);
|
|
112
|
+
tunnel.log = !!options.log;
|
|
113
|
+
tunnel.verify = !!options.verify;
|
|
114
|
+
tunnel.http2 = !!options.http2;
|
|
115
|
+
tunnel.compression = !!options.compression;
|
|
116
|
+
}
|
|
117
|
+
else if (type === utils_js_1.TUNNEL_TLS) {
|
|
118
|
+
tunnel.terminate = input_js_1.default.terminate(options.terminate);
|
|
119
|
+
if (options.key !== undefined || options.cert !== undefined) {
|
|
120
|
+
const { key, cert } = input_js_1.default.keyCert(options.key, options.cert);
|
|
121
|
+
tunnel.key = key;
|
|
122
|
+
tunnel.cert = cert;
|
|
123
|
+
}
|
|
124
|
+
if (options.ca !== undefined)
|
|
125
|
+
tunnel.ca = input_js_1.default.ca(options.ca);
|
|
126
|
+
}
|
|
127
|
+
if (options.name !== undefined)
|
|
128
|
+
tunnel.name = input_js_1.default.name(options.name);
|
|
129
|
+
return tunnel;
|
|
130
|
+
}
|
|
131
|
+
async addTunnel(name, type, target, options) {
|
|
132
|
+
this.ensureTunnels();
|
|
133
|
+
this.json.tunnels[name] = await this.prepareTunnel(type, target, {
|
|
134
|
+
name,
|
|
135
|
+
...options,
|
|
136
|
+
}, false);
|
|
137
|
+
this.save();
|
|
138
|
+
}
|
|
139
|
+
removeTunnel(name) {
|
|
140
|
+
this.ensureTunnels();
|
|
141
|
+
delete this.json.tunnels[name];
|
|
142
|
+
this.save();
|
|
143
|
+
}
|
|
144
|
+
getTunnels() {
|
|
145
|
+
this.ensureTunnels();
|
|
146
|
+
return this.json.tunnels;
|
|
147
|
+
}
|
|
148
|
+
hasTunnel(name) {
|
|
149
|
+
this.ensureTunnels();
|
|
150
|
+
return !!this.json.tunnels[name];
|
|
151
|
+
}
|
|
152
|
+
getTunnel(name) {
|
|
153
|
+
this.ensureTunnels();
|
|
154
|
+
return this.json.tunnels[name];
|
|
155
|
+
}
|
|
156
|
+
setToken(token) {
|
|
157
|
+
if (!token)
|
|
158
|
+
delete this.json.token;
|
|
159
|
+
else
|
|
160
|
+
this.json.token = token;
|
|
161
|
+
this.save();
|
|
162
|
+
}
|
|
163
|
+
setWhitelist(whitelist) {
|
|
164
|
+
if (!whitelist || !whitelist.length)
|
|
165
|
+
delete this.json.whitelist;
|
|
166
|
+
else
|
|
167
|
+
this.json.whitelist = whitelist;
|
|
168
|
+
this.save();
|
|
169
|
+
}
|
|
170
|
+
setTimeout(timeout) {
|
|
171
|
+
if (!timeout)
|
|
172
|
+
delete this.json.timeout;
|
|
173
|
+
else
|
|
174
|
+
this.json.timeout = timeout;
|
|
175
|
+
this.save();
|
|
176
|
+
}
|
|
177
|
+
getToken() {
|
|
178
|
+
return this.json.token || '';
|
|
179
|
+
}
|
|
180
|
+
getTokenHost() {
|
|
181
|
+
const token = this.getToken();
|
|
182
|
+
if (!token) {
|
|
183
|
+
throw new Error(texts_js_1.ERR_TOKEN_NOT_PROVIDED);
|
|
184
|
+
}
|
|
185
|
+
const d = (0, jsonwebtoken_1.decode)(token);
|
|
186
|
+
if (d === null) {
|
|
187
|
+
throw new Error(texts_js_1.ERR_WRONG_TOKEN);
|
|
188
|
+
}
|
|
189
|
+
if (!d.host) {
|
|
190
|
+
throw new Error(texts_js_1.ERR_WRONG_TOKEN);
|
|
191
|
+
}
|
|
192
|
+
return d.host;
|
|
193
|
+
}
|
|
194
|
+
getRegion() {
|
|
195
|
+
return (this.json.region || '').toUpperCase();
|
|
196
|
+
}
|
|
197
|
+
getTimeout() {
|
|
198
|
+
return this.json.timeout || utils_js_1.DEFAULT_TIMEOUT;
|
|
199
|
+
}
|
|
200
|
+
getWhitelist() {
|
|
201
|
+
return this.json.whitelist || [];
|
|
202
|
+
}
|
|
203
|
+
setRegion(region) {
|
|
204
|
+
this.json.region = region;
|
|
205
|
+
this.save();
|
|
206
|
+
}
|
|
207
|
+
setRegionIfNotSet(region) {
|
|
208
|
+
if (!this.json.region && region)
|
|
209
|
+
this.json.region = region.toUpperCase();
|
|
210
|
+
this.save();
|
|
211
|
+
}
|
|
212
|
+
load() {
|
|
213
|
+
this.ensureFile();
|
|
214
|
+
try {
|
|
215
|
+
const txt = (0, fs_1.readFileSync)(this.file, 'utf-8');
|
|
216
|
+
this.json = JSON.parse(txt);
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
throw new Error(texts_js_1.ERR_CONFIG_CORRUPTED);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
save() {
|
|
223
|
+
this.ensureDir();
|
|
224
|
+
try {
|
|
225
|
+
(0, fs_1.writeFileSync)(this.file, JSON.stringify(this.json, null, 4), 'utf-8');
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
throw new Error((0, texts_js_1.ERR_CANT_CREATE_DIR_IN_HOME)('.bdy/cfg.json'));
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
(0, fs_1.chmodSync)(this.file, 0o666);
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
// do nothing
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.default = new Cfg();
|
|
@@ -0,0 +1,106 @@
|
|
|
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 output_js_1 = __importDefault(require("../../output.js"));
|
|
7
|
+
const input_js_1 = __importDefault(require("../../input.js"));
|
|
8
|
+
const texts_js_1 = require("../../texts.js");
|
|
9
|
+
const cfg_js_1 = __importDefault(require("../../cfg.js"));
|
|
10
|
+
const manager_js_1 = __importDefault(require("../../agent/manager.js"));
|
|
11
|
+
const buddy_js_1 = __importDefault(require("../../api/buddy.js"));
|
|
12
|
+
const agent_1 = __importDefault(require("../../api/agent"));
|
|
13
|
+
const wait_js_1 = __importDefault(require("../../agent/wait.js"));
|
|
14
|
+
const utils_1 = require("../../utils");
|
|
15
|
+
const removeAllAndExit = async (txt, id, host, token) => {
|
|
16
|
+
try {
|
|
17
|
+
await manager_js_1.default.system.disable();
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// do nothing
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
await buddy_js_1.default.unregister(id, host, token);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// do nothing
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
manager_js_1.default.system.clearSystemFiles();
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// do nothing
|
|
33
|
+
}
|
|
34
|
+
output_js_1.default.exitError(txt);
|
|
35
|
+
};
|
|
36
|
+
const commandAgentInstall = (0, utils_1.newCommand)('install', texts_js_1.DESC_COMMAND_AGENT_INSTALL);
|
|
37
|
+
commandAgentInstall.option('-s, --start', texts_js_1.OPTION_AGENT_START);
|
|
38
|
+
commandAgentInstall.option('-i, --id <id>', texts_js_1.OPTION_AGENT_ID);
|
|
39
|
+
commandAgentInstall.option('-t, --token <token>', texts_js_1.OPTION_AGENT_TOKEN);
|
|
40
|
+
commandAgentInstall.option('-p, --port <port>', texts_js_1.OPTION_AGENT_PORT, '7456');
|
|
41
|
+
commandAgentInstall.option('-u, --user <user>', texts_js_1.OPTION_USER);
|
|
42
|
+
commandAgentInstall.option('--pass <password>', texts_js_1.OPTION_PASS);
|
|
43
|
+
commandAgentInstall.option('-d, --debug', texts_js_1.OPTION_AGENT_DEBUG);
|
|
44
|
+
commandAgentInstall.action(async (options) => {
|
|
45
|
+
const hasAdminRights = await manager_js_1.default.system.hasAdminRights();
|
|
46
|
+
if (!hasAdminRights) {
|
|
47
|
+
output_js_1.default.exitError(texts_js_1.ERR_AGENT_ADMIN_RIGHTS);
|
|
48
|
+
}
|
|
49
|
+
const isSupported = await manager_js_1.default.system.isSupported();
|
|
50
|
+
if (!isSupported) {
|
|
51
|
+
output_js_1.default.exitError(texts_js_1.ERR_AGENT_NOT_SUPPORTED);
|
|
52
|
+
}
|
|
53
|
+
const isEnabled = await manager_js_1.default.system.isEnabled();
|
|
54
|
+
if (isEnabled) {
|
|
55
|
+
output_js_1.default.exitSuccess(texts_js_1.TXT_AGENT_ALREADY_ENABLED);
|
|
56
|
+
}
|
|
57
|
+
let id;
|
|
58
|
+
let token;
|
|
59
|
+
let agent;
|
|
60
|
+
let port = input_js_1.default.port(options.port);
|
|
61
|
+
if (options.id && options.token) {
|
|
62
|
+
// if id & token passed set as it is
|
|
63
|
+
id = options.id;
|
|
64
|
+
token = options.token;
|
|
65
|
+
try {
|
|
66
|
+
agent = await buddy_js_1.default.fetchAgent(id, cfg_js_1.default.getTokenHost(), token);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
output_js_1.default.exitError(texts_js_1.ERR_AGENT_NOT_FOUND);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (options.token) {
|
|
73
|
+
// set global token if passed
|
|
74
|
+
cfg_js_1.default.setToken(options.token);
|
|
75
|
+
}
|
|
76
|
+
let host = cfg_js_1.default.getTokenHost();
|
|
77
|
+
if (!agent) {
|
|
78
|
+
agent = await buddy_js_1.default.register(true, host, cfg_js_1.default.getToken(), (region) => {
|
|
79
|
+
cfg_js_1.default.setRegionIfNotSet(region);
|
|
80
|
+
});
|
|
81
|
+
id = agent.id;
|
|
82
|
+
token = agent.token;
|
|
83
|
+
}
|
|
84
|
+
const saved = manager_js_1.default.system.saveSystemConfig(id, host, token, port);
|
|
85
|
+
if (!saved) {
|
|
86
|
+
await removeAllAndExit(texts_js_1.ERR_SWW_AGENT_ENABLING, id, host, token);
|
|
87
|
+
}
|
|
88
|
+
await output_js_1.default.spinner(texts_js_1.TXT_ENABLING_AGENT);
|
|
89
|
+
if (process.env.DEBUG === '1') {
|
|
90
|
+
manager_js_1.default.start(id, host, token, port, !!options.start);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
await manager_js_1.default.system.enable(id, host, token, port, !!options.start, options.user, options.pass, !!options.debug);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
await removeAllAndExit(texts_js_1.ERR_SWW_AGENT_ENABLING, id, host, token);
|
|
98
|
+
}
|
|
99
|
+
const api = new agent_1.default(port);
|
|
100
|
+
await (0, wait_js_1.default)(api, 15000, () => {
|
|
101
|
+
removeAllAndExit(texts_js_1.ERR_SWW_AGENT_ENABLING, id, host, token);
|
|
102
|
+
}, () => {
|
|
103
|
+
output_js_1.default.exitSuccess(texts_js_1.TXT_AGENT_ENABLED);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
exports.default = commandAgentInstall;
|
|
@@ -0,0 +1,27 @@
|
|
|
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 output_js_1 = __importDefault(require("../../output.js"));
|
|
7
|
+
const texts_js_1 = require("../../texts.js");
|
|
8
|
+
const agent_js_1 = __importDefault(require("../../api/agent.js"));
|
|
9
|
+
const manager_1 = __importDefault(require("../../agent/manager"));
|
|
10
|
+
const utils_1 = require("../../utils");
|
|
11
|
+
const commandAgentRestart = (0, utils_1.newCommand)('restart', texts_js_1.DESC_COMMAND_AGENT_RESTART);
|
|
12
|
+
commandAgentRestart.action(async () => {
|
|
13
|
+
const isEnabled = await manager_1.default.system.isEnabled();
|
|
14
|
+
if (!isEnabled) {
|
|
15
|
+
output_js_1.default.exitError(texts_js_1.ERR_AGENT_NOT_ENABLED);
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const json = manager_1.default.system.loadSystemConfig();
|
|
19
|
+
const api = new agent_js_1.default(json.port);
|
|
20
|
+
await api.restartAgent();
|
|
21
|
+
output_js_1.default.exitSuccess(texts_js_1.TXT_AGENT_RESTARTED);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
output_js_1.default.exitError(err);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
exports.default = commandAgentRestart;
|
|
@@ -0,0 +1,19 @@
|
|
|
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 manager_1 = __importDefault(require("../../agent/manager"));
|
|
7
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const commandAgentRun = (0, utils_1.newCommand)('run');
|
|
10
|
+
commandAgentRun.option('--id <id>');
|
|
11
|
+
commandAgentRun.option('--host <host>');
|
|
12
|
+
commandAgentRun.option('--token <token>');
|
|
13
|
+
commandAgentRun.option('--port <port>');
|
|
14
|
+
commandAgentRun.option('--start <start>');
|
|
15
|
+
commandAgentRun.action(async (options) => {
|
|
16
|
+
logger_1.default.changeRootPath(manager_1.default.system.getAgentConfigDir());
|
|
17
|
+
manager_1.default.start(options.id, options.host, options.token, options.port, !!options.start);
|
|
18
|
+
});
|
|
19
|
+
module.exports = commandAgentRun;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 output_js_1 = __importDefault(require("../../output.js"));
|
|
7
|
+
const texts_js_1 = require("../../texts.js");
|
|
8
|
+
const agent_js_1 = __importDefault(require("../../api/agent.js"));
|
|
9
|
+
const texts_1 = require("../../texts");
|
|
10
|
+
const manager_1 = __importDefault(require("../../agent/manager"));
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const commandAgentStart = (0, utils_1.newCommand)('start', texts_js_1.DESC_COMMAND_AGENT_START);
|
|
13
|
+
commandAgentStart.action(async () => {
|
|
14
|
+
const isEnabled = await manager_1.default.system.isEnabled();
|
|
15
|
+
if (!isEnabled) {
|
|
16
|
+
output_js_1.default.exitError(texts_1.ERR_AGENT_NOT_ENABLED);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const json = manager_1.default.system.loadSystemConfig();
|
|
20
|
+
const api = new agent_js_1.default(json.port);
|
|
21
|
+
await api.startAgent();
|
|
22
|
+
output_js_1.default.exitSuccess(texts_js_1.TXT_AGENT_STARTED);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
output_js_1.default.exitError(err);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
exports.default = commandAgentStart;
|
|
@@ -0,0 +1,35 @@
|
|
|
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 output_js_1 = __importDefault(require("../../output.js"));
|
|
7
|
+
const texts_js_1 = require("../../texts.js");
|
|
8
|
+
const utils_js_1 = require("../../utils.js");
|
|
9
|
+
const manager_1 = __importDefault(require("../../agent/manager"));
|
|
10
|
+
const texts_1 = require("../../texts");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const commandAgentStatus = (0, utils_1.newCommand)('status', texts_js_1.DESC_COMMAND_AGENT_STATUS);
|
|
13
|
+
commandAgentStatus.action(async () => {
|
|
14
|
+
const isEnabled = await manager_1.default.system.isEnabled();
|
|
15
|
+
if (!isEnabled) {
|
|
16
|
+
output_js_1.default.exitError(texts_js_1.ERR_AGENT_NOT_ENABLED);
|
|
17
|
+
}
|
|
18
|
+
if (!commandAgentStatus.agentStatus) {
|
|
19
|
+
output_js_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
20
|
+
}
|
|
21
|
+
if (commandAgentStatus.agentStatus.status === utils_js_1.AGENT_STATUS_INITIALIZING) {
|
|
22
|
+
output_js_1.default.exitError(texts_js_1.TXT_AGENT_IS_ENABLED_AND_INITIALIZING);
|
|
23
|
+
}
|
|
24
|
+
if (commandAgentStatus.agentStatus.status === utils_js_1.AGENT_STATUS_FETCH_FAILED) {
|
|
25
|
+
output_js_1.default.exitError(texts_js_1.TXT_AGENT_IS_ENABLED_AND_HAVE_TROUBLES);
|
|
26
|
+
}
|
|
27
|
+
if (commandAgentStatus.agentStatus.status !== utils_js_1.AGENT_STATUS_ENABLED) {
|
|
28
|
+
output_js_1.default.exitError(texts_js_1.TXT_AGENT_IS_DISABLED);
|
|
29
|
+
}
|
|
30
|
+
if (commandAgentStatus.agentStatus.started) {
|
|
31
|
+
output_js_1.default.exitSuccess(texts_js_1.TXT_AGENT_IS_ENABLED_AND_STARTED);
|
|
32
|
+
}
|
|
33
|
+
output_js_1.default.exitError(texts_js_1.TXT_AGENT_IS_ENABLED_AND_STOPPED);
|
|
34
|
+
});
|
|
35
|
+
exports.default = commandAgentStatus;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 utils_1 = require("../../utils");
|
|
7
|
+
const texts_1 = require("../../texts");
|
|
8
|
+
const manager_1 = __importDefault(require("../../agent/manager"));
|
|
9
|
+
const agent_js_1 = __importDefault(require("../../api/agent.js"));
|
|
10
|
+
const texts_js_1 = require("../../texts.js");
|
|
11
|
+
const output_js_1 = __importDefault(require("../../output.js"));
|
|
12
|
+
const commandAgentStop = (0, utils_1.newCommand)('stop', texts_js_1.DESC_COMMAND_AGENT_STOP);
|
|
13
|
+
commandAgentStop.action(async () => {
|
|
14
|
+
const isEnabled = await manager_1.default.system.isEnabled();
|
|
15
|
+
if (!isEnabled) {
|
|
16
|
+
output_js_1.default.exitError(texts_1.ERR_AGENT_NOT_ENABLED);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const json = manager_1.default.system.loadSystemConfig();
|
|
20
|
+
const api = new agent_js_1.default(json.port);
|
|
21
|
+
await api.stopAgent();
|
|
22
|
+
output_js_1.default.exitSuccess(texts_js_1.TXT_AGENT_STOPPED);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
output_js_1.default.exitError(err);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
exports.default = commandAgentStop;
|
|
@@ -0,0 +1,44 @@
|
|
|
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 utils_js_1 = require("../../../utils.js");
|
|
7
|
+
const output_js_1 = __importDefault(require("../../../output.js"));
|
|
8
|
+
const cfg_js_1 = __importDefault(require("../../../cfg.js"));
|
|
9
|
+
const texts_js_1 = require("../../../texts.js");
|
|
10
|
+
const tunnel_1 = __importDefault(require("../../../agent/socket/tunnel"));
|
|
11
|
+
const texts_1 = require("../../../texts");
|
|
12
|
+
const manager_1 = __importDefault(require("../../../agent/manager"));
|
|
13
|
+
const utils_1 = require("../../../utils");
|
|
14
|
+
const agent_js_1 = __importDefault(require("../../../api/agent.js"));
|
|
15
|
+
const commandAgentTunnelHttp = (0, utils_1.getBasicCommandHttp)();
|
|
16
|
+
commandAgentTunnelHttp.description(texts_js_1.DESC_COMMAND_AGENT_TUNNEL_HTTP);
|
|
17
|
+
commandAgentTunnelHttp.option('-f, --follow', texts_1.OPTION_FOLLOW);
|
|
18
|
+
commandAgentTunnelHttp.argument('[protocol://host:port]', texts_js_1.OPTION_TARGET);
|
|
19
|
+
commandAgentTunnelHttp.action(async (target, options) => {
|
|
20
|
+
const isEnabled = await manager_1.default.system.isEnabled();
|
|
21
|
+
if (!isEnabled) {
|
|
22
|
+
output_js_1.default.exitError(texts_js_1.ERR_AGENT_NOT_ENABLED);
|
|
23
|
+
}
|
|
24
|
+
const prepared = await cfg_js_1.default.prepareTunnel(utils_js_1.TUNNEL_HTTP, target, options, true);
|
|
25
|
+
try {
|
|
26
|
+
await output_js_1.default.spinner(texts_js_1.TXT_OPENING_TUNNEL);
|
|
27
|
+
const json = manager_1.default.system.loadSystemConfig();
|
|
28
|
+
const api = new agent_js_1.default(json.port);
|
|
29
|
+
const data = await api.addTunnel(prepared);
|
|
30
|
+
if (options.follow) {
|
|
31
|
+
const ws = await api.socketTunnel(data.id);
|
|
32
|
+
const tunnel = new tunnel_1.default(ws, data.id);
|
|
33
|
+
await tunnel.waitForReady();
|
|
34
|
+
output_js_1.default.tunnel(tunnel);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
output_js_1.default.exitSuccess((0, texts_js_1.TXT_TUNNEL_STARTED)(data.type));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
output_js_1.default.exitError(err);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
exports.default = commandAgentTunnelHttp;
|