bdy 1.16.2-stage → 1.16.5-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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.16.2-stage",
4
+ "version": "1.16.5-beta",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -152,6 +152,11 @@ class Agent extends events_1.default {
152
152
  this.socket.fetch(!this.disabled, '', this.disabled, true, this.getTunnelsUpdate(), true);
153
153
  }
154
154
  }
155
+ async markInactive() {
156
+ if (this.socket) {
157
+ this.socket.fetch(false, '', null, false, this.getTunnelsUpdate(true), true);
158
+ }
159
+ }
155
160
  async disable() {
156
161
  this.disabled = true;
157
162
  this.tunnels.forEach((t) => {
@@ -256,12 +261,12 @@ class Agent extends events_1.default {
256
261
  output_1.default.exitError(texts_1.ERR_TUNNEL_REMOVED);
257
262
  }
258
263
  }
259
- getTunnelsUpdate() {
264
+ getTunnelsUpdate(forceInactive = false) {
260
265
  const update = [];
261
266
  this.tunnels.forEach((t) => {
262
267
  update.push({
263
268
  id: t.id,
264
- active: t.status === tunnel_2.TUNNEL_STATUS.OPEN,
269
+ active: t.status === tunnel_2.TUNNEL_STATUS.OPEN && !forceInactive,
265
270
  regionLatency: t.regionLatency ? t.regionLatency.latency : -1,
266
271
  targetLatency: t.targetLatency ? t.targetLatency.latency : -1,
267
272
  totalConnections: t.totalConnections,
@@ -113,7 +113,7 @@ WantedBy=multi-user.target`;
113
113
  async start() {
114
114
  await this.systemctl('enable --now bdy');
115
115
  }
116
- async disable() {
116
+ async uninstall() {
117
117
  await this.stop();
118
118
  }
119
119
  systemctl(cmd) {
@@ -297,6 +297,16 @@ class AgentManagerClass {
297
297
  success: true,
298
298
  });
299
299
  }
300
+ async processAgentMarkInactive(res) {
301
+ if (!this.agent) {
302
+ this.serverError(res, 'Agent not enabled');
303
+ return;
304
+ }
305
+ await this.agent.markInactive();
306
+ this.serverOutput(res, {
307
+ success: true,
308
+ });
309
+ }
300
310
  async processAgentDisable(res) {
301
311
  if (!this.agent) {
302
312
  this.serverError(res, 'Agent not enabled');
@@ -358,6 +368,8 @@ class AgentManagerClass {
358
368
  return this.processAgentDebug(req, res);
359
369
  if (req.url === '/agent/disable')
360
370
  return this.processAgentDisable(res);
371
+ if (req.url === '/agent/mark-inactive')
372
+ return this.processAgentMarkInactive(res);
361
373
  if (req.url === '/agent/enable')
362
374
  return this.processAgentEnable(res);
363
375
  this.server404(res);
@@ -113,6 +113,12 @@ const installService = async (options) => {
113
113
  });
114
114
  }
115
115
  else {
116
+ try {
117
+ await buddy_1.default.markAgentAsInactive(id, host, token);
118
+ }
119
+ catch {
120
+ // do nothing
121
+ }
116
122
  output_1.default.exitSuccess(texts_1.TXT_AGENT_INSTALLED);
117
123
  }
118
124
  };
@@ -179,6 +185,12 @@ const installApp = async (options) => {
179
185
  manager_1.default.system.startStandaloneProc();
180
186
  }
181
187
  else {
188
+ try {
189
+ await buddy_1.default.markAgentAsInactive(id, host, token);
190
+ }
191
+ catch {
192
+ // do nothing
193
+ }
182
194
  output_1.default.exitSuccess(texts_1.TXT_AGENT_INSTALLED);
183
195
  }
184
196
  };
@@ -8,6 +8,7 @@ const texts_1 = require("../../texts");
8
8
  const manager_1 = __importDefault(require("../../agent/manager"));
9
9
  const output_1 = __importDefault(require("../../output"));
10
10
  const logger_1 = __importDefault(require("../../logger"));
11
+ const agent_1 = __importDefault(require("../../tunnel/api/agent"));
11
12
  const commandAgentStop = (0, utils_1.newCommand)('stop', texts_1.DESC_COMMAND_AGENT_STOP);
12
13
  commandAgentStop.action(async () => {
13
14
  const hasAdminRights = await manager_1.default.system.hasAdminRights();
@@ -17,6 +18,13 @@ commandAgentStop.action(async () => {
17
18
  if (!commandAgentStop.agentInstalled) {
18
19
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
19
20
  }
21
+ try {
22
+ const api = new agent_1.default(commandAgentStop.agentPort || 0);
23
+ await api.markInactive();
24
+ }
25
+ catch {
26
+ // do nothing
27
+ }
20
28
  if (commandAgentStop.agentStandalone) {
21
29
  await manager_1.default.system.killStandaloneProc();
22
30
  output_1.default.exitSuccess(texts_1.TXT_AGENT_STOPPED);
@@ -8,12 +8,20 @@ const texts_1 = require("../../texts");
8
8
  const manager_1 = __importDefault(require("../../agent/manager"));
9
9
  const buddy_1 = __importDefault(require("../../tunnel/api/buddy"));
10
10
  const utils_1 = require("../../utils");
11
+ const agent_1 = __importDefault(require("../../tunnel/api/agent"));
11
12
  const commandAgentUninstall = (0, utils_1.newCommand)('uninstall', texts_1.DESC_COMMAND_AGENT_UNINSTALL);
12
13
  commandAgentUninstall.action(async () => {
13
14
  const hasAdminRights = await manager_1.default.system.hasAdminRights();
14
15
  if (!hasAdminRights) {
15
16
  output_1.default.exitError(texts_1.ERR_AGENT_ADMIN_RIGHTS);
16
17
  }
18
+ try {
19
+ const api = new agent_1.default(commandAgentUninstall.agentPort || 0);
20
+ await api.markInactive();
21
+ }
22
+ catch {
23
+ // do nothing
24
+ }
17
25
  try {
18
26
  await manager_1.default.system.uninstall();
19
27
  }
@@ -83,6 +83,9 @@ class ApiAgent {
83
83
  id,
84
84
  });
85
85
  }
86
+ async markInactive() {
87
+ return makeRequest(this.port, '/agent/mark-inactive');
88
+ }
86
89
  async disableAgent() {
87
90
  return makeRequest(this.port, '/agent/disable');
88
91
  }
@@ -114,6 +114,12 @@ class ApiBuddyClass {
114
114
  token,
115
115
  });
116
116
  }
117
+ async markAgentAsInactive(agentId, host, token) {
118
+ await makeRequest(host, '/tunnel/agent/target/mark-inactive', {
119
+ agentId,
120
+ token
121
+ });
122
+ }
117
123
  async addTunnel(agentId, host, token, prepared, sshHostKey) {
118
124
  logger_1.default.info(texts_1.LOG_REGISTERING_TUNNEL);
119
125
  const config = await makeRequest(host, '/tunnel/add', {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.16.2-stage",
4
+ "version": "1.16.5-beta",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {