bdy 1.12.8-beta → 1.12.8-dev-pipeline-run
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distTs/package.json +1 -1
- package/package.json +1 -1
- package/distTs/bin/cli.js +0 -5
- package/distTs/src/agent/agent.js +0 -328
- package/distTs/src/agent/linux.js +0 -124
- package/distTs/src/agent/manager.js +0 -519
- package/distTs/src/agent/osx.js +0 -146
- package/distTs/src/agent/socket/client.js +0 -178
- package/distTs/src/agent/socket/tunnel.js +0 -237
- package/distTs/src/agent/socket.js +0 -242
- package/distTs/src/agent/system.js +0 -179
- package/distTs/src/agent/wait.js +0 -23
- package/distTs/src/agent/windows.js +0 -159
- package/distTs/src/agent.js +0 -302
- package/distTs/src/api/agent.js +0 -99
- package/distTs/src/api/buddy.js +0 -139
- package/distTs/src/api/socket.js +0 -159
- package/distTs/src/cfg.js +0 -234
- package/distTs/src/command/agent/disable.js +0 -27
- package/distTs/src/command/agent/enable.js +0 -27
- package/distTs/src/command/agent/install.js +0 -117
- package/distTs/src/command/agent/restart.js +0 -27
- package/distTs/src/command/agent/run.js +0 -19
- package/distTs/src/command/agent/start.js +0 -28
- package/distTs/src/command/agent/status.js +0 -34
- package/distTs/src/command/agent/stop.js +0 -28
- package/distTs/src/command/agent/target/disable.js +0 -27
- package/distTs/src/command/agent/target/enable.js +0 -27
- package/distTs/src/command/agent/target/status.js +0 -32
- package/distTs/src/command/agent/target.js +0 -15
- package/distTs/src/command/agent/tunnel/http.js +0 -43
- package/distTs/src/command/agent/tunnel/list.js +0 -27
- package/distTs/src/command/agent/tunnel/remove.js +0 -28
- package/distTs/src/command/agent/tunnel/start.js +0 -34
- package/distTs/src/command/agent/tunnel/status.js +0 -31
- package/distTs/src/command/agent/tunnel/tcp.js +0 -43
- package/distTs/src/command/agent/tunnel/tls.js +0 -43
- package/distTs/src/command/agent/tunnel.js +0 -23
- package/distTs/src/command/agent/uninstall.js +0 -44
- package/distTs/src/command/agent/update.js +0 -38
- package/distTs/src/command/agent/version.js +0 -21
- package/distTs/src/command/agent.js +0 -35
- package/distTs/src/command/config/add/http.js +0 -25
- package/distTs/src/command/config/add/tcp.js +0 -25
- package/distTs/src/command/config/add/tls.js +0 -25
- package/distTs/src/command/config/add.js +0 -15
- package/distTs/src/command/config/get/region.js +0 -15
- package/distTs/src/command/config/get/timeout.js +0 -15
- package/distTs/src/command/config/get/token.js +0 -15
- package/distTs/src/command/config/get/tunnel.js +0 -19
- package/distTs/src/command/config/get/tunnels.js +0 -15
- package/distTs/src/command/config/get/whitelist.js +0 -15
- package/distTs/src/command/config/get.js +0 -21
- package/distTs/src/command/config/remove/tunnel.js +0 -19
- package/distTs/src/command/config/remove.js +0 -11
- package/distTs/src/command/config/set/region.js +0 -17
- package/distTs/src/command/config/set/timeout.js +0 -17
- package/distTs/src/command/config/set/token.js +0 -16
- package/distTs/src/command/config/set/whitelist.js +0 -17
- package/distTs/src/command/config/set.js +0 -17
- package/distTs/src/command/config.js +0 -17
- package/distTs/src/command/http.js +0 -30
- package/distTs/src/command/pre.js +0 -49
- package/distTs/src/command/start.js +0 -28
- package/distTs/src/command/tcp.js +0 -30
- package/distTs/src/command/tls.js +0 -30
- package/distTs/src/command/tunnel/config.js +0 -17
- package/distTs/src/command/tunnel/http.js +0 -31
- package/distTs/src/command/tunnel/start.js +0 -28
- package/distTs/src/command/tunnel/tcp.js +0 -30
- package/distTs/src/command/tunnel/tls.js +0 -30
- package/distTs/src/command/tunnel.js +0 -19
- package/distTs/src/command/ut/upload.js +0 -108
- package/distTs/src/command/ut.js +0 -12
- package/distTs/src/command/version.js +0 -13
- package/distTs/src/command/vt/close.js +0 -27
- package/distTs/src/command/vt/compare/validation.js +0 -173
- package/distTs/src/command/vt/compare.js +0 -97
- package/distTs/src/command/vt/exec.js +0 -81
- package/distTs/src/command/vt/installBrowser.js +0 -20
- package/distTs/src/command/vt/scrap.js +0 -193
- package/distTs/src/command/vt/storybook.js +0 -92
- package/distTs/src/command/vt.js +0 -22
- package/distTs/src/format.js +0 -174
- package/distTs/src/index.js +0 -34
- package/distTs/src/input.js +0 -270
- package/distTs/src/logger.js +0 -95
- package/distTs/src/output/interactive/tunnel.js +0 -860
- package/distTs/src/output/noninteractive/agent/tunnels.js +0 -43
- package/distTs/src/output/noninteractive/config/tunnel.js +0 -65
- package/distTs/src/output/noninteractive/config/tunnels.js +0 -18
- package/distTs/src/output/noninteractive/tunnel.js +0 -59
- package/distTs/src/output.js +0 -143
- package/distTs/src/server/cert.js +0 -52
- package/distTs/src/server/http1.js +0 -75
- package/distTs/src/server/http2.js +0 -78
- package/distTs/src/server/sftp.js +0 -497
- package/distTs/src/server/ssh.js +0 -446
- package/distTs/src/server/tls.js +0 -41
- package/distTs/src/ssh/client.js +0 -197
- package/distTs/src/texts.js +0 -421
- package/distTs/src/tunnel/agent.js +0 -103
- package/distTs/src/tunnel/api/agent.js +0 -100
- package/distTs/src/tunnel/api/buddy.js +0 -141
- package/distTs/src/tunnel/cfg.js +0 -243
- package/distTs/src/tunnel/compression.js +0 -44
- package/distTs/src/tunnel/dns.js +0 -53
- package/distTs/src/tunnel/html/503.html +0 -338
- package/distTs/src/tunnel/html.js +0 -33
- package/distTs/src/tunnel/http/log.js +0 -218
- package/distTs/src/tunnel/http/serve.js +0 -133
- package/distTs/src/tunnel/http/stream.js +0 -34
- package/distTs/src/tunnel/http.js +0 -508
- package/distTs/src/tunnel/identification.js +0 -103
- package/distTs/src/tunnel/latency.js +0 -83
- package/distTs/src/tunnel/output/interactive/tunnel.js +0 -867
- package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +0 -45
- package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +0 -67
- package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +0 -20
- package/distTs/src/tunnel/output/noninteractive/tunnel.js +0 -61
- package/distTs/src/tunnel/server/cert.js +0 -54
- package/distTs/src/tunnel/server/http1.js +0 -80
- package/distTs/src/tunnel/server/http2.js +0 -84
- package/distTs/src/tunnel/server/sftp.js +0 -514
- package/distTs/src/tunnel/server/ssh.js +0 -464
- package/distTs/src/tunnel/server/tls.js +0 -47
- package/distTs/src/tunnel/ssh/client.js +0 -211
- package/distTs/src/tunnel/tcp.js +0 -113
- package/distTs/src/tunnel/tunnel.js +0 -1010
- package/distTs/src/tunnel.js +0 -656
- package/distTs/src/types/ciInfo.js +0 -10
- package/distTs/src/types/options.js +0 -2
- package/distTs/src/types/plugin.js +0 -2
- package/distTs/src/types/queue.js +0 -2
- package/distTs/src/types/requests.js +0 -2
- package/distTs/src/types/resources.js +0 -2
- package/distTs/src/types/schemas.js +0 -54
- package/distTs/src/types/scrape.js +0 -2
- package/distTs/src/types/snapshots.js +0 -2
- package/distTs/src/types/storybook.js +0 -2
- package/distTs/src/types/tunnel.js +0 -141
- package/distTs/src/unitTest/ci.js +0 -108
- package/distTs/src/unitTest/requests.js +0 -72
- package/distTs/src/utils.js +0 -378
- package/distTs/src/visualTest/browser.js +0 -39
- package/distTs/src/visualTest/ci.js +0 -241
- package/distTs/src/visualTest/context.js +0 -52
- package/distTs/src/visualTest/exec.js +0 -51
- package/distTs/src/visualTest/linkUtils.js +0 -21
- package/distTs/src/visualTest/queue.js +0 -43
- package/distTs/src/visualTest/requests.js +0 -365
- package/distTs/src/visualTest/resources.js +0 -259
- package/distTs/src/visualTest/server.js +0 -109
- package/distTs/src/visualTest/snapshots.js +0 -129
- package/distTs/src/visualTest/utils/parseDom.js +0 -238
- package/distTs/src/visualTest/validation.js +0 -18
|
@@ -1,519 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AgentManagerClass = void 0;
|
|
7
|
-
const utils_1 = require("../utils");
|
|
8
|
-
const ws_1 = require("ws");
|
|
9
|
-
const logger_1 = __importDefault(require("../logger"));
|
|
10
|
-
const http_1 = __importDefault(require("http"));
|
|
11
|
-
const output_1 = __importDefault(require("../output"));
|
|
12
|
-
const texts_1 = require("../texts");
|
|
13
|
-
const windows_1 = __importDefault(require("./windows"));
|
|
14
|
-
const linux_1 = __importDefault(require("./linux"));
|
|
15
|
-
const system_1 = __importDefault(require("./system"));
|
|
16
|
-
const osx_1 = __importDefault(require("./osx"));
|
|
17
|
-
const buddy_1 = __importDefault(require("../tunnel/api/buddy"));
|
|
18
|
-
const socket_1 = __importDefault(require("./socket"));
|
|
19
|
-
const tunnel_1 = require("../types/tunnel");
|
|
20
|
-
class AgentManagerClass {
|
|
21
|
-
status;
|
|
22
|
-
id;
|
|
23
|
-
host;
|
|
24
|
-
token;
|
|
25
|
-
port;
|
|
26
|
-
shouldStart;
|
|
27
|
-
sshHostKey;
|
|
28
|
-
agent;
|
|
29
|
-
ws;
|
|
30
|
-
server;
|
|
31
|
-
system;
|
|
32
|
-
constructor() {
|
|
33
|
-
this.status = tunnel_1.TUNNEL_AGENT_STATUS.DISABLED;
|
|
34
|
-
this.id = null;
|
|
35
|
-
this.host = null;
|
|
36
|
-
this.token = null;
|
|
37
|
-
this.port = null;
|
|
38
|
-
this.shouldStart = null;
|
|
39
|
-
this.sshHostKey = null;
|
|
40
|
-
this.agent = null;
|
|
41
|
-
this.server = null;
|
|
42
|
-
this.ws = null;
|
|
43
|
-
if ((0, utils_1.isOsx)()) {
|
|
44
|
-
this.system = new osx_1.default();
|
|
45
|
-
}
|
|
46
|
-
else if ((0, utils_1.isLinux)()) {
|
|
47
|
-
this.system = new linux_1.default();
|
|
48
|
-
}
|
|
49
|
-
else if ((0, utils_1.isWindows)()) {
|
|
50
|
-
this.system = new windows_1.default();
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
this.system = new system_1.default();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
start(id, host, token, port, start) {
|
|
57
|
-
this.load(id, host, token, port, start).then();
|
|
58
|
-
}
|
|
59
|
-
async tryFetch() {
|
|
60
|
-
try {
|
|
61
|
-
this.agent = await buddy_1.default.fetchAgent(this.id || '', this.host || '', this.token || '');
|
|
62
|
-
this.agent.manager = this;
|
|
63
|
-
this.agent.startRefreshingConfiguration((success) => {
|
|
64
|
-
if (success)
|
|
65
|
-
this.status = tunnel_1.TUNNEL_AGENT_STATUS.ENABLED;
|
|
66
|
-
else
|
|
67
|
-
this.status = tunnel_1.TUNNEL_AGENT_STATUS.FETCH_FAILED;
|
|
68
|
-
});
|
|
69
|
-
if (this.shouldStart)
|
|
70
|
-
await this.agent.start();
|
|
71
|
-
this.status = tunnel_1.TUNNEL_AGENT_STATUS.ENABLED;
|
|
72
|
-
}
|
|
73
|
-
catch (err) {
|
|
74
|
-
if (err instanceof utils_1.ApiErrorAgentNotFound) {
|
|
75
|
-
await this.disableAgentAndExit(texts_1.ERR_AGENT_NOT_FOUND);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
output_1.default.normal(texts_1.AGENT_FETCH_RETRY);
|
|
79
|
-
this.status = tunnel_1.TUNNEL_AGENT_STATUS.FETCH_FAILED;
|
|
80
|
-
await (0, utils_1.sleep)(3000);
|
|
81
|
-
return this.tryFetch();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
serverOutput(res, data) {
|
|
86
|
-
res.statusCode = 200;
|
|
87
|
-
res.setHeader('content-type', 'application/json');
|
|
88
|
-
res.end(JSON.stringify(data));
|
|
89
|
-
}
|
|
90
|
-
server404(res) {
|
|
91
|
-
res.statusCode = 404;
|
|
92
|
-
res.end('Not found');
|
|
93
|
-
}
|
|
94
|
-
serverError(res, message) {
|
|
95
|
-
res.statusCode = 400;
|
|
96
|
-
res.end(JSON.stringify({
|
|
97
|
-
message,
|
|
98
|
-
}));
|
|
99
|
-
}
|
|
100
|
-
async processTunnels(res) {
|
|
101
|
-
const tunnels = [];
|
|
102
|
-
if (this.agent) {
|
|
103
|
-
this.agent.tunnels.forEach((tunnel) => {
|
|
104
|
-
if (tunnel.type === tunnel_1.TUNNEL_TYPE.SSH)
|
|
105
|
-
return;
|
|
106
|
-
tunnels.push({
|
|
107
|
-
id: tunnel.id,
|
|
108
|
-
type: tunnel.type,
|
|
109
|
-
target: tunnel.target,
|
|
110
|
-
domain: tunnel.domain,
|
|
111
|
-
subdomain: tunnel.subdomain,
|
|
112
|
-
serve: tunnel.serve,
|
|
113
|
-
status: tunnel.status,
|
|
114
|
-
region: tunnel.region,
|
|
115
|
-
sshId: tunnel.sshId,
|
|
116
|
-
sshForwardPort: tunnel.sshForwardPort,
|
|
117
|
-
regionLatency: tunnel.regionLatency
|
|
118
|
-
? tunnel.regionLatency.latency
|
|
119
|
-
: -1,
|
|
120
|
-
targetLatency: tunnel.targetLatency
|
|
121
|
-
? tunnel.targetLatency.latency
|
|
122
|
-
: -1,
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
this.serverOutput(res, {
|
|
127
|
-
tunnels,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
async processAgentTarget(res) {
|
|
131
|
-
if (!this.agent) {
|
|
132
|
-
this.serverError(res, 'Agent not enabled');
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
this.serverOutput(res, {
|
|
136
|
-
target: this.agent.target,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
async processAgentTargetEnable(res) {
|
|
140
|
-
if (!this.agent) {
|
|
141
|
-
this.serverError(res, 'Agent not enabled');
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
try {
|
|
145
|
-
await buddy_1.default.enableTarget(this.id || '', this.host || '', this.token || '');
|
|
146
|
-
this.agent.target = true;
|
|
147
|
-
}
|
|
148
|
-
catch (err) {
|
|
149
|
-
this.serverError(res, err.message);
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
this.serverOutput(res, {});
|
|
153
|
-
}
|
|
154
|
-
async processAgentTargetDisable(res) {
|
|
155
|
-
if (!this.agent) {
|
|
156
|
-
this.serverError(res, 'Agent not enabled');
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
try {
|
|
160
|
-
await buddy_1.default.disableTarget(this.id || '', this.host || '', this.token || '');
|
|
161
|
-
this.agent.target = false;
|
|
162
|
-
}
|
|
163
|
-
catch (err) {
|
|
164
|
-
this.serverError(res, err.message);
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
this.serverOutput(res, {});
|
|
168
|
-
}
|
|
169
|
-
async processStatus(res) {
|
|
170
|
-
this.serverOutput(res, {
|
|
171
|
-
id: this.id,
|
|
172
|
-
status: this.status,
|
|
173
|
-
version: (0, utils_1.getVersion)(),
|
|
174
|
-
started: this.shouldStart,
|
|
175
|
-
enabled: this.status === tunnel_1.TUNNEL_AGENT_STATUS.ENABLED,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
processBody(req) {
|
|
179
|
-
return new Promise((resolve, reject) => {
|
|
180
|
-
let data = '';
|
|
181
|
-
req.setEncoding('utf-8');
|
|
182
|
-
req.on('data', (d) => {
|
|
183
|
-
data += d;
|
|
184
|
-
});
|
|
185
|
-
req.on('end', () => {
|
|
186
|
-
try {
|
|
187
|
-
resolve(JSON.parse(data));
|
|
188
|
-
}
|
|
189
|
-
catch (err) {
|
|
190
|
-
reject(err);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
async processTunnelStop(req, res) {
|
|
196
|
-
if (!this.agent) {
|
|
197
|
-
this.serverError(res, 'Agent not enabled');
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
let data;
|
|
201
|
-
try {
|
|
202
|
-
data = await this.processBody(req);
|
|
203
|
-
}
|
|
204
|
-
catch {
|
|
205
|
-
this.serverError(res, 'Wrong input data');
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
const tunnel = this.agent.destroyTunnel(data.id);
|
|
209
|
-
if (!tunnel) {
|
|
210
|
-
this.serverError(res, 'Tunnel not found');
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
try {
|
|
214
|
-
await buddy_1.default.removeTunnel(this.id || '', tunnel.id, this.host || '', this.token || '');
|
|
215
|
-
}
|
|
216
|
-
catch (err) {
|
|
217
|
-
this.serverError(res, err.message);
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
this.serverOutput(res, {
|
|
221
|
-
success: true,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
async agentRestart() {
|
|
225
|
-
const saved = await this.agentStop();
|
|
226
|
-
if (!saved)
|
|
227
|
-
return false;
|
|
228
|
-
await (0, utils_1.sleep)(100);
|
|
229
|
-
return await this.agentStart();
|
|
230
|
-
}
|
|
231
|
-
async disableAgentAndExit(txt) {
|
|
232
|
-
logger_1.default.error(txt);
|
|
233
|
-
try {
|
|
234
|
-
await this.system.disable();
|
|
235
|
-
}
|
|
236
|
-
catch {
|
|
237
|
-
// do nothing
|
|
238
|
-
}
|
|
239
|
-
try {
|
|
240
|
-
await buddy_1.default.unregister(this.id || '', this.host || '', this.token || '');
|
|
241
|
-
}
|
|
242
|
-
catch {
|
|
243
|
-
// do nothing
|
|
244
|
-
}
|
|
245
|
-
try {
|
|
246
|
-
this.system.clearSystemFiles();
|
|
247
|
-
}
|
|
248
|
-
catch {
|
|
249
|
-
// do nothing
|
|
250
|
-
}
|
|
251
|
-
try {
|
|
252
|
-
this.system.clearAgentFiles();
|
|
253
|
-
}
|
|
254
|
-
catch {
|
|
255
|
-
// do nothing
|
|
256
|
-
}
|
|
257
|
-
output_1.default.exitError(txt);
|
|
258
|
-
}
|
|
259
|
-
async agentStop() {
|
|
260
|
-
const saved = this.resaveAgentConfig(false, true);
|
|
261
|
-
if (!saved || !this.agent)
|
|
262
|
-
return false;
|
|
263
|
-
await this.agent.stop();
|
|
264
|
-
return true;
|
|
265
|
-
}
|
|
266
|
-
async agentDisable() {
|
|
267
|
-
const saved = this.resaveAgentConfig(false, true);
|
|
268
|
-
if (!saved || !this.agent)
|
|
269
|
-
return false;
|
|
270
|
-
await this.agent.disable();
|
|
271
|
-
return true;
|
|
272
|
-
}
|
|
273
|
-
async agentEnable() {
|
|
274
|
-
const saved = this.resaveAgentConfig(true, true);
|
|
275
|
-
if (!saved || !this.agent)
|
|
276
|
-
return false;
|
|
277
|
-
await this.agent.enable();
|
|
278
|
-
return true;
|
|
279
|
-
}
|
|
280
|
-
async processAgentRestart(res) {
|
|
281
|
-
if (!this.agent) {
|
|
282
|
-
this.serverError(res, 'Agent not enabled');
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
if (this.agent.disabled) {
|
|
286
|
-
this.serverError(res, 'Agent is disabled');
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
const saved = await this.agentRestart();
|
|
290
|
-
if (!saved) {
|
|
291
|
-
this.serverError(res, 'Something went wrong');
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
this.serverOutput(res, {
|
|
295
|
-
success: true,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
async processAgentEnable(res) {
|
|
299
|
-
if (!this.agent) {
|
|
300
|
-
this.serverError(res, 'Agent not enabled');
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
const saved = await this.agentEnable();
|
|
304
|
-
if (!saved) {
|
|
305
|
-
this.serverError(res, 'Something went wrong');
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
this.serverOutput(res, {
|
|
309
|
-
success: true,
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
async processAgentDisable(res) {
|
|
313
|
-
if (!this.agent) {
|
|
314
|
-
this.serverError(res, 'Agent not enabled');
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const saved = await this.agentDisable();
|
|
318
|
-
if (!saved) {
|
|
319
|
-
this.serverError(res, 'Something went wrong');
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
this.serverOutput(res, {
|
|
323
|
-
success: true,
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
async processAgentStop(res) {
|
|
327
|
-
if (!this.agent) {
|
|
328
|
-
this.serverError(res, 'Agent not enabled');
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
if (this.agent.disabled) {
|
|
332
|
-
this.serverError(res, 'Agent is disabled');
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
const saved = await this.agentStop();
|
|
336
|
-
if (!saved) {
|
|
337
|
-
this.serverError(res, 'Something went wrong');
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
this.serverOutput(res, {
|
|
341
|
-
success: true,
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
async agentStart() {
|
|
345
|
-
if (!this.agent)
|
|
346
|
-
return false;
|
|
347
|
-
const saved = this.resaveAgentConfig(true, true);
|
|
348
|
-
if (!saved) {
|
|
349
|
-
return false;
|
|
350
|
-
}
|
|
351
|
-
await this.agent.start();
|
|
352
|
-
return true;
|
|
353
|
-
}
|
|
354
|
-
async processAgentStart(res) {
|
|
355
|
-
if (!this.agent) {
|
|
356
|
-
this.serverError(res, 'Agent not enabled');
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
if (this.agent.disabled) {
|
|
360
|
-
this.serverError(res, 'Agent is disabled');
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
const saved = await this.agentStart();
|
|
364
|
-
if (!saved) {
|
|
365
|
-
this.serverError(res, 'Something went wrong');
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
this.serverOutput(res, {
|
|
369
|
-
success: true,
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
async processTunnelAdd(req, res) {
|
|
373
|
-
if (!this.agent) {
|
|
374
|
-
this.serverError(res, 'Agent not enabled');
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
let data;
|
|
378
|
-
try {
|
|
379
|
-
data = await this.processBody(req);
|
|
380
|
-
}
|
|
381
|
-
catch {
|
|
382
|
-
this.serverError(res, 'Wrong input data');
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
let tunnel;
|
|
386
|
-
try {
|
|
387
|
-
tunnel = await buddy_1.default.addTunnel(this.id || '', this.host || '', this.token || '', data, this.sshHostKey || '');
|
|
388
|
-
}
|
|
389
|
-
catch (err) {
|
|
390
|
-
this.serverError(res, err.message);
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
this.agent.addTunnel(tunnel);
|
|
394
|
-
this.serverOutput(res, {
|
|
395
|
-
id: tunnel.id,
|
|
396
|
-
type: tunnel.type,
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
async processRequest(req, res) {
|
|
400
|
-
logger_1.default.info((0, texts_1.LOG_REQUEST)(req.url || ''));
|
|
401
|
-
if (req.url === '/status')
|
|
402
|
-
return this.processStatus(res);
|
|
403
|
-
if (req.url === '/target')
|
|
404
|
-
return this.processAgentTarget(res);
|
|
405
|
-
if (req.url === '/target/enable')
|
|
406
|
-
return this.processAgentTargetEnable(res);
|
|
407
|
-
if (req.url === '/target/disable')
|
|
408
|
-
return this.processAgentTargetDisable(res);
|
|
409
|
-
if (req.url === '/tunnels')
|
|
410
|
-
return this.processTunnels(res);
|
|
411
|
-
if (req.url === '/tunnel/add')
|
|
412
|
-
return this.processTunnelAdd(req, res);
|
|
413
|
-
if (req.url === '/tunnel/stop')
|
|
414
|
-
return this.processTunnelStop(req, res);
|
|
415
|
-
if (req.url === '/agent/start')
|
|
416
|
-
return this.processAgentStart(res);
|
|
417
|
-
if (req.url === '/agent/stop')
|
|
418
|
-
return this.processAgentStop(res);
|
|
419
|
-
if (req.url === '/agent/restart')
|
|
420
|
-
return this.processAgentRestart(res);
|
|
421
|
-
if (req.url === '/agent/disable')
|
|
422
|
-
return this.processAgentDisable(res);
|
|
423
|
-
if (req.url === '/agent/enable')
|
|
424
|
-
return this.processAgentEnable(res);
|
|
425
|
-
this.server404(res);
|
|
426
|
-
}
|
|
427
|
-
processUpgrade(req, socket, head) {
|
|
428
|
-
logger_1.default.info((0, texts_1.LOG_REQUEST)(req.url || ''));
|
|
429
|
-
const url = new URL(req.url || '', 'http://localhost');
|
|
430
|
-
const id = url.searchParams.get('id');
|
|
431
|
-
if (url.pathname === '/tunnel' && id && this.ws) {
|
|
432
|
-
this.ws.handleUpgrade(req, socket, head, (con) => {
|
|
433
|
-
if (this.ws)
|
|
434
|
-
this.ws.emit('connection', con, id);
|
|
435
|
-
});
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
socket.destroy();
|
|
439
|
-
}
|
|
440
|
-
processWebsocketConnection(con, id) {
|
|
441
|
-
if (!this.agent) {
|
|
442
|
-
con.close();
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
const tunnel = this.agent.tunnels.find((t) => t.id === id);
|
|
446
|
-
if (!tunnel || tunnel.type === tunnel_1.TUNNEL_TYPE.SSH) {
|
|
447
|
-
con.close();
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
new socket_1.default(con, tunnel);
|
|
451
|
-
}
|
|
452
|
-
createServer() {
|
|
453
|
-
this.server = http_1.default.createServer((req, res) => this.processRequest(req, res));
|
|
454
|
-
this.ws = new ws_1.WebSocketServer({ noServer: true });
|
|
455
|
-
this.ws.on('connection', (con, id) => this.processWebsocketConnection(con, id));
|
|
456
|
-
this.server.on('upgrade', (req, socket, head) => this.processUpgrade(req, socket, head));
|
|
457
|
-
this.server.on('error', async (err) => {
|
|
458
|
-
if (err.code === 'EADDRINUSE') {
|
|
459
|
-
await this.disableAgentAndExit(texts_1.LOG_ERROR_STARTING_AGENT_SERVER);
|
|
460
|
-
}
|
|
461
|
-
else {
|
|
462
|
-
logger_1.default.error(err);
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
this.server.listen(this.port, () => {
|
|
466
|
-
logger_1.default.info(texts_1.LOG_AGENT_SERVER_STARTED);
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
resaveAgentConfig(shouldStart, forceParam = false) {
|
|
470
|
-
if (!forceParam) {
|
|
471
|
-
try {
|
|
472
|
-
// load from config
|
|
473
|
-
const json = this.system.loadAgentConfig();
|
|
474
|
-
this.shouldStart = !!json.shouldStart;
|
|
475
|
-
this.sshHostKey = json.sshHostKey;
|
|
476
|
-
}
|
|
477
|
-
catch {
|
|
478
|
-
// save from param
|
|
479
|
-
this.shouldStart = shouldStart;
|
|
480
|
-
}
|
|
481
|
-
if (!this.sshHostKey)
|
|
482
|
-
this.sshHostKey = (0, utils_1.createSshHostKey)();
|
|
483
|
-
}
|
|
484
|
-
else {
|
|
485
|
-
// save from param
|
|
486
|
-
this.shouldStart = shouldStart;
|
|
487
|
-
}
|
|
488
|
-
try {
|
|
489
|
-
// resave config
|
|
490
|
-
this.system.saveAgentConfig(this.shouldStart, this.sshHostKey || '');
|
|
491
|
-
return true;
|
|
492
|
-
}
|
|
493
|
-
catch {
|
|
494
|
-
return false;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
async load(id, host, token, port, start) {
|
|
498
|
-
this.status = tunnel_1.TUNNEL_AGENT_STATUS.INITIALIZING;
|
|
499
|
-
this.id = id;
|
|
500
|
-
this.host = host;
|
|
501
|
-
this.token = token;
|
|
502
|
-
this.port = port;
|
|
503
|
-
if (!this.id || !this.token || !this.host || !this.port) {
|
|
504
|
-
await this.disableAgentAndExit(texts_1.ERR_AGENT_NOT_REGISTERED);
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
const ok = this.resaveAgentConfig(start);
|
|
508
|
-
if (!ok) {
|
|
509
|
-
await this.disableAgentAndExit(texts_1.ERR_SAVING_AGENT_CONFIG);
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
this.createServer();
|
|
513
|
-
await this.tryFetch();
|
|
514
|
-
logger_1.default.info(texts_1.LOG_AGENT_STARTED);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
exports.AgentManagerClass = AgentManagerClass;
|
|
518
|
-
const AgentManager = new AgentManagerClass();
|
|
519
|
-
exports.default = AgentManager;
|
package/distTs/src/agent/osx.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const texts_1 = require("../texts");
|
|
7
|
-
const logger_1 = __importDefault(require("../logger"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const child_process_1 = require("child_process");
|
|
10
|
-
const system_1 = __importDefault(require("./system"));
|
|
11
|
-
class AgentOsx extends system_1.default {
|
|
12
|
-
hasAdminRights() {
|
|
13
|
-
return new Promise((resolve) => {
|
|
14
|
-
if (process.getuid) {
|
|
15
|
-
resolve(process.getuid() === 0);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
resolve(false);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
isSupported() {
|
|
23
|
-
// cant check for process.arch because of rosetta (process.arch returns x64 for m1)
|
|
24
|
-
return Promise.resolve(true);
|
|
25
|
-
}
|
|
26
|
-
isEnabled() {
|
|
27
|
-
return new Promise((resolve) => {
|
|
28
|
-
this.launchCtl('print system/bdy | grep domain')
|
|
29
|
-
.then((str) => {
|
|
30
|
-
resolve(!!str && !!str.match(/domain\s=\ssystem/i));
|
|
31
|
-
})
|
|
32
|
-
.catch(() => {
|
|
33
|
-
resolve(false);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
getBinaryArchive() {
|
|
38
|
-
return 'darwin-arm64.tar.gz';
|
|
39
|
-
}
|
|
40
|
-
getSystemConfigDir() {
|
|
41
|
-
return '/Library/Application Support/bdy';
|
|
42
|
-
}
|
|
43
|
-
getSystemConfigPath() {
|
|
44
|
-
return path_1.default.join(this.getSystemConfigDir(), 'agent.json');
|
|
45
|
-
}
|
|
46
|
-
getServicePath() {
|
|
47
|
-
return '/Library/LaunchDaemons/bdy.plist';
|
|
48
|
-
}
|
|
49
|
-
getServiceConfig(id, host, token, port, start, user, debug) {
|
|
50
|
-
const cli = this.getSystemBinaryPath();
|
|
51
|
-
let cfg = `<?xml version='1.0' encoding='UTF-8'?>
|
|
52
|
-
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
53
|
-
<plist version='1.0'>
|
|
54
|
-
<dict>
|
|
55
|
-
<key>Label</key>
|
|
56
|
-
<string>bdy</string>
|
|
57
|
-
<key>ProgramArguments</key>
|
|
58
|
-
<array>
|
|
59
|
-
<string>${cli}</string>
|
|
60
|
-
<string>agent</string>
|
|
61
|
-
<string>run</string>
|
|
62
|
-
<string>--id</string>
|
|
63
|
-
<string>${id}</string>
|
|
64
|
-
<string>--host</string>
|
|
65
|
-
<string>${host}</string>
|
|
66
|
-
<string>--token</string>
|
|
67
|
-
<string>${token}</string>
|
|
68
|
-
<string>--port</string>
|
|
69
|
-
<string>${port}</string>
|
|
70
|
-
<string>--start</string>
|
|
71
|
-
<string>${!!start}</string>
|
|
72
|
-
</array>
|
|
73
|
-
<key>EnvironmentVariables</key>
|
|
74
|
-
<dict>
|
|
75
|
-
<key>DEBUG</key>
|
|
76
|
-
<string>${debug ? 1 : 0}</string>
|
|
77
|
-
</dict>
|
|
78
|
-
<key>KeepAlive</key>
|
|
79
|
-
<true/>
|
|
80
|
-
<key>RunAtLoad</key>
|
|
81
|
-
<true/>`;
|
|
82
|
-
if (user) {
|
|
83
|
-
cfg += `
|
|
84
|
-
<key>UserName</key>
|
|
85
|
-
<string>${user}</string>`;
|
|
86
|
-
}
|
|
87
|
-
cfg += `
|
|
88
|
-
</dict>
|
|
89
|
-
</plist>`;
|
|
90
|
-
return cfg;
|
|
91
|
-
}
|
|
92
|
-
async enable(id, host, token, port, start, user, pass, debug) {
|
|
93
|
-
try {
|
|
94
|
-
logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
|
|
95
|
-
await this.ensureSystemConfigDir();
|
|
96
|
-
logger_1.default.info(texts_1.LOG_AGENT_DOWNLOADING_ARCHIVE);
|
|
97
|
-
await this.downloadBinaryArchive();
|
|
98
|
-
logger_1.default.info(texts_1.LOG_AGENT_EXTRACTING_ARCHIVE);
|
|
99
|
-
await this.extractBinaryArchive();
|
|
100
|
-
logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_SERVICE_CONFIG);
|
|
101
|
-
await this.saveFile(this.getServicePath(), this.getServiceConfig(id, host, token, port, start, user, debug));
|
|
102
|
-
logger_1.default.info(texts_1.LOG_AGENT_ENABLING_SYSTEM);
|
|
103
|
-
await this.launchCtl(`bootstrap system ${this.getServicePath()}`);
|
|
104
|
-
logger_1.default.info(texts_1.LOG_AGENT_ENABLED);
|
|
105
|
-
}
|
|
106
|
-
catch (err) {
|
|
107
|
-
logger_1.default.info(err);
|
|
108
|
-
throw err;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async update() {
|
|
112
|
-
try {
|
|
113
|
-
logger_1.default.info(texts_1.LOG_AGENT_STOPPING_SYSTEM);
|
|
114
|
-
await this.launchCtl('bootout system/bdy');
|
|
115
|
-
logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
|
|
116
|
-
await this.ensureSystemConfigDir();
|
|
117
|
-
logger_1.default.info(texts_1.LOG_AGENT_DOWNLOADING_ARCHIVE);
|
|
118
|
-
await this.downloadBinaryArchive();
|
|
119
|
-
logger_1.default.info(texts_1.LOG_AGENT_EXTRACTING_ARCHIVE);
|
|
120
|
-
await this.extractBinaryArchive();
|
|
121
|
-
logger_1.default.info(texts_1.LOG_AGENT_STARTING_SYSTEM);
|
|
122
|
-
await this.launchCtl(`bootstrap system ${this.getServicePath()}`);
|
|
123
|
-
logger_1.default.info(texts_1.LOG_AGENT_ENABLED);
|
|
124
|
-
}
|
|
125
|
-
catch (err) {
|
|
126
|
-
logger_1.default.error(err);
|
|
127
|
-
throw err;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
disable() {
|
|
131
|
-
return new Promise((resolve, reject) => {
|
|
132
|
-
this.launchCtl('bootout system/bdy').then(() => resolve()).catch(reject);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
launchCtl(cmd) {
|
|
136
|
-
return new Promise((resolve, reject) => {
|
|
137
|
-
(0, child_process_1.exec)(`launchctl ${cmd}`, (err, stdout) => {
|
|
138
|
-
if (!err)
|
|
139
|
-
resolve(stdout);
|
|
140
|
-
else
|
|
141
|
-
reject(err);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
exports.default = AgentOsx;
|