bdy 1.12.8-beta → 1.12.8-dev-pipeline-run
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distTs/package.json +1 -1
- package/package.json +1 -1
- package/distTs/bin/cli.js +0 -5
- package/distTs/src/agent/agent.js +0 -328
- package/distTs/src/agent/linux.js +0 -124
- package/distTs/src/agent/manager.js +0 -519
- package/distTs/src/agent/osx.js +0 -146
- package/distTs/src/agent/socket/client.js +0 -178
- package/distTs/src/agent/socket/tunnel.js +0 -237
- package/distTs/src/agent/socket.js +0 -242
- package/distTs/src/agent/system.js +0 -179
- package/distTs/src/agent/wait.js +0 -23
- package/distTs/src/agent/windows.js +0 -159
- package/distTs/src/agent.js +0 -302
- package/distTs/src/api/agent.js +0 -99
- package/distTs/src/api/buddy.js +0 -139
- package/distTs/src/api/socket.js +0 -159
- package/distTs/src/cfg.js +0 -234
- package/distTs/src/command/agent/disable.js +0 -27
- package/distTs/src/command/agent/enable.js +0 -27
- package/distTs/src/command/agent/install.js +0 -117
- package/distTs/src/command/agent/restart.js +0 -27
- package/distTs/src/command/agent/run.js +0 -19
- package/distTs/src/command/agent/start.js +0 -28
- package/distTs/src/command/agent/status.js +0 -34
- package/distTs/src/command/agent/stop.js +0 -28
- package/distTs/src/command/agent/target/disable.js +0 -27
- package/distTs/src/command/agent/target/enable.js +0 -27
- package/distTs/src/command/agent/target/status.js +0 -32
- package/distTs/src/command/agent/target.js +0 -15
- package/distTs/src/command/agent/tunnel/http.js +0 -43
- package/distTs/src/command/agent/tunnel/list.js +0 -27
- package/distTs/src/command/agent/tunnel/remove.js +0 -28
- package/distTs/src/command/agent/tunnel/start.js +0 -34
- package/distTs/src/command/agent/tunnel/status.js +0 -31
- package/distTs/src/command/agent/tunnel/tcp.js +0 -43
- package/distTs/src/command/agent/tunnel/tls.js +0 -43
- package/distTs/src/command/agent/tunnel.js +0 -23
- package/distTs/src/command/agent/uninstall.js +0 -44
- package/distTs/src/command/agent/update.js +0 -38
- package/distTs/src/command/agent/version.js +0 -21
- package/distTs/src/command/agent.js +0 -35
- package/distTs/src/command/config/add/http.js +0 -25
- package/distTs/src/command/config/add/tcp.js +0 -25
- package/distTs/src/command/config/add/tls.js +0 -25
- package/distTs/src/command/config/add.js +0 -15
- package/distTs/src/command/config/get/region.js +0 -15
- package/distTs/src/command/config/get/timeout.js +0 -15
- package/distTs/src/command/config/get/token.js +0 -15
- package/distTs/src/command/config/get/tunnel.js +0 -19
- package/distTs/src/command/config/get/tunnels.js +0 -15
- package/distTs/src/command/config/get/whitelist.js +0 -15
- package/distTs/src/command/config/get.js +0 -21
- package/distTs/src/command/config/remove/tunnel.js +0 -19
- package/distTs/src/command/config/remove.js +0 -11
- package/distTs/src/command/config/set/region.js +0 -17
- package/distTs/src/command/config/set/timeout.js +0 -17
- package/distTs/src/command/config/set/token.js +0 -16
- package/distTs/src/command/config/set/whitelist.js +0 -17
- package/distTs/src/command/config/set.js +0 -17
- package/distTs/src/command/config.js +0 -17
- package/distTs/src/command/http.js +0 -30
- package/distTs/src/command/pre.js +0 -49
- package/distTs/src/command/start.js +0 -28
- package/distTs/src/command/tcp.js +0 -30
- package/distTs/src/command/tls.js +0 -30
- package/distTs/src/command/tunnel/config.js +0 -17
- package/distTs/src/command/tunnel/http.js +0 -31
- package/distTs/src/command/tunnel/start.js +0 -28
- package/distTs/src/command/tunnel/tcp.js +0 -30
- package/distTs/src/command/tunnel/tls.js +0 -30
- package/distTs/src/command/tunnel.js +0 -19
- package/distTs/src/command/ut/upload.js +0 -108
- package/distTs/src/command/ut.js +0 -12
- package/distTs/src/command/version.js +0 -13
- package/distTs/src/command/vt/close.js +0 -27
- package/distTs/src/command/vt/compare/validation.js +0 -173
- package/distTs/src/command/vt/compare.js +0 -97
- package/distTs/src/command/vt/exec.js +0 -81
- package/distTs/src/command/vt/installBrowser.js +0 -20
- package/distTs/src/command/vt/scrap.js +0 -193
- package/distTs/src/command/vt/storybook.js +0 -92
- package/distTs/src/command/vt.js +0 -22
- package/distTs/src/format.js +0 -174
- package/distTs/src/index.js +0 -34
- package/distTs/src/input.js +0 -270
- package/distTs/src/logger.js +0 -95
- package/distTs/src/output/interactive/tunnel.js +0 -860
- package/distTs/src/output/noninteractive/agent/tunnels.js +0 -43
- package/distTs/src/output/noninteractive/config/tunnel.js +0 -65
- package/distTs/src/output/noninteractive/config/tunnels.js +0 -18
- package/distTs/src/output/noninteractive/tunnel.js +0 -59
- package/distTs/src/output.js +0 -143
- package/distTs/src/server/cert.js +0 -52
- package/distTs/src/server/http1.js +0 -75
- package/distTs/src/server/http2.js +0 -78
- package/distTs/src/server/sftp.js +0 -497
- package/distTs/src/server/ssh.js +0 -446
- package/distTs/src/server/tls.js +0 -41
- package/distTs/src/ssh/client.js +0 -197
- package/distTs/src/texts.js +0 -421
- package/distTs/src/tunnel/agent.js +0 -103
- package/distTs/src/tunnel/api/agent.js +0 -100
- package/distTs/src/tunnel/api/buddy.js +0 -141
- package/distTs/src/tunnel/cfg.js +0 -243
- package/distTs/src/tunnel/compression.js +0 -44
- package/distTs/src/tunnel/dns.js +0 -53
- package/distTs/src/tunnel/html/503.html +0 -338
- package/distTs/src/tunnel/html.js +0 -33
- package/distTs/src/tunnel/http/log.js +0 -218
- package/distTs/src/tunnel/http/serve.js +0 -133
- package/distTs/src/tunnel/http/stream.js +0 -34
- package/distTs/src/tunnel/http.js +0 -508
- package/distTs/src/tunnel/identification.js +0 -103
- package/distTs/src/tunnel/latency.js +0 -83
- package/distTs/src/tunnel/output/interactive/tunnel.js +0 -867
- package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +0 -45
- package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +0 -67
- package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +0 -20
- package/distTs/src/tunnel/output/noninteractive/tunnel.js +0 -61
- package/distTs/src/tunnel/server/cert.js +0 -54
- package/distTs/src/tunnel/server/http1.js +0 -80
- package/distTs/src/tunnel/server/http2.js +0 -84
- package/distTs/src/tunnel/server/sftp.js +0 -514
- package/distTs/src/tunnel/server/ssh.js +0 -464
- package/distTs/src/tunnel/server/tls.js +0 -47
- package/distTs/src/tunnel/ssh/client.js +0 -211
- package/distTs/src/tunnel/tcp.js +0 -113
- package/distTs/src/tunnel/tunnel.js +0 -1010
- package/distTs/src/tunnel.js +0 -656
- package/distTs/src/types/ciInfo.js +0 -10
- package/distTs/src/types/options.js +0 -2
- package/distTs/src/types/plugin.js +0 -2
- package/distTs/src/types/queue.js +0 -2
- package/distTs/src/types/requests.js +0 -2
- package/distTs/src/types/resources.js +0 -2
- package/distTs/src/types/schemas.js +0 -54
- package/distTs/src/types/scrape.js +0 -2
- package/distTs/src/types/snapshots.js +0 -2
- package/distTs/src/types/storybook.js +0 -2
- package/distTs/src/types/tunnel.js +0 -141
- package/distTs/src/unitTest/ci.js +0 -108
- package/distTs/src/unitTest/requests.js +0 -72
- package/distTs/src/utils.js +0 -378
- package/distTs/src/visualTest/browser.js +0 -39
- package/distTs/src/visualTest/ci.js +0 -241
- package/distTs/src/visualTest/context.js +0 -52
- package/distTs/src/visualTest/exec.js +0 -51
- package/distTs/src/visualTest/linkUtils.js +0 -21
- package/distTs/src/visualTest/queue.js +0 -43
- package/distTs/src/visualTest/requests.js +0 -365
- package/distTs/src/visualTest/resources.js +0 -259
- package/distTs/src/visualTest/server.js +0 -109
- package/distTs/src/visualTest/snapshots.js +0 -129
- package/distTs/src/visualTest/utils/parseDom.js +0 -238
- package/distTs/src/visualTest/validation.js +0 -18
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ApiBuddyClass = void 0;
|
|
7
|
-
const https_1 = require("https");
|
|
8
|
-
const tunnel_1 = __importDefault(require("../tunnel"));
|
|
9
|
-
const logger_1 = __importDefault(require("../../logger"));
|
|
10
|
-
const agent_1 = __importDefault(require("../../agent/agent"));
|
|
11
|
-
const utils_1 = require("../../utils");
|
|
12
|
-
const texts_1 = require("../../texts");
|
|
13
|
-
const TIMEOUT = 120000;
|
|
14
|
-
const nodeFetch = (url, opts) => {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
import('node-fetch')
|
|
17
|
-
.then(({ default: fetch }) => {
|
|
18
|
-
fetch(url, opts).then(resolve).catch(reject);
|
|
19
|
-
})
|
|
20
|
-
.catch(reject);
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
const makeRequest = async (host, path, body, method = 'POST', respAsJson = true, timeout = TIMEOUT) => {
|
|
24
|
-
let data;
|
|
25
|
-
try {
|
|
26
|
-
const c = new AbortController();
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
c.abort();
|
|
29
|
-
}, timeout);
|
|
30
|
-
const response = await nodeFetch(`${host}${path}`, {
|
|
31
|
-
body: body ? JSON.stringify(body) : null,
|
|
32
|
-
headers: body ? { 'Content-Type': 'application/json' } : null,
|
|
33
|
-
method,
|
|
34
|
-
signal: c.signal,
|
|
35
|
-
agent: new https_1.Agent({
|
|
36
|
-
rejectUnauthorized: false,
|
|
37
|
-
}),
|
|
38
|
-
});
|
|
39
|
-
if (respAsJson)
|
|
40
|
-
data = await response.json();
|
|
41
|
-
else
|
|
42
|
-
data = await response.text();
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
throw new utils_1.ApiErrorFailedToConnect(host);
|
|
46
|
-
}
|
|
47
|
-
if (respAsJson) {
|
|
48
|
-
if (data.code !== 200) {
|
|
49
|
-
throw (0, utils_1.apiErrorCodeToClass)(data.result.code, host);
|
|
50
|
-
}
|
|
51
|
-
return data.result;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
class ApiBuddyClass {
|
|
58
|
-
async register(service, target, host, token, onDefaultRegion) {
|
|
59
|
-
const version = (0, utils_1.getVersion)();
|
|
60
|
-
const hostname = (0, utils_1.getHostname)();
|
|
61
|
-
const platform = (0, utils_1.getPlatform)();
|
|
62
|
-
logger_1.default.info(texts_1.LOG_REGISTERING_AGENT);
|
|
63
|
-
const r = await makeRequest(host, '/tunnel/agent/add', {
|
|
64
|
-
token,
|
|
65
|
-
version,
|
|
66
|
-
hostname,
|
|
67
|
-
platform,
|
|
68
|
-
service,
|
|
69
|
-
target,
|
|
70
|
-
});
|
|
71
|
-
logger_1.default.info((0, texts_1.LOG_AGENT_REGISTERED)(r.id));
|
|
72
|
-
logger_1.default.info((0, texts_1.LOG_REGION_DETECTED)(r.region));
|
|
73
|
-
if (onDefaultRegion)
|
|
74
|
-
onDefaultRegion(r.region);
|
|
75
|
-
return new agent_1.default(r.id, host, r.token, service, target, this, false);
|
|
76
|
-
}
|
|
77
|
-
async unregister(id, host, token) {
|
|
78
|
-
logger_1.default.info(texts_1.LOG_UNREGISTERING_AGENT);
|
|
79
|
-
await makeRequest(host, '/tunnel/agent/remove', {
|
|
80
|
-
token,
|
|
81
|
-
id,
|
|
82
|
-
});
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
async fetchAgent(id, host, token) {
|
|
86
|
-
logger_1.default.info(texts_1.LOG_GETTING_AGENT);
|
|
87
|
-
const r = await makeRequest(host, '/tunnel/agent/fetch', {
|
|
88
|
-
token,
|
|
89
|
-
id,
|
|
90
|
-
});
|
|
91
|
-
return new agent_1.default(r.id, host, token, !!r.service, !!r.target, this, !!r.disabled);
|
|
92
|
-
}
|
|
93
|
-
async fetchAgentKeys(id, host, token) {
|
|
94
|
-
return await makeRequest(host, '/tunnel/agent/fetch/keys', {
|
|
95
|
-
token,
|
|
96
|
-
id,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
async disableTarget(agentId, host, token) {
|
|
100
|
-
logger_1.default.info(texts_1.LOG_DISABLING_AGENT_TARGET);
|
|
101
|
-
await makeRequest(host, '/tunnel/agent/target/disable', {
|
|
102
|
-
agentId,
|
|
103
|
-
token,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
async enableTarget(agentId, host, token) {
|
|
107
|
-
logger_1.default.info(texts_1.LOG_ENABLING_AGENT_TARGET);
|
|
108
|
-
await makeRequest(host, '/tunnel/agent/target/enable', {
|
|
109
|
-
agentId,
|
|
110
|
-
token,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
async addTunnel(agentId, host, token, prepared, sshHostKey) {
|
|
114
|
-
logger_1.default.info(texts_1.LOG_REGISTERING_TUNNEL);
|
|
115
|
-
const config = await makeRequest(host, '/tunnel/add', {
|
|
116
|
-
...prepared,
|
|
117
|
-
token,
|
|
118
|
-
agentId,
|
|
119
|
-
});
|
|
120
|
-
logger_1.default.info((0, texts_1.LOG_TUNNEL_REGISTERED)(config.id));
|
|
121
|
-
return new tunnel_1.default({
|
|
122
|
-
...config,
|
|
123
|
-
sshHostKey,
|
|
124
|
-
agent: { id: agentId, host, token },
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
async removeTunnel(agentId, tunnelId, host, token) {
|
|
128
|
-
logger_1.default.info(texts_1.LOG_REMOVING_TUNNEL);
|
|
129
|
-
await makeRequest(host, '/tunnel/remove', {
|
|
130
|
-
agentId,
|
|
131
|
-
tunnelId,
|
|
132
|
-
token,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
async fetchMyIp() {
|
|
136
|
-
return makeRequest('https://es.buddy.works', '/ip', null, 'GET', false);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exports.ApiBuddyClass = ApiBuddyClass;
|
|
140
|
-
const ApiBuddy = new ApiBuddyClass();
|
|
141
|
-
exports.default = ApiBuddy;
|
package/distTs/src/tunnel/cfg.js
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
9
|
-
const utils_1 = require("../utils");
|
|
10
|
-
const input_1 = __importDefault(require("../input"));
|
|
11
|
-
const texts_1 = require("../texts");
|
|
12
|
-
const tunnel_1 = require("../types/tunnel");
|
|
13
|
-
class Cfg {
|
|
14
|
-
dir;
|
|
15
|
-
file;
|
|
16
|
-
json;
|
|
17
|
-
constructor() {
|
|
18
|
-
this.dir = (0, utils_1.getHomeDirectory)();
|
|
19
|
-
this.file = (0, path_1.resolve)(this.dir, 'cfg.json');
|
|
20
|
-
this.json = {};
|
|
21
|
-
this.load();
|
|
22
|
-
}
|
|
23
|
-
createDir() {
|
|
24
|
-
try {
|
|
25
|
-
(0, fs_1.mkdirSync)(this.dir, {
|
|
26
|
-
recursive: true,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
throw new Error((0, texts_1.ERR_CANT_CREATE_DIR_IN_HOME)('.bdy'));
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
(0, fs_1.chmodSync)(this.dir, 0o777);
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
// do nothing
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
createEmptyFile() {
|
|
40
|
-
try {
|
|
41
|
-
(0, fs_1.writeFileSync)(this.file, '{}', 'utf-8');
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
throw new Error((0, texts_1.ERR_CANT_CREATE_DIR_IN_HOME)('.bdy/cfg.json'));
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
(0, fs_1.chmodSync)(this.file, 0o666);
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
// do nothing
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
ensureDir() {
|
|
54
|
-
try {
|
|
55
|
-
(0, fs_1.statSync)(this.dir);
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
this.createDir();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
ensureFile() {
|
|
62
|
-
this.ensureDir();
|
|
63
|
-
try {
|
|
64
|
-
(0, fs_1.statSync)(this.file);
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
this.createEmptyFile();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
ensureTunnels() {
|
|
71
|
-
if (!this.json.tunnels)
|
|
72
|
-
this.json.tunnels = {};
|
|
73
|
-
}
|
|
74
|
-
async prepareTunnel(tunnelType, target, options, useDefaults) {
|
|
75
|
-
const type = input_1.default.type(tunnelType);
|
|
76
|
-
const tunnel = {
|
|
77
|
-
type,
|
|
78
|
-
target: input_1.default.target(target, type),
|
|
79
|
-
};
|
|
80
|
-
if (options.region !== undefined)
|
|
81
|
-
tunnel.region = input_1.default.region(options.region);
|
|
82
|
-
else if (useDefaults)
|
|
83
|
-
tunnel.region = this.getRegion();
|
|
84
|
-
if (options.whitelist !== undefined)
|
|
85
|
-
tunnel.whitelist = input_1.default.whitelist(options.whitelist);
|
|
86
|
-
else if (useDefaults)
|
|
87
|
-
tunnel.whitelist = this.getWhitelist();
|
|
88
|
-
if (options.timeout !== undefined)
|
|
89
|
-
tunnel.timeout = input_1.default.timeout(options.timeout);
|
|
90
|
-
else if (useDefaults)
|
|
91
|
-
tunnel.timeout = this.getTimeout();
|
|
92
|
-
if (type === tunnel_1.TUNNEL_TYPE.HTTP) {
|
|
93
|
-
tunnel.authType = tunnel_1.TUNNEL_HTTP_AUTH_TYPE.NONE;
|
|
94
|
-
if (options.host !== undefined)
|
|
95
|
-
tunnel.host = options.host;
|
|
96
|
-
if (options.auth !== undefined) {
|
|
97
|
-
const { password, login } = input_1.default.auth(options.auth);
|
|
98
|
-
tunnel.login = login;
|
|
99
|
-
tunnel.password = password;
|
|
100
|
-
tunnel.authType = tunnel_1.TUNNEL_HTTP_AUTH_TYPE.BASIC;
|
|
101
|
-
}
|
|
102
|
-
else if (options.buddy) {
|
|
103
|
-
tunnel.authType = tunnel_1.TUNNEL_HTTP_AUTH_TYPE.BUDDY;
|
|
104
|
-
}
|
|
105
|
-
if (options.ca !== undefined)
|
|
106
|
-
tunnel.ca = input_1.default.ca(options.ca);
|
|
107
|
-
if (options.serve !== undefined)
|
|
108
|
-
tunnel.serve = input_1.default.serve(options.serve);
|
|
109
|
-
if (options.useragent !== undefined)
|
|
110
|
-
tunnel.useragents = input_1.default.useragents(options.useragent);
|
|
111
|
-
if (options.header !== undefined)
|
|
112
|
-
tunnel.headers = input_1.default.headers(options.header);
|
|
113
|
-
if (options.responseHeader !== undefined)
|
|
114
|
-
tunnel.responseHeaders = input_1.default.headers(options.responseHeader);
|
|
115
|
-
if (options.circuitBreaker !== undefined)
|
|
116
|
-
tunnel.circuitBreaker = input_1.default.circuitBreaker(options.circuitBreaker);
|
|
117
|
-
tunnel.log = !!options.log;
|
|
118
|
-
tunnel.verify = !!options.verify;
|
|
119
|
-
tunnel.http2 = !!options.http2;
|
|
120
|
-
tunnel.compression = !!options.compression;
|
|
121
|
-
}
|
|
122
|
-
else if (type === tunnel_1.TUNNEL_TYPE.TLS) {
|
|
123
|
-
tunnel.terminate = input_1.default.terminate(options.terminate);
|
|
124
|
-
if (options.key !== undefined || options.cert !== undefined) {
|
|
125
|
-
const { key, cert } = input_1.default.keyCert(options.key, options.cert);
|
|
126
|
-
tunnel.key = key;
|
|
127
|
-
tunnel.cert = cert;
|
|
128
|
-
}
|
|
129
|
-
if (options.ca !== undefined)
|
|
130
|
-
tunnel.ca = input_1.default.ca(options.ca);
|
|
131
|
-
}
|
|
132
|
-
if (options.name !== undefined)
|
|
133
|
-
tunnel.name = input_1.default.name(options.name);
|
|
134
|
-
return tunnel;
|
|
135
|
-
}
|
|
136
|
-
async addTunnel(name, type, target, options) {
|
|
137
|
-
this.ensureTunnels();
|
|
138
|
-
this.json.tunnels[name] = await this.prepareTunnel(type, target, {
|
|
139
|
-
name,
|
|
140
|
-
...options,
|
|
141
|
-
}, false);
|
|
142
|
-
this.save();
|
|
143
|
-
}
|
|
144
|
-
removeTunnel(name) {
|
|
145
|
-
this.ensureTunnels();
|
|
146
|
-
delete this.json.tunnels[name];
|
|
147
|
-
this.save();
|
|
148
|
-
}
|
|
149
|
-
getTunnels() {
|
|
150
|
-
this.ensureTunnels();
|
|
151
|
-
return this.json.tunnels;
|
|
152
|
-
}
|
|
153
|
-
hasTunnel(name) {
|
|
154
|
-
this.ensureTunnels();
|
|
155
|
-
return !!this.json.tunnels[name];
|
|
156
|
-
}
|
|
157
|
-
getTunnel(name) {
|
|
158
|
-
this.ensureTunnels();
|
|
159
|
-
return this.json.tunnels[name];
|
|
160
|
-
}
|
|
161
|
-
setToken(token) {
|
|
162
|
-
if (!token)
|
|
163
|
-
delete this.json.token;
|
|
164
|
-
else
|
|
165
|
-
this.json.token = token;
|
|
166
|
-
this.save();
|
|
167
|
-
}
|
|
168
|
-
setWhitelist(whitelist) {
|
|
169
|
-
if (!whitelist || !whitelist.length)
|
|
170
|
-
delete this.json.whitelist;
|
|
171
|
-
else
|
|
172
|
-
this.json.whitelist = whitelist;
|
|
173
|
-
this.save();
|
|
174
|
-
}
|
|
175
|
-
setTimeout(timeout) {
|
|
176
|
-
if (!timeout)
|
|
177
|
-
delete this.json.timeout;
|
|
178
|
-
else
|
|
179
|
-
this.json.timeout = timeout;
|
|
180
|
-
this.save();
|
|
181
|
-
}
|
|
182
|
-
getToken() {
|
|
183
|
-
return this.json.token || '';
|
|
184
|
-
}
|
|
185
|
-
getTokenHost() {
|
|
186
|
-
const token = this.getToken();
|
|
187
|
-
if (!token) {
|
|
188
|
-
throw new Error(texts_1.ERR_TOKEN_NOT_PROVIDED);
|
|
189
|
-
}
|
|
190
|
-
const d = (0, jsonwebtoken_1.decode)(token);
|
|
191
|
-
if (d === null) {
|
|
192
|
-
throw new Error(texts_1.ERR_WRONG_TOKEN);
|
|
193
|
-
}
|
|
194
|
-
if (!d.host) {
|
|
195
|
-
throw new Error(texts_1.ERR_WRONG_TOKEN);
|
|
196
|
-
}
|
|
197
|
-
return d.host;
|
|
198
|
-
}
|
|
199
|
-
getRegion() {
|
|
200
|
-
return (this.json.region || '').toUpperCase();
|
|
201
|
-
}
|
|
202
|
-
getTimeout() {
|
|
203
|
-
return this.json.timeout || utils_1.DEFAULT_TIMEOUT;
|
|
204
|
-
}
|
|
205
|
-
getWhitelist() {
|
|
206
|
-
return this.json.whitelist || [];
|
|
207
|
-
}
|
|
208
|
-
setRegion(region) {
|
|
209
|
-
this.json.region = region;
|
|
210
|
-
this.save();
|
|
211
|
-
}
|
|
212
|
-
setRegionIfNotSet(region) {
|
|
213
|
-
if (!this.json.region && region)
|
|
214
|
-
this.json.region = region.toUpperCase();
|
|
215
|
-
this.save();
|
|
216
|
-
}
|
|
217
|
-
load() {
|
|
218
|
-
this.ensureFile();
|
|
219
|
-
try {
|
|
220
|
-
const txt = (0, fs_1.readFileSync)(this.file, 'utf-8');
|
|
221
|
-
this.json = JSON.parse(txt);
|
|
222
|
-
}
|
|
223
|
-
catch {
|
|
224
|
-
throw new Error(texts_1.ERR_CONFIG_CORRUPTED);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
save() {
|
|
228
|
-
this.ensureDir();
|
|
229
|
-
try {
|
|
230
|
-
(0, fs_1.writeFileSync)(this.file, JSON.stringify(this.json, null, 4), 'utf-8');
|
|
231
|
-
}
|
|
232
|
-
catch {
|
|
233
|
-
throw new Error((0, texts_1.ERR_CANT_CREATE_DIR_IN_HOME)('.bdy/cfg.json'));
|
|
234
|
-
}
|
|
235
|
-
try {
|
|
236
|
-
(0, fs_1.chmodSync)(this.file, 0o666);
|
|
237
|
-
}
|
|
238
|
-
catch {
|
|
239
|
-
// do nothing
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
exports.default = new Cfg();
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const zlib_1 = __importDefault(require("zlib"));
|
|
7
|
-
const mime_db_1 = __importDefault(require("mime-db"));
|
|
8
|
-
const accept_negotiator_1 = require("@fastify/accept-negotiator");
|
|
9
|
-
const stream_1 = __importDefault(require("stream"));
|
|
10
|
-
const tunnel_1 = require("../types/tunnel");
|
|
11
|
-
class TunnelCompression {
|
|
12
|
-
static detect(canCompress, reqHeaders, resHeaders) {
|
|
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');
|
|
17
|
-
const mimeData = mime_db_1.default[contentType.split(';', 1)[0].trim().toLowerCase()];
|
|
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,
|
|
26
|
-
]);
|
|
27
|
-
if (!encoding)
|
|
28
|
-
return tunnel_1.TUNNEL_COMPRESSION_METHOD.IDENTITY;
|
|
29
|
-
return encoding;
|
|
30
|
-
}
|
|
31
|
-
static compress(method) {
|
|
32
|
-
let outStream;
|
|
33
|
-
if (method === tunnel_1.TUNNEL_COMPRESSION_METHOD.BR)
|
|
34
|
-
outStream = zlib_1.default.createBrotliCompress();
|
|
35
|
-
else if (method === tunnel_1.TUNNEL_COMPRESSION_METHOD.GZIP)
|
|
36
|
-
outStream = zlib_1.default.createGzip();
|
|
37
|
-
else if (method === tunnel_1.TUNNEL_COMPRESSION_METHOD.DEFLATE)
|
|
38
|
-
outStream = zlib_1.default.createDeflate();
|
|
39
|
-
else
|
|
40
|
-
outStream = new stream_1.default.PassThrough();
|
|
41
|
-
return outStream;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.default = TunnelCompression;
|
package/distTs/src/tunnel/dns.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const dns_1 = require("dns");
|
|
4
|
-
class TunnelDns {
|
|
5
|
-
region;
|
|
6
|
-
sshId;
|
|
7
|
-
sshIp;
|
|
8
|
-
domain;
|
|
9
|
-
subdomain;
|
|
10
|
-
valid;
|
|
11
|
-
checking;
|
|
12
|
-
ts;
|
|
13
|
-
constructor(sshIp, domain, subdomain, region, sshId) {
|
|
14
|
-
this.region = region;
|
|
15
|
-
this.sshId = sshId;
|
|
16
|
-
this.sshIp = sshIp;
|
|
17
|
-
this.domain = domain;
|
|
18
|
-
this.subdomain = subdomain;
|
|
19
|
-
this.valid = false;
|
|
20
|
-
this.checking = true;
|
|
21
|
-
this.ts = null;
|
|
22
|
-
}
|
|
23
|
-
check() {
|
|
24
|
-
const r = new dns_1.Resolver();
|
|
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
|
-
});
|
|
36
|
-
}
|
|
37
|
-
startChecking() {
|
|
38
|
-
this.stopChecking();
|
|
39
|
-
setTimeout(() => {
|
|
40
|
-
this.check();
|
|
41
|
-
}, 1000);
|
|
42
|
-
this.ts = setInterval(() => {
|
|
43
|
-
this.check();
|
|
44
|
-
}, 15000);
|
|
45
|
-
}
|
|
46
|
-
stopChecking() {
|
|
47
|
-
if (this.ts) {
|
|
48
|
-
clearInterval(this.ts);
|
|
49
|
-
this.ts = null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.default = TunnelDns;
|