bdy 1.11.0-dev → 1.12.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 +16 -5
- package/distTs/src/agent/agent.js +62 -36
- package/distTs/src/agent/linux.js +9 -4
- package/distTs/src/agent/manager.js +61 -42
- package/distTs/src/agent/osx.js +12 -5
- package/distTs/src/agent/socket/client.js +26 -7
- package/distTs/src/agent/socket/tunnel.js +56 -32
- package/distTs/src/agent/socket.js +83 -63
- package/distTs/src/agent/system.js +3 -1
- package/distTs/src/agent/windows.js +6 -6
- package/distTs/src/command/agent/install.js +4 -4
- package/distTs/src/command/agent/run.js +2 -2
- package/distTs/src/command/agent/status.js +6 -7
- package/distTs/src/command/agent/tunnel/http.js +4 -5
- package/distTs/src/command/agent/tunnel/tcp.js +3 -3
- package/distTs/src/command/agent/tunnel/tls.js +3 -3
- package/distTs/src/command/config/add/http.js +3 -3
- package/distTs/src/command/config/add/tcp.js +3 -3
- package/distTs/src/command/config/add/tls.js +3 -3
- package/distTs/src/command/config/get/region.js +1 -1
- package/distTs/src/command/pre.js +1 -1
- package/distTs/src/command/tunnel/http.js +2 -1
- package/distTs/src/command/tunnel/tcp.js +3 -3
- package/distTs/src/command/tunnel/tls.js +4 -4
- package/distTs/src/format.js +14 -15
- package/distTs/src/index.js +1 -1
- package/distTs/src/input.js +13 -12
- package/distTs/src/logger.js +12 -13
- package/distTs/src/tunnel/agent.js +3 -1
- package/distTs/src/tunnel/api/agent.js +1 -0
- package/distTs/src/tunnel/api/buddy.js +2 -0
- package/distTs/src/tunnel/cfg.js +6 -2
- package/distTs/src/tunnel/compression.js +17 -14
- package/distTs/src/tunnel/dns.js +20 -29
- package/distTs/src/tunnel/html.js +2 -0
- package/distTs/src/tunnel/http/log.js +30 -8
- package/distTs/src/tunnel/http/serve.js +3 -2
- package/distTs/src/tunnel/http/stream.js +5 -1
- package/distTs/src/tunnel/http.js +67 -26
- package/distTs/src/tunnel/identification.js +21 -14
- package/distTs/src/tunnel/latency.js +19 -11
- package/distTs/src/tunnel/output/interactive/tunnel.js +16 -9
- package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +4 -2
- package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +6 -4
- package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +2 -0
- package/distTs/src/tunnel/output/noninteractive/tunnel.js +13 -11
- package/distTs/src/tunnel/server/cert.js +2 -0
- package/distTs/src/tunnel/server/http1.js +15 -10
- package/distTs/src/tunnel/server/http2.js +18 -12
- package/distTs/src/tunnel/server/sftp.js +32 -15
- package/distTs/src/tunnel/server/ssh.js +49 -31
- package/distTs/src/tunnel/server/tls.js +11 -5
- package/distTs/src/tunnel/ssh/client.js +45 -31
- package/distTs/src/tunnel/tcp.js +61 -42
- package/distTs/src/tunnel/tunnel.js +196 -112
- package/distTs/src/types/tunnel.js +135 -0
- package/distTs/src/utils.js +2 -87
- package/package.json +16 -5
|
@@ -8,10 +8,10 @@ const output_1 = __importDefault(require("../../../output"));
|
|
|
8
8
|
const cfg_1 = __importDefault(require("../../../tunnel/cfg"));
|
|
9
9
|
const texts_1 = require("../../../texts");
|
|
10
10
|
const manager_1 = __importDefault(require("../../../agent/manager"));
|
|
11
|
-
const utils_2 = require("../../../utils");
|
|
12
11
|
const tunnel_1 = __importDefault(require("../../../agent/socket/tunnel"));
|
|
13
12
|
const agent_1 = __importDefault(require("../../../tunnel/api/agent"));
|
|
14
|
-
const
|
|
13
|
+
const tunnel_2 = require("../../../types/tunnel");
|
|
14
|
+
const commandAgentTunnelTcp = (0, utils_1.getBasicCommandTcp)();
|
|
15
15
|
commandAgentTunnelTcp.description(texts_1.DESC_COMMAND_TCP);
|
|
16
16
|
commandAgentTunnelTcp.option('-f, --follow', texts_1.OPTION_FOLLOW);
|
|
17
17
|
commandAgentTunnelTcp.argument('[host:port]', texts_1.OPTION_TARGET);
|
|
@@ -20,7 +20,7 @@ commandAgentTunnelTcp.action(async (target, options) => {
|
|
|
20
20
|
if (!isEnabled) {
|
|
21
21
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_ENABLED);
|
|
22
22
|
}
|
|
23
|
-
const prepared = await cfg_1.default.prepareTunnel(
|
|
23
|
+
const prepared = await cfg_1.default.prepareTunnel(tunnel_2.TUNNEL_TYPE.TCP, target, options, true);
|
|
24
24
|
try {
|
|
25
25
|
await output_1.default.spinner(texts_1.TXT_OPENING_TUNNEL);
|
|
26
26
|
const json = manager_1.default.system.loadSystemConfig();
|
|
@@ -9,9 +9,9 @@ const cfg_1 = __importDefault(require("../../../tunnel/cfg"));
|
|
|
9
9
|
const texts_1 = require("../../../texts");
|
|
10
10
|
const tunnel_1 = __importDefault(require("../../../agent/socket/tunnel"));
|
|
11
11
|
const manager_1 = __importDefault(require("../../../agent/manager"));
|
|
12
|
-
const utils_2 = require("../../../utils");
|
|
13
12
|
const agent_1 = __importDefault(require("../../../tunnel/api/agent"));
|
|
14
|
-
const
|
|
13
|
+
const tunnel_2 = require("../../../types/tunnel");
|
|
14
|
+
const commandAgentTunnelTls = (0, utils_1.getBasicCommandTls)();
|
|
15
15
|
commandAgentTunnelTls.description(texts_1.DESC_COMMAND_TLS);
|
|
16
16
|
commandAgentTunnelTls.option('-f, --follow', texts_1.OPTION_FOLLOW);
|
|
17
17
|
commandAgentTunnelTls.argument('[host:port]', texts_1.OPTION_TARGET);
|
|
@@ -20,7 +20,7 @@ commandAgentTunnelTls.action(async (target, options) => {
|
|
|
20
20
|
if (!isEnabled) {
|
|
21
21
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_ENABLED);
|
|
22
22
|
}
|
|
23
|
-
const prepared = await cfg_1.default.prepareTunnel(
|
|
23
|
+
const prepared = await cfg_1.default.prepareTunnel(tunnel_2.TUNNEL_TYPE.TLS, target, options, true);
|
|
24
24
|
try {
|
|
25
25
|
await output_1.default.spinner(texts_1.TXT_OPENING_TUNNEL);
|
|
26
26
|
const json = manager_1.default.system.loadSystemConfig();
|
|
@@ -8,8 +8,8 @@ const input_1 = __importDefault(require("../../../input"));
|
|
|
8
8
|
const cfg_1 = __importDefault(require("../../../tunnel/cfg"));
|
|
9
9
|
const output_1 = __importDefault(require("../../../output"));
|
|
10
10
|
const texts_1 = require("../../../texts");
|
|
11
|
-
const
|
|
12
|
-
const commandConfigAddHttp = (0,
|
|
11
|
+
const tunnel_1 = require("../../../types/tunnel");
|
|
12
|
+
const commandConfigAddHttp = (0, utils_1.getBasicCommandHttp)();
|
|
13
13
|
commandConfigAddHttp.description(texts_1.DESC_COMMAND_CONFIG_ADD_HTTP);
|
|
14
14
|
commandConfigAddHttp.option('-f, --force', texts_1.OPTION_FORCE);
|
|
15
15
|
commandConfigAddHttp.argument('<name>', texts_1.OPTION_NAME);
|
|
@@ -19,7 +19,7 @@ commandConfigAddHttp.action(async (n, target, options) => {
|
|
|
19
19
|
if (cfg_1.default.hasTunnel(name) && !options.force) {
|
|
20
20
|
output_1.default.exitError(texts_1.ERR_TUNNEL_ALREADY_EXISTS);
|
|
21
21
|
}
|
|
22
|
-
await cfg_1.default.addTunnel(name,
|
|
22
|
+
await cfg_1.default.addTunnel(name, tunnel_1.TUNNEL_TYPE.HTTP, target, options);
|
|
23
23
|
output_1.default.exitSuccess(texts_1.TXT_TUNNEL_ADDED);
|
|
24
24
|
});
|
|
25
25
|
exports.default = commandConfigAddHttp;
|
|
@@ -8,8 +8,8 @@ const input_1 = __importDefault(require("../../../input"));
|
|
|
8
8
|
const cfg_1 = __importDefault(require("../../../tunnel/cfg"));
|
|
9
9
|
const output_1 = __importDefault(require("../../../output"));
|
|
10
10
|
const texts_1 = require("../../../texts");
|
|
11
|
-
const
|
|
12
|
-
const commandConfigAddTcp = (0,
|
|
11
|
+
const tunnel_1 = require("../../../types/tunnel");
|
|
12
|
+
const commandConfigAddTcp = (0, utils_1.getBasicCommandTcp)();
|
|
13
13
|
commandConfigAddTcp.description(texts_1.DESC_COMMAND_CONFIG_ADD_TCP);
|
|
14
14
|
commandConfigAddTcp.option('-f, --force', texts_1.OPTION_FORCE);
|
|
15
15
|
commandConfigAddTcp.argument('<name>', texts_1.OPTION_NAME);
|
|
@@ -19,7 +19,7 @@ commandConfigAddTcp.action(async (n, target, options) => {
|
|
|
19
19
|
if (cfg_1.default.hasTunnel(name) && !options.force) {
|
|
20
20
|
output_1.default.exitError(texts_1.ERR_TUNNEL_ALREADY_EXISTS);
|
|
21
21
|
}
|
|
22
|
-
await cfg_1.default.addTunnel(name,
|
|
22
|
+
await cfg_1.default.addTunnel(name, tunnel_1.TUNNEL_TYPE.TCP, target, options);
|
|
23
23
|
output_1.default.exitSuccess(texts_1.TXT_TUNNEL_ADDED);
|
|
24
24
|
});
|
|
25
25
|
exports.default = commandConfigAddTcp;
|
|
@@ -8,8 +8,8 @@ const input_1 = __importDefault(require("../../../input"));
|
|
|
8
8
|
const cfg_1 = __importDefault(require("../../../tunnel/cfg"));
|
|
9
9
|
const output_1 = __importDefault(require("../../../output"));
|
|
10
10
|
const texts_1 = require("../../../texts");
|
|
11
|
-
const
|
|
12
|
-
const commandConfigAddTls = (0,
|
|
11
|
+
const tunnel_1 = require("../../../types/tunnel");
|
|
12
|
+
const commandConfigAddTls = (0, utils_1.getBasicCommandTls)();
|
|
13
13
|
commandConfigAddTls.description(texts_1.DESC_COMMAND_CONFIG_ADD_TLS);
|
|
14
14
|
commandConfigAddTls.option('-f, --force', texts_1.OPTION_FORCE);
|
|
15
15
|
commandConfigAddTls.argument('<name>', texts_1.OPTION_NAME);
|
|
@@ -19,7 +19,7 @@ commandConfigAddTls.action(async (n, target, options) => {
|
|
|
19
19
|
if (cfg_1.default.hasTunnel(name) && !options.force) {
|
|
20
20
|
output_1.default.exitError(texts_1.ERR_TUNNEL_ALREADY_EXISTS);
|
|
21
21
|
}
|
|
22
|
-
await cfg_1.default.addTunnel(name,
|
|
22
|
+
await cfg_1.default.addTunnel(name, tunnel_1.TUNNEL_TYPE.TLS, target, options);
|
|
23
23
|
output_1.default.exitSuccess(texts_1.TXT_TUNNEL_ADDED);
|
|
24
24
|
});
|
|
25
25
|
exports.default = commandConfigAddTls;
|
|
@@ -12,4 +12,4 @@ const commandConfigGetRegion = (0, utils_1.newCommand)('region', texts_1.DESC_CO
|
|
|
12
12
|
commandConfigGetRegion.action(() => {
|
|
13
13
|
output_1.default.exitNormal(format_1.default.region(cfg_1.default.getRegion()));
|
|
14
14
|
});
|
|
15
|
-
|
|
15
|
+
exports.default = commandConfigGetRegion;
|
|
@@ -43,7 +43,7 @@ const commandPre = async (_, command) => {
|
|
|
43
43
|
output_1.default.newCliVersion(command.latestVersion);
|
|
44
44
|
}
|
|
45
45
|
else if (newAgent) {
|
|
46
|
-
output_1.default.newAgentVersion(
|
|
46
|
+
output_1.default.newAgentVersion();
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
exports.default = commandPre;
|
|
@@ -8,6 +8,7 @@ const cfg_1 = __importDefault(require("../../tunnel/cfg"));
|
|
|
8
8
|
const output_1 = __importDefault(require("../../output"));
|
|
9
9
|
const texts_1 = require("../../texts");
|
|
10
10
|
const buddy_1 = __importDefault(require("../../tunnel/api/buddy"));
|
|
11
|
+
const tunnel_1 = require("../../types/tunnel");
|
|
11
12
|
const commandHttp = (0, utils_1.getBasicCommandHttp)();
|
|
12
13
|
commandHttp.description(texts_1.DESC_COMMAND_HTTP);
|
|
13
14
|
commandHttp.option('-s, --serve <directory>', texts_1.OPTION_SERVE);
|
|
@@ -16,7 +17,7 @@ commandHttp.argument('[protocol://host:port]', texts_1.OPTION_TARGET);
|
|
|
16
17
|
commandHttp.action(async (target, options) => {
|
|
17
18
|
if (options.token)
|
|
18
19
|
cfg_1.default.setToken(options.token);
|
|
19
|
-
const prepared = await cfg_1.default.prepareTunnel(
|
|
20
|
+
const prepared = await cfg_1.default.prepareTunnel(tunnel_1.TUNNEL_TYPE.HTTP, target, options, true);
|
|
20
21
|
await output_1.default.spinner(texts_1.TXT_OPENING_TUNNEL);
|
|
21
22
|
const agent = await buddy_1.default.register(false, false, cfg_1.default.getTokenHost(), cfg_1.default.getToken(), (region) => {
|
|
22
23
|
cfg_1.default.setRegionIfNotSet(region);
|
|
@@ -7,16 +7,16 @@ const utils_1 = require("../../utils");
|
|
|
7
7
|
const cfg_1 = __importDefault(require("../../tunnel/cfg"));
|
|
8
8
|
const output_1 = __importDefault(require("../../output"));
|
|
9
9
|
const texts_1 = require("../../texts");
|
|
10
|
-
const utils_2 = require("../../utils");
|
|
11
10
|
const buddy_1 = __importDefault(require("../../tunnel/api/buddy"));
|
|
12
|
-
const
|
|
11
|
+
const tunnel_1 = require("../../types/tunnel");
|
|
12
|
+
const commandTcp = (0, utils_1.getBasicCommandTcp)();
|
|
13
13
|
commandTcp.description(texts_1.DESC_COMMAND_TCP);
|
|
14
14
|
commandTcp.option('--token <token>', texts_1.OPTION_TOKEN);
|
|
15
15
|
commandTcp.argument('[host:port]', texts_1.OPTION_TARGET);
|
|
16
16
|
commandTcp.action(async (target, options) => {
|
|
17
17
|
if (options.token)
|
|
18
18
|
cfg_1.default.setToken(options.token);
|
|
19
|
-
const prepared = await cfg_1.default.prepareTunnel(
|
|
19
|
+
const prepared = await cfg_1.default.prepareTunnel(tunnel_1.TUNNEL_TYPE.TCP, target, options, true);
|
|
20
20
|
await output_1.default.spinner(texts_1.TXT_OPENING_TUNNEL);
|
|
21
21
|
const agent = await buddy_1.default.register(false, false, cfg_1.default.getTokenHost(), cfg_1.default.getToken(), (region) => {
|
|
22
22
|
cfg_1.default.setRegionIfNotSet(region);
|
|
@@ -7,18 +7,18 @@ const utils_1 = require("../../utils");
|
|
|
7
7
|
const cfg_1 = __importDefault(require("../../tunnel/cfg"));
|
|
8
8
|
const output_1 = __importDefault(require("../../output"));
|
|
9
9
|
const texts_1 = require("../../texts");
|
|
10
|
-
const utils_2 = require("../../utils");
|
|
11
10
|
const buddy_1 = __importDefault(require("../../tunnel/api/buddy"));
|
|
12
|
-
const
|
|
11
|
+
const tunnel_1 = require("../../types/tunnel");
|
|
12
|
+
const commandTls = (0, utils_1.getBasicCommandTls)();
|
|
13
13
|
commandTls.description(texts_1.DESC_COMMAND_TLS);
|
|
14
14
|
commandTls.option('--token <token>', texts_1.OPTION_TOKEN);
|
|
15
15
|
commandTls.argument('[host:port]', texts_1.OPTION_TARGET);
|
|
16
16
|
commandTls.action(async (target, options) => {
|
|
17
17
|
if (options.token)
|
|
18
18
|
cfg_1.default.setToken(options.token);
|
|
19
|
-
const prepared = await cfg_1.default.prepareTunnel(
|
|
19
|
+
const prepared = await cfg_1.default.prepareTunnel(tunnel_1.TUNNEL_TYPE.TLS, target, options, true);
|
|
20
20
|
await output_1.default.spinner(texts_1.TXT_OPENING_TUNNEL);
|
|
21
|
-
const agent = await buddy_1.default.register(false, cfg_1.default.getTokenHost(), cfg_1.default.getToken(), (region) => {
|
|
21
|
+
const agent = await buddy_1.default.register(false, false, cfg_1.default.getTokenHost(), cfg_1.default.getToken(), (region) => {
|
|
22
22
|
cfg_1.default.setRegionIfNotSet(region);
|
|
23
23
|
});
|
|
24
24
|
await agent.start();
|
package/distTs/src/format.js
CHANGED
|
@@ -4,7 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
-
const
|
|
7
|
+
const punycode_1 = __importDefault(require("punycode/"));
|
|
8
|
+
const tunnel_1 = require("./types/tunnel");
|
|
8
9
|
class Format {
|
|
9
10
|
static date() {
|
|
10
11
|
const dt = new Date();
|
|
@@ -66,14 +67,14 @@ class Format {
|
|
|
66
67
|
return this.region(region);
|
|
67
68
|
}
|
|
68
69
|
static identify(identifyType) {
|
|
69
|
-
if (identifyType ===
|
|
70
|
+
if (identifyType === tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP1)
|
|
70
71
|
return 'Ver. 1.1';
|
|
71
72
|
return 'Ver. 2';
|
|
72
73
|
}
|
|
73
74
|
static terminate(terminate) {
|
|
74
|
-
if (terminate ===
|
|
75
|
+
if (terminate === tunnel_1.TUNNEL_TERMINATE_AT.AGENT)
|
|
75
76
|
return 'AGENT';
|
|
76
|
-
if (terminate ===
|
|
77
|
+
if (terminate === tunnel_1.TUNNEL_TERMINATE_AT.REGION)
|
|
77
78
|
return 'REGION';
|
|
78
79
|
return 'TARGET';
|
|
79
80
|
}
|
|
@@ -105,32 +106,30 @@ class Format {
|
|
|
105
106
|
static entryHost(tunnel) {
|
|
106
107
|
let host = '';
|
|
107
108
|
host += tunnel.subdomain;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
host += tunnel.sshId;
|
|
113
|
-
}
|
|
109
|
+
host += '.';
|
|
110
|
+
host += (tunnel.region || '').toLowerCase();
|
|
111
|
+
host += '-';
|
|
112
|
+
host += tunnel.sshId;
|
|
114
113
|
host += '.';
|
|
115
114
|
host += tunnel.domain;
|
|
116
115
|
return host;
|
|
117
116
|
}
|
|
118
117
|
static entryHostEncoded(tunnel) {
|
|
119
|
-
return
|
|
118
|
+
return punycode_1.default.toASCII(this.entryHost(tunnel));
|
|
120
119
|
}
|
|
121
120
|
static entry(tunnel) {
|
|
122
121
|
let entry = '';
|
|
123
|
-
if (tunnel.type ===
|
|
122
|
+
if (tunnel.type === tunnel_1.TUNNEL_TYPE.HTTP)
|
|
124
123
|
entry += 'https://';
|
|
125
124
|
entry += this.entryHost(tunnel);
|
|
126
|
-
if (tunnel.type ===
|
|
125
|
+
if (tunnel.type === tunnel_1.TUNNEL_TYPE.TCP)
|
|
127
126
|
entry += `:${tunnel.sshForwardPort}`;
|
|
128
|
-
else if (tunnel.type ===
|
|
127
|
+
else if (tunnel.type === tunnel_1.TUNNEL_TYPE.TLS)
|
|
129
128
|
entry += ':443';
|
|
130
129
|
return entry;
|
|
131
130
|
}
|
|
132
131
|
static target(type, target) {
|
|
133
|
-
if (type ===
|
|
132
|
+
if (type === tunnel_1.TUNNEL_TYPE.HTTP) {
|
|
134
133
|
let port = '80';
|
|
135
134
|
let host = 'localhost';
|
|
136
135
|
let proto = 'http';
|
package/distTs/src/index.js
CHANGED
|
@@ -20,7 +20,7 @@ process.on('uncaughtException', (err) => {
|
|
|
20
20
|
logger_1.default.fatal(err);
|
|
21
21
|
output_1.default.exitError(err);
|
|
22
22
|
});
|
|
23
|
-
const program = (0, utils_1.newCommand)(
|
|
23
|
+
const program = (0, utils_1.newCommand)('', texts_1.DESC_PROGRAM);
|
|
24
24
|
program.hook('preAction', pre_1.default);
|
|
25
25
|
program.configureHelp({
|
|
26
26
|
formatHelp: utils_1.formatHelp,
|
package/distTs/src/input.js
CHANGED
|
@@ -28,12 +28,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const output_1 = __importDefault(require("./output"));
|
|
30
30
|
const netmask_1 = __importDefault(require("netmask"));
|
|
31
|
-
const
|
|
31
|
+
const punycode_1 = __importDefault(require("punycode/"));
|
|
32
32
|
const fs_1 = __importStar(require("fs"));
|
|
33
33
|
const tls_1 = __importDefault(require("tls"));
|
|
34
34
|
const crypto_1 = __importDefault(require("crypto"));
|
|
35
35
|
const utils_1 = require("./utils");
|
|
36
36
|
const texts_1 = require("./texts");
|
|
37
|
+
const tunnel_1 = require("./types/tunnel");
|
|
37
38
|
class Input {
|
|
38
39
|
static timeout(timeout) {
|
|
39
40
|
const t = parseInt(timeout, 10);
|
|
@@ -131,20 +132,18 @@ class Input {
|
|
|
131
132
|
if (!region)
|
|
132
133
|
output_1.default.exitError((0, texts_1.ERR_REGION_IS_NOT_VALID)(''));
|
|
133
134
|
region = region.toUpperCase();
|
|
134
|
-
|
|
135
|
+
const vals = Object.values(tunnel_1.TUNNEL_REGION);
|
|
136
|
+
if (!vals.includes(region)) {
|
|
135
137
|
output_1.default.exitError((0, texts_1.ERR_REGION_IS_NOT_VALID)(region));
|
|
136
138
|
}
|
|
137
139
|
return region;
|
|
138
140
|
}
|
|
139
141
|
static terminate(terminate) {
|
|
140
142
|
if (!terminate)
|
|
141
|
-
return
|
|
143
|
+
return tunnel_1.TUNNEL_TERMINATE_AT.REGION;
|
|
142
144
|
terminate = terminate.toUpperCase();
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
utils_1.TLS_TERMINATE_AT_REGION,
|
|
146
|
-
utils_1.TLS_TERMINATE_AT_TARGET,
|
|
147
|
-
].includes(terminate)) {
|
|
145
|
+
const vals = Object.values(tunnel_1.TUNNEL_TERMINATE_AT);
|
|
146
|
+
if (!vals.includes(terminate)) {
|
|
148
147
|
output_1.default.exitError((0, texts_1.ERR_TERMINATE_IS_NOT_VALID)(terminate));
|
|
149
148
|
}
|
|
150
149
|
return terminate;
|
|
@@ -164,7 +163,8 @@ class Input {
|
|
|
164
163
|
// http://user:pass@localhost
|
|
165
164
|
// http://user:pass@localhost:80
|
|
166
165
|
let port;
|
|
167
|
-
|
|
166
|
+
const types = [tunnel_1.TUNNEL_TYPE.TCP, tunnel_1.TUNNEL_TYPE.TLS];
|
|
167
|
+
if (types.includes(type)) {
|
|
168
168
|
const m = target.match(utils_1.TARGET_TCP_TLS_REGEX);
|
|
169
169
|
if (!m) {
|
|
170
170
|
output_1.default.exitError((0, texts_1.ERR_TARGET_IS_NOT_VALID)(target));
|
|
@@ -197,7 +197,7 @@ class Input {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
Input.port(port);
|
|
200
|
-
return
|
|
200
|
+
return punycode_1.default.toUnicode(target);
|
|
201
201
|
}
|
|
202
202
|
static port(port) {
|
|
203
203
|
const p = parseInt(port, 10);
|
|
@@ -207,9 +207,10 @@ class Input {
|
|
|
207
207
|
}
|
|
208
208
|
static type(type) {
|
|
209
209
|
if (!type)
|
|
210
|
-
return
|
|
210
|
+
return tunnel_1.TUNNEL_TYPE.TCP;
|
|
211
211
|
type = type.toUpperCase();
|
|
212
|
-
|
|
212
|
+
const vals = [tunnel_1.TUNNEL_TYPE.HTTP, tunnel_1.TUNNEL_TYPE.TLS, tunnel_1.TUNNEL_TYPE.TCP];
|
|
213
|
+
if (!vals.includes(type)) {
|
|
213
214
|
output_1.default.exitError((0, texts_1.ERR_TYPE_IS_NOT_VALID)(type));
|
|
214
215
|
}
|
|
215
216
|
return type;
|
package/distTs/src/logger.js
CHANGED
|
@@ -8,7 +8,7 @@ const path_1 = require("path");
|
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
10
|
class Logger {
|
|
11
|
-
rootPath
|
|
11
|
+
rootPath;
|
|
12
12
|
logPath = null;
|
|
13
13
|
log1Path = null;
|
|
14
14
|
logStream = null;
|
|
@@ -18,6 +18,8 @@ class Logger {
|
|
|
18
18
|
this.rootPath = (0, utils_1.getHomeDirectory)();
|
|
19
19
|
}
|
|
20
20
|
checkLogSize() {
|
|
21
|
+
if (!this.logPath || !this.log1Path)
|
|
22
|
+
return;
|
|
21
23
|
try {
|
|
22
24
|
const s = fs_1.default.statSync(this.logPath);
|
|
23
25
|
if (s.size > 5242880) {
|
|
@@ -57,20 +59,17 @@ class Logger {
|
|
|
57
59
|
}
|
|
58
60
|
return this.p;
|
|
59
61
|
}
|
|
60
|
-
error(...args) {
|
|
61
|
-
this.getPino().error(...args);
|
|
62
|
+
error(obj, ...args) {
|
|
63
|
+
this.getPino().error(obj, ...args);
|
|
62
64
|
}
|
|
63
|
-
info(...args) {
|
|
64
|
-
this.getPino().info(...args);
|
|
65
|
+
info(obj, ...args) {
|
|
66
|
+
this.getPino().info(obj, ...args);
|
|
65
67
|
}
|
|
66
|
-
debug(...args) {
|
|
67
|
-
this.getPino().debug(...args);
|
|
68
|
+
debug(obj, ...args) {
|
|
69
|
+
this.getPino().debug(obj, ...args);
|
|
68
70
|
}
|
|
69
|
-
|
|
70
|
-
this.getPino().
|
|
71
|
-
}
|
|
72
|
-
fatal(...args) {
|
|
73
|
-
this.getPino().fatal(...args);
|
|
71
|
+
fatal(obj, ...args) {
|
|
72
|
+
this.getPino().fatal(obj, ...args);
|
|
74
73
|
}
|
|
75
74
|
stack() {
|
|
76
75
|
this.getPino().info(new Error().stack);
|
|
@@ -82,7 +81,7 @@ class Logger {
|
|
|
82
81
|
}
|
|
83
82
|
if (this.logStream) {
|
|
84
83
|
try {
|
|
85
|
-
this.logStream
|
|
84
|
+
fs_1.default.closeSync(this.logStream);
|
|
86
85
|
}
|
|
87
86
|
catch {
|
|
88
87
|
// do nothing
|
|
@@ -11,6 +11,9 @@ const texts_1 = require("../texts");
|
|
|
11
11
|
const CONNECTION_TIMEOUT = 5000;
|
|
12
12
|
const STREAM_LIMIT = 10;
|
|
13
13
|
class TunnelAgent {
|
|
14
|
+
static httpAgent1;
|
|
15
|
+
static httpsAgent1;
|
|
16
|
+
static http2Clients;
|
|
14
17
|
static getHttp1() {
|
|
15
18
|
if (!this.httpAgent1) {
|
|
16
19
|
this.httpAgent1 = new http_1.default.Agent({
|
|
@@ -40,7 +43,6 @@ class TunnelAgent {
|
|
|
40
43
|
const client = http2_1.default.connect(authority, {
|
|
41
44
|
rejectUnauthorized: verify,
|
|
42
45
|
maxSessionMemory: 100,
|
|
43
|
-
noDelay: true,
|
|
44
46
|
servername,
|
|
45
47
|
});
|
|
46
48
|
client.once('close', () => {
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ApiBuddyClass = void 0;
|
|
6
7
|
const https_1 = require("https");
|
|
7
8
|
const tunnel_1 = __importDefault(require("../tunnel"));
|
|
8
9
|
const logger_1 = __importDefault(require("../../logger"));
|
|
@@ -135,5 +136,6 @@ class ApiBuddyClass {
|
|
|
135
136
|
return makeRequest('https://es.buddy.works', '/ip', null, 'GET', false);
|
|
136
137
|
}
|
|
137
138
|
}
|
|
139
|
+
exports.ApiBuddyClass = ApiBuddyClass;
|
|
138
140
|
const ApiBuddy = new ApiBuddyClass();
|
|
139
141
|
exports.default = ApiBuddy;
|
package/distTs/src/tunnel/cfg.js
CHANGED
|
@@ -9,7 +9,11 @@ const jsonwebtoken_1 = require("jsonwebtoken");
|
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
10
|
const input_1 = __importDefault(require("../input"));
|
|
11
11
|
const texts_1 = require("../texts");
|
|
12
|
+
const tunnel_1 = require("../types/tunnel");
|
|
12
13
|
class Cfg {
|
|
14
|
+
dir;
|
|
15
|
+
file;
|
|
16
|
+
json;
|
|
13
17
|
constructor() {
|
|
14
18
|
this.dir = (0, utils_1.getHomeDirectory)();
|
|
15
19
|
this.file = (0, path_1.resolve)(this.dir, 'cfg.json');
|
|
@@ -85,7 +89,7 @@ class Cfg {
|
|
|
85
89
|
tunnel.timeout = input_1.default.timeout(options.timeout);
|
|
86
90
|
else if (useDefaults)
|
|
87
91
|
tunnel.timeout = this.getTimeout();
|
|
88
|
-
if (type ===
|
|
92
|
+
if (type === tunnel_1.TUNNEL_TYPE.HTTP) {
|
|
89
93
|
if (options.host !== undefined)
|
|
90
94
|
tunnel.host = options.host;
|
|
91
95
|
if (options.auth !== undefined) {
|
|
@@ -110,7 +114,7 @@ class Cfg {
|
|
|
110
114
|
tunnel.http2 = !!options.http2;
|
|
111
115
|
tunnel.compression = !!options.compression;
|
|
112
116
|
}
|
|
113
|
-
else if (type ===
|
|
117
|
+
else if (type === tunnel_1.TUNNEL_TYPE.TLS) {
|
|
114
118
|
tunnel.terminate = input_1.default.terminate(options.terminate);
|
|
115
119
|
if (options.key !== undefined || options.cert !== undefined) {
|
|
116
120
|
const { key, cert } = input_1.default.keyCert(options.key, options.cert);
|
|
@@ -7,31 +7,34 @@ const zlib_1 = __importDefault(require("zlib"));
|
|
|
7
7
|
const mime_db_1 = __importDefault(require("mime-db"));
|
|
8
8
|
const accept_negotiator_1 = require("@fastify/accept-negotiator");
|
|
9
9
|
const stream_1 = __importDefault(require("stream"));
|
|
10
|
-
const
|
|
10
|
+
const tunnel_1 = require("../types/tunnel");
|
|
11
11
|
class TunnelCompression {
|
|
12
12
|
static detect(canCompress, reqHeaders, resHeaders) {
|
|
13
|
-
if (!canCompress || resHeaders['content-encoding'])
|
|
14
|
-
return
|
|
15
|
-
|
|
13
|
+
if (!canCompress || resHeaders['content-encoding']) {
|
|
14
|
+
return tunnel_1.TUNNEL_COMPRESSION_METHOD.IDENTITY; // already compressed
|
|
15
|
+
}
|
|
16
|
+
const contentType = (resHeaders['content-type'] || 'application/json');
|
|
16
17
|
const mimeData = mime_db_1.default[contentType.split(';', 1)[0].trim().toLowerCase()];
|
|
17
|
-
if (!mimeData || !mimeData.compressible)
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
if (!mimeData || !mimeData.compressible) {
|
|
19
|
+
return tunnel_1.TUNNEL_COMPRESSION_METHOD.IDENTITY;
|
|
20
|
+
}
|
|
21
|
+
const acceptEncoding = (reqHeaders['accept-encoding'] || '');
|
|
22
|
+
const encoding = (0, accept_negotiator_1.negotiate)(acceptEncoding, [
|
|
23
|
+
tunnel_1.TUNNEL_COMPRESSION_METHOD.BR,
|
|
24
|
+
tunnel_1.TUNNEL_COMPRESSION_METHOD.GZIP,
|
|
25
|
+
tunnel_1.TUNNEL_COMPRESSION_METHOD.DEFLATE,
|
|
23
26
|
]);
|
|
24
27
|
if (!encoding)
|
|
25
|
-
return
|
|
28
|
+
return tunnel_1.TUNNEL_COMPRESSION_METHOD.IDENTITY;
|
|
26
29
|
return encoding;
|
|
27
30
|
}
|
|
28
31
|
static compress(method) {
|
|
29
32
|
let outStream;
|
|
30
|
-
if (method ===
|
|
33
|
+
if (method === tunnel_1.TUNNEL_COMPRESSION_METHOD.BR)
|
|
31
34
|
outStream = zlib_1.default.createBrotliCompress();
|
|
32
|
-
else if (method ===
|
|
35
|
+
else if (method === tunnel_1.TUNNEL_COMPRESSION_METHOD.GZIP)
|
|
33
36
|
outStream = zlib_1.default.createGzip();
|
|
34
|
-
else if (method ===
|
|
37
|
+
else if (method === tunnel_1.TUNNEL_COMPRESSION_METHOD.DEFLATE)
|
|
35
38
|
outStream = zlib_1.default.createDeflate();
|
|
36
39
|
else
|
|
37
40
|
outStream = new stream_1.default.PassThrough();
|
package/distTs/src/tunnel/dns.js
CHANGED
|
@@ -2,46 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const dns_1 = require("dns");
|
|
4
4
|
class TunnelDns {
|
|
5
|
-
|
|
5
|
+
region;
|
|
6
|
+
sshId;
|
|
7
|
+
sshIp;
|
|
8
|
+
domain;
|
|
9
|
+
subdomain;
|
|
10
|
+
valid;
|
|
11
|
+
checking;
|
|
12
|
+
ts;
|
|
13
|
+
constructor(sshIp, domain, subdomain, region, sshId) {
|
|
6
14
|
this.region = region;
|
|
7
15
|
this.sshId = sshId;
|
|
8
16
|
this.sshIp = sshIp;
|
|
9
17
|
this.domain = domain;
|
|
10
18
|
this.subdomain = subdomain;
|
|
11
|
-
this.customDomain = customDomain;
|
|
12
19
|
this.valid = false;
|
|
13
20
|
this.checking = true;
|
|
14
21
|
this.ts = null;
|
|
15
22
|
}
|
|
16
23
|
check() {
|
|
17
24
|
const r = new dns_1.Resolver();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
hostname = `${this.subdomain}.${this.region.toLowerCase()}-${this.sshId}.${this.domain}`;
|
|
34
|
-
r.resolve4(hostname, (err, a2) => {
|
|
35
|
-
if (err || !a2 || a2.length !== 1) {
|
|
36
|
-
this.valid = false;
|
|
37
|
-
this.checking = false;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this.valid = a2[0] === this.sshIp;
|
|
41
|
-
this.checking = false;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
25
|
+
const hostname = `${this.subdomain}.${this.region.toLowerCase()}-${this.sshId}.${this.domain}`;
|
|
26
|
+
r.resolve4(hostname, (err, a2) => {
|
|
27
|
+
if (err || !a2 || a2.length !== 1) {
|
|
28
|
+
this.valid = false;
|
|
29
|
+
this.checking = false;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.valid = a2[0] === this.sshIp;
|
|
33
|
+
this.checking = false;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
45
36
|
}
|
|
46
37
|
startChecking() {
|
|
47
38
|
this.stopChecking();
|