bdy 1.7.59-dev → 1.8.3-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/package.json +42 -11
- package/.eslintrc.yml +0 -23
- package/bin/cli.js +0 -5
- package/dockerfile +0 -15
- package/link.sh +0 -3
- package/src/agent/linux.js +0 -127
- package/src/agent/manager.js +0 -404
- package/src/agent/osx.js +0 -150
- package/src/agent/socket/tunnel.js +0 -232
- package/src/agent/socket.js +0 -260
- package/src/agent/system.js +0 -205
- package/src/agent/wait.js +0 -20
- package/src/agent/windows.js +0 -168
- package/src/agent.js +0 -256
- package/src/api/agent.js +0 -95
- package/src/api/buddy.js +0 -131
- package/src/api/socket.js +0 -148
- package/src/cfg.js +0 -239
- package/src/command/agent/install.js +0 -116
- package/src/command/agent/restart.js +0 -27
- package/src/command/agent/run.js +0 -16
- package/src/command/agent/start.js +0 -27
- package/src/command/agent/status.js +0 -44
- package/src/command/agent/stop.js +0 -27
- package/src/command/agent/tunnel/http.js +0 -45
- package/src/command/agent/tunnel/list.js +0 -26
- package/src/command/agent/tunnel/remove.js +0 -29
- package/src/command/agent/tunnel/start.js +0 -37
- package/src/command/agent/tunnel/status.js +0 -31
- package/src/command/agent/tunnel/tcp.js +0 -45
- package/src/command/agent/tunnel/tls.js +0 -45
- package/src/command/agent/tunnel.js +0 -20
- package/src/command/agent/uninstall.js +0 -36
- package/src/command/agent/update.js +0 -42
- package/src/command/agent/version.js +0 -22
- package/src/command/agent.js +0 -26
- package/src/command/config/add/http.js +0 -31
- package/src/command/config/add/tcp.js +0 -31
- package/src/command/config/add/tls.js +0 -31
- package/src/command/config/add.js +0 -12
- package/src/command/config/get/region.js +0 -12
- package/src/command/config/get/timeout.js +0 -12
- package/src/command/config/get/token.js +0 -12
- package/src/command/config/get/tunnel.js +0 -20
- package/src/command/config/get/tunnels.js +0 -12
- package/src/command/config/get/whitelist.js +0 -12
- package/src/command/config/get.js +0 -18
- package/src/command/config/remove/tunnel.js +0 -21
- package/src/command/config/remove.js +0 -8
- package/src/command/config/set/region.js +0 -18
- package/src/command/config/set/timeout.js +0 -21
- package/src/command/config/set/token.js +0 -18
- package/src/command/config/set/whitelist.js +0 -18
- package/src/command/config/set.js +0 -14
- package/src/command/config.js +0 -14
- package/src/command/http.js +0 -33
- package/src/command/pre.js +0 -45
- package/src/command/start.js +0 -30
- package/src/command/tcp.js +0 -31
- package/src/command/tls.js +0 -31
- package/src/command/version.js +0 -10
- package/src/format.js +0 -171
- package/src/index.js +0 -38
- package/src/input.js +0 -283
- package/src/logger.js +0 -92
- package/src/output/interactive/tunnel.js +0 -871
- package/src/output/noninteractive/agent/tunnels.js +0 -32
- package/src/output/noninteractive/config/tunnel.js +0 -51
- package/src/output/noninteractive/config/tunnels.js +0 -19
- package/src/output/noninteractive/tunnel.js +0 -79
- package/src/output.js +0 -131
- package/src/server/cert.js +0 -51
- package/src/server/http1.js +0 -79
- package/src/server/http2.js +0 -79
- package/src/server/sftp.js +0 -474
- package/src/server/ssh.js +0 -107
- package/src/server/tls.js +0 -41
- package/src/ssh/client.js +0 -196
- package/src/texts.js +0 -445
- package/src/tunnel/agent.js +0 -100
- package/src/tunnel/compression.js +0 -32
- package/src/tunnel/dns.js +0 -55
- package/src/tunnel/html/404.html +0 -129
- package/src/tunnel/html/503.html +0 -136
- package/src/tunnel/html.js +0 -32
- package/src/tunnel/http/log.js +0 -204
- package/src/tunnel/http/serve.js +0 -127
- package/src/tunnel/http/stream.js +0 -46
- package/src/tunnel/http.js +0 -406
- package/src/tunnel/identification.js +0 -95
- package/src/tunnel/latency.js +0 -63
- package/src/tunnel/tcp.js +0 -71
- package/src/tunnel.js +0 -696
- package/src/utils.js +0 -577
- package/unlink.sh +0 -3
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
const Output = require('../../output.js');
|
|
2
|
-
const Input = require('../../input.js');
|
|
3
|
-
const {
|
|
4
|
-
DESC_COMMAND_AGENT_INSTALL,
|
|
5
|
-
ERR_SWW_AGENT_ENABLING,
|
|
6
|
-
OPTION_AGENT_ID,
|
|
7
|
-
OPTION_AGENT_PORT,
|
|
8
|
-
OPTION_AGENT_START,
|
|
9
|
-
OPTION_AGENT_TOKEN,
|
|
10
|
-
TXT_AGENT_ALREADY_ENABLED
|
|
11
|
-
} = require('../../texts.js');
|
|
12
|
-
const Cfg = require('../../cfg.js');
|
|
13
|
-
const AgentManager = require('../../agent/manager.js');
|
|
14
|
-
const ApiBuddy = require('../../api/buddy.js');
|
|
15
|
-
const ApiAgent = require('../../api/agent');
|
|
16
|
-
const waitUntilAgentEnabled = require('../../agent/wait.js');
|
|
17
|
-
const {
|
|
18
|
-
ERR_AGENT_NOT_FOUND,
|
|
19
|
-
ERR_AGENT_ADMIN_RIGHTS,
|
|
20
|
-
TXT_ENABLING_AGENT,
|
|
21
|
-
ERR_AGENT_NOT_SUPPORTED,
|
|
22
|
-
OPTION_USER,
|
|
23
|
-
OPTION_PASS,
|
|
24
|
-
TXT_AGENT_ENABLED,
|
|
25
|
-
OPTION_AGENT_DEBUG
|
|
26
|
-
} = require('../../texts');
|
|
27
|
-
const { newCommand } = require('../../utils');
|
|
28
|
-
|
|
29
|
-
const removeAllAndExit = async (txt, id, host, token) => {
|
|
30
|
-
try {
|
|
31
|
-
await AgentManager.system.disable();
|
|
32
|
-
} catch {
|
|
33
|
-
// do nothing
|
|
34
|
-
}
|
|
35
|
-
try {
|
|
36
|
-
await ApiBuddy.unregister(id, host, token);
|
|
37
|
-
} catch {
|
|
38
|
-
// do nothing
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
AgentManager.system.clearSystemFiles();
|
|
42
|
-
} catch {
|
|
43
|
-
// do nothing
|
|
44
|
-
}
|
|
45
|
-
Output.exitError(txt);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const commandAgentInstall = newCommand('install', DESC_COMMAND_AGENT_INSTALL);
|
|
49
|
-
commandAgentInstall.option('-s, --start', OPTION_AGENT_START);
|
|
50
|
-
commandAgentInstall.option('-i, --id <id>', OPTION_AGENT_ID);
|
|
51
|
-
commandAgentInstall.option('-t, --token <token>', OPTION_AGENT_TOKEN);
|
|
52
|
-
commandAgentInstall.option('-p, --port <port>', OPTION_AGENT_PORT, '7456');
|
|
53
|
-
commandAgentInstall.option('-u, --user <user>', OPTION_USER);
|
|
54
|
-
commandAgentInstall.option('--pass <password>', OPTION_PASS);
|
|
55
|
-
commandAgentInstall.option('-d, --debug', OPTION_AGENT_DEBUG);
|
|
56
|
-
commandAgentInstall.action(async (options) => {
|
|
57
|
-
const hasAdminRights = await AgentManager.system.hasAdminRights();
|
|
58
|
-
if (!hasAdminRights) {
|
|
59
|
-
Output.exitError(ERR_AGENT_ADMIN_RIGHTS);
|
|
60
|
-
}
|
|
61
|
-
const isSupported = await AgentManager.system.isSupported();
|
|
62
|
-
if (!isSupported) {
|
|
63
|
-
Output.exitError(ERR_AGENT_NOT_SUPPORTED);
|
|
64
|
-
}
|
|
65
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
66
|
-
if (isEnabled) {
|
|
67
|
-
Output.exitSuccess(TXT_AGENT_ALREADY_ENABLED);
|
|
68
|
-
}
|
|
69
|
-
let id;
|
|
70
|
-
let token;
|
|
71
|
-
let agent;
|
|
72
|
-
let port = Input.port(options.port);
|
|
73
|
-
if (options.id && options.token) {
|
|
74
|
-
// if id & token passed set as it is
|
|
75
|
-
id = options.id;
|
|
76
|
-
token = options.token;
|
|
77
|
-
try {
|
|
78
|
-
agent = await ApiBuddy.fetchAgent(id, Cfg.getTokenHost(), token);
|
|
79
|
-
} catch {
|
|
80
|
-
Output.exitError(ERR_AGENT_NOT_FOUND);
|
|
81
|
-
}
|
|
82
|
-
} else if (options.token) {
|
|
83
|
-
// set global token if passed
|
|
84
|
-
Cfg.setToken(options.token);
|
|
85
|
-
}
|
|
86
|
-
let host = Cfg.getTokenHost();
|
|
87
|
-
if (!agent) {
|
|
88
|
-
agent = await ApiBuddy.register(true, host, Cfg.getToken(), (region) => {
|
|
89
|
-
Cfg.setRegionIfNotSet(region);
|
|
90
|
-
});
|
|
91
|
-
id = agent.id;
|
|
92
|
-
token = agent.token;
|
|
93
|
-
}
|
|
94
|
-
const saved = AgentManager.system.saveSystemConfig(id, host, token, port);
|
|
95
|
-
if (!saved) {
|
|
96
|
-
await removeAllAndExit(ERR_SWW_AGENT_ENABLING, id, host, token);
|
|
97
|
-
}
|
|
98
|
-
await Output.spinner(TXT_ENABLING_AGENT);
|
|
99
|
-
if (process.env.DEBUG === '1') {
|
|
100
|
-
AgentManager.start(id, host, token, port, !!options.start);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
try {
|
|
104
|
-
await AgentManager.system.enable(id, host, token, port, !!options.start, options.user, options.pass, !!options.debug);
|
|
105
|
-
} catch {
|
|
106
|
-
await removeAllAndExit(ERR_SWW_AGENT_ENABLING, id, host, token);
|
|
107
|
-
}
|
|
108
|
-
const api = new ApiAgent(port);
|
|
109
|
-
await waitUntilAgentEnabled(api,15000, () => {
|
|
110
|
-
removeAllAndExit(ERR_SWW_AGENT_ENABLING, id, host, token);
|
|
111
|
-
}, () => {
|
|
112
|
-
Output.exitSuccess(TXT_AGENT_ENABLED);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
module.exports = commandAgentInstall;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const Output = require('../../output.js');
|
|
2
|
-
const {
|
|
3
|
-
DESC_COMMAND_AGENT_RESTART,
|
|
4
|
-
TXT_AGENT_RESTARTED
|
|
5
|
-
} = require('../../texts.js');
|
|
6
|
-
const ApiAgent = require('../../api/agent.js');
|
|
7
|
-
const AgentManager = require('../../agent/manager');
|
|
8
|
-
const { ERR_AGENT_NOT_ENABLED } = require('../../texts');
|
|
9
|
-
const { newCommand } = require('../../utils');
|
|
10
|
-
|
|
11
|
-
const commandAgentRestart = newCommand('restart', DESC_COMMAND_AGENT_RESTART);
|
|
12
|
-
commandAgentRestart.action(async () => {
|
|
13
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
14
|
-
if (!isEnabled) {
|
|
15
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
const json = AgentManager.system.loadSystemConfig();
|
|
19
|
-
const api = new ApiAgent(json.port);
|
|
20
|
-
await api.restartAgent();
|
|
21
|
-
Output.exitSuccess(TXT_AGENT_RESTARTED);
|
|
22
|
-
} catch (err) {
|
|
23
|
-
Output.exitError(err);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
module.exports = commandAgentRestart;
|
package/src/command/agent/run.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const AgentManager = require('../../agent/manager');
|
|
2
|
-
const logger = require('../../logger');
|
|
3
|
-
const { newCommand } = require('../../utils');
|
|
4
|
-
|
|
5
|
-
const commandAgentRun = newCommand('run');
|
|
6
|
-
commandAgentRun.option('--id <id>');
|
|
7
|
-
commandAgentRun.option('--host <host>');
|
|
8
|
-
commandAgentRun.option('--token <token>');
|
|
9
|
-
commandAgentRun.option('--port <port>');
|
|
10
|
-
commandAgentRun.option('--start <start>');
|
|
11
|
-
commandAgentRun.action(async (options) => {
|
|
12
|
-
logger.changeRootPath(AgentManager.system.getAgentConfigDir());
|
|
13
|
-
AgentManager.start(options.id, options.host, options.token, options.port, !!options.start);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
module.exports = commandAgentRun;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const Output = require('../../output.js');
|
|
2
|
-
const {
|
|
3
|
-
DESC_COMMAND_AGENT_START,
|
|
4
|
-
TXT_AGENT_STARTED
|
|
5
|
-
} = require('../../texts.js');
|
|
6
|
-
const ApiAgent = require('../../api/agent.js');
|
|
7
|
-
const AgentManager = require('../../agent/manager');
|
|
8
|
-
const { ERR_AGENT_NOT_ENABLED } = require('../../texts');
|
|
9
|
-
const { newCommand } = require('../../utils');
|
|
10
|
-
|
|
11
|
-
const commandAgentStart = newCommand('start', DESC_COMMAND_AGENT_START);
|
|
12
|
-
commandAgentStart.action(async () => {
|
|
13
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
14
|
-
if (!isEnabled) {
|
|
15
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
const json = AgentManager.system.loadSystemConfig();
|
|
19
|
-
const api = new ApiAgent(json.port);
|
|
20
|
-
await api.startAgent();
|
|
21
|
-
Output.exitSuccess(TXT_AGENT_STARTED);
|
|
22
|
-
} catch (err) {
|
|
23
|
-
Output.exitError(err);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
module.exports = commandAgentStart;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const Output = require('../../output.js');
|
|
2
|
-
const {
|
|
3
|
-
DESC_COMMAND_AGENT_STATUS,
|
|
4
|
-
ERR_AGENT_NOT_ENABLED,
|
|
5
|
-
TXT_AGENT_IS_DISABLED,
|
|
6
|
-
TXT_AGENT_IS_ENABLED_AND_HAVE_TROUBLES,
|
|
7
|
-
TXT_AGENT_IS_ENABLED_AND_INITIALIZING,
|
|
8
|
-
TXT_AGENT_IS_ENABLED_AND_STARTED,
|
|
9
|
-
TXT_AGENT_IS_ENABLED_AND_STOPPED
|
|
10
|
-
} = require('../../texts.js');
|
|
11
|
-
const {
|
|
12
|
-
AGENT_STATUS_ENABLED,
|
|
13
|
-
AGENT_STATUS_FETCH_FAILED,
|
|
14
|
-
AGENT_STATUS_INITIALIZING
|
|
15
|
-
} = require('../../utils.js');
|
|
16
|
-
const AgentManager = require('../../agent/manager');
|
|
17
|
-
const { ERR_AGENT_NOT_RUNNING } = require('../../texts');
|
|
18
|
-
const { newCommand } = require('../../utils');
|
|
19
|
-
|
|
20
|
-
const commandAgentStatus = newCommand('status', DESC_COMMAND_AGENT_STATUS);
|
|
21
|
-
commandAgentStatus.action(async () => {
|
|
22
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
23
|
-
if (!isEnabled) {
|
|
24
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
25
|
-
}
|
|
26
|
-
if (!commandAgentStatus.agentStatus) {
|
|
27
|
-
Output.exitError(ERR_AGENT_NOT_RUNNING);
|
|
28
|
-
}
|
|
29
|
-
if (commandAgentStatus.agentStatus.status === AGENT_STATUS_INITIALIZING) {
|
|
30
|
-
Output.exitError(TXT_AGENT_IS_ENABLED_AND_INITIALIZING);
|
|
31
|
-
}
|
|
32
|
-
if (commandAgentStatus.agentStatus.status === AGENT_STATUS_FETCH_FAILED) {
|
|
33
|
-
Output.exitError(TXT_AGENT_IS_ENABLED_AND_HAVE_TROUBLES);
|
|
34
|
-
}
|
|
35
|
-
if (commandAgentStatus.agentStatus.status !== AGENT_STATUS_ENABLED) {
|
|
36
|
-
Output.exitError(TXT_AGENT_IS_DISABLED);
|
|
37
|
-
}
|
|
38
|
-
if (commandAgentStatus.agentStatus.started) {
|
|
39
|
-
Output.exitSuccess(TXT_AGENT_IS_ENABLED_AND_STARTED);
|
|
40
|
-
}
|
|
41
|
-
Output.exitError(TXT_AGENT_IS_ENABLED_AND_STOPPED);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
module.exports = commandAgentStatus;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const Output = require('../../output.js');
|
|
2
|
-
const {
|
|
3
|
-
DESC_COMMAND_AGENT_STOP,
|
|
4
|
-
TXT_AGENT_STOPPED
|
|
5
|
-
} = require('../../texts.js');
|
|
6
|
-
const ApiAgent = require('../../api/agent.js');
|
|
7
|
-
const AgentManager = require('../../agent/manager');
|
|
8
|
-
const { ERR_AGENT_NOT_ENABLED } = require('../../texts');
|
|
9
|
-
const { newCommand } = require('../../utils');
|
|
10
|
-
|
|
11
|
-
const commandAgentStop = newCommand('stop', DESC_COMMAND_AGENT_STOP);
|
|
12
|
-
commandAgentStop.action(async () => {
|
|
13
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
14
|
-
if (!isEnabled) {
|
|
15
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
const json = AgentManager.system.loadSystemConfig();
|
|
19
|
-
const api = new ApiAgent(json.port);
|
|
20
|
-
await api.stopAgent();
|
|
21
|
-
Output.exitSuccess(TXT_AGENT_STOPPED);
|
|
22
|
-
} catch (err) {
|
|
23
|
-
Output.exitError(err);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
module.exports = commandAgentStop;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const { TUNNEL_HTTP } = require('../../../utils.js');
|
|
2
|
-
const Output = require('../../../output.js');
|
|
3
|
-
const Cfg = require('../../../cfg.js');
|
|
4
|
-
const {
|
|
5
|
-
DESC_COMMAND_AGENT_TUNNEL_HTTP,
|
|
6
|
-
ERR_AGENT_NOT_ENABLED,
|
|
7
|
-
OPTION_TARGET,
|
|
8
|
-
TXT_OPENING_TUNNEL,
|
|
9
|
-
TXT_TUNNEL_STARTED
|
|
10
|
-
} = require('../../../texts.js');
|
|
11
|
-
const ApiAgent = require('../../../api/agent.js');
|
|
12
|
-
const { getBasicCommandHttp } = require('../../../utils');
|
|
13
|
-
const AgentManager = require('../../../agent/manager');
|
|
14
|
-
const { OPTION_FOLLOW } = require('../../../texts');
|
|
15
|
-
const AgentSocketTunnel = require('../../../agent/socket/tunnel');
|
|
16
|
-
|
|
17
|
-
const commandAgentTunnelHttp = getBasicCommandHttp();
|
|
18
|
-
commandAgentTunnelHttp.description(DESC_COMMAND_AGENT_TUNNEL_HTTP);
|
|
19
|
-
commandAgentTunnelHttp.option('-f, --follow', OPTION_FOLLOW);
|
|
20
|
-
commandAgentTunnelHttp.argument('[protocol://host:port]', OPTION_TARGET);
|
|
21
|
-
commandAgentTunnelHttp.action(async (target, options) => {
|
|
22
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
23
|
-
if (!isEnabled) {
|
|
24
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
25
|
-
}
|
|
26
|
-
const prepared = await Cfg.prepareTunnel(TUNNEL_HTTP, target, options, true);
|
|
27
|
-
try {
|
|
28
|
-
await Output.spinner(TXT_OPENING_TUNNEL);
|
|
29
|
-
const json = AgentManager.system.loadSystemConfig();
|
|
30
|
-
const api = new ApiAgent(json.port);
|
|
31
|
-
const data = await api.addTunnel(prepared);
|
|
32
|
-
if (options.follow) {
|
|
33
|
-
const ws = await api.socketTunnel(data.id);
|
|
34
|
-
const tunnel = new AgentSocketTunnel(ws, data.id);
|
|
35
|
-
await tunnel.waitForReady();
|
|
36
|
-
Output.tunnel(tunnel);
|
|
37
|
-
} else {
|
|
38
|
-
Output.exitSuccess(TXT_TUNNEL_STARTED(data.type));
|
|
39
|
-
}
|
|
40
|
-
} catch (err) {
|
|
41
|
-
Output.exitError(err);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
module.exports = commandAgentTunnelHttp;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const Output = require('../../../output.js');
|
|
2
|
-
const {
|
|
3
|
-
DESC_COMMAND_AGENT_TUNNEL_LIST,
|
|
4
|
-
ERR_AGENT_NOT_ENABLED
|
|
5
|
-
} = require('../../../texts.js');
|
|
6
|
-
const ApiAgent = require('../../../api/agent');
|
|
7
|
-
const AgentManager = require('../../../agent/manager');
|
|
8
|
-
const { newCommand } = require('../../../utils');
|
|
9
|
-
|
|
10
|
-
const commandAgentTunnelList = newCommand('list', DESC_COMMAND_AGENT_TUNNEL_LIST);
|
|
11
|
-
commandAgentTunnelList.action(async () => {
|
|
12
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
13
|
-
if (!isEnabled) {
|
|
14
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
const json = AgentManager.system.loadSystemConfig();
|
|
18
|
-
const api = new ApiAgent(json.port);
|
|
19
|
-
const data = await api.fetchTunnels();
|
|
20
|
-
Output.agentTunnels(data.tunnels);
|
|
21
|
-
} catch (err) {
|
|
22
|
-
Output.exitError(err);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
module.exports = commandAgentTunnelList;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const Output = require('../../../output.js');
|
|
2
|
-
const {
|
|
3
|
-
DESC_COMMAND_AGENT_TUNNEL_REMOVE,
|
|
4
|
-
ERR_AGENT_NOT_ENABLED,
|
|
5
|
-
OPTION_ID,
|
|
6
|
-
TXT_TUNNEL_STOPPED
|
|
7
|
-
} = require('../../../texts.js');
|
|
8
|
-
const ApiAgent = require('../../../api/agent.js');
|
|
9
|
-
const AgentManager = require('../../../agent/manager');
|
|
10
|
-
const { newCommand } = require('../../../utils');
|
|
11
|
-
|
|
12
|
-
const commandAgentTunnelRemove = newCommand('rm', DESC_COMMAND_AGENT_TUNNEL_REMOVE);
|
|
13
|
-
commandAgentTunnelRemove.argument('<id>', OPTION_ID);
|
|
14
|
-
commandAgentTunnelRemove.action(async (id) => {
|
|
15
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
16
|
-
if (!isEnabled) {
|
|
17
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
const json = AgentManager.system.loadSystemConfig();
|
|
21
|
-
const api = new ApiAgent(json.port);
|
|
22
|
-
await api.stopTunnel(id);
|
|
23
|
-
Output.exitSuccess(TXT_TUNNEL_STOPPED);
|
|
24
|
-
} catch (err) {
|
|
25
|
-
Output.exitError(err);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
module.exports = commandAgentTunnelRemove;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const Cfg = require('../../../cfg.js');
|
|
2
|
-
const Output = require('../../../output.js');
|
|
3
|
-
const {
|
|
4
|
-
DESC_COMMAND_AGENT_TUNNEL_START,
|
|
5
|
-
ERR_AGENT_NOT_ENABLED,
|
|
6
|
-
ERR_TUNNEL_NOT_FOUND,
|
|
7
|
-
OPTION_NAME,
|
|
8
|
-
TXT_OPENING_TUNNEL,
|
|
9
|
-
TXT_TUNNEL_STARTED
|
|
10
|
-
} = require('../../../texts.js');
|
|
11
|
-
const ApiAgent = require('../../../api/agent.js');
|
|
12
|
-
const AgentManager = require('../../../agent/manager');
|
|
13
|
-
const { newCommand } = require('../../../utils');
|
|
14
|
-
|
|
15
|
-
const commandAgentTunnelStart = newCommand('start', DESC_COMMAND_AGENT_TUNNEL_START);
|
|
16
|
-
commandAgentTunnelStart.argument('<name>', OPTION_NAME);
|
|
17
|
-
commandAgentTunnelStart.action(async (name) => {
|
|
18
|
-
if (!Cfg.hasTunnel(name)) {
|
|
19
|
-
Output.exitError(ERR_TUNNEL_NOT_FOUND(name));
|
|
20
|
-
}
|
|
21
|
-
const prepared = Cfg.getTunnel(name);
|
|
22
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
23
|
-
if (!isEnabled) {
|
|
24
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
await Output.spinner(TXT_OPENING_TUNNEL);
|
|
28
|
-
const json = AgentManager.system.loadSystemConfig();
|
|
29
|
-
const api = new ApiAgent(json.port);
|
|
30
|
-
const data = await api.addTunnel(prepared);
|
|
31
|
-
Output.exitSuccess(TXT_TUNNEL_STARTED(data.type));
|
|
32
|
-
} catch (err) {
|
|
33
|
-
Output.exitError(err);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
module.exports = commandAgentTunnelStart;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
DESC_COMMAND_AGENT_TUNNEL_STATUS,
|
|
3
|
-
ERR_AGENT_NOT_ENABLED,
|
|
4
|
-
OPTION_ID
|
|
5
|
-
} = require('../../../texts.js');
|
|
6
|
-
const Output = require('../../../output.js');
|
|
7
|
-
const ApiAgent = require('../../../api/agent.js');
|
|
8
|
-
const AgentSocketTunnel = require('../../../agent/socket/tunnel.js');
|
|
9
|
-
const AgentManager = require('../../../agent/manager');
|
|
10
|
-
const { newCommand } = require('../../../utils');
|
|
11
|
-
|
|
12
|
-
const commandAgentTunnelStatus = newCommand('status', DESC_COMMAND_AGENT_TUNNEL_STATUS);
|
|
13
|
-
commandAgentTunnelStatus.argument('<id>', OPTION_ID);
|
|
14
|
-
commandAgentTunnelStatus.action(async (id) => {
|
|
15
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
16
|
-
if (!isEnabled) {
|
|
17
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
const json = AgentManager.system.loadSystemConfig();
|
|
21
|
-
const api = new ApiAgent(json.port);
|
|
22
|
-
const ws = await api.socketTunnel(id);
|
|
23
|
-
const tunnel = new AgentSocketTunnel(ws, id);
|
|
24
|
-
await tunnel.waitForReady();
|
|
25
|
-
Output.tunnel(tunnel);
|
|
26
|
-
} catch (err) {
|
|
27
|
-
Output.exitError(err);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
module.exports = commandAgentTunnelStatus;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const { TUNNEL_TCP } = require('../../../utils.js');
|
|
2
|
-
const Output = require('../../../output.js');
|
|
3
|
-
const Cfg = require('../../../cfg.js');
|
|
4
|
-
const {
|
|
5
|
-
DESC_COMMAND_AGENT_TUNNEL_TCP,
|
|
6
|
-
ERR_AGENT_NOT_ENABLED,
|
|
7
|
-
OPTION_FOLLOW,
|
|
8
|
-
OPTION_TARGET,
|
|
9
|
-
TXT_OPENING_TUNNEL,
|
|
10
|
-
TXT_TUNNEL_STARTED
|
|
11
|
-
} = require('../../../texts.js');
|
|
12
|
-
const ApiAgent = require('../../../api/agent.js');
|
|
13
|
-
const AgentSocketTunnel = require('../../../agent/socket/tunnel.js');
|
|
14
|
-
const { getBasicCommandTcp } = require('../../../utils');
|
|
15
|
-
const AgentManager = require('../../../agent/manager');
|
|
16
|
-
|
|
17
|
-
const commandAgentTunnelTcp = getBasicCommandTcp();
|
|
18
|
-
commandAgentTunnelTcp.description(DESC_COMMAND_AGENT_TUNNEL_TCP);
|
|
19
|
-
commandAgentTunnelTcp.option('-f, --follow', OPTION_FOLLOW);
|
|
20
|
-
commandAgentTunnelTcp.argument('[host:port]', OPTION_TARGET);
|
|
21
|
-
commandAgentTunnelTcp.action(async (target, options) => {
|
|
22
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
23
|
-
if (!isEnabled) {
|
|
24
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
25
|
-
}
|
|
26
|
-
const prepared = await Cfg.prepareTunnel(TUNNEL_TCP, target, options, true);
|
|
27
|
-
try {
|
|
28
|
-
await Output.spinner(TXT_OPENING_TUNNEL);
|
|
29
|
-
const json = AgentManager.system.loadSystemConfig();
|
|
30
|
-
const api = new ApiAgent(json.port);
|
|
31
|
-
const data = await api.addTunnel(prepared);
|
|
32
|
-
if (options.follow) {
|
|
33
|
-
const ws = await api.socketTunnel(data.id);
|
|
34
|
-
const tunnel = new AgentSocketTunnel(ws, data.id);
|
|
35
|
-
await tunnel.waitForReady();
|
|
36
|
-
Output.tunnel(tunnel);
|
|
37
|
-
} else {
|
|
38
|
-
Output.exitSuccess(TXT_TUNNEL_STARTED(data.type));
|
|
39
|
-
}
|
|
40
|
-
} catch (err) {
|
|
41
|
-
Output.exitError(err);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
module.exports = commandAgentTunnelTcp;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const { TUNNEL_TLS } = require('../../../utils.js');
|
|
2
|
-
const Output = require('../../../output.js');
|
|
3
|
-
const Cfg = require('../../../cfg.js');
|
|
4
|
-
const {
|
|
5
|
-
DESC_COMMAND_AGENT_TUNNEL_TLS,
|
|
6
|
-
ERR_AGENT_NOT_ENABLED,
|
|
7
|
-
OPTION_TARGET,
|
|
8
|
-
TXT_OPENING_TUNNEL,
|
|
9
|
-
TXT_TUNNEL_STARTED
|
|
10
|
-
} = require('../../../texts.js');
|
|
11
|
-
const ApiAgent = require('../../../api/agent.js');
|
|
12
|
-
const { getBasicCommandTls } = require('../../../utils');
|
|
13
|
-
const AgentManager = require('../../../agent/manager');
|
|
14
|
-
const { OPTION_FOLLOW } = require('../../../texts');
|
|
15
|
-
const AgentSocketTunnel = require('../../../agent/socket/tunnel');
|
|
16
|
-
|
|
17
|
-
const commandAgentTunnelTls = getBasicCommandTls();
|
|
18
|
-
commandAgentTunnelTls.description(DESC_COMMAND_AGENT_TUNNEL_TLS);
|
|
19
|
-
commandAgentTunnelTls.option('-f, --follow', OPTION_FOLLOW);
|
|
20
|
-
commandAgentTunnelTls.argument('[host:port]', OPTION_TARGET);
|
|
21
|
-
commandAgentTunnelTls.action(async (target, options) => {
|
|
22
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
23
|
-
if (!isEnabled) {
|
|
24
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
25
|
-
}
|
|
26
|
-
const prepared = await Cfg.prepareTunnel(TUNNEL_TLS, target, options, true);
|
|
27
|
-
try {
|
|
28
|
-
await Output.spinner(TXT_OPENING_TUNNEL);
|
|
29
|
-
const json = AgentManager.system.loadSystemConfig();
|
|
30
|
-
const api = new ApiAgent(json.port);
|
|
31
|
-
const data = await api.addTunnel(prepared);
|
|
32
|
-
if (options.follow) {
|
|
33
|
-
const ws = await api.socketTunnel(data.id);
|
|
34
|
-
const tunnel = new AgentSocketTunnel(ws, data.id);
|
|
35
|
-
await tunnel.waitForReady();
|
|
36
|
-
Output.tunnel(tunnel);
|
|
37
|
-
} else {
|
|
38
|
-
Output.exitSuccess(TXT_TUNNEL_STARTED(data.type));
|
|
39
|
-
}
|
|
40
|
-
} catch (err) {
|
|
41
|
-
Output.exitError(err);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
module.exports = commandAgentTunnelTls;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const commandAgentTunnelTcp = require('./tunnel/tcp.js');
|
|
2
|
-
const commandAgentTunnelList = require('./tunnel/list.js');
|
|
3
|
-
const commandAgentTunnelRemove = require('./tunnel/remove.js');
|
|
4
|
-
const commandAgentTunnelTls = require('./tunnel/tls.js');
|
|
5
|
-
const commandAgentTunnelHttp = require('./tunnel/http.js');
|
|
6
|
-
const commandAgentTunnelStart = require('./tunnel/start.js');
|
|
7
|
-
const { DESC_COMMAND_AGENT_TUNNEL } = require('../../texts.js');
|
|
8
|
-
const commandAgentTunnelStatus = require('./tunnel/status.js');
|
|
9
|
-
const { newCommand } = require('../../utils');
|
|
10
|
-
|
|
11
|
-
const commandAgentTunnel = newCommand('tunnel', DESC_COMMAND_AGENT_TUNNEL);
|
|
12
|
-
commandAgentTunnel.addCommand(commandAgentTunnelTcp);
|
|
13
|
-
commandAgentTunnel.addCommand(commandAgentTunnelTls);
|
|
14
|
-
commandAgentTunnel.addCommand(commandAgentTunnelHttp);
|
|
15
|
-
commandAgentTunnel.addCommand(commandAgentTunnelStart);
|
|
16
|
-
commandAgentTunnel.addCommand(commandAgentTunnelRemove);
|
|
17
|
-
commandAgentTunnel.addCommand(commandAgentTunnelList);
|
|
18
|
-
commandAgentTunnel.addCommand(commandAgentTunnelStatus);
|
|
19
|
-
|
|
20
|
-
module.exports = commandAgentTunnel;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const Output = require('../../output.js');
|
|
2
|
-
const {
|
|
3
|
-
DESC_COMMAND_AGENT_UNINSTALL,
|
|
4
|
-
TXT_AGENT_DISABLED
|
|
5
|
-
} = require('../../texts.js');
|
|
6
|
-
const AgentManager = require('../../agent/manager.js');
|
|
7
|
-
const ApiBuddy = require('../../api/buddy.js');
|
|
8
|
-
const { ERR_AGENT_ADMIN_RIGHTS } = require('../../texts');
|
|
9
|
-
const { newCommand } = require('../../utils');
|
|
10
|
-
|
|
11
|
-
const commandAgentUninstall = newCommand('uninstall', DESC_COMMAND_AGENT_UNINSTALL);
|
|
12
|
-
commandAgentUninstall.action(async () => {
|
|
13
|
-
const hasAdminRights = await AgentManager.system.hasAdminRights();
|
|
14
|
-
if (!hasAdminRights) {
|
|
15
|
-
Output.exitError(ERR_AGENT_ADMIN_RIGHTS);
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
await AgentManager.system.disable();
|
|
19
|
-
} catch {
|
|
20
|
-
// do nothing
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
const json = AgentManager.system.loadSystemConfig();
|
|
24
|
-
await ApiBuddy.unregister(json.id, json.host, json.token);
|
|
25
|
-
} catch {
|
|
26
|
-
// do nothing
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
AgentManager.system.clearSystemFiles();
|
|
30
|
-
} catch {
|
|
31
|
-
// do nothing
|
|
32
|
-
}
|
|
33
|
-
Output.exitSuccess(TXT_AGENT_DISABLED);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
module.exports = commandAgentUninstall;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
DESC_COMMAND_AGENT_UPDATE,
|
|
3
|
-
ERR_AGENT_NOT_ENABLED,
|
|
4
|
-
ERR_SWW_AGENT_UPDATING,
|
|
5
|
-
} = require('../../texts.js');
|
|
6
|
-
const Output = require('../../output.js');
|
|
7
|
-
const waitUntilAgentEnabled = require('../../agent/wait.js');
|
|
8
|
-
const AgentManager = require('../../agent/manager');
|
|
9
|
-
const { ERR_AGENT_ADMIN_RIGHTS,
|
|
10
|
-
TXT_AGENT_UPDATED,
|
|
11
|
-
TXT_UPDATING_AGENT
|
|
12
|
-
} = require('../../texts');
|
|
13
|
-
const ApiAgent = require('../../api/agent');
|
|
14
|
-
const { newCommand } = require('../../utils');
|
|
15
|
-
|
|
16
|
-
const commandAgentUpdate = newCommand('update', DESC_COMMAND_AGENT_UPDATE);
|
|
17
|
-
commandAgentUpdate.hideVersionUpdate = true;
|
|
18
|
-
commandAgentUpdate.action(async () => {
|
|
19
|
-
const hasAdminRights = await AgentManager.system.hasAdminRights();
|
|
20
|
-
if (!hasAdminRights) {
|
|
21
|
-
Output.exitError(ERR_AGENT_ADMIN_RIGHTS);
|
|
22
|
-
}
|
|
23
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
24
|
-
if (!isEnabled) {
|
|
25
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
26
|
-
}
|
|
27
|
-
Output.normal(TXT_UPDATING_AGENT);
|
|
28
|
-
try {
|
|
29
|
-
await AgentManager.system.update();
|
|
30
|
-
const json = AgentManager.system.loadSystemConfig();
|
|
31
|
-
const api = new ApiAgent(json.port);
|
|
32
|
-
await waitUntilAgentEnabled(api,15000, () => {
|
|
33
|
-
Output.exitError(ERR_SWW_AGENT_UPDATING);
|
|
34
|
-
}, () => {
|
|
35
|
-
Output.exitSuccess(TXT_AGENT_UPDATED);
|
|
36
|
-
});
|
|
37
|
-
} catch {
|
|
38
|
-
Output.exitError(ERR_SWW_AGENT_UPDATING);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
module.exports = commandAgentUpdate;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const Output = require('../../output.js');
|
|
2
|
-
const {
|
|
3
|
-
DESC_COMMAND_AGENT_VERSION,
|
|
4
|
-
ERR_AGENT_NOT_ENABLED,
|
|
5
|
-
ERR_SWW
|
|
6
|
-
} = require('../../texts.js');
|
|
7
|
-
const AgentManager = require('../../agent/manager');
|
|
8
|
-
const { newCommand } = require('../../utils');
|
|
9
|
-
|
|
10
|
-
const commandAgentVersion = newCommand('version', DESC_COMMAND_AGENT_VERSION);
|
|
11
|
-
commandAgentVersion.action(async () => {
|
|
12
|
-
const isEnabled = await AgentManager.system.isEnabled();
|
|
13
|
-
if (!isEnabled) {
|
|
14
|
-
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
15
|
-
}
|
|
16
|
-
if (!commandAgentVersion.agentStatus) {
|
|
17
|
-
Output.exitError(ERR_SWW);
|
|
18
|
-
}
|
|
19
|
-
Output.exitNormal(commandAgentVersion.agentStatus.version);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
module.exports = commandAgentVersion;
|