bdy 1.15.7-dev-package → 1.16.2-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distTs/package.json +1 -1
- package/distTs/src/agent/agent.js +28 -56
- package/distTs/src/agent/linux.js +22 -23
- package/distTs/src/agent/manager.js +12 -105
- package/distTs/src/agent/osx.js +22 -27
- package/distTs/src/agent/socket/client.js +4 -4
- package/distTs/src/agent/system.js +89 -21
- package/distTs/src/agent/windows.js +21 -32
- package/distTs/src/api/client.js +25 -101
- package/distTs/src/command/agent/debug.js +10 -3
- package/distTs/src/command/agent/disable.js +6 -6
- package/distTs/src/command/agent/enable.js +6 -6
- package/distTs/src/command/agent/install.js +109 -27
- package/distTs/src/command/agent/restart.js +21 -11
- package/distTs/src/command/agent/run.js +1 -1
- package/distTs/src/command/agent/standalone/kill.js +22 -0
- package/distTs/src/command/agent/standalone.js +136 -0
- package/distTs/src/command/agent/start.js +19 -12
- package/distTs/src/command/agent/status.js +44 -17
- package/distTs/src/command/agent/stop.js +20 -13
- package/distTs/src/command/agent/target/disable.js +6 -6
- package/distTs/src/command/agent/target/enable.js +6 -6
- package/distTs/src/command/agent/target/status.js +6 -6
- package/distTs/src/command/agent/tunnel/http.js +6 -6
- package/distTs/src/command/agent/tunnel/list.js +6 -6
- package/distTs/src/command/agent/tunnel/remove.js +6 -6
- package/distTs/src/command/agent/tunnel/start.js +7 -7
- package/distTs/src/command/agent/tunnel/status.js +6 -6
- package/distTs/src/command/agent/tunnel/tcp.js +6 -6
- package/distTs/src/command/agent/tunnel/tls.js +6 -6
- package/distTs/src/command/agent/uninstall.js +2 -2
- package/distTs/src/command/agent/update.js +19 -17
- package/distTs/src/command/agent/version.js +3 -5
- package/distTs/src/command/agent.js +0 -4
- package/distTs/src/command/pipeline/run.js +3 -3
- package/distTs/src/command/pre.js +10 -2
- package/distTs/src/command/vt/scrap.js +193 -0
- package/distTs/src/index.js +0 -2
- package/distTs/src/input.js +1 -24
- package/distTs/src/output.js +16 -4
- package/distTs/src/texts.js +22 -85
- package/distTs/src/tunnel/api/agent.js +0 -9
- package/distTs/src/types/tunnel.js +0 -3
- package/package.json +1 -1
- package/distTs/src/command/package/download.js +0 -259
- package/distTs/src/command/package/publish.js +0 -231
- package/distTs/src/command/package.js +0 -14
package/distTs/package.json
CHANGED
|
@@ -20,7 +20,6 @@ class Agent extends events_1.default {
|
|
|
20
20
|
disabled;
|
|
21
21
|
tunnels;
|
|
22
22
|
tunnelsUpdating;
|
|
23
|
-
started;
|
|
24
23
|
api;
|
|
25
24
|
socket;
|
|
26
25
|
manager;
|
|
@@ -35,7 +34,6 @@ class Agent extends events_1.default {
|
|
|
35
34
|
this.disabled = disabled;
|
|
36
35
|
this.tunnels = [];
|
|
37
36
|
this.tunnelsUpdating = false;
|
|
38
|
-
this.started = false;
|
|
39
37
|
this.api = api;
|
|
40
38
|
this.manager = null;
|
|
41
39
|
this.onRefresh = null;
|
|
@@ -67,8 +65,9 @@ class Agent extends events_1.default {
|
|
|
67
65
|
}
|
|
68
66
|
else {
|
|
69
67
|
logger_1.default.debug('Socket fetch tunnel after sync push');
|
|
70
|
-
if (this.socket)
|
|
71
|
-
this.socket.fetch(this.
|
|
68
|
+
if (this.socket) {
|
|
69
|
+
this.socket.fetch(!this.disabled, null, null, false, []);
|
|
70
|
+
}
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
73
|
async _onSocketAgent(data, action) {
|
|
@@ -80,11 +79,13 @@ class Agent extends events_1.default {
|
|
|
80
79
|
}
|
|
81
80
|
else {
|
|
82
81
|
this.target = !!data.target;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
if (!!data.disabled !== this.disabled) {
|
|
83
|
+
if (data.disabled)
|
|
84
|
+
await this.disable();
|
|
85
|
+
else
|
|
86
|
+
await this.enable();
|
|
86
87
|
}
|
|
87
|
-
|
|
88
|
+
if (data.action) {
|
|
88
89
|
try {
|
|
89
90
|
await this.makeAction(data.action);
|
|
90
91
|
}
|
|
@@ -133,44 +134,32 @@ class Agent extends events_1.default {
|
|
|
133
134
|
this.refreshIn15();
|
|
134
135
|
}
|
|
135
136
|
async start() {
|
|
136
|
-
this.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
137
|
+
if (!this.disabled) {
|
|
138
|
+
this.tunnels.forEach((t) => {
|
|
139
|
+
t.start();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (this.socket) {
|
|
143
|
+
this.socket.fetch(!this.disabled, '', null, true, this.getTunnelsUpdate(), true);
|
|
144
|
+
}
|
|
142
145
|
}
|
|
143
146
|
async enable() {
|
|
144
147
|
this.disabled = false;
|
|
145
|
-
this.started = true;
|
|
146
148
|
this.tunnels.forEach((t) => {
|
|
147
149
|
t.start();
|
|
148
150
|
});
|
|
149
|
-
if (this.socket)
|
|
150
|
-
this.socket.fetch(this.
|
|
151
|
-
|
|
152
|
-
async stop(clearAction = true) {
|
|
153
|
-
this.started = false;
|
|
154
|
-
this.tunnels.forEach((t) => {
|
|
155
|
-
t.stop();
|
|
156
|
-
});
|
|
157
|
-
if (!this.socket)
|
|
158
|
-
return;
|
|
159
|
-
this.socket.fetch(this.started, clearAction ? '' : null, null, false, this.getTunnelsUpdate());
|
|
151
|
+
if (this.socket) {
|
|
152
|
+
this.socket.fetch(!this.disabled, '', this.disabled, true, this.getTunnelsUpdate(), true);
|
|
153
|
+
}
|
|
160
154
|
}
|
|
161
155
|
async disable() {
|
|
162
156
|
this.disabled = true;
|
|
163
|
-
this.started = false;
|
|
164
157
|
this.tunnels.forEach((t) => {
|
|
165
158
|
t.stop();
|
|
166
159
|
});
|
|
167
|
-
if (this.socket)
|
|
168
|
-
this.socket.fetch(this.
|
|
169
|
-
|
|
170
|
-
async restart() {
|
|
171
|
-
await this.stop(false);
|
|
172
|
-
await (0, utils_1.sleep)(100);
|
|
173
|
-
await this.start();
|
|
160
|
+
if (this.socket) {
|
|
161
|
+
this.socket.fetch(!this.disabled, '', this.disabled, false, this.getTunnelsUpdate(), true);
|
|
162
|
+
}
|
|
174
163
|
}
|
|
175
164
|
async delete() {
|
|
176
165
|
try {
|
|
@@ -189,7 +178,7 @@ class Agent extends events_1.default {
|
|
|
189
178
|
if (fetch || counter >= 3) {
|
|
190
179
|
counter = 0;
|
|
191
180
|
if (this.socket) {
|
|
192
|
-
this.socket.fetch(this.
|
|
181
|
+
this.socket.fetch(!this.disabled, null, null, false, this.getTunnelsUpdate());
|
|
193
182
|
}
|
|
194
183
|
}
|
|
195
184
|
else {
|
|
@@ -207,28 +196,11 @@ class Agent extends events_1.default {
|
|
|
207
196
|
this.socket.request(tunnelId, logRequest);
|
|
208
197
|
}
|
|
209
198
|
update(force = false) {
|
|
210
|
-
if (this.socket)
|
|
211
|
-
this.socket.update(this.
|
|
199
|
+
if (this.socket) {
|
|
200
|
+
this.socket.update(!this.disabled, this.getTunnelsUpdate(), force);
|
|
201
|
+
}
|
|
212
202
|
}
|
|
213
203
|
async makeAction(action) {
|
|
214
|
-
if (action === tunnel_2.TUNNEL_AGENT_ACTION.STOP) {
|
|
215
|
-
if (this.manager) {
|
|
216
|
-
return this.manager.agentStop();
|
|
217
|
-
}
|
|
218
|
-
return this.stop();
|
|
219
|
-
}
|
|
220
|
-
if (action === tunnel_2.TUNNEL_AGENT_ACTION.START) {
|
|
221
|
-
if (this.manager) {
|
|
222
|
-
return this.manager.agentStart();
|
|
223
|
-
}
|
|
224
|
-
return this.start();
|
|
225
|
-
}
|
|
226
|
-
if (action === tunnel_2.TUNNEL_AGENT_ACTION.RESTART) {
|
|
227
|
-
if (this.manager) {
|
|
228
|
-
return this.manager.agentRestart();
|
|
229
|
-
}
|
|
230
|
-
return this.restart();
|
|
231
|
-
}
|
|
232
204
|
if (action === tunnel_2.TUNNEL_AGENT_ACTION.DELETE) {
|
|
233
205
|
if (this.manager) {
|
|
234
206
|
return this.manager.disableAgentAndExit(texts_1.ERR_AGENT_REMOVED);
|
|
@@ -301,7 +273,7 @@ class Agent extends events_1.default {
|
|
|
301
273
|
}
|
|
302
274
|
addTunnel(tunnel) {
|
|
303
275
|
this.tunnels.push(tunnel);
|
|
304
|
-
if (this.
|
|
276
|
+
if (!this.disabled)
|
|
305
277
|
tunnel.start();
|
|
306
278
|
tunnel.on(tunnel_2.TUNNEL_EVENT.OPEN, () => this.update(true));
|
|
307
279
|
tunnel.on(tunnel_2.TUNNEL_EVENT.CLOSED, () => this.update());
|
|
@@ -30,21 +30,6 @@ class AgentLinux extends system_1.default {
|
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
isEnabled() {
|
|
34
|
-
return new Promise((resolve) => {
|
|
35
|
-
if (this.isStandaloneProcRunning()) {
|
|
36
|
-
resolve(true);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
this.systemctl('is-enabled bdy')
|
|
40
|
-
.then(() => {
|
|
41
|
-
resolve(true);
|
|
42
|
-
})
|
|
43
|
-
.catch(() => {
|
|
44
|
-
resolve(false);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
33
|
getBinaryArchive() {
|
|
49
34
|
return `linux-${process.arch}.tar.gz`;
|
|
50
35
|
}
|
|
@@ -60,7 +45,7 @@ class AgentLinux extends system_1.default {
|
|
|
60
45
|
getServicePath() {
|
|
61
46
|
return '/etc/systemd/system/bdy.service';
|
|
62
47
|
}
|
|
63
|
-
getServiceConfig(id, host, token, port,
|
|
48
|
+
getServiceConfig(id, host, token, port, user, debug) {
|
|
64
49
|
const cli = this.getSystemBinaryPath();
|
|
65
50
|
return `[Unit]
|
|
66
51
|
Description=Buddy Tunnel Agent
|
|
@@ -70,14 +55,21 @@ After=network.target
|
|
|
70
55
|
Environment="DEBUG=${debug ? 1 : 0}"
|
|
71
56
|
User=${user || 'root'}
|
|
72
57
|
WorkingDirectory=/
|
|
73
|
-
ExecStart=${cli} agent run --id="${id}" --host="${host}" --token="${token}" --port=${port}
|
|
58
|
+
ExecStart=${cli} agent run --id="${id}" --host="${host}" --token="${token}" --port=${port}
|
|
74
59
|
Restart=always
|
|
75
60
|
RestartSec=3
|
|
76
61
|
|
|
77
62
|
[Install]
|
|
78
63
|
WantedBy=multi-user.target`;
|
|
79
64
|
}
|
|
80
|
-
async
|
|
65
|
+
async install(id, host, token, port, start, user, pass, debug) {
|
|
66
|
+
try {
|
|
67
|
+
// ensure service clear
|
|
68
|
+
await this.uninstall();
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// do nothing
|
|
72
|
+
}
|
|
81
73
|
try {
|
|
82
74
|
logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
|
|
83
75
|
await this.ensureSystemConfigDir();
|
|
@@ -86,9 +78,10 @@ WantedBy=multi-user.target`;
|
|
|
86
78
|
logger_1.default.info(texts_1.LOG_AGENT_EXTRACTING_ARCHIVE);
|
|
87
79
|
await this.extractBinaryArchive();
|
|
88
80
|
logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_SERVICE_CONFIG);
|
|
89
|
-
await this.saveFile(this.getServicePath(), this.getServiceConfig(id, host, token, port,
|
|
81
|
+
await this.saveFile(this.getServicePath(), this.getServiceConfig(id, host, token, port, user, debug));
|
|
90
82
|
logger_1.default.info(texts_1.LOG_AGENT_ENABLING_SYSTEM);
|
|
91
|
-
|
|
83
|
+
if (start)
|
|
84
|
+
await this.start();
|
|
92
85
|
logger_1.default.info(texts_1.LOG_AGENT_ENABLED);
|
|
93
86
|
}
|
|
94
87
|
catch (err) {
|
|
@@ -99,7 +92,7 @@ WantedBy=multi-user.target`;
|
|
|
99
92
|
async update() {
|
|
100
93
|
try {
|
|
101
94
|
logger_1.default.info(texts_1.LOG_AGENT_STOPPING_SYSTEM);
|
|
102
|
-
await this.
|
|
95
|
+
await this.stop();
|
|
103
96
|
logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
|
|
104
97
|
await this.ensureSystemConfigDir();
|
|
105
98
|
logger_1.default.info(texts_1.LOG_AGENT_DOWNLOADING_ARCHIVE);
|
|
@@ -107,15 +100,21 @@ WantedBy=multi-user.target`;
|
|
|
107
100
|
logger_1.default.info(texts_1.LOG_AGENT_EXTRACTING_ARCHIVE);
|
|
108
101
|
await this.extractBinaryArchive();
|
|
109
102
|
logger_1.default.info(texts_1.LOG_AGENT_STARTING_SYSTEM);
|
|
110
|
-
await this.
|
|
103
|
+
await this.start();
|
|
111
104
|
}
|
|
112
105
|
catch (err) {
|
|
113
106
|
logger_1.default.error(err);
|
|
114
107
|
throw err;
|
|
115
108
|
}
|
|
116
109
|
}
|
|
110
|
+
async stop() {
|
|
111
|
+
await this.systemctl('disable --now bdy');
|
|
112
|
+
}
|
|
113
|
+
async start() {
|
|
114
|
+
await this.systemctl('enable --now bdy');
|
|
115
|
+
}
|
|
117
116
|
async disable() {
|
|
118
|
-
|
|
117
|
+
await this.stop();
|
|
119
118
|
}
|
|
120
119
|
systemctl(cmd) {
|
|
121
120
|
return new Promise((resolve, reject) => {
|
|
@@ -23,7 +23,6 @@ class AgentManagerClass {
|
|
|
23
23
|
host;
|
|
24
24
|
token;
|
|
25
25
|
port;
|
|
26
|
-
shouldStart;
|
|
27
26
|
sshHostKey;
|
|
28
27
|
agent;
|
|
29
28
|
ws;
|
|
@@ -35,7 +34,6 @@ class AgentManagerClass {
|
|
|
35
34
|
this.host = null;
|
|
36
35
|
this.token = null;
|
|
37
36
|
this.port = null;
|
|
38
|
-
this.shouldStart = null;
|
|
39
37
|
this.sshHostKey = null;
|
|
40
38
|
this.agent = null;
|
|
41
39
|
this.server = null;
|
|
@@ -53,8 +51,8 @@ class AgentManagerClass {
|
|
|
53
51
|
this.system = new system_1.default();
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
|
-
start(id, host, token, port
|
|
57
|
-
this.load(id, host, token, port
|
|
54
|
+
start(id, host, token, port) {
|
|
55
|
+
this.load(id, host, token, port).then();
|
|
58
56
|
}
|
|
59
57
|
async tryFetch() {
|
|
60
58
|
try {
|
|
@@ -66,8 +64,7 @@ class AgentManagerClass {
|
|
|
66
64
|
else
|
|
67
65
|
this.status = tunnel_1.TUNNEL_AGENT_STATUS.FETCH_FAILED;
|
|
68
66
|
});
|
|
69
|
-
|
|
70
|
-
await this.agent.start();
|
|
67
|
+
await this.agent.start();
|
|
71
68
|
this.status = tunnel_1.TUNNEL_AGENT_STATUS.ENABLED;
|
|
72
69
|
}
|
|
73
70
|
catch (err) {
|
|
@@ -171,8 +168,8 @@ class AgentManagerClass {
|
|
|
171
168
|
id: this.id,
|
|
172
169
|
status: this.status,
|
|
173
170
|
version: (0, utils_1.getVersion)(),
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
enabled: !this.agent?.disabled,
|
|
172
|
+
target: !!this.agent?.target
|
|
176
173
|
});
|
|
177
174
|
}
|
|
178
175
|
processBody(req) {
|
|
@@ -240,17 +237,10 @@ class AgentManagerClass {
|
|
|
240
237
|
success: true,
|
|
241
238
|
});
|
|
242
239
|
}
|
|
243
|
-
async agentRestart() {
|
|
244
|
-
const saved = await this.agentStop();
|
|
245
|
-
if (!saved)
|
|
246
|
-
return false;
|
|
247
|
-
await (0, utils_1.sleep)(100);
|
|
248
|
-
return await this.agentStart();
|
|
249
|
-
}
|
|
250
240
|
async disableAgentAndExit(txt) {
|
|
251
241
|
logger_1.default.error(txt);
|
|
252
242
|
try {
|
|
253
|
-
await this.system.
|
|
243
|
+
await this.system.uninstall();
|
|
254
244
|
}
|
|
255
245
|
catch {
|
|
256
246
|
// do nothing
|
|
@@ -281,45 +271,18 @@ class AgentManagerClass {
|
|
|
281
271
|
}
|
|
282
272
|
output_1.default.exitError(txt);
|
|
283
273
|
}
|
|
284
|
-
async agentStop() {
|
|
285
|
-
const saved = this.resaveAgentConfig(false, true);
|
|
286
|
-
if (!saved || !this.agent)
|
|
287
|
-
return false;
|
|
288
|
-
await this.agent.stop();
|
|
289
|
-
return true;
|
|
290
|
-
}
|
|
291
274
|
async agentDisable() {
|
|
292
|
-
|
|
293
|
-
if (!saved || !this.agent)
|
|
275
|
+
if (!this.agent)
|
|
294
276
|
return false;
|
|
295
277
|
await this.agent.disable();
|
|
296
278
|
return true;
|
|
297
279
|
}
|
|
298
280
|
async agentEnable() {
|
|
299
|
-
|
|
300
|
-
if (!saved || !this.agent)
|
|
281
|
+
if (!this.agent)
|
|
301
282
|
return false;
|
|
302
283
|
await this.agent.enable();
|
|
303
284
|
return true;
|
|
304
285
|
}
|
|
305
|
-
async processAgentRestart(res) {
|
|
306
|
-
if (!this.agent) {
|
|
307
|
-
this.serverError(res, 'Agent not enabled');
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
if (this.agent.disabled) {
|
|
311
|
-
this.serverError(res, 'Agent is disabled');
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
const saved = await this.agentRestart();
|
|
315
|
-
if (!saved) {
|
|
316
|
-
this.serverError(res, 'Something went wrong');
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
this.serverOutput(res, {
|
|
320
|
-
success: true,
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
286
|
async processAgentEnable(res) {
|
|
324
287
|
if (!this.agent) {
|
|
325
288
|
this.serverError(res, 'Agent not enabled');
|
|
@@ -348,52 +311,6 @@ class AgentManagerClass {
|
|
|
348
311
|
success: true,
|
|
349
312
|
});
|
|
350
313
|
}
|
|
351
|
-
async processAgentStop(res) {
|
|
352
|
-
if (!this.agent) {
|
|
353
|
-
this.serverError(res, 'Agent not enabled');
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
if (this.agent.disabled) {
|
|
357
|
-
this.serverError(res, 'Agent is disabled');
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
const saved = await this.agentStop();
|
|
361
|
-
if (!saved) {
|
|
362
|
-
this.serverError(res, 'Something went wrong');
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
this.serverOutput(res, {
|
|
366
|
-
success: true,
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
async agentStart() {
|
|
370
|
-
if (!this.agent)
|
|
371
|
-
return false;
|
|
372
|
-
const saved = this.resaveAgentConfig(true, true);
|
|
373
|
-
if (!saved) {
|
|
374
|
-
return false;
|
|
375
|
-
}
|
|
376
|
-
await this.agent.start();
|
|
377
|
-
return true;
|
|
378
|
-
}
|
|
379
|
-
async processAgentStart(res) {
|
|
380
|
-
if (!this.agent) {
|
|
381
|
-
this.serverError(res, 'Agent not enabled');
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
if (this.agent.disabled) {
|
|
385
|
-
this.serverError(res, 'Agent is disabled');
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
const saved = await this.agentStart();
|
|
389
|
-
if (!saved) {
|
|
390
|
-
this.serverError(res, 'Something went wrong');
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
this.serverOutput(res, {
|
|
394
|
-
success: true,
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
314
|
async processTunnelAdd(req, res) {
|
|
398
315
|
if (!this.agent) {
|
|
399
316
|
this.serverError(res, 'Agent not enabled');
|
|
@@ -437,12 +354,6 @@ class AgentManagerClass {
|
|
|
437
354
|
return this.processTunnelAdd(req, res);
|
|
438
355
|
if (req.url === '/tunnel/stop')
|
|
439
356
|
return this.processTunnelStop(req, res);
|
|
440
|
-
if (req.url === '/agent/start')
|
|
441
|
-
return this.processAgentStart(res);
|
|
442
|
-
if (req.url === '/agent/stop')
|
|
443
|
-
return this.processAgentStop(res);
|
|
444
|
-
if (req.url === '/agent/restart')
|
|
445
|
-
return this.processAgentRestart(res);
|
|
446
357
|
if (req.url === '/agent/debug')
|
|
447
358
|
return this.processAgentDebug(req, res);
|
|
448
359
|
if (req.url === '/agent/disable')
|
|
@@ -493,31 +404,27 @@ class AgentManagerClass {
|
|
|
493
404
|
logger_1.default.info(texts_1.LOG_AGENT_SERVER_STARTED);
|
|
494
405
|
});
|
|
495
406
|
}
|
|
496
|
-
resaveAgentConfig(
|
|
407
|
+
resaveAgentConfig() {
|
|
497
408
|
try {
|
|
498
409
|
// load from config
|
|
499
410
|
const json = this.system.loadNewAgentConfig();
|
|
500
|
-
this.shouldStart = !!json.shouldStart;
|
|
501
411
|
this.sshHostKey = json.sshHostKey;
|
|
502
412
|
}
|
|
503
413
|
catch {
|
|
504
414
|
// save from param
|
|
505
|
-
this.shouldStart = shouldStart;
|
|
506
415
|
}
|
|
507
416
|
if (!this.sshHostKey)
|
|
508
417
|
this.sshHostKey = (0, utils_1.createSshHostKey)();
|
|
509
|
-
if (forceParam)
|
|
510
|
-
this.shouldStart = shouldStart;
|
|
511
418
|
try {
|
|
512
419
|
// resave config
|
|
513
|
-
this.system.saveNewAgentConfig(this.
|
|
420
|
+
this.system.saveNewAgentConfig(this.sshHostKey || '');
|
|
514
421
|
return true;
|
|
515
422
|
}
|
|
516
423
|
catch {
|
|
517
424
|
return false;
|
|
518
425
|
}
|
|
519
426
|
}
|
|
520
|
-
async load(id, host, token, port
|
|
427
|
+
async load(id, host, token, port) {
|
|
521
428
|
this.status = tunnel_1.TUNNEL_AGENT_STATUS.INITIALIZING;
|
|
522
429
|
this.id = id;
|
|
523
430
|
this.host = host;
|
|
@@ -527,7 +434,7 @@ class AgentManagerClass {
|
|
|
527
434
|
await this.disableAgentAndExit(texts_1.ERR_AGENT_NOT_REGISTERED);
|
|
528
435
|
return;
|
|
529
436
|
}
|
|
530
|
-
const ok = this.resaveAgentConfig(
|
|
437
|
+
const ok = this.resaveAgentConfig();
|
|
531
438
|
if (!ok) {
|
|
532
439
|
await this.disableAgentAndExit(texts_1.ERR_SAVING_AGENT_CONFIG);
|
|
533
440
|
return;
|
package/distTs/src/agent/osx.js
CHANGED
|
@@ -23,21 +23,6 @@ class AgentOsx extends system_1.default {
|
|
|
23
23
|
// cant check for process.arch because of rosetta (process.arch returns x64 for m1)
|
|
24
24
|
return Promise.resolve(true);
|
|
25
25
|
}
|
|
26
|
-
isEnabled() {
|
|
27
|
-
return new Promise((resolve) => {
|
|
28
|
-
if (this.isStandaloneProcRunning()) {
|
|
29
|
-
resolve(true);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
this.launchCtl('print system/bdy | grep domain')
|
|
33
|
-
.then((str) => {
|
|
34
|
-
resolve(!!str && !!str.match(/domain\s=\ssystem/i));
|
|
35
|
-
})
|
|
36
|
-
.catch(() => {
|
|
37
|
-
resolve(false);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
26
|
getBinaryArchive() {
|
|
42
27
|
return 'darwin-arm64.tar.gz';
|
|
43
28
|
}
|
|
@@ -53,7 +38,7 @@ class AgentOsx extends system_1.default {
|
|
|
53
38
|
getServicePath() {
|
|
54
39
|
return '/Library/LaunchDaemons/bdy.plist';
|
|
55
40
|
}
|
|
56
|
-
getServiceConfig(id, host, token, port,
|
|
41
|
+
getServiceConfig(id, host, token, port, user, debug) {
|
|
57
42
|
const cli = this.getSystemBinaryPath();
|
|
58
43
|
let cfg = `<?xml version='1.0' encoding='UTF-8'?>
|
|
59
44
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
@@ -74,8 +59,6 @@ class AgentOsx extends system_1.default {
|
|
|
74
59
|
<string>${token}</string>
|
|
75
60
|
<string>--port</string>
|
|
76
61
|
<string>${port}</string>
|
|
77
|
-
<string>--start</string>
|
|
78
|
-
<string>${!!start}</string>
|
|
79
62
|
</array>
|
|
80
63
|
<key>EnvironmentVariables</key>
|
|
81
64
|
<dict>
|
|
@@ -96,7 +79,14 @@ class AgentOsx extends system_1.default {
|
|
|
96
79
|
</plist>`;
|
|
97
80
|
return cfg;
|
|
98
81
|
}
|
|
99
|
-
async
|
|
82
|
+
async install(id, host, token, port, start, user, pass, debug) {
|
|
83
|
+
try {
|
|
84
|
+
// ensure service clear
|
|
85
|
+
await this.uninstall();
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// do nothing
|
|
89
|
+
}
|
|
100
90
|
try {
|
|
101
91
|
logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
|
|
102
92
|
await this.ensureSystemConfigDir();
|
|
@@ -105,9 +95,10 @@ class AgentOsx extends system_1.default {
|
|
|
105
95
|
logger_1.default.info(texts_1.LOG_AGENT_EXTRACTING_ARCHIVE);
|
|
106
96
|
await this.extractBinaryArchive();
|
|
107
97
|
logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_SERVICE_CONFIG);
|
|
108
|
-
await this.saveFile(this.getServicePath(), this.getServiceConfig(id, host, token, port,
|
|
98
|
+
await this.saveFile(this.getServicePath(), this.getServiceConfig(id, host, token, port, user, debug));
|
|
109
99
|
logger_1.default.info(texts_1.LOG_AGENT_ENABLING_SYSTEM);
|
|
110
|
-
|
|
100
|
+
if (start)
|
|
101
|
+
await this.start();
|
|
111
102
|
logger_1.default.info(texts_1.LOG_AGENT_ENABLED);
|
|
112
103
|
}
|
|
113
104
|
catch (err) {
|
|
@@ -118,7 +109,7 @@ class AgentOsx extends system_1.default {
|
|
|
118
109
|
async update() {
|
|
119
110
|
try {
|
|
120
111
|
logger_1.default.info(texts_1.LOG_AGENT_STOPPING_SYSTEM);
|
|
121
|
-
await this.
|
|
112
|
+
await this.stop();
|
|
122
113
|
logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
|
|
123
114
|
await this.ensureSystemConfigDir();
|
|
124
115
|
logger_1.default.info(texts_1.LOG_AGENT_DOWNLOADING_ARCHIVE);
|
|
@@ -126,7 +117,7 @@ class AgentOsx extends system_1.default {
|
|
|
126
117
|
logger_1.default.info(texts_1.LOG_AGENT_EXTRACTING_ARCHIVE);
|
|
127
118
|
await this.extractBinaryArchive();
|
|
128
119
|
logger_1.default.info(texts_1.LOG_AGENT_STARTING_SYSTEM);
|
|
129
|
-
await this.
|
|
120
|
+
await this.start();
|
|
130
121
|
logger_1.default.info(texts_1.LOG_AGENT_ENABLED);
|
|
131
122
|
}
|
|
132
123
|
catch (err) {
|
|
@@ -134,10 +125,14 @@ class AgentOsx extends system_1.default {
|
|
|
134
125
|
throw err;
|
|
135
126
|
}
|
|
136
127
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
128
|
+
async stop() {
|
|
129
|
+
await this.launchCtl('bootout system/bdy');
|
|
130
|
+
}
|
|
131
|
+
async start() {
|
|
132
|
+
await this.launchCtl(`bootstrap system ${this.getServicePath()}`);
|
|
133
|
+
}
|
|
134
|
+
async uninstall() {
|
|
135
|
+
await this.stop();
|
|
141
136
|
}
|
|
142
137
|
launchCtl(cmd) {
|
|
143
138
|
return new Promise((resolve, reject) => {
|
|
@@ -22,14 +22,14 @@ class AgentSocketClient extends events_1.default {
|
|
|
22
22
|
connected;
|
|
23
23
|
lastUpdate;
|
|
24
24
|
tunnelRequests;
|
|
25
|
-
socketEmit(msg, data) {
|
|
26
|
-
if (!this.socket || !this.connected)
|
|
25
|
+
socketEmit(msg, data, forceThrough = false) {
|
|
26
|
+
if (!this.socket || !forceThrough && !this.connected)
|
|
27
27
|
return;
|
|
28
28
|
logger_1.default.debug(`AGENT SOCKET CLIENT EMIT: ${msg}`);
|
|
29
29
|
logger_1.default.debug(data);
|
|
30
30
|
this.socket.emit(msg, data);
|
|
31
31
|
}
|
|
32
|
-
fetch(activate = true, action = null, disabled = null, resetFirstHeard = false, tunnels) {
|
|
32
|
+
fetch(activate = true, action = null, disabled = null, resetFirstHeard = false, tunnels, forceThrough = false) {
|
|
33
33
|
this.socketEmit('fetchTunnelAgent', {
|
|
34
34
|
id: this.id,
|
|
35
35
|
token: this.token,
|
|
@@ -41,7 +41,7 @@ class AgentSocketClient extends events_1.default {
|
|
|
41
41
|
disabled,
|
|
42
42
|
resetFirstHeard,
|
|
43
43
|
tunnels,
|
|
44
|
-
});
|
|
44
|
+
}, forceThrough);
|
|
45
45
|
}
|
|
46
46
|
update(activate, tunnels, force = false) {
|
|
47
47
|
const now = Date.now();
|