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