bdy 1.7.48-dev → 1.7.51-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 +1 -1
- package/src/cfg.js +9 -10
- package/src/command/agent/{enable.js → install.js} +12 -12
- package/src/command/agent/tunnel/http.js +1 -3
- package/src/command/agent/tunnel/tcp.js +1 -3
- package/src/command/agent/tunnel/tls.js +1 -3
- package/src/command/agent/{disable.js → uninstall.js} +5 -5
- package/src/command/agent.js +4 -4
- package/src/command/config/add/http.js +1 -3
- package/src/command/config/add/tcp.js +1 -3
- package/src/command/config/add/tls.js +1 -3
- package/src/command/http.js +1 -2
- package/src/command/tcp.js +1 -2
- package/src/command/tls.js +1 -2
- package/src/format.js +1 -1
- package/src/index.js +2 -0
- package/src/logger.js +1 -0
- package/src/texts.js +20 -18
- package/src/utils.js +18 -4
package/package.json
CHANGED
package/src/cfg.js
CHANGED
|
@@ -2,6 +2,7 @@ const { resolve } = require('path');
|
|
|
2
2
|
const {
|
|
3
3
|
mkdirSync,
|
|
4
4
|
readFileSync,
|
|
5
|
+
chmodSync,
|
|
5
6
|
statSync,
|
|
6
7
|
writeFileSync
|
|
7
8
|
} = require('fs');
|
|
@@ -31,8 +32,9 @@ class Cfg {
|
|
|
31
32
|
createDir() {
|
|
32
33
|
try {
|
|
33
34
|
mkdirSync(this.dir, {
|
|
34
|
-
recursive: true
|
|
35
|
+
recursive: true,
|
|
35
36
|
});
|
|
37
|
+
chmodSync(this.dir, 0o777);
|
|
36
38
|
} catch (err) {
|
|
37
39
|
throw new Error(ERR_CANT_CREATE_DIR_IN_HOME('.bdy'));
|
|
38
40
|
}
|
|
@@ -41,6 +43,7 @@ class Cfg {
|
|
|
41
43
|
createEmptyFile() {
|
|
42
44
|
try {
|
|
43
45
|
writeFileSync(this.file, '{}', 'utf-8');
|
|
46
|
+
chmodSync(this.file, 0o666);
|
|
44
47
|
} catch (err) {
|
|
45
48
|
throw new Error(ERR_CANT_CREATE_DIR_IN_HOME('.bdy/cfg.json'));
|
|
46
49
|
}
|
|
@@ -67,7 +70,7 @@ class Cfg {
|
|
|
67
70
|
if (!this.json.tunnels) this.json.tunnels = {};
|
|
68
71
|
}
|
|
69
72
|
|
|
70
|
-
async prepareTunnel(tunnelType, target, options, useDefaults
|
|
73
|
+
async prepareTunnel(tunnelType, target, options, useDefaults) {
|
|
71
74
|
const type = Input.type(tunnelType);
|
|
72
75
|
const tunnel = {
|
|
73
76
|
type,
|
|
@@ -76,12 +79,7 @@ class Cfg {
|
|
|
76
79
|
if (options.region !== undefined) tunnel.region = Input.region(options.region);
|
|
77
80
|
else if (useDefaults) tunnel.region = this.getRegion();
|
|
78
81
|
if (options.whitelist !== undefined) tunnel.whitelist = Input.whitelist(options.whitelist);
|
|
79
|
-
else if (useDefaults)
|
|
80
|
-
tunnel.whitelist = this.getWhitelist();
|
|
81
|
-
if (!tunnel.whitelist.length) {
|
|
82
|
-
tunnel.whitelist.push(myIp);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
82
|
+
else if (useDefaults) tunnel.whitelist = this.getWhitelist();
|
|
85
83
|
if (options.timeout !== undefined) tunnel.timeout = Input.timeout(options.timeout);
|
|
86
84
|
else if (useDefaults) tunnel.timeout = this.getTimeout();
|
|
87
85
|
if (options.domain !== undefined) tunnel.domain = Input.domain(options.domain);
|
|
@@ -116,12 +114,12 @@ class Cfg {
|
|
|
116
114
|
return tunnel;
|
|
117
115
|
}
|
|
118
116
|
|
|
119
|
-
async addTunnel(name, type, target, options
|
|
117
|
+
async addTunnel(name, type, target, options) {
|
|
120
118
|
this.ensureTunnels();
|
|
121
119
|
this.json.tunnels[name] = await this.prepareTunnel(type, target, {
|
|
122
120
|
name,
|
|
123
121
|
...options
|
|
124
|
-
}, false
|
|
122
|
+
}, false);
|
|
125
123
|
this.save();
|
|
126
124
|
}
|
|
127
125
|
|
|
@@ -219,6 +217,7 @@ class Cfg {
|
|
|
219
217
|
this.ensureDir();
|
|
220
218
|
try {
|
|
221
219
|
writeFileSync(this.file, JSON.stringify(this.json, null, 4), 'utf-8');
|
|
220
|
+
chmodSync(this.file, 0o666);
|
|
222
221
|
} catch (err) {
|
|
223
222
|
throw new Error(ERR_CANT_CREATE_DIR_IN_HOME('.bdy/cfg.json'));
|
|
224
223
|
}
|
|
@@ -2,7 +2,7 @@ const { Command } = require('commander');
|
|
|
2
2
|
const Output = require('../../output.js');
|
|
3
3
|
const Input = require('../../input.js');
|
|
4
4
|
const {
|
|
5
|
-
|
|
5
|
+
DESC_COMMAND_AGENT_INSTALL,
|
|
6
6
|
ERR_SWW_AGENT_ENABLING,
|
|
7
7
|
OPTION_AGENT_ID,
|
|
8
8
|
OPTION_AGENT_PORT,
|
|
@@ -45,16 +45,16 @@ const removeAllAndExit = async (txt, id, host, token) => {
|
|
|
45
45
|
Output.exitError(txt);
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
const commandAgentInstall = new Command('install');
|
|
49
|
+
commandAgentInstall.description(DESC_COMMAND_AGENT_INSTALL);
|
|
50
|
+
commandAgentInstall.option('-s, --start', OPTION_AGENT_START);
|
|
51
|
+
commandAgentInstall.option('-i, --id <id>', OPTION_AGENT_ID);
|
|
52
|
+
commandAgentInstall.option('-t, --token <token>', OPTION_AGENT_TOKEN);
|
|
53
|
+
commandAgentInstall.option('-p, --port <port>', OPTION_AGENT_PORT, '7456');
|
|
54
|
+
commandAgentInstall.option('-u, --user <user>', OPTION_USER);
|
|
55
|
+
commandAgentInstall.option('--pass <password>', OPTION_PASS);
|
|
56
|
+
commandAgentInstall.option('-d, --debug', OPTION_AGENT_DEBUG);
|
|
57
|
+
commandAgentInstall.action(async (options) => {
|
|
58
58
|
const hasAdminRights = await AgentManager.system.hasAdminRights();
|
|
59
59
|
if (!hasAdminRights) {
|
|
60
60
|
Output.exitError(ERR_AGENT_ADMIN_RIGHTS);
|
|
@@ -114,4 +114,4 @@ commandAgentEnable.action(async (options) => {
|
|
|
114
114
|
});
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
-
module.exports =
|
|
117
|
+
module.exports = commandAgentInstall;
|
|
@@ -9,7 +9,6 @@ const {
|
|
|
9
9
|
TXT_TUNNEL_STARTED
|
|
10
10
|
} = require('../../../texts.js');
|
|
11
11
|
const ApiAgent = require('../../../api/agent.js');
|
|
12
|
-
const ApiBuddy = require('../../../api/buddy');
|
|
13
12
|
const { getBasicCommandHttp } = require('../../../utils');
|
|
14
13
|
const AgentManager = require('../../../agent/manager');
|
|
15
14
|
const { OPTION_FOLLOW } = require('../../../texts');
|
|
@@ -24,8 +23,7 @@ commandAgentTunnelHttp.action(async (target, options) => {
|
|
|
24
23
|
if (!isEnabled) {
|
|
25
24
|
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
26
25
|
}
|
|
27
|
-
const
|
|
28
|
-
const prepared = await Cfg.prepareTunnel(TUNNEL_HTTP, target, options, true, myIp);
|
|
26
|
+
const prepared = await Cfg.prepareTunnel(TUNNEL_HTTP, target, options, true);
|
|
29
27
|
try {
|
|
30
28
|
await Output.spinner(TXT_OPENING_TUNNEL);
|
|
31
29
|
const json = AgentManager.system.loadSystemConfig();
|
|
@@ -11,7 +11,6 @@ const {
|
|
|
11
11
|
} = require('../../../texts.js');
|
|
12
12
|
const ApiAgent = require('../../../api/agent.js');
|
|
13
13
|
const AgentSocketTunnel = require('../../../agent/socket/tunnel.js');
|
|
14
|
-
const ApiBuddy = require('../../../api/buddy');
|
|
15
14
|
const { getBasicCommandTcp } = require('../../../utils');
|
|
16
15
|
const AgentManager = require('../../../agent/manager');
|
|
17
16
|
|
|
@@ -24,8 +23,7 @@ commandAgentTunnelTcp.action(async (target, options) => {
|
|
|
24
23
|
if (!isEnabled) {
|
|
25
24
|
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
26
25
|
}
|
|
27
|
-
const
|
|
28
|
-
const prepared = await Cfg.prepareTunnel(TUNNEL_TCP, target, options, true, myIp);
|
|
26
|
+
const prepared = await Cfg.prepareTunnel(TUNNEL_TCP, target, options, true);
|
|
29
27
|
try {
|
|
30
28
|
await Output.spinner(TXT_OPENING_TUNNEL);
|
|
31
29
|
const json = AgentManager.system.loadSystemConfig();
|
|
@@ -9,7 +9,6 @@ const {
|
|
|
9
9
|
TXT_TUNNEL_STARTED
|
|
10
10
|
} = require('../../../texts.js');
|
|
11
11
|
const ApiAgent = require('../../../api/agent.js');
|
|
12
|
-
const ApiBuddy = require('../../../api/buddy');
|
|
13
12
|
const { getBasicCommandTls } = require('../../../utils');
|
|
14
13
|
const AgentManager = require('../../../agent/manager');
|
|
15
14
|
const { OPTION_FOLLOW } = require('../../../texts');
|
|
@@ -24,8 +23,7 @@ commandAgentTunnelTls.action(async (target, options) => {
|
|
|
24
23
|
if (!isEnabled) {
|
|
25
24
|
Output.exitError(ERR_AGENT_NOT_ENABLED);
|
|
26
25
|
}
|
|
27
|
-
const
|
|
28
|
-
const prepared = await Cfg.prepareTunnel(TUNNEL_TLS, target, options, true, myIp);
|
|
26
|
+
const prepared = await Cfg.prepareTunnel(TUNNEL_TLS, target, options, true);
|
|
29
27
|
try {
|
|
30
28
|
await Output.spinner(TXT_OPENING_TUNNEL);
|
|
31
29
|
const json = AgentManager.system.loadSystemConfig();
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
const { Command } = require('commander');
|
|
2
2
|
const Output = require('../../output.js');
|
|
3
3
|
const {
|
|
4
|
-
|
|
4
|
+
DESC_COMMAND_AGENT_UNINSTALL,
|
|
5
5
|
TXT_AGENT_DISABLED
|
|
6
6
|
} = require('../../texts.js');
|
|
7
7
|
const AgentManager = require('../../agent/manager.js');
|
|
8
8
|
const ApiBuddy = require('../../api/buddy.js');
|
|
9
9
|
const { ERR_AGENT_ADMIN_RIGHTS } = require('../../texts');
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const commandAgentUninstall = new Command('disable');
|
|
12
|
+
commandAgentUninstall.description(DESC_COMMAND_AGENT_UNINSTALL);
|
|
13
|
+
commandAgentUninstall.action(async () => {
|
|
14
14
|
const hasAdminRights = await AgentManager.system.hasAdminRights();
|
|
15
15
|
if (!hasAdminRights) {
|
|
16
16
|
Output.exitError(ERR_AGENT_ADMIN_RIGHTS);
|
|
@@ -34,4 +34,4 @@ commandAgentDisable.action(async () => {
|
|
|
34
34
|
Output.exitSuccess(TXT_AGENT_DISABLED);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
module.exports =
|
|
37
|
+
module.exports = commandAgentUninstall;
|
package/src/command/agent.js
CHANGED
|
@@ -5,19 +5,19 @@ const commandAgentRestart = require('./agent/restart.js');
|
|
|
5
5
|
const commandAgentStop = require('./agent/stop.js');
|
|
6
6
|
const commandAgentUpdate = require('./agent/update.js');
|
|
7
7
|
const commandAgentTunnel = require('./agent/tunnel.js');
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const commandAgentInstall = require('./agent/install');
|
|
9
|
+
const commandAgentUninstall = require('./agent/uninstall.js');
|
|
10
10
|
const commandAgentVersion = require('./agent/version.js');
|
|
11
11
|
const { DESC_COMMAND_AGENT } = require('../texts.js');
|
|
12
12
|
const commandAgentRun = require('./agent/run');
|
|
13
13
|
|
|
14
14
|
const commandAgent = new Command('agent');
|
|
15
15
|
commandAgent.description(DESC_COMMAND_AGENT);
|
|
16
|
-
commandAgent.addCommand(
|
|
16
|
+
commandAgent.addCommand(commandAgentInstall);
|
|
17
17
|
commandAgent.addCommand(commandAgentStart);
|
|
18
18
|
commandAgent.addCommand(commandAgentStop);
|
|
19
19
|
commandAgent.addCommand(commandAgentRestart);
|
|
20
|
-
commandAgent.addCommand(
|
|
20
|
+
commandAgent.addCommand(commandAgentUninstall);
|
|
21
21
|
commandAgent.addCommand(commandAgentStatus);
|
|
22
22
|
commandAgent.addCommand(commandAgentTunnel);
|
|
23
23
|
commandAgent.addCommand(commandAgentUpdate);
|
|
@@ -12,7 +12,6 @@ const {
|
|
|
12
12
|
OPTION_TARGET,
|
|
13
13
|
TXT_TUNNEL_ADDED
|
|
14
14
|
} = require('../../../texts.js');
|
|
15
|
-
const ApiBuddy = require('../../../api/buddy');
|
|
16
15
|
const { getBasicCommandHttp } = require('../../../utils');
|
|
17
16
|
|
|
18
17
|
const commandConfigAddHttp = getBasicCommandHttp();
|
|
@@ -25,8 +24,7 @@ commandConfigAddHttp.action(async (n, target, options) => {
|
|
|
25
24
|
if (Cfg.hasTunnel(name) && !options.force) {
|
|
26
25
|
Output.exitError(ERR_TUNNEL_ALREADY_EXISTS);
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
await Cfg.addTunnel(name, TUNNEL_HTTP, target, options, myIp);
|
|
27
|
+
await Cfg.addTunnel(name, TUNNEL_HTTP, target, options);
|
|
30
28
|
Output.exitSuccess(TXT_TUNNEL_ADDED);
|
|
31
29
|
});
|
|
32
30
|
|
|
@@ -12,7 +12,6 @@ const {
|
|
|
12
12
|
OPTION_TARGET,
|
|
13
13
|
TXT_TUNNEL_ADDED
|
|
14
14
|
} = require('../../../texts.js');
|
|
15
|
-
const ApiBuddy = require('../../../api/buddy');
|
|
16
15
|
const { getBasicCommandTcp } = require('../../../utils');
|
|
17
16
|
|
|
18
17
|
const commandConfigAddTcp = getBasicCommandTcp();
|
|
@@ -25,8 +24,7 @@ commandConfigAddTcp.action(async (n, target, options) => {
|
|
|
25
24
|
if (Cfg.hasTunnel(name) && !options.force) {
|
|
26
25
|
Output.exitError(ERR_TUNNEL_ALREADY_EXISTS);
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
await Cfg.addTunnel(name, TUNNEL_TCP, target, options, myIp);
|
|
27
|
+
await Cfg.addTunnel(name, TUNNEL_TCP, target, options);
|
|
30
28
|
Output.exitSuccess(TXT_TUNNEL_ADDED);
|
|
31
29
|
});
|
|
32
30
|
|
|
@@ -12,7 +12,6 @@ const {
|
|
|
12
12
|
OPTION_TARGET,
|
|
13
13
|
TXT_TUNNEL_ADDED
|
|
14
14
|
} = require('../../../texts.js');
|
|
15
|
-
const ApiBuddy = require('../../../api/buddy');
|
|
16
15
|
const { getBasicCommandTls } = require('../../../utils');
|
|
17
16
|
|
|
18
17
|
const commandConfigAddTls = getBasicCommandTls();
|
|
@@ -25,8 +24,7 @@ commandConfigAddTls.action(async (n, target, options) => {
|
|
|
25
24
|
if (Cfg.hasTunnel(name) && !options.force) {
|
|
26
25
|
Output.exitError(ERR_TUNNEL_ALREADY_EXISTS);
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
await Cfg.addTunnel(name, TUNNEL_TLS, target, options, myIp);
|
|
27
|
+
await Cfg.addTunnel(name, TUNNEL_TLS, target, options);
|
|
30
28
|
Output.exitSuccess(TXT_TUNNEL_ADDED);
|
|
31
29
|
});
|
|
32
30
|
|
package/src/command/http.js
CHANGED
|
@@ -18,8 +18,7 @@ commandHttp.option('--token <token>', OPTION_TOKEN);
|
|
|
18
18
|
commandHttp.argument('[protocol://host:port]', OPTION_TARGET);
|
|
19
19
|
commandHttp.action(async (target, options) => {
|
|
20
20
|
if (options.token) Cfg.setToken(options.token);
|
|
21
|
-
const
|
|
22
|
-
const prepared = await Cfg.prepareTunnel(TUNNEL_HTTP, target, options, true, myIp);
|
|
21
|
+
const prepared = await Cfg.prepareTunnel(TUNNEL_HTTP, target, options, true);
|
|
23
22
|
await Output.spinner(TXT_OPENING_TUNNEL);
|
|
24
23
|
const agent = await ApiBuddy.register(false, Cfg.getTokenHost(), Cfg.getToken(), (region) => {
|
|
25
24
|
Cfg.setRegionIfNotSet(region);
|
package/src/command/tcp.js
CHANGED
|
@@ -16,8 +16,7 @@ commandTcp.option('--token <token>', OPTION_TOKEN);
|
|
|
16
16
|
commandTcp.argument('[host:port]', OPTION_TARGET);
|
|
17
17
|
commandTcp.action(async (target, options) => {
|
|
18
18
|
if (options.token) Cfg.setToken(options.token);
|
|
19
|
-
const
|
|
20
|
-
const prepared = await Cfg.prepareTunnel(TUNNEL_TCP, target, options, true, myIp);
|
|
19
|
+
const prepared = await Cfg.prepareTunnel(TUNNEL_TCP, target, options, true);
|
|
21
20
|
await Output.spinner(TXT_OPENING_TUNNEL);
|
|
22
21
|
const agent = await ApiBuddy.register(false, Cfg.getTokenHost(), Cfg.getToken(), (region) => {
|
|
23
22
|
Cfg.setRegionIfNotSet(region);
|
package/src/command/tls.js
CHANGED
|
@@ -16,8 +16,7 @@ commandTls.option('--token <token>', OPTION_TOKEN);
|
|
|
16
16
|
commandTls.argument('[host:port]', OPTION_TARGET);
|
|
17
17
|
commandTls.action(async (target, options) => {
|
|
18
18
|
if (options.token) Cfg.setToken(options.token);
|
|
19
|
-
const
|
|
20
|
-
const prepared = await Cfg.prepareTunnel(TUNNEL_TLS, target, options, true, myIp);
|
|
19
|
+
const prepared = await Cfg.prepareTunnel(TUNNEL_TLS, target, options, true);
|
|
21
20
|
await Output.spinner(TXT_OPENING_TUNNEL);
|
|
22
21
|
const agent = await ApiBuddy.register(false, Cfg.getTokenHost(), Cfg.getToken(), (region) => {
|
|
23
22
|
Cfg.setRegionIfNotSet(region);
|
package/src/format.js
CHANGED
package/src/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const commandVersion = require('./command/version.js');
|
|
|
11
11
|
const commandPre = require('./command/pre.js');
|
|
12
12
|
const stream = require('stream');
|
|
13
13
|
const { isDocker } = require('./utils');
|
|
14
|
+
const { DESC_PROGRAM } = require('./texts');
|
|
14
15
|
|
|
15
16
|
stream.setDefaultHighWaterMark(false, 67108864);
|
|
16
17
|
process.title = 'bdy';
|
|
@@ -20,6 +21,7 @@ process.on('uncaughtException', (err) => {
|
|
|
20
21
|
});
|
|
21
22
|
|
|
22
23
|
const program = new Command();
|
|
24
|
+
program.description(DESC_PROGRAM);
|
|
23
25
|
program.hook('preAction', commandPre);
|
|
24
26
|
program.addCommand(commandConfig);
|
|
25
27
|
program.addCommand(commandTcp);
|
package/src/logger.js
CHANGED
|
@@ -31,6 +31,7 @@ class Logger {
|
|
|
31
31
|
this.logPath = resolve(this.rootPath, 'cli.log');
|
|
32
32
|
this.log1Path = resolve(this.rootPath, 'cli.1.log');
|
|
33
33
|
this.logStream = fs.openSync(this.logPath, 'w');
|
|
34
|
+
fs.chmodSync(this.logPath, 0o666);
|
|
34
35
|
this.p = pino({
|
|
35
36
|
level: process.env.DEBUG === '1' ? 'debug' : 'info',
|
|
36
37
|
timestamp: () => `, "time": "${new Date().toISOString()}"`,
|
package/src/texts.js
CHANGED
|
@@ -98,7 +98,7 @@ const DESC_COMMAND_CONFIG_SET_WHITELIST = 'set default whitelist';
|
|
|
98
98
|
const DESC_COMMAND_CONFIG_ADD = 'add configuration';
|
|
99
99
|
const DESC_COMMAND_CONFIG_GET = 'get configuration';
|
|
100
100
|
const DESC_COMMAND_CONFIG_REMOVE = 'remove configuration';
|
|
101
|
-
const DESC_COMMAND_CONFIG_SET = '
|
|
101
|
+
const DESC_COMMAND_CONFIG_SET = 'Set configuration token/region/whitelist/timeout';
|
|
102
102
|
const DESC_COMMAND_AGENT_TUNNEL_HTTP = 'start HTTP tunnel in agent';
|
|
103
103
|
const DESC_COMMAND_AGENT_TUNNEL_LIST = 'list tunnels in agent';
|
|
104
104
|
const DESC_COMMAND_AGENT_TUNNEL_START = 'start tunnel in agent from config';
|
|
@@ -106,21 +106,22 @@ const DESC_COMMAND_AGENT_TUNNEL_STATUS = 'status of tunnel in agent';
|
|
|
106
106
|
const DESC_COMMAND_AGENT_TUNNEL_STOP = 'stop tunnel in agent';
|
|
107
107
|
const DESC_COMMAND_AGENT_TUNNEL_TCP = 'start TCP tunnel in agent';
|
|
108
108
|
const DESC_COMMAND_AGENT_TUNNEL_TLS = 'start TLS tunnel in agent';
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
const DESC_COMMAND_AGENT_START = '
|
|
112
|
-
const DESC_COMMAND_AGENT_RESTART = '
|
|
113
|
-
const DESC_COMMAND_AGENT_STATUS = '
|
|
114
|
-
const DESC_COMMAND_AGENT_STOP = '
|
|
115
|
-
const DESC_COMMAND_AGENT_TUNNEL = '
|
|
116
|
-
const DESC_COMMAND_AGENT_UPDATE = '
|
|
117
|
-
const DESC_COMMAND_AGENT_VERSION = '
|
|
118
|
-
const DESC_COMMAND_CONFIG = '
|
|
119
|
-
const DESC_COMMAND_HTTP = '
|
|
120
|
-
const DESC_COMMAND_AGENT = '
|
|
121
|
-
const DESC_COMMAND_START = '
|
|
122
|
-
const DESC_COMMAND_TCP = '
|
|
123
|
-
const DESC_COMMAND_TLS = '
|
|
109
|
+
const DESC_COMMAND_AGENT_UNINSTALL = 'Uninstall bdy service';
|
|
110
|
+
const DESC_COMMAND_AGENT_INSTALL = 'Install bdy as operating system service on Windows, OS X and Linux systems';
|
|
111
|
+
const DESC_COMMAND_AGENT_START = 'Starts agent and all tunnels from configuration file';
|
|
112
|
+
const DESC_COMMAND_AGENT_RESTART = 'Restarts agent and all tunnels';
|
|
113
|
+
const DESC_COMMAND_AGENT_STATUS = 'Show the status of Buddy agent';
|
|
114
|
+
const DESC_COMMAND_AGENT_STOP = 'Stops agent and all tunnels';
|
|
115
|
+
const DESC_COMMAND_AGENT_TUNNEL = 'Manage agent\'s tunnels';
|
|
116
|
+
const DESC_COMMAND_AGENT_UPDATE = 'Install a new version of Buddy agent';
|
|
117
|
+
const DESC_COMMAND_AGENT_VERSION = 'Show the currently installed version';
|
|
118
|
+
const DESC_COMMAND_CONFIG = 'The config command gives a quick way to create or update configuration file.';
|
|
119
|
+
const DESC_COMMAND_HTTP = 'Starts a tunnel listening for HTTP/HTTPS traffic with a specific hostname.';
|
|
120
|
+
const DESC_COMMAND_AGENT = 'The agent command manages installation and execution of bdy as an operating system service on Windows, OS X and Linux systems';
|
|
121
|
+
const DESC_COMMAND_START = 'Starts tunnel from the configuration file.';
|
|
122
|
+
const DESC_COMMAND_TCP = 'Starts a tunnel which forwards all TCP traffic on a public port to a local address. This is extremely useful for exposing services that run non-HTTP traffic (ssh, sip, rdp, game servers, etc).';
|
|
123
|
+
const DESC_COMMAND_TLS = 'Starts a tunnel listening for TLS traffic on port 443 with a specific hostname.';
|
|
124
|
+
const DESC_PROGRAM = 'Buddy exposes local networked services behinds NATs and firewalls to the public internet over a secure tunnel. Share local websites, build/test webhook consumers, and self-host personal services.';
|
|
124
125
|
|
|
125
126
|
const TXT_NEW_CLI_DOCKER_VERSION = (version) => `There is a new CLI Docker image version (${version})\n\n`;
|
|
126
127
|
const TXT_NEW_CLI_VERSION = (version) => `There is a new CLI version (${version})\n\n`;
|
|
@@ -297,6 +298,7 @@ module.exports = {
|
|
|
297
298
|
OPTION_USER,
|
|
298
299
|
OPTION_PASS,
|
|
299
300
|
OPTION_REGION,
|
|
301
|
+
DESC_PROGRAM,
|
|
300
302
|
DESC_COMMAND_TLS,
|
|
301
303
|
DESC_COMMAND_TCP,
|
|
302
304
|
DESC_COMMAND_START,
|
|
@@ -310,8 +312,8 @@ module.exports = {
|
|
|
310
312
|
DESC_COMMAND_AGENT_STATUS,
|
|
311
313
|
DESC_COMMAND_AGENT_START,
|
|
312
314
|
DESC_COMMAND_AGENT_RESTART,
|
|
313
|
-
|
|
314
|
-
|
|
315
|
+
DESC_COMMAND_AGENT_INSTALL,
|
|
316
|
+
DESC_COMMAND_AGENT_UNINSTALL,
|
|
315
317
|
DESC_COMMAND_AGENT_TUNNEL_TLS,
|
|
316
318
|
DESC_COMMAND_AGENT_TUNNEL_TCP,
|
|
317
319
|
DESC_COMMAND_AGENT_TUNNEL_STOP,
|
package/src/utils.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
const { resolve } = require('path');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
readFileSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
existsSync,
|
|
7
|
+
chmodSync
|
|
8
|
+
} = require('fs');
|
|
4
9
|
const { homedir } = require('os');
|
|
5
10
|
const os = require('os');
|
|
6
11
|
const { ERR_FETCH_VERSION } = require('./texts.js');
|
|
7
12
|
const { Command } = require('commander');
|
|
8
|
-
const {
|
|
13
|
+
const {
|
|
14
|
+
getAsset,
|
|
15
|
+
isSea
|
|
16
|
+
} = require('node:sea');
|
|
9
17
|
const Ssh2 = require('ssh2');
|
|
10
18
|
const {
|
|
11
19
|
OPTION_REGION,
|
|
@@ -138,7 +146,7 @@ const SOCKET_IO_EVENT_FETCH_FAILED = 'fetch failed';
|
|
|
138
146
|
const SOCKET_IO_EVENT_AGENT = 'agent';
|
|
139
147
|
const SOCKET_IO_EVENT_TUNNEL = 'tunnel';
|
|
140
148
|
|
|
141
|
-
function apiErrorCodeToClass
|
|
149
|
+
function apiErrorCodeToClass(code, host) {
|
|
142
150
|
if (code === 234000) {
|
|
143
151
|
return new ApiErrorAgentNotFound();
|
|
144
152
|
}
|
|
@@ -165,16 +173,19 @@ class ApiErrorAgentNotFound extends Error {
|
|
|
165
173
|
super(ERR_AGENT_REMOVED);
|
|
166
174
|
}
|
|
167
175
|
}
|
|
176
|
+
|
|
168
177
|
class ApiErrorFailedToConnect extends Error {
|
|
169
178
|
constructor(host) {
|
|
170
179
|
super(ERR_FAILED_TO_CONNECT(host));
|
|
171
180
|
}
|
|
172
181
|
}
|
|
182
|
+
|
|
173
183
|
class ApiErrorWrongToken extends Error {
|
|
174
184
|
constructor() {
|
|
175
185
|
super(ERR_WRONG_TOKEN);
|
|
176
186
|
}
|
|
177
187
|
}
|
|
188
|
+
|
|
178
189
|
class ApiErrorSubdomainTaken extends Error {
|
|
179
190
|
constructor() {
|
|
180
191
|
super(ERR_SUBDOMAIN_TAKEN);
|
|
@@ -236,7 +247,10 @@ const getHomeDirectory = () => {
|
|
|
236
247
|
if (isDocker()) return '/buddy';
|
|
237
248
|
const r = homedir();
|
|
238
249
|
const p = path.join(r, '.bdy');
|
|
239
|
-
if (!existsSync(p))
|
|
250
|
+
if (!existsSync(p)) {
|
|
251
|
+
mkdirSync(p, { recursive: true });
|
|
252
|
+
chmodSync(p, 0o777);
|
|
253
|
+
}
|
|
240
254
|
return p;
|
|
241
255
|
};
|
|
242
256
|
|