bdy 1.15.6 → 1.16.0-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/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 +106 -27
- package/distTs/src/command/agent/restart.js +21 -11
- package/distTs/src/command/agent/run.js +1 -1
- 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/pre.js +10 -2
- package/distTs/src/output.js +16 -4
- package/distTs/src/texts.js +17 -34
- package/distTs/src/tunnel/api/agent.js +0 -9
- package/distTs/src/types/tunnel.js +0 -3
- package/package.json +1 -1
|
@@ -9,22 +9,26 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
10
|
const texts_1 = require("../texts");
|
|
11
11
|
const logger_1 = __importDefault(require("../logger"));
|
|
12
|
+
const manager_1 = __importDefault(require("./manager"));
|
|
13
|
+
const output_1 = __importDefault(require("../output"));
|
|
12
14
|
class AgentSystem {
|
|
13
|
-
// extend
|
|
14
|
-
isEnabled() {
|
|
15
|
-
return Promise.resolve(false);
|
|
16
|
-
}
|
|
17
15
|
// extend
|
|
18
16
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
-
|
|
17
|
+
async install(id, host, token, port, start, user, pass, debug) {
|
|
20
18
|
return Promise.reject();
|
|
21
19
|
}
|
|
22
20
|
// extend
|
|
23
|
-
update() {
|
|
21
|
+
async update() {
|
|
24
22
|
return Promise.reject();
|
|
25
23
|
}
|
|
26
24
|
// extend
|
|
27
|
-
|
|
25
|
+
async uninstall() {
|
|
26
|
+
return Promise.reject();
|
|
27
|
+
}
|
|
28
|
+
async stop() {
|
|
29
|
+
return Promise.reject();
|
|
30
|
+
}
|
|
31
|
+
async start() {
|
|
28
32
|
return Promise.reject();
|
|
29
33
|
}
|
|
30
34
|
// extend
|
|
@@ -182,29 +186,83 @@ class AgentSystem {
|
|
|
182
186
|
return this.downloadFile(`https://es.buddy.works/bdy/${env}/${version}/${archive}`, archivePath);
|
|
183
187
|
}
|
|
184
188
|
killStandaloneProc() {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
189
|
+
return new Promise((resolve) => {
|
|
190
|
+
let pid = 0;
|
|
191
|
+
try {
|
|
192
|
+
const str = this.loadStandaloneProcConfig();
|
|
193
|
+
pid = Number.parseInt(str, 10);
|
|
194
|
+
if (pid) {
|
|
195
|
+
process.kill(pid);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
// do nothing
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
this.clearStandaloneProcConfig();
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// do nothing
|
|
190
206
|
}
|
|
207
|
+
let tsInterval = null;
|
|
208
|
+
let tsTimeout = null;
|
|
209
|
+
const finish = () => {
|
|
210
|
+
if (tsInterval)
|
|
211
|
+
clearInterval(tsInterval);
|
|
212
|
+
if (tsTimeout)
|
|
213
|
+
clearTimeout(tsTimeout);
|
|
214
|
+
resolve();
|
|
215
|
+
};
|
|
216
|
+
if (!pid) {
|
|
217
|
+
finish();
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
tsTimeout = setTimeout(finish, 30000);
|
|
221
|
+
tsInterval = setInterval(() => {
|
|
222
|
+
try {
|
|
223
|
+
process.kill(pid, 0);
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
finish();
|
|
227
|
+
}
|
|
228
|
+
}, 100);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
startStandaloneProc() {
|
|
232
|
+
let json;
|
|
233
|
+
try {
|
|
234
|
+
json = this.loadSystemConfig();
|
|
191
235
|
}
|
|
192
236
|
catch {
|
|
193
|
-
|
|
237
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
194
238
|
}
|
|
195
|
-
|
|
196
|
-
|
|
239
|
+
if (json.debug) {
|
|
240
|
+
logger_1.default.setDebug(true);
|
|
197
241
|
}
|
|
198
|
-
|
|
199
|
-
|
|
242
|
+
const saved = this.saveStandaloneProcConfig();
|
|
243
|
+
if (!saved) {
|
|
244
|
+
output_1.default.exitError(texts_1.ERR_SWW_AGENT_ENABLING);
|
|
200
245
|
}
|
|
246
|
+
logger_1.default.changeRootPath(this.getNewAgentConfigDir());
|
|
247
|
+
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_STARTED);
|
|
248
|
+
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_STARTED);
|
|
249
|
+
const onProcessExit = () => {
|
|
250
|
+
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_EXITING);
|
|
251
|
+
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_EXITING);
|
|
252
|
+
this.clearStandaloneProcConfig();
|
|
253
|
+
process.exit(0);
|
|
254
|
+
};
|
|
255
|
+
process.on('SIGINT', onProcessExit);
|
|
256
|
+
process.on('SIGTERM', onProcessExit);
|
|
257
|
+
process.on('SIGQUIT', onProcessExit);
|
|
258
|
+
manager_1.default.start(json.id, json.host, json.token, json.port);
|
|
201
259
|
}
|
|
202
260
|
clearStandaloneProcConfig() {
|
|
203
261
|
try {
|
|
204
262
|
logger_1.default.info(texts_1.LOG_REMOVING_AGENT_PROC_ID);
|
|
205
263
|
this.ensureSystemConfigDir();
|
|
206
264
|
(0, fs_1.rmSync)(this.getSystemStandalonePath(), {
|
|
207
|
-
force: true
|
|
265
|
+
force: true,
|
|
208
266
|
});
|
|
209
267
|
return true;
|
|
210
268
|
}
|
|
@@ -227,7 +285,16 @@ class AgentSystem {
|
|
|
227
285
|
return false;
|
|
228
286
|
}
|
|
229
287
|
}
|
|
230
|
-
|
|
288
|
+
hasSystemConfig() {
|
|
289
|
+
try {
|
|
290
|
+
this.loadSystemConfig();
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
saveSystemConfig(id, host, token, port, standalone, debug) {
|
|
231
298
|
try {
|
|
232
299
|
logger_1.default.info(texts_1.LOG_SAVING_AGENT_SYSTEM_CONFIG);
|
|
233
300
|
this.ensureSystemConfigDir();
|
|
@@ -236,6 +303,8 @@ class AgentSystem {
|
|
|
236
303
|
host,
|
|
237
304
|
token,
|
|
238
305
|
port,
|
|
306
|
+
standalone,
|
|
307
|
+
debug
|
|
239
308
|
}), 'utf-8');
|
|
240
309
|
return true;
|
|
241
310
|
}
|
|
@@ -245,7 +314,7 @@ class AgentSystem {
|
|
|
245
314
|
return false;
|
|
246
315
|
}
|
|
247
316
|
}
|
|
248
|
-
saveNewAgentConfig(
|
|
317
|
+
saveNewAgentConfig(sshHostKey) {
|
|
249
318
|
try {
|
|
250
319
|
this.clearAgentFiles();
|
|
251
320
|
}
|
|
@@ -255,7 +324,6 @@ class AgentSystem {
|
|
|
255
324
|
try {
|
|
256
325
|
logger_1.default.info(texts_1.LOG_SAVING_AGENT_LOCAL_CONFIG);
|
|
257
326
|
(0, fs_1.writeFileSync)(this.getNewAgentConfigPath(), JSON.stringify({
|
|
258
|
-
shouldStart,
|
|
259
327
|
sshHostKey,
|
|
260
328
|
}), 'utf-8');
|
|
261
329
|
return true;
|
|
@@ -20,21 +20,6 @@ class AgentWindows extends system_1.default {
|
|
|
20
20
|
isSupported() {
|
|
21
21
|
return Promise.resolve(process.arch === 'x64');
|
|
22
22
|
}
|
|
23
|
-
isEnabled() {
|
|
24
|
-
return new Promise((resolve) => {
|
|
25
|
-
if (this.isStandaloneProcRunning()) {
|
|
26
|
-
resolve(true);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
this.sc('query bdy')
|
|
30
|
-
.then(() => {
|
|
31
|
-
resolve(true);
|
|
32
|
-
})
|
|
33
|
-
.catch(() => {
|
|
34
|
-
resolve(false);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
23
|
getBinaryArchive() {
|
|
39
24
|
return 'win-x64.zip';
|
|
40
25
|
}
|
|
@@ -79,7 +64,7 @@ class AgentWindows extends system_1.default {
|
|
|
79
64
|
async update() {
|
|
80
65
|
try {
|
|
81
66
|
logger_1.default.info(texts_1.LOG_AGENT_STOPPING_SYSTEM);
|
|
82
|
-
await this.
|
|
67
|
+
await this.stop();
|
|
83
68
|
logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
|
|
84
69
|
await this.ensureSystemConfigDir();
|
|
85
70
|
logger_1.default.info(texts_1.LOG_AGENT_DOWNLOADING_ARCHIVE);
|
|
@@ -88,7 +73,7 @@ class AgentWindows extends system_1.default {
|
|
|
88
73
|
await this.extractBinaryArchive();
|
|
89
74
|
try {
|
|
90
75
|
logger_1.default.info(texts_1.LOG_AGENT_STARTING_SYSTEM);
|
|
91
|
-
await this.
|
|
76
|
+
await this.start();
|
|
92
77
|
}
|
|
93
78
|
catch {
|
|
94
79
|
// do nothing, it will throw operation pending
|
|
@@ -99,7 +84,14 @@ class AgentWindows extends system_1.default {
|
|
|
99
84
|
throw err;
|
|
100
85
|
}
|
|
101
86
|
}
|
|
102
|
-
async
|
|
87
|
+
async install(id, host, token, port, start, user, pass, debug) {
|
|
88
|
+
try {
|
|
89
|
+
// ensure srv was clear
|
|
90
|
+
await this.uninstall();
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// do nothing
|
|
94
|
+
}
|
|
103
95
|
try {
|
|
104
96
|
logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
|
|
105
97
|
await this.ensureSystemConfigDir();
|
|
@@ -115,7 +107,7 @@ class AgentWindows extends system_1.default {
|
|
|
115
107
|
await this.extractBinaryArchive();
|
|
116
108
|
logger_1.default.info(texts_1.LOG_AGENT_ENABLING_SYSTEM);
|
|
117
109
|
await this.nssm(`install bdy ${this.getSystemBinaryPath()}`);
|
|
118
|
-
await this.nssm(`set bdy AppParameters agent run --id="${id}" --host="${host}" --token="${token}" --port=${port}
|
|
110
|
+
await this.nssm(`set bdy AppParameters agent run --id="${id}" --host="${host}" --token="${token}" --port=${port}`);
|
|
119
111
|
await this.nssm('set bdy DisplayName Buddy Tunnel Agent');
|
|
120
112
|
await this.nssm('set bdy AppThrottle 5000');
|
|
121
113
|
await this.nssm('set bdy AppRestartDelay 0');
|
|
@@ -125,7 +117,8 @@ class AgentWindows extends system_1.default {
|
|
|
125
117
|
if (user && pass) {
|
|
126
118
|
await this.nssm(`set bdy ObjectName ${user} ${pass}`);
|
|
127
119
|
}
|
|
128
|
-
|
|
120
|
+
if (start)
|
|
121
|
+
await this.start();
|
|
129
122
|
logger_1.default.info(texts_1.LOG_AGENT_ENABLED);
|
|
130
123
|
}
|
|
131
124
|
catch (err) {
|
|
@@ -133,9 +126,15 @@ class AgentWindows extends system_1.default {
|
|
|
133
126
|
throw err;
|
|
134
127
|
}
|
|
135
128
|
}
|
|
136
|
-
async
|
|
129
|
+
async stop() {
|
|
130
|
+
await this.nssm('stop bdy');
|
|
131
|
+
}
|
|
132
|
+
async start() {
|
|
133
|
+
await this.nssm('start bdy');
|
|
134
|
+
}
|
|
135
|
+
async uninstall() {
|
|
137
136
|
try {
|
|
138
|
-
await this.
|
|
137
|
+
await this.stop();
|
|
139
138
|
}
|
|
140
139
|
catch {
|
|
141
140
|
// do nothing
|
|
@@ -152,15 +151,5 @@ class AgentWindows extends system_1.default {
|
|
|
152
151
|
});
|
|
153
152
|
});
|
|
154
153
|
}
|
|
155
|
-
sc(cmd) {
|
|
156
|
-
return new Promise((resolve, reject) => {
|
|
157
|
-
(0, child_process_1.exec)(`sc ${cmd}`, (err) => {
|
|
158
|
-
if (!err)
|
|
159
|
-
resolve();
|
|
160
|
-
else
|
|
161
|
-
reject(err);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
154
|
}
|
|
166
155
|
exports.default = AgentWindows;
|
|
@@ -11,15 +11,22 @@ const agent_1 = __importDefault(require("../../tunnel/api/agent"));
|
|
|
11
11
|
const commandAgentDebug = (0, utils_1.newCommand)('debug', texts_1.DESC_COMMAND_AGENT_DEBUG);
|
|
12
12
|
commandAgentDebug.argument('<on/off>');
|
|
13
13
|
commandAgentDebug.action(async (debug) => {
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
output_1.default.exitError(texts_1.
|
|
14
|
+
const hasAdminRights = await manager_1.default.system.hasAdminRights();
|
|
15
|
+
if (!hasAdminRights) {
|
|
16
|
+
output_1.default.exitError(texts_1.ERR_AGENT_ADMIN_RIGHTS);
|
|
17
|
+
}
|
|
18
|
+
if (!commandAgentDebug.agentInstalled) {
|
|
19
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
20
|
+
}
|
|
21
|
+
if (!commandAgentDebug.agentStatus) {
|
|
22
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
17
23
|
}
|
|
18
24
|
try {
|
|
19
25
|
const debugOn = debug === 'on';
|
|
20
26
|
const json = manager_1.default.system.loadSystemConfig();
|
|
21
27
|
const api = new agent_1.default(json.port);
|
|
22
28
|
await api.debugChange(debugOn);
|
|
29
|
+
manager_1.default.system.saveSystemConfig(json.id, json.host, json.token, json.port, !!json.standalone, debugOn);
|
|
23
30
|
output_1.default.exitSuccess(debugOn ? texts_1.TXT_AGENT_DEBUG_ON : texts_1.TXT_AGENT_DEBUG_OFF);
|
|
24
31
|
}
|
|
25
32
|
catch (err) {
|
|
@@ -5,18 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const texts_1 = require("../../texts");
|
|
8
|
-
const manager_1 = __importDefault(require("../../agent/manager"));
|
|
9
8
|
const output_1 = __importDefault(require("../../output"));
|
|
10
9
|
const agent_1 = __importDefault(require("../../tunnel/api/agent"));
|
|
11
10
|
const commandAgentDisable = (0, utils_1.newCommand)('disable', texts_1.DESC_COMMAND_AGENT_DISABLE);
|
|
12
11
|
commandAgentDisable.action(async () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
if (!commandAgentDisable.agentInstalled) {
|
|
13
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
14
|
+
}
|
|
15
|
+
if (!commandAgentDisable.agentStatus) {
|
|
16
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
16
17
|
}
|
|
17
18
|
try {
|
|
18
|
-
const
|
|
19
|
-
const api = new agent_1.default(json.port);
|
|
19
|
+
const api = new agent_1.default(commandAgentDisable.agentPort || 0);
|
|
20
20
|
await api.disableAgent();
|
|
21
21
|
output_1.default.exitSuccess(texts_1.TXT_AGENT_STOPPED);
|
|
22
22
|
}
|
|
@@ -5,18 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const texts_1 = require("../../texts");
|
|
8
|
-
const manager_1 = __importDefault(require("../../agent/manager"));
|
|
9
8
|
const output_1 = __importDefault(require("../../output"));
|
|
10
9
|
const agent_1 = __importDefault(require("../../tunnel/api/agent"));
|
|
11
10
|
const commandAgentEnable = (0, utils_1.newCommand)('enable', texts_1.DESC_COMMAND_AGENT_ENABLE);
|
|
12
11
|
commandAgentEnable.action(async () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
if (!commandAgentEnable.agentInstalled) {
|
|
13
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
14
|
+
}
|
|
15
|
+
if (!commandAgentEnable.agentStatus) {
|
|
16
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
16
17
|
}
|
|
17
18
|
try {
|
|
18
|
-
const
|
|
19
|
-
const api = new agent_1.default(json.port);
|
|
19
|
+
const api = new agent_1.default(commandAgentEnable.agentPort || 0);
|
|
20
20
|
await api.enableAgent();
|
|
21
21
|
output_1.default.exitSuccess(texts_1.TXT_AGENT_STARTED);
|
|
22
22
|
}
|
|
@@ -12,9 +12,10 @@ const buddy_1 = __importDefault(require("../../tunnel/api/buddy"));
|
|
|
12
12
|
const agent_1 = __importDefault(require("../../tunnel/api/agent"));
|
|
13
13
|
const wait_1 = __importDefault(require("../../agent/wait"));
|
|
14
14
|
const utils_1 = require("../../utils");
|
|
15
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
15
16
|
const removeAllAndExit = async (txt, id, host, token) => {
|
|
16
17
|
try {
|
|
17
|
-
await manager_1.default.system.
|
|
18
|
+
await manager_1.default.system.uninstall();
|
|
18
19
|
}
|
|
19
20
|
catch {
|
|
20
21
|
// do nothing
|
|
@@ -45,28 +46,11 @@ const removeAllAndExit = async (txt, id, host, token) => {
|
|
|
45
46
|
}
|
|
46
47
|
output_1.default.exitError(txt);
|
|
47
48
|
};
|
|
48
|
-
const
|
|
49
|
-
commandAgentInstall.option('-s, --start', texts_1.OPTION_AGENT_START);
|
|
50
|
-
commandAgentInstall.option('-i, --id <id>', texts_1.OPTION_AGENT_ID);
|
|
51
|
-
commandAgentInstall.option('-t, --token <token>', texts_1.OPTION_AGENT_TOKEN);
|
|
52
|
-
commandAgentInstall.option('-p, --port <port>', texts_1.OPTION_AGENT_PORT, '7456');
|
|
53
|
-
commandAgentInstall.option('-u, --user <user>', texts_1.OPTION_USER);
|
|
54
|
-
commandAgentInstall.option('--pass <password>', texts_1.OPTION_PASS);
|
|
55
|
-
commandAgentInstall.option('--target', texts_1.OPTION_AGENT_TARGET);
|
|
56
|
-
commandAgentInstall.option('-d, --debug', texts_1.OPTION_AGENT_DEBUG);
|
|
57
|
-
commandAgentInstall.action(async (options) => {
|
|
58
|
-
const hasAdminRights = await manager_1.default.system.hasAdminRights();
|
|
59
|
-
if (!hasAdminRights) {
|
|
60
|
-
output_1.default.exitError(texts_1.ERR_AGENT_ADMIN_RIGHTS);
|
|
61
|
-
}
|
|
49
|
+
const installService = async (options) => {
|
|
62
50
|
const isSupported = await manager_1.default.system.isSupported();
|
|
63
51
|
if (!isSupported) {
|
|
64
52
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_SUPPORTED);
|
|
65
53
|
}
|
|
66
|
-
const isEnabled = await manager_1.default.system.isEnabled();
|
|
67
|
-
if (isEnabled) {
|
|
68
|
-
output_1.default.exitSuccess(texts_1.TXT_AGENT_ALREADY_ENABLED);
|
|
69
|
-
}
|
|
70
54
|
let id = '';
|
|
71
55
|
let token = '';
|
|
72
56
|
let agent;
|
|
@@ -97,7 +81,7 @@ commandAgentInstall.action(async (options) => {
|
|
|
97
81
|
agent.destroy();
|
|
98
82
|
agent = null;
|
|
99
83
|
}
|
|
100
|
-
const saved = manager_1.default.system.saveSystemConfig(id, host, token, port);
|
|
84
|
+
const saved = manager_1.default.system.saveSystemConfig(id, host, token, port, false, !!options.debug);
|
|
101
85
|
if (!saved) {
|
|
102
86
|
await removeAllAndExit(texts_1.ERR_SWW_AGENT_ENABLING, id, host, token);
|
|
103
87
|
}
|
|
@@ -115,16 +99,111 @@ commandAgentInstall.action(async (options) => {
|
|
|
115
99
|
}
|
|
116
100
|
await output_1.default.spinner(texts_1.TXT_ENABLING_AGENT);
|
|
117
101
|
try {
|
|
118
|
-
await manager_1.default.system.
|
|
102
|
+
await manager_1.default.system.install(id, host, token, port, !!options.start, options.user, options.pass, !!options.debug);
|
|
119
103
|
}
|
|
120
104
|
catch {
|
|
121
105
|
await removeAllAndExit(texts_1.ERR_SWW_AGENT_ENABLING, id, host, token);
|
|
122
106
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
107
|
+
if (options.start) {
|
|
108
|
+
const api = new agent_1.default(port);
|
|
109
|
+
await (0, wait_1.default)(api, 15000, () => {
|
|
110
|
+
removeAllAndExit(texts_1.ERR_SWW_AGENT_ENABLING, id, host, token);
|
|
111
|
+
}, () => {
|
|
112
|
+
output_1.default.exitSuccess(texts_1.TXT_AGENT_INSTALLED);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const installApp = async (options) => {
|
|
117
|
+
if (options.debug) {
|
|
118
|
+
logger_1.default.setDebug(true);
|
|
119
|
+
}
|
|
120
|
+
let id;
|
|
121
|
+
let host;
|
|
122
|
+
let token;
|
|
123
|
+
const port = input_1.default.port(options.port);
|
|
124
|
+
if (options.id) {
|
|
125
|
+
id = options.id;
|
|
126
|
+
}
|
|
127
|
+
if (!token) {
|
|
128
|
+
token = options.token;
|
|
129
|
+
}
|
|
130
|
+
if (!id) {
|
|
131
|
+
if (token)
|
|
132
|
+
cfg_1.default.setToken(token);
|
|
133
|
+
host = cfg_1.default.getTokenHost();
|
|
134
|
+
try {
|
|
135
|
+
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_AGENT_REGISTERING, false);
|
|
136
|
+
const agent = await buddy_1.default.register(true, !!options.target, host, cfg_1.default.getToken(), (region) => {
|
|
137
|
+
cfg_1.default.setRegionIfNotSet(region);
|
|
138
|
+
});
|
|
139
|
+
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_AGENT_REGISTERED);
|
|
140
|
+
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_AGENT_REGISTERED);
|
|
141
|
+
id = agent.id;
|
|
142
|
+
token = agent.token;
|
|
143
|
+
agent.destroy();
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_AGENT_REGISTER_ERROR);
|
|
147
|
+
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_AGENT_REGISTER_ERROR);
|
|
148
|
+
logger_1.default.error(err);
|
|
149
|
+
output_1.default.exitError(err);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
if (!host) {
|
|
154
|
+
host = cfg_1.default.getTokenHost();
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_AGENT_FETCHING);
|
|
158
|
+
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_AGENT_FETCHING, false);
|
|
159
|
+
const agent = await buddy_1.default.fetchAgent(id, host, token);
|
|
160
|
+
agent.destroy();
|
|
161
|
+
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_AGENT_FETCHED);
|
|
162
|
+
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_AGENT_FETCHED);
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_AGENT_FETCH_ERROR);
|
|
166
|
+
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_AGENT_FETCH_ERROR);
|
|
167
|
+
logger_1.default.error(err);
|
|
168
|
+
output_1.default.exitError(err);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const saved = manager_1.default.system.saveSystemConfig(id, host, token, port, true, !!options.debug);
|
|
172
|
+
if (!saved) {
|
|
173
|
+
output_1.default.exitError(texts_1.ERR_SWW_AGENT_ENABLING);
|
|
174
|
+
}
|
|
175
|
+
if (options.start) {
|
|
176
|
+
manager_1.default.system.startStandaloneProc();
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
output_1.default.exitSuccess(texts_1.TXT_AGENT_INSTALLED);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const commandAgentInstall = (0, utils_1.newCommand)('install', texts_1.DESC_COMMAND_AGENT_INSTALL);
|
|
183
|
+
commandAgentInstall.option('-s, --start [true|false]', texts_1.OPTION_AGENT_START, 'true');
|
|
184
|
+
commandAgentInstall.option('-i, --id <id>', texts_1.OPTION_AGENT_ID);
|
|
185
|
+
commandAgentInstall.option('-t, --token <token>', texts_1.OPTION_AGENT_TOKEN);
|
|
186
|
+
commandAgentInstall.option('-p, --port <port>', texts_1.OPTION_AGENT_PORT, '7456');
|
|
187
|
+
commandAgentInstall.option('-u, --user <user>', texts_1.OPTION_USER);
|
|
188
|
+
commandAgentInstall.option('-a,--app', texts_1.OPTION_APP);
|
|
189
|
+
commandAgentInstall.option('--pass <password>', texts_1.OPTION_PASS);
|
|
190
|
+
commandAgentInstall.option('--target', texts_1.OPTION_AGENT_TARGET);
|
|
191
|
+
commandAgentInstall.option('-d, --debug', texts_1.OPTION_AGENT_DEBUG);
|
|
192
|
+
commandAgentInstall.action(async (options) => {
|
|
193
|
+
options.start = options.start === 'true';
|
|
194
|
+
const hasAdminRights = await manager_1.default.system.hasAdminRights();
|
|
195
|
+
if (!hasAdminRights) {
|
|
196
|
+
output_1.default.exitError(texts_1.ERR_AGENT_ADMIN_RIGHTS);
|
|
197
|
+
}
|
|
198
|
+
const hasSystemConfig = manager_1.default.system.hasSystemConfig();
|
|
199
|
+
if (hasSystemConfig) {
|
|
200
|
+
output_1.default.exitError(texts_1.TXT_AGENT_ALREADY_INSTALLED);
|
|
201
|
+
}
|
|
202
|
+
if (options.app) {
|
|
203
|
+
await installApp(options);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
await installService(options);
|
|
207
|
+
}
|
|
129
208
|
});
|
|
130
209
|
exports.default = commandAgentInstall;
|
|
@@ -5,23 +5,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const output_1 = __importDefault(require("../../output"));
|
|
7
7
|
const texts_1 = require("../../texts");
|
|
8
|
-
const agent_1 = __importDefault(require("../../tunnel/api/agent"));
|
|
9
8
|
const manager_1 = __importDefault(require("../../agent/manager"));
|
|
10
9
|
const utils_1 = require("../../utils");
|
|
10
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
11
11
|
const commandAgentRestart = (0, utils_1.newCommand)('restart', texts_1.DESC_COMMAND_AGENT_RESTART);
|
|
12
12
|
commandAgentRestart.action(async () => {
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
15
|
-
output_1.default.exitError(texts_1.
|
|
13
|
+
const hasAdminRights = await manager_1.default.system.hasAdminRights();
|
|
14
|
+
if (!hasAdminRights) {
|
|
15
|
+
output_1.default.exitError(texts_1.ERR_AGENT_ADMIN_RIGHTS);
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const api = new agent_1.default(json.port);
|
|
20
|
-
await api.restartAgent();
|
|
21
|
-
output_1.default.exitSuccess(texts_1.TXT_AGENT_RESTARTED);
|
|
17
|
+
if (!commandAgentRestart.agentInstalled) {
|
|
18
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
22
19
|
}
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
if (commandAgentRestart.agentStandalone) {
|
|
21
|
+
await manager_1.default.system.killStandaloneProc();
|
|
22
|
+
manager_1.default.system.startStandaloneProc();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
try {
|
|
26
|
+
await manager_1.default.system.stop();
|
|
27
|
+
output_1.default.normal(texts_1.TXT_AGENT_STOPPED);
|
|
28
|
+
await manager_1.default.system.start();
|
|
29
|
+
output_1.default.exitSuccess(texts_1.TXT_AGENT_RESTARTED);
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
logger_1.default.error(err);
|
|
33
|
+
output_1.default.exitError(err);
|
|
34
|
+
}
|
|
25
35
|
}
|
|
26
36
|
});
|
|
27
37
|
exports.default = commandAgentRestart;
|
|
@@ -14,6 +14,6 @@ commandAgentRun.option('--port <port>');
|
|
|
14
14
|
commandAgentRun.option('--start <start>');
|
|
15
15
|
commandAgentRun.action(async (options) => {
|
|
16
16
|
logger_1.default.changeRootPath(manager_1.default.system.getNewAgentConfigDir());
|
|
17
|
-
manager_1.default.start(options.id, options.host, options.token, parseInt(options.port, 10)
|
|
17
|
+
manager_1.default.start(options.id, options.host, options.token, parseInt(options.port, 10));
|
|
18
18
|
});
|
|
19
19
|
exports.default = commandAgentRun;
|
|
@@ -5,24 +5,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const output_1 = __importDefault(require("../../output"));
|
|
7
7
|
const texts_1 = require("../../texts");
|
|
8
|
-
const agent_1 = __importDefault(require("../../tunnel/api/agent"));
|
|
9
|
-
const texts_2 = require("../../texts");
|
|
10
8
|
const manager_1 = __importDefault(require("../../agent/manager"));
|
|
11
9
|
const utils_1 = require("../../utils");
|
|
10
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
12
11
|
const commandAgentStart = (0, utils_1.newCommand)('start', texts_1.DESC_COMMAND_AGENT_START);
|
|
13
12
|
commandAgentStart.action(async () => {
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
output_1.default.exitError(
|
|
13
|
+
const hasAdminRights = await manager_1.default.system.hasAdminRights();
|
|
14
|
+
if (!hasAdminRights) {
|
|
15
|
+
output_1.default.exitError(texts_1.ERR_AGENT_ADMIN_RIGHTS);
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const api = new agent_1.default(json.port);
|
|
21
|
-
await api.startAgent();
|
|
22
|
-
output_1.default.exitSuccess(texts_1.TXT_AGENT_STARTED);
|
|
17
|
+
if (!commandAgentStart.agentInstalled) {
|
|
18
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
23
19
|
}
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
if (commandAgentStart.agentStandalone) {
|
|
21
|
+
await manager_1.default.system.killStandaloneProc();
|
|
22
|
+
manager_1.default.system.startStandaloneProc();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
try {
|
|
26
|
+
await manager_1.default.system.start();
|
|
27
|
+
output_1.default.exitSuccess(texts_1.TXT_AGENT_STARTED);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
logger_1.default.error(err);
|
|
31
|
+
output_1.default.exitError(err);
|
|
32
|
+
}
|
|
26
33
|
}
|
|
27
34
|
});
|
|
28
35
|
exports.default = commandAgentStart;
|