bdy 1.12.5 → 1.12.6-beta
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 +2 -1
- package/distTs/src/texts.js +5 -4
- package/distTs/src/tunnel/cfg.js +5 -0
- package/distTs/src/tunnel/tunnel.js +284 -14
- package/distTs/src/types/tunnel.js +7 -1
- package/distTs/src/utils.js +1 -0
- package/package.json +2 -1
package/distTs/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bdy",
|
|
3
3
|
"preferGlobal": false,
|
|
4
|
-
"version": "1.12.
|
|
4
|
+
"version": "1.12.6-beta",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"@xhmikosr/decompress": "10.0.1",
|
|
24
24
|
"basic-auth": "2.0.1",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
|
+
"cookie": "1.0.2",
|
|
26
27
|
"commander": "12.1.0",
|
|
27
28
|
"content-disposition": "0.5.4",
|
|
28
29
|
"cross-spawn": "7.0.6",
|
package/distTs/src/texts.js
CHANGED
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ERR_CONNECTION_ERROR = exports.ERR_CONNECTION_TIMEOUT = exports.ERR_WRONG_STREAM = exports.ERR_WRONG_HANDSHAKE = exports.ERR_FETCH_VERSION = exports.ERR_SWW = exports.ERR_NOT_FOUND = exports.ERR_FAILED_TO_CONNECT_TO_AGENT = exports.ERR_TUNNEL_REMOVED = exports.ERR_TUNNELS_DISABLED = exports.ERR_AGENT_LIMIT_REACHED = exports.ERR_TUNNEL_TARGET_INVALID = exports.ERR_WORKSPACE_FLAGGED = exports.ERR_TUNNEL_LIMIT_REACHED = exports.ERR_DOMAIN_RESTRICTED = exports.ERR_AGENT_REMOVED = exports.ERR_FAILED_TO_CONNECT = exports.ERR_TUNNEL_ALREADY_EXISTS = exports.ERR_AGENT_NOT_SUPPORTED = exports.ERR_AGENT_ADMIN_RIGHTS = exports.ERR_AGENT_ENABLE = exports.ERR_SWW_AGENT_UPDATING = exports.ERR_SWW_AGENT_DISABLING = exports.ERR_SWW_AGENT_ENABLING = exports.ERR_AGENT_NOT_FOUND = exports.ERR_AGENT_NOT_RUNNING = exports.ERR_AGENT_NOT_ENABLED = exports.ERR_TUNNEL_NOT_FOUND = exports.ERR_WHITELIST_IS_NOT_VALID = exports.ERR_USER_AGENT_IS_NOT_VALID = exports.ERR_BA_IS_NOT_VALID = exports.ERR_BA_LOGIN_NOT_PROVIDED = exports.ERR_BA_PASSWORD_NOT_PROVIDED = exports.ERR_CB_THRESHOLD_IS_NOT_VALID = exports.ERR_CERT_PATH_IS_NOT_VALID = exports.ERR_KEY_PATH_IS_NOT_VALID = exports.ERR_CA_PATH_IS_NOT_VALID = exports.ERR_WRONG_CA = exports.ERR_WRONG_KEY_CERT = exports.ERR_NAME_WITHOUT_ASTERISK = exports.ERR_PORT_IS_NOT_VALID = exports.ERR_REGION_IS_NOT_VALID = exports.ERR_PATH_IS_NOT_DIRECTORY = exports.ERR_DIRECTORY_DOES_NOT_EXISTS = exports.ERR_TERMINATE_IS_NOT_VALID = exports.ERR_TIMEOUT_IS_NOT_VALID = exports.ERR_TYPE_IS_NOT_VALID = exports.ERR_TARGET_IS_NOT_VALID = exports.ERR_SAVING_AGENT_CONFIG = exports.ERR_AGENT_NOT_REGISTERED = void 0;
|
|
4
4
|
exports.TXT_AGENT_ENABLED = exports.TXT_AGENT_TARGET_DISABLED = exports.TXT_AGENT_TARGET_ENABLED = exports.TXT_AGENT_IS_DISABLED = exports.TXT_AGENT_IS_ENABLED_AND_HAVE_TROUBLES = exports.TXT_AGENT_IS_ENABLED_AND_INITIALIZING = exports.TXT_AGENT_IS_ENABLED_AND_STOPPED = exports.TXT_AGENT_IS_ENABLED_AND_STARTED = exports.TXT_AGENT_RESTARTED = exports.TXT_AGENT_STARTED = exports.TXT_AGENT_STOPPED = exports.WARN_BROWSER_VERSION = exports.ERR_NO_SNAPSHOTS_TO_SEND = exports.ERR_INVALID_SNAPSHOT = exports.ERR_GETTING_COMMIT_DETAILS = exports.ERR_GETTING_BASE_COMMIT = exports.ERR_HEAD_BRANCH_NOT_DEFINED = exports.ERR_BASE_BRANCH_NOT_DEFINED = exports.ERR_INVALID_COMMIT_HASH = exports.ERR_GETTING_COMMIT_HASH = exports.ERR_INVALID_BRANCH_NAME = exports.ERR_GETTING_BRANCH_NAME = exports.ERR_MISSING_HEAD_COMMIT_IN_FILE = exports.ERR_READING_FILE_WITH_HEAD_COMMIT = exports.ERR_MISSING_FILE_WITH_HEAD_COMMIT = exports.ERR_GITHUB_EVENT_PATH_NOT_FOUND = exports.ERR_TEST_EXECUTION = exports.ERR_INVALID_JSON = exports.ERR_INVALID_DOWNLOAD_RESPONSE = exports.ERR_INVALID_SCRAP_RESPONSE = exports.ERR_INVALID_COMPARE_LINKS_RESPONSE = exports.ERR_INVALID_STORYBOOK_RESPONSE = exports.ERR_INVALID_DEFAULT_SETTINGS_RESPONSE = exports.ERR_INVALID_CLOSE_SESSION_RESPONSE = exports.ERR_INVALID_SNAPSHOTS_RESPONSE = exports.ERR_INVALID_SNAPSHOT_RESPONSE = exports.ERR_MISSING_URLS = exports.ERR_RESOURCE_NOT_FOUND = exports.ERR_MISSING_EXEC_COMMAND = exports.ERR_PARSING_STORIES = exports.ERR_UNSUPPORTED_STORYBOOK = exports.ERR_MISSING_STORYBOOK_INDEX_FILE = exports.ERR_WRONG_STORYBOOK_DIRECTORY = exports.ERR_MISSING_BUILD_ID = exports.ERR_MISSING_UT_TOKEN = exports.ERR_MISSING_VT_TOKEN = exports.ERR_CONFIG_CORRUPTED = exports.ERR_WRONG_TOKEN = exports.ERR_TOKEN_NOT_PROVIDED = exports.ERR_CANT_CREATE_DIR_IN_HOME = void 0;
|
|
5
5
|
exports.DESC_COMMAND_AGENT_VERSION = exports.DESC_COMMAND_AGENT_UPDATE = exports.DESC_COMMAND_AGENT_TARGET = exports.DESC_COMMAND_AGENT_TUNNEL = exports.DESC_COMMAND_AGENT_STOP = exports.DESC_COMMAND_AGENT_TARGET_DISABLE = exports.DESC_COMMAND_AGENT_TARGET_ENABLE = exports.DESC_COMMAND_AGENT_TARGET_STATUS = exports.DESC_COMMAND_AGENT_STATUS = exports.DESC_COMMAND_AGENT_RESTART = exports.DESC_COMMAND_AGENT_ENABLE = exports.DESC_COMMAND_AGENT_DISABLE = exports.DESC_COMMAND_AGENT_START = exports.DESC_COMMAND_AGENT_INSTALL = exports.DESC_COMMAND_AGENT_UNINSTALL = exports.DESC_COMMAND_AGENT_TUNNEL_REMOVE = exports.DESC_COMMAND_AGENT_TUNNEL_STATUS = exports.DESC_COMMAND_AGENT_TUNNEL_LIST = exports.DESC_COMMAND_CONFIG_SET = exports.DESC_COMMAND_CONFIG_REMOVE = exports.DESC_COMMAND_CONFIG_GET = exports.DESC_COMMAND_CONFIG_ADD = exports.DESC_COMMAND_CONFIG_SET_WHITELIST = exports.DESC_COMMAND_CONFIG_SET_TOKEN = exports.DESC_COMMAND_CONFIG_SET_TIMEOUT = exports.DESC_COMMAND_CONFIG_SET_REGION = exports.DESC_COMMAND_CONFIG_REMOVE_TUNNEL = exports.DESC_COMMAND_CONFIG_GET_WHITELIST = exports.DESC_COMMAND_CONFIG_GET_TUNNELS = exports.DESC_COMMAND_CONFIG_GET_TUNNEL = exports.DESC_COMMAND_CONFIG_GET_TOKEN = exports.DESC_COMMAND_CONFIG_GET_TIMEOUT = exports.DESC_COMMAND_CONFIG_GET_REGION = exports.DESC_COMMAND_CONFIG_ADD_TLS = exports.DESC_COMMAND_CONFIG_ADD_TCP = exports.DESC_COMMAND_CONFIG_ADD_HTTP = exports.AGENT_FETCH_RETRY = exports.NO_TUNNELS_STARTED = exports.TXT_TUNNEL_ADDED = exports.TXT_TUNNEL_REMOVED = exports.TXT_REGION_SAVED = exports.TXT_TIMEOUT_SAVED = exports.TXT_TOKEN_REMOVED = exports.TXT_TOKEN_SAVED = exports.TXT_WHITELIST_SAVED = exports.TXT_TUNNEL_STOPPED = exports.TXT_TUNNEL_STARTED = exports.TXT_AGENT_DISABLED = exports.TXT_AGENT_ALREADY_ENABLED = exports.TXT_AGENT_UPDATED = void 0;
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.DEBUG_WAIT_FOR_IDLE_TIMEOUT = exports.DEBUG_WAIT_FOR_IDLE = exports.DEBUG_RESOURCE_DISCOVERY_TIMEOUT = exports.DEBUG_AUTO_WIDTH = exports.DEBUG_AUTO_SCROLL = exports.DEBUG_RESOURCE_SCRAPPING_URL = exports.DEBUG_SNAPSHOT_PROCESSING = exports.DEBUG_SNAPSHOTS_PROCESSING = exports.DEBUG_EXEC_COMMAND = exports.DEBUG_EXEC_TEST_COMMAND = exports.LOG_INSTALLED_BROWSER = exports.LOG_SESSION_LINK = exports.LOG_SENDING_DATA = exports.LOG_SENDING_REQUEST = exports.LOG_PROCESSING_SNAPSHOTS = exports.LOG_RUNNING_EXEC_COMMAND = exports.LOG_TUNNEL_SSH_STREAM = void 0;
|
|
6
|
+
exports.OPTION_TLS_CERT = exports.OPTION_TLS_KEY = exports.OPTION_HTTP_CIRCUIT_BREAKER = exports.OPTION_HTTP_COMPRESSION = exports.OPTION_HTTP_2 = exports.OPTION_HTTP_VERIFY = exports.OPTION_HTTP_LOG = exports.OPTION_HTTP_AUTH_BUDDY = exports.OPTION_HTTP_AUTH = exports.OPTION_HTTP_HOST = exports.OPTION_FORCE = exports.OPTION_TOKEN = exports.OPTION_TIMEOUT = exports.OPTION_FOLLOW = exports.OPTION_SERVE = exports.OPTION_HEADER_USER_AGENT = exports.OPTION_RESPONSE_HEADER = exports.OPTION_HEADER = exports.OPTION_WHITELIST = exports.OPTION_DEFAULT_REGION = exports.OPTION_REGION = exports.TXT_CI_INFO = exports.TXT_STORIES_AMOUNT = exports.TXT_OPENING_TUNNEL = exports.TXT_UPDATING_AGENT = exports.TXT_ENABLING_AGENT = exports.TXT_DISABLING_AGENT = exports.TXT_NEW_AGENT_VERSION = exports.TXT_NEW_CLI_VERSION = exports.TXT_NEW_CLI_DOCKER_VERSION = exports.OPTION_UPLOAD_DRY_RUN = exports.OPTION_UPLOAD_REPORT_FORMAT = exports.OPTION_UPLOAD_REPORT_GLOB = exports.DESC_COMMAND_UT_UPLOAD = exports.DESC_COMMAND_UT = exports.DESC_COMMAND_VT_INSTALL_BROWSER = exports.DESC_COMMAND_VT_EXEC = exports.DESC_COMMAND_VT_SCRAP = exports.DESC_COMMAND_VT_COMPARE = exports.DESC_COMMAND_VT_STORYBOOK = exports.DESC_COMMAND_VT_CLOSE = exports.DESC_COMMAND_VT = exports.DESC_PROGRAM = exports.DESC_COMMAND_TLS = exports.DESC_COMMAND_TCP = exports.DESC_COMMAND_START = exports.DESC_COMMAND_TUNNEL = exports.DESC_COMMAND_AGENT = exports.DESC_COMMAND_HTTP = exports.DESC_COMMAND_CONFIG = void 0;
|
|
7
|
+
exports.LOG_ERROR_SAVING_AGENT_LOCAL_CONFIG = exports.LOG_ERROR_SAVING_AGENT_SYSTEM_CONFIG = exports.LOG_ERROR_SAVING_AGENT_CONFIG = exports.LOG_SAVING_AGENT_LOCAL_CONFIG = exports.LOG_SAVING_AGENT_SYSTEM_CONFIG = exports.LOG_SAVING_AGENT_CONFIG = exports.LOG_REGISTERING_AGENT = exports.OPTION_SCRAP_OUTPUT_DIR = exports.OPTION_SCRAP_DELAY = exports.OPTION_SCRAP_DARK_MODE = exports.OPTION_SCRAP_WAIT_FOR_ELEMENT = exports.OPTION_SCRAP_DEVICE_PIXEL_RATIO = exports.OPTION_SCRAP_VIEWPORT = exports.OPTION_SCRAP_BROWSER = exports.OPTION_SCRAP_XPATH_SELECTOR = exports.OPTION_SCRAP_CSS_SELECTOR = exports.OPTION_SCRAP_FULL_PAGE = exports.OPTION_SCRAP_QUALITY = exports.OPTION_SCRAP_OUTPUT_TYPE = exports.OPTION_SCRAP_FOLLOW = exports.OPTION_SCRAP_URL = exports.OPTION_COMPARE_WAIT_FOR = exports.OPTION_COMPARE_DELAY = exports.OPTION_COMPARE_HEADER = exports.OPTION_COMPARE_COOKIE = exports.OPTION_COMPARE_IGNORE = exports.OPTION_COMPARE_IGNORE_URLS = exports.OPTION_COMPARE_DRY_RUN = exports.OPTION_COMPARE_URLS_FILE = exports.OPTION_COMPARE_SITEMAP = exports.OPTION_COMPARE_URLS = exports.OPTION_COMPARE_RESPECT_ROBOTS = exports.OPTION_COMPARE_FOLLOW = exports.OPTION_EXEC_PARALLEL = exports.OPTION_EXEC_ONE_BY_ONE = exports.OPTION_EXEC_SKIP_DISCOVERY = exports.OPTION_EXEC_COMMAND = exports.OPTION_AGENT_DEBUG = exports.OPTION_AGENT_PORT = exports.OPTION_AGENT_TARGET = exports.OPTION_PASS = exports.OPTION_USER = exports.OPTION_AGENT_TOKEN = exports.OPTION_AGENT_START = exports.OPTION_AGENT_ID = exports.OPTION_ID = exports.OPTION_NAME = exports.OPTION_TARGET = exports.OPTION_TLS_TERMINATE = exports.OPTION_TLS_CA = void 0;
|
|
8
|
+
exports.LOG_TUNNEL_TLS_REGION_STREAM = exports.LOG_TUNNEL_TLS_TARGET_STREAM = exports.LOG_TUNNEL_HTTP2_STREAM = exports.LOG_TUNNEL_HTTP1_STREAM = exports.LOG_TUNNEL_TCP_STREAM = exports.LOG_TUNNEL_HTTP_WRONG_USER_AGENTS = exports.LOG_TUNNEL_HTTP_CIRCUIT_BREAKER_OPEN = exports.LOG_TUNNEL_HTTP_RATE_LIMIT = exports.LOG_TUNNEL_HTTP_WRON_AUTH = exports.LOG_TUNNEL_IDENTIFIED = exports.LOG_TUNNEL_DISCONNECTED = exports.LOG_TUNNEL_FAILED = exports.LOG_TUNNEL_CONNECTED = exports.LOG_AGENT_STARTED = exports.LOG_AGENT_SERVER_STARTED = exports.LOG_ERROR_STARTING_AGENT_SERVER = exports.LOG_REQUEST = exports.LOG_SSH_CONNECTION = exports.LOG_WRONG_STREAM = exports.LOG_DETECTED_STREAM = exports.LOG_HTTP2_REQUEST = exports.LOG_HTTP2_CONNECTION = exports.LOG_HTTP1_REQUEST = exports.LOG_HTTP1_CONNECTION = exports.LOG_ERROR = exports.LOG_STOPPING_TUNNEL = exports.LOG_STARTING_TUNNEL = exports.LOG_ENABLING_AGENT_TARGET = exports.LOG_DISABLING_AGENT_TARGET = exports.LOG_REMOVING_TUNNEL = exports.LOG_TUNNEL_REGISTERED = exports.LOG_ERROR_WHILE_REFRESHING_AGENT = exports.LOG_REGISTERING_TUNNEL = exports.LOG_GETTING_AGENT = exports.LOG_UNREGISTERING_AGENT = exports.LOG_REGION_DETECTED = exports.LOG_AGENT_REGISTERED = exports.LOG_SOCKET_DISCONNECTED = exports.LOG_SOCKET_CONNECTED = exports.LOG_AGENT_NSSM_CLEARING = exports.LOG_AGENT_NSSM_EXTRACTING = exports.LOG_AGENT_NSSM_DOWNLOADING = exports.LOG_AGENT_ENABLED = exports.LOG_AGENT_STARTING_SYSTEM = exports.LOG_AGENT_STOPPING_SYSTEM = exports.LOG_AGENT_ENABLING_SYSTEM = exports.LOG_AGENT_SYSTEM_SERVICE_CONFIG = exports.LOG_AGENT_EXTRACTING_ARCHIVE = exports.LOG_AGENT_DOWNLOADING_ARCHIVE = exports.LOG_AGENT_SYSTEM_DIR = void 0;
|
|
9
|
+
exports.DEBUG_WAIT_FOR_IDLE_TIMEOUT = exports.DEBUG_WAIT_FOR_IDLE = exports.DEBUG_RESOURCE_DISCOVERY_TIMEOUT = exports.DEBUG_AUTO_WIDTH = exports.DEBUG_AUTO_SCROLL = exports.DEBUG_RESOURCE_SCRAPPING_URL = exports.DEBUG_SNAPSHOT_PROCESSING = exports.DEBUG_SNAPSHOTS_PROCESSING = exports.DEBUG_EXEC_COMMAND = exports.DEBUG_EXEC_TEST_COMMAND = exports.LOG_INSTALLED_BROWSER = exports.LOG_SESSION_LINK = exports.LOG_SENDING_DATA = exports.LOG_SENDING_REQUEST = exports.LOG_PROCESSING_SNAPSHOTS = exports.LOG_RUNNING_EXEC_COMMAND = exports.LOG_TUNNEL_SSH_STREAM = exports.LOG_TUNNEL_TLS_AGENT_STREAM = void 0;
|
|
10
10
|
const ciInfo_1 = require("./types/ciInfo");
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
12
|
exports.ERR_AGENT_NOT_REGISTERED = 'Agent not registered. Exiting.';
|
|
@@ -257,6 +257,7 @@ exports.OPTION_TOKEN = 'token to authorize agent';
|
|
|
257
257
|
exports.OPTION_FORCE = 'overwrite tunnel if it already exist';
|
|
258
258
|
exports.OPTION_HTTP_HOST = 'provide custom HTTP host header';
|
|
259
259
|
exports.OPTION_HTTP_AUTH = 'enforce HTTP basic authorization';
|
|
260
|
+
exports.OPTION_HTTP_AUTH_BUDDY = 'enforce HTTP Buddy authorization';
|
|
260
261
|
exports.OPTION_HTTP_LOG = 'log HTTP requests';
|
|
261
262
|
exports.OPTION_HTTP_VERIFY = 'enforce TLS verify';
|
|
262
263
|
exports.OPTION_HTTP_2 = 'enforce HTTP/2';
|
package/distTs/src/tunnel/cfg.js
CHANGED
|
@@ -90,12 +90,17 @@ class Cfg {
|
|
|
90
90
|
else if (useDefaults)
|
|
91
91
|
tunnel.timeout = this.getTimeout();
|
|
92
92
|
if (type === tunnel_1.TUNNEL_TYPE.HTTP) {
|
|
93
|
+
tunnel.authType = tunnel_1.TUNNEL_HTTP_AUTH_TYPE.NONE;
|
|
93
94
|
if (options.host !== undefined)
|
|
94
95
|
tunnel.host = options.host;
|
|
95
96
|
if (options.auth !== undefined) {
|
|
96
97
|
const { password, login } = input_1.default.auth(options.auth);
|
|
97
98
|
tunnel.login = login;
|
|
98
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;
|
|
99
104
|
}
|
|
100
105
|
if (options.ca !== undefined)
|
|
101
106
|
tunnel.ca = input_1.default.ca(options.ca);
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -18,12 +41,21 @@ const http2_1 = __importDefault(require("./server/http2"));
|
|
|
18
41
|
const http1_1 = __importDefault(require("./server/http1"));
|
|
19
42
|
const log_1 = __importDefault(require("./http/log"));
|
|
20
43
|
const format_1 = __importDefault(require("../format"));
|
|
44
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
45
|
+
const cookie = __importStar(require("cookie"));
|
|
46
|
+
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
47
|
+
const undici_1 = require("undici");
|
|
21
48
|
const texts_1 = require("../texts");
|
|
22
49
|
const dns_1 = __importDefault(require("./dns"));
|
|
23
50
|
const tunnel_1 = require("../types/tunnel");
|
|
51
|
+
const cfg_1 = __importDefault(require("./cfg"));
|
|
52
|
+
const CIPHER_ALG = 'aes-256-cbc';
|
|
53
|
+
const CIPHER_IV = Buffer.alloc(16).fill(0);
|
|
54
|
+
const COOKIE_NAME = 'jwt_token';
|
|
24
55
|
class Tunnel extends events_1.default {
|
|
25
56
|
agent;
|
|
26
57
|
id;
|
|
58
|
+
cipherKey;
|
|
27
59
|
sshHostKey;
|
|
28
60
|
type;
|
|
29
61
|
region;
|
|
@@ -43,6 +75,7 @@ class Tunnel extends events_1.default {
|
|
|
43
75
|
host;
|
|
44
76
|
login;
|
|
45
77
|
password;
|
|
78
|
+
authType;
|
|
46
79
|
serve;
|
|
47
80
|
circuitBreaker;
|
|
48
81
|
log;
|
|
@@ -81,6 +114,7 @@ class Tunnel extends events_1.default {
|
|
|
81
114
|
sshHostKey = (0, utils_1.createSshHostKey)();
|
|
82
115
|
this.agent = agent;
|
|
83
116
|
this.id = id;
|
|
117
|
+
this.cipherKey = node_crypto_1.default.createHash('sha512').update(this.id).digest('hex').substring(0, 32);
|
|
84
118
|
this.sshHostKey = sshHostKey;
|
|
85
119
|
this.create({
|
|
86
120
|
type,
|
|
@@ -116,8 +150,21 @@ class Tunnel extends events_1.default {
|
|
|
116
150
|
}
|
|
117
151
|
if (httpSettings) {
|
|
118
152
|
this.host = httpSettings.host;
|
|
119
|
-
|
|
120
|
-
|
|
153
|
+
if (httpSettings.authType) {
|
|
154
|
+
this.authType = httpSettings.authType;
|
|
155
|
+
if (this.authType === tunnel_1.TUNNEL_HTTP_AUTH_TYPE.BASIC) {
|
|
156
|
+
this.login = httpSettings.login || '';
|
|
157
|
+
this.password = httpSettings.password || '';
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else if (httpSettings.login || httpSettings.password) {
|
|
161
|
+
this.authType = tunnel_1.TUNNEL_HTTP_AUTH_TYPE.BASIC;
|
|
162
|
+
this.login = httpSettings.login || '';
|
|
163
|
+
this.password = httpSettings.password || '';
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
this.authType = tunnel_1.TUNNEL_HTTP_AUTH_TYPE.NONE;
|
|
167
|
+
}
|
|
121
168
|
this.ca = httpSettings.ca;
|
|
122
169
|
this.serve = httpSettings.serve;
|
|
123
170
|
this.useragents = httpSettings.userAgents || [];
|
|
@@ -381,17 +428,231 @@ class Tunnel extends events_1.default {
|
|
|
381
428
|
}
|
|
382
429
|
this.emit(tunnel_1.TUNNEL_EVENT.HTTP_CLOSED, this);
|
|
383
430
|
}
|
|
384
|
-
httpBasicAuth(req, res) {
|
|
385
|
-
if (this.
|
|
431
|
+
async httpBasicAuth(req, res) {
|
|
432
|
+
if (this.authType === tunnel_1.TUNNEL_HTTP_AUTH_TYPE.BASIC) {
|
|
386
433
|
const user = (0, basic_auth_1.default)(req);
|
|
387
|
-
if (
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
434
|
+
if (user && user.name === this.login && user.pass === this.password) {
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
const authorized = await this._checkHttpPat(req, res, false);
|
|
438
|
+
if (authorized) {
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
logger_1.default.debug(texts_1.LOG_TUNNEL_HTTP_WRON_AUTH);
|
|
442
|
+
this.httpEndFast(req, res, 401, 'Unauthorised', {
|
|
443
|
+
'WWW-Authenticate': 'Basic real="Buddy"',
|
|
444
|
+
});
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
async _checkHttpPat(req, res, setCookie) {
|
|
450
|
+
const user = (0, basic_auth_1.default)(req);
|
|
451
|
+
if (!user || !user.name || !user.pass)
|
|
452
|
+
return false;
|
|
453
|
+
const client = this._getHttpAuthClient();
|
|
454
|
+
try {
|
|
455
|
+
const { statusCode, body } = await client.request({
|
|
456
|
+
path: `/tunnel/auth/pat`,
|
|
457
|
+
method: 'POST',
|
|
458
|
+
headers: {
|
|
459
|
+
'content-type': 'application/json',
|
|
460
|
+
},
|
|
461
|
+
body: JSON.stringify({
|
|
462
|
+
id: this.id,
|
|
463
|
+
agentId: this.agent.id,
|
|
464
|
+
login: user.name,
|
|
465
|
+
password: user.pass,
|
|
466
|
+
})
|
|
467
|
+
});
|
|
468
|
+
if (statusCode !== 200)
|
|
469
|
+
return false;
|
|
470
|
+
const result = await body.json();
|
|
471
|
+
if (!result.success)
|
|
392
472
|
return false;
|
|
473
|
+
if (setCookie)
|
|
474
|
+
this._httpSetAuthCookie(res, result.token);
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
catch {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
_getHttpAuthClient() {
|
|
482
|
+
return new undici_1.Client(cfg_1.default.getTokenHost(), {
|
|
483
|
+
connect: {
|
|
484
|
+
rejectUnauthorized: false
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
async _httpExchangeAuthCode(code) {
|
|
489
|
+
const client = this._getHttpAuthClient();
|
|
490
|
+
try {
|
|
491
|
+
const r = await client.request({
|
|
492
|
+
path: `/external-api/auth/token?grant_type=authorization_code`,
|
|
493
|
+
method: 'POST',
|
|
494
|
+
headers: {
|
|
495
|
+
'content-type': 'application/json',
|
|
496
|
+
},
|
|
497
|
+
body: JSON.stringify({
|
|
498
|
+
code
|
|
499
|
+
})
|
|
500
|
+
});
|
|
501
|
+
const o = await r.body.json();
|
|
502
|
+
if (o.accessToken) {
|
|
503
|
+
return o.accessToken;
|
|
393
504
|
}
|
|
394
505
|
}
|
|
506
|
+
catch {
|
|
507
|
+
// do nothing
|
|
508
|
+
}
|
|
509
|
+
return '';
|
|
510
|
+
}
|
|
511
|
+
_httpParseAuthToken(token) {
|
|
512
|
+
const msg = 'Invalid authorization token';
|
|
513
|
+
if (!token)
|
|
514
|
+
throw new Error(msg);
|
|
515
|
+
const data = (0, jsonwebtoken_1.decode)(token);
|
|
516
|
+
if (data === null || !data.tunnelId || !data.userId || data.aud !== 'tunnels' || data.sub !== 'tunnel_read')
|
|
517
|
+
throw new Error(msg);
|
|
518
|
+
return {
|
|
519
|
+
tunnelId: data.tunnelId,
|
|
520
|
+
userId: data.userId,
|
|
521
|
+
token
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
_httpSetAuthCookie(res, token) {
|
|
525
|
+
res.setHeader('set-cookie', cookie.serialize(COOKIE_NAME, token, {
|
|
526
|
+
maxAge: 3600,
|
|
527
|
+
path: '/',
|
|
528
|
+
secure: false,
|
|
529
|
+
httpOnly: true,
|
|
530
|
+
sameSite: 'lax'
|
|
531
|
+
}));
|
|
532
|
+
}
|
|
533
|
+
async _checkHttpAuthToken(code, token, req, res) {
|
|
534
|
+
let fromCookie = false;
|
|
535
|
+
if (code && !token) {
|
|
536
|
+
token = await this._httpExchangeAuthCode(code);
|
|
537
|
+
}
|
|
538
|
+
if (!token) {
|
|
539
|
+
const cookies = cookie.parse(req.headers.cookie || '');
|
|
540
|
+
token = cookies[COOKIE_NAME] || '';
|
|
541
|
+
fromCookie = true;
|
|
542
|
+
}
|
|
543
|
+
if (!token) {
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
try {
|
|
547
|
+
const data = this._httpParseAuthToken(token);
|
|
548
|
+
if (data.tunnelId !== this.id) {
|
|
549
|
+
return false;
|
|
550
|
+
}
|
|
551
|
+
if (!data.userId) {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
if (fromCookie) {
|
|
555
|
+
return true;
|
|
556
|
+
}
|
|
557
|
+
this._httpSetAuthCookie(res, token);
|
|
558
|
+
return true;
|
|
559
|
+
}
|
|
560
|
+
catch {
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
_httpEncryptState(str) {
|
|
565
|
+
try {
|
|
566
|
+
const cipher = node_crypto_1.default.createCipheriv(CIPHER_ALG, Buffer.from(this.cipherKey), Buffer.from(CIPHER_IV));
|
|
567
|
+
let enc = cipher.update(JSON.stringify({ str }), 'utf8', 'hex');
|
|
568
|
+
enc += cipher.final('hex');
|
|
569
|
+
return enc;
|
|
570
|
+
}
|
|
571
|
+
catch {
|
|
572
|
+
// do nothing
|
|
573
|
+
}
|
|
574
|
+
return '';
|
|
575
|
+
}
|
|
576
|
+
_httpDecryptState(state) {
|
|
577
|
+
if (state) {
|
|
578
|
+
try {
|
|
579
|
+
const decipher = node_crypto_1.default.createDecipheriv(CIPHER_ALG, Buffer.from(this.cipherKey), Buffer.from(CIPHER_IV));
|
|
580
|
+
let dec = decipher.update(state, 'hex', 'utf8');
|
|
581
|
+
dec += decipher.final('utf8');
|
|
582
|
+
const url = JSON.parse(dec).str;
|
|
583
|
+
if (url) {
|
|
584
|
+
new URL(url);
|
|
585
|
+
return url;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
catch {
|
|
589
|
+
// do nothing
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return '';
|
|
593
|
+
}
|
|
594
|
+
_redirectHttpToBuddyAuth(pathname, search, req, res) {
|
|
595
|
+
let host = this.agent.host;
|
|
596
|
+
if (/^https:\/\/\d+\.\d+\.\d+\.\d+$/.test(host)) {
|
|
597
|
+
host = 'https://app.local.io';
|
|
598
|
+
}
|
|
599
|
+
const callback = `https://${this.subdomain}.${(this.region || '').toLowerCase()}-${this.sshId}.${this.domain}`;
|
|
600
|
+
let state;
|
|
601
|
+
if (req.headers['x-forwarded-host']) {
|
|
602
|
+
if (req.headers['x-forwarded-proto'] === 'http') {
|
|
603
|
+
state = 'http://';
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
state = 'https://';
|
|
607
|
+
}
|
|
608
|
+
state += req.headers['x-forwarded-host'];
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
state = callback;
|
|
612
|
+
}
|
|
613
|
+
state += pathname;
|
|
614
|
+
if (search)
|
|
615
|
+
state += search;
|
|
616
|
+
const enc = this._httpEncryptState(state);
|
|
617
|
+
let url = `${host}/tunnel/auth?redirect_url=${encodeURIComponent(callback)}&id=${encodeURIComponent(this.id)}&agentId=${encodeURIComponent(this.agent.id)}&state=${encodeURIComponent(enc)}`;
|
|
618
|
+
if (/app\.local\.io/.test(host)) {
|
|
619
|
+
url += '&response_type=token';
|
|
620
|
+
}
|
|
621
|
+
this.httpEndFast(req, res, 302, 'Found', {
|
|
622
|
+
location: url,
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
async httpBuddyAuth(req, res) {
|
|
626
|
+
if (this.authType === tunnel_1.TUNNEL_HTTP_AUTH_TYPE.BUDDY) {
|
|
627
|
+
const { searchParams, pathname, search } = new URL(req.url, 'https://abc.com');
|
|
628
|
+
const code = searchParams.get('code') || '';
|
|
629
|
+
const state = searchParams.get('state') || '';
|
|
630
|
+
const token = searchParams.get('access_token') || '';
|
|
631
|
+
const url = this._httpDecryptState(state);
|
|
632
|
+
const authByToken = await this._checkHttpAuthToken(code, token, req, res);
|
|
633
|
+
if (authByToken) {
|
|
634
|
+
if (url) {
|
|
635
|
+
this.httpEndFast(req, res, 302, 'Found', {
|
|
636
|
+
location: url,
|
|
637
|
+
});
|
|
638
|
+
return false;
|
|
639
|
+
}
|
|
640
|
+
return true;
|
|
641
|
+
}
|
|
642
|
+
else if ((code || token) && url) {
|
|
643
|
+
this.httpEndFast(req, res, 404, 'Not found');
|
|
644
|
+
return false;
|
|
645
|
+
}
|
|
646
|
+
const auth = (0, basic_auth_1.default)(req);
|
|
647
|
+
if (auth) {
|
|
648
|
+
const authorized = await this._checkHttpPat(req, res, true);
|
|
649
|
+
if (authorized) {
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
this._redirectHttpToBuddyAuth(pathname, search, req, res);
|
|
654
|
+
return false;
|
|
655
|
+
}
|
|
395
656
|
return true;
|
|
396
657
|
}
|
|
397
658
|
httpEndFast(req, res, statusCode, msg, headers = {}) {
|
|
@@ -487,8 +748,9 @@ class Tunnel extends events_1.default {
|
|
|
487
748
|
return this.http1server.retryRequest(logRequest);
|
|
488
749
|
}
|
|
489
750
|
}
|
|
490
|
-
httpRequest(req, res) {
|
|
491
|
-
const isAuth = this.httpBasicAuth(req, res) &&
|
|
751
|
+
async httpRequest(req, res) {
|
|
752
|
+
const isAuth = (await this.httpBasicAuth(req, res)) &&
|
|
753
|
+
(await this.httpBuddyAuth(req, res)) &&
|
|
492
754
|
this.httpUserAgent(req, res) &&
|
|
493
755
|
this.httpRateLimit(req, res) &&
|
|
494
756
|
this.httpCircuitBreaker(req, res);
|
|
@@ -624,7 +886,15 @@ class Tunnel extends events_1.default {
|
|
|
624
886
|
this.safeEndStream(stream);
|
|
625
887
|
}
|
|
626
888
|
start() {
|
|
627
|
-
if (this.started ||
|
|
889
|
+
if (this.started ||
|
|
890
|
+
!this.sshIp ||
|
|
891
|
+
!this.sshPort ||
|
|
892
|
+
!this.domain ||
|
|
893
|
+
!this.subdomain ||
|
|
894
|
+
!this.region ||
|
|
895
|
+
!this.sshId ||
|
|
896
|
+
!this.sshUser ||
|
|
897
|
+
!this.sshPassword)
|
|
628
898
|
return;
|
|
629
899
|
this.started = true;
|
|
630
900
|
logger_1.default.info((0, texts_1.LOG_STARTING_TUNNEL)(this.id));
|
|
@@ -657,11 +927,11 @@ class Tunnel extends events_1.default {
|
|
|
657
927
|
this.http2server = new http2_1.default(host);
|
|
658
928
|
this.http2server.on(tunnel_1.TUNNEL_EVENT.HTTP_SESSION_OPEN, (session) => this.httpConnectionOpen(session));
|
|
659
929
|
this.http2server.on(tunnel_1.TUNNEL_EVENT.HTTP_SESSION_CLOSED, (session) => this.httpConnectionClosed(session));
|
|
660
|
-
this.http2server.on(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, (req, res) => this.httpRequest(req, res));
|
|
930
|
+
this.http2server.on(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, async (req, res) => await this.httpRequest(req, res));
|
|
661
931
|
this.http1server = new http1_1.default(host);
|
|
662
932
|
this.http1server.on(tunnel_1.TUNNEL_HTTP_SOCKET.OPEN, (socket) => this.httpConnectionOpen(socket));
|
|
663
933
|
this.http1server.on(tunnel_1.TUNNEL_HTTP_SOCKET.CLOSED, (socket) => this.httpConnectionClosed(socket));
|
|
664
|
-
this.http1server.on(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, (req, res) => this.httpRequest(req, res));
|
|
934
|
+
this.http1server.on(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, async (req, res) => await this.httpRequest(req, res));
|
|
665
935
|
}
|
|
666
936
|
else if (this.type === tunnel_1.TUNNEL_TYPE.SSH) {
|
|
667
937
|
// ssh server
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TUNNEL_AGENT_ACTION = exports.TUNNEL_AGENT_STATUS = exports.TUNNEL_TERMINATE_AT = exports.TUNNEL_REGION = exports.TUNNEL_SOCKET_TYPE = exports.TUNNEL_EVENT_LATENCY = exports.TUNNEL_EVENT_TCP = exports.TUNNEL_EVENT_HTTP = exports.TUNNEL_EVENT = exports.TUNNEL_SOCKET_MESSAGE = exports.TUNNEL_SOCKET_EVENT = exports.TUNNEL_COMPRESSION_METHOD = exports.TUNNEL_HTTP_SOCKET = exports.TUNNEL_SSH_EVENT = exports.TUNNEL_HTTP_IDENTIFY = exports.TUNNEL_STATUS = exports.TUNNEL_TYPE = void 0;
|
|
3
|
+
exports.TUNNEL_AGENT_ACTION = exports.TUNNEL_AGENT_STATUS = exports.TUNNEL_TERMINATE_AT = exports.TUNNEL_REGION = exports.TUNNEL_SOCKET_TYPE = exports.TUNNEL_EVENT_LATENCY = exports.TUNNEL_EVENT_TCP = exports.TUNNEL_EVENT_HTTP = exports.TUNNEL_EVENT = exports.TUNNEL_SOCKET_MESSAGE = exports.TUNNEL_SOCKET_EVENT = exports.TUNNEL_COMPRESSION_METHOD = exports.TUNNEL_HTTP_SOCKET = exports.TUNNEL_SSH_EVENT = exports.TUNNEL_HTTP_IDENTIFY = exports.TUNNEL_STATUS = exports.TUNNEL_HTTP_AUTH_TYPE = exports.TUNNEL_TYPE = void 0;
|
|
4
4
|
var TUNNEL_TYPE;
|
|
5
5
|
(function (TUNNEL_TYPE) {
|
|
6
6
|
TUNNEL_TYPE["TCP"] = "TCP";
|
|
@@ -8,6 +8,12 @@ var TUNNEL_TYPE;
|
|
|
8
8
|
TUNNEL_TYPE["HTTP"] = "HTTP";
|
|
9
9
|
TUNNEL_TYPE["SSH"] = "SSH";
|
|
10
10
|
})(TUNNEL_TYPE || (exports.TUNNEL_TYPE = TUNNEL_TYPE = {}));
|
|
11
|
+
var TUNNEL_HTTP_AUTH_TYPE;
|
|
12
|
+
(function (TUNNEL_HTTP_AUTH_TYPE) {
|
|
13
|
+
TUNNEL_HTTP_AUTH_TYPE["NONE"] = "NONE";
|
|
14
|
+
TUNNEL_HTTP_AUTH_TYPE["BUDDY"] = "BUDDY";
|
|
15
|
+
TUNNEL_HTTP_AUTH_TYPE["BASIC"] = "BASIC";
|
|
16
|
+
})(TUNNEL_HTTP_AUTH_TYPE || (exports.TUNNEL_HTTP_AUTH_TYPE = TUNNEL_HTTP_AUTH_TYPE = {}));
|
|
11
17
|
var TUNNEL_STATUS;
|
|
12
18
|
(function (TUNNEL_STATUS) {
|
|
13
19
|
TUNNEL_STATUS["OPEN"] = "OPEN";
|
package/distTs/src/utils.js
CHANGED
|
@@ -344,6 +344,7 @@ const getBasicCommandHttp = () => {
|
|
|
344
344
|
commandHttp.option('--response-header <headers...>', texts_1.OPTION_RESPONSE_HEADER);
|
|
345
345
|
commandHttp.option('--useragent <useragent...>', texts_1.OPTION_HEADER_USER_AGENT);
|
|
346
346
|
commandHttp.option('-a, --auth <user:pass>', texts_1.OPTION_HTTP_AUTH);
|
|
347
|
+
commandHttp.option('-b, --buddy', texts_1.OPTION_HTTP_AUTH_BUDDY);
|
|
347
348
|
commandHttp.option('-l, --log', texts_1.OPTION_HTTP_LOG);
|
|
348
349
|
commandHttp.option('-v, --verify', texts_1.OPTION_HTTP_VERIFY);
|
|
349
350
|
commandHttp.option('-2, --http2', texts_1.OPTION_HTTP_2);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bdy",
|
|
3
3
|
"preferGlobal": false,
|
|
4
|
-
"version": "1.12.
|
|
4
|
+
"version": "1.12.6-beta",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"@xhmikosr/decompress": "10.0.1",
|
|
24
24
|
"basic-auth": "2.0.1",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
|
+
"cookie": "1.0.2",
|
|
26
27
|
"commander": "12.1.0",
|
|
27
28
|
"content-disposition": "0.5.4",
|
|
28
29
|
"cross-spawn": "7.0.6",
|