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.
Files changed (58) hide show
  1. package/distTs/package.json +16 -5
  2. package/distTs/src/agent/agent.js +62 -36
  3. package/distTs/src/agent/linux.js +9 -4
  4. package/distTs/src/agent/manager.js +61 -42
  5. package/distTs/src/agent/osx.js +12 -5
  6. package/distTs/src/agent/socket/client.js +26 -7
  7. package/distTs/src/agent/socket/tunnel.js +56 -32
  8. package/distTs/src/agent/socket.js +83 -63
  9. package/distTs/src/agent/system.js +3 -1
  10. package/distTs/src/agent/windows.js +6 -6
  11. package/distTs/src/command/agent/install.js +4 -4
  12. package/distTs/src/command/agent/run.js +2 -2
  13. package/distTs/src/command/agent/status.js +6 -7
  14. package/distTs/src/command/agent/tunnel/http.js +4 -5
  15. package/distTs/src/command/agent/tunnel/tcp.js +3 -3
  16. package/distTs/src/command/agent/tunnel/tls.js +3 -3
  17. package/distTs/src/command/config/add/http.js +3 -3
  18. package/distTs/src/command/config/add/tcp.js +3 -3
  19. package/distTs/src/command/config/add/tls.js +3 -3
  20. package/distTs/src/command/config/get/region.js +1 -1
  21. package/distTs/src/command/pre.js +1 -1
  22. package/distTs/src/command/tunnel/http.js +2 -1
  23. package/distTs/src/command/tunnel/tcp.js +3 -3
  24. package/distTs/src/command/tunnel/tls.js +4 -4
  25. package/distTs/src/format.js +14 -15
  26. package/distTs/src/index.js +1 -1
  27. package/distTs/src/input.js +13 -12
  28. package/distTs/src/logger.js +12 -13
  29. package/distTs/src/tunnel/agent.js +3 -1
  30. package/distTs/src/tunnel/api/agent.js +1 -0
  31. package/distTs/src/tunnel/api/buddy.js +2 -0
  32. package/distTs/src/tunnel/cfg.js +6 -2
  33. package/distTs/src/tunnel/compression.js +17 -14
  34. package/distTs/src/tunnel/dns.js +20 -29
  35. package/distTs/src/tunnel/html.js +2 -0
  36. package/distTs/src/tunnel/http/log.js +30 -8
  37. package/distTs/src/tunnel/http/serve.js +3 -2
  38. package/distTs/src/tunnel/http/stream.js +5 -1
  39. package/distTs/src/tunnel/http.js +67 -26
  40. package/distTs/src/tunnel/identification.js +21 -14
  41. package/distTs/src/tunnel/latency.js +19 -11
  42. package/distTs/src/tunnel/output/interactive/tunnel.js +16 -9
  43. package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +4 -2
  44. package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +6 -4
  45. package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +2 -0
  46. package/distTs/src/tunnel/output/noninteractive/tunnel.js +13 -11
  47. package/distTs/src/tunnel/server/cert.js +2 -0
  48. package/distTs/src/tunnel/server/http1.js +15 -10
  49. package/distTs/src/tunnel/server/http2.js +18 -12
  50. package/distTs/src/tunnel/server/sftp.js +32 -15
  51. package/distTs/src/tunnel/server/ssh.js +49 -31
  52. package/distTs/src/tunnel/server/tls.js +11 -5
  53. package/distTs/src/tunnel/ssh/client.js +45 -31
  54. package/distTs/src/tunnel/tcp.js +61 -42
  55. package/distTs/src/tunnel/tunnel.js +196 -112
  56. package/distTs/src/types/tunnel.js +135 -0
  57. package/distTs/src/utils.js +2 -87
  58. package/package.json +16 -5
@@ -7,8 +7,14 @@ const ssh2_1 = require("ssh2");
7
7
  const events_1 = __importDefault(require("events"));
8
8
  const logger_1 = __importDefault(require("../../logger"));
9
9
  const texts_1 = require("../../texts");
10
- const utils_1 = require("../../utils");
10
+ const tunnel_1 = require("../../types/tunnel");
11
11
  class SshClient extends events_1.default {
12
+ ip;
13
+ port;
14
+ username;
15
+ password;
16
+ keepalive;
17
+ client;
12
18
  constructor(ip, port, username, password) {
13
19
  super();
14
20
  this.ip = ip;
@@ -24,12 +30,16 @@ class SshClient extends events_1.default {
24
30
  this.client = new ssh2_1.Client();
25
31
  this.client.setNoDelay();
26
32
  this.client.on('ready', () => {
27
- this.client.removeAllListeners();
28
- this.client.on('error', () => { });
33
+ if (this.client) {
34
+ this.client.removeAllListeners();
35
+ this.client.on('error', () => { });
36
+ }
29
37
  resolve();
30
38
  });
31
39
  this.client.once('error', (err) => {
32
- this.client.removeAllListeners();
40
+ if (this.client) {
41
+ this.client.removeAllListeners();
42
+ }
33
43
  reject(err);
34
44
  });
35
45
  try {
@@ -112,29 +122,29 @@ class SshClient extends events_1.default {
112
122
  stream.emit('error', err);
113
123
  return;
114
124
  }
115
- if (type === utils_1.SOCKET_TYPE_TLS) {
125
+ if (type === tunnel_1.TUNNEL_SOCKET_TYPE.TLS) {
116
126
  logger_1.default.debug((0, texts_1.LOG_DETECTED_STREAM)('TLS'));
117
- triggerStream(utils_1.SSH_CLIENT_EVENT_STREAM_TLS, ip);
127
+ triggerStream(tunnel_1.TUNNEL_SSH_EVENT.STREAM_TLS, ip);
118
128
  return;
119
129
  }
120
- if (type === utils_1.SOCKET_TYPE_HTTP1) {
130
+ if (type === tunnel_1.TUNNEL_SOCKET_TYPE.HTTP1) {
121
131
  logger_1.default.debug((0, texts_1.LOG_DETECTED_STREAM)('HTTP1'));
122
- triggerStream(utils_1.SSH_CLIENT_EVENT_STREAM_HTTP1, ip);
132
+ triggerStream(tunnel_1.TUNNEL_SSH_EVENT.STREAM_HTTP1, ip);
123
133
  return;
124
134
  }
125
- if (type === utils_1.SOCKET_TYPE_HTTP2) {
135
+ if (type === tunnel_1.TUNNEL_SOCKET_TYPE.HTTP2) {
126
136
  logger_1.default.debug((0, texts_1.LOG_DETECTED_STREAM)('HTTP2'));
127
- triggerStream(utils_1.SSH_CLIENT_EVENT_STREAM_HTTP2, ip);
137
+ triggerStream(tunnel_1.TUNNEL_SSH_EVENT.STREAM_HTTP2, ip);
128
138
  return;
129
139
  }
130
- if (type === utils_1.SOCKET_TYPE_TCP) {
140
+ if (type === tunnel_1.TUNNEL_SOCKET_TYPE.TCP) {
131
141
  logger_1.default.debug((0, texts_1.LOG_DETECTED_STREAM)('TCP'));
132
- triggerStream(utils_1.SSH_CLIENT_EVENT_STREAM_TCP, ip);
142
+ triggerStream(tunnel_1.TUNNEL_SSH_EVENT.STREAM_TCP, ip);
133
143
  return;
134
144
  }
135
- if (type === utils_1.SOCKET_TYPE_SSH) {
145
+ if (type === tunnel_1.TUNNEL_SOCKET_TYPE.SSH) {
136
146
  logger_1.default.debug((0, texts_1.LOG_DETECTED_STREAM)('SSH'));
137
- triggerStream(utils_1.SSH_CLIENT_EVENT_STREAM_SSH, ip);
147
+ triggerStream(tunnel_1.TUNNEL_SSH_EVENT.STREAM_SSH, ip);
138
148
  return;
139
149
  }
140
150
  logger_1.default.debug(texts_1.LOG_WRONG_STREAM);
@@ -142,16 +152,18 @@ class SshClient extends events_1.default {
142
152
  }
143
153
  forwardIn(port) {
144
154
  return new Promise((resolve, reject) => {
145
- this.client.on('tcp connection', async (info, accept) => {
146
- logger_1.default.debug(texts_1.LOG_SSH_CONNECTION);
147
- return this.processStream(accept(), info);
148
- });
149
- this.client.forwardIn('0.0.0.0', port, (err) => {
150
- if (err)
151
- reject(err);
152
- else
153
- resolve(err);
154
- });
155
+ if (this.client) {
156
+ this.client.on('tcp connection', async (info, accept) => {
157
+ logger_1.default.debug(texts_1.LOG_SSH_CONNECTION);
158
+ return this.processStream(accept(), info);
159
+ });
160
+ this.client.forwardIn('0.0.0.0', port, (err) => {
161
+ if (err)
162
+ reject(err);
163
+ else
164
+ resolve(err);
165
+ });
166
+ }
155
167
  });
156
168
  }
157
169
  closeKeepAlive() {
@@ -164,16 +176,18 @@ class SshClient extends events_1.default {
164
176
  this.open()
165
177
  .then(() => {
166
178
  logger_1.default.debug(`SSH client opened`);
167
- this.emit(utils_1.SSH_CLIENT_EVENT_CONNECTED);
168
- this.client.on('close', () => {
169
- logger_1.default.debug(`SSH client closed`);
170
- if (this.keepalive)
171
- this.openKeepAlive();
172
- });
179
+ this.emit(tunnel_1.TUNNEL_SSH_EVENT.CONNECTED);
180
+ if (this.client) {
181
+ this.client.on('close', () => {
182
+ logger_1.default.debug(`SSH client closed`);
183
+ if (this.keepalive)
184
+ this.openKeepAlive();
185
+ });
186
+ }
173
187
  })
174
188
  .catch(() => {
175
189
  logger_1.default.debug(`SSH client closed`);
176
- this.emit(utils_1.SSH_CLIENT_EVENT_DISCONNECTED);
190
+ this.emit(tunnel_1.TUNNEL_SSH_EVENT.DISCONNECTED);
177
191
  setTimeout(() => {
178
192
  if (this.keepalive)
179
193
  this.openKeepAlive();
@@ -7,8 +7,13 @@ const net_1 = require("net");
7
7
  const uuid_1 = require("uuid");
8
8
  const events_1 = __importDefault(require("events"));
9
9
  const utils_1 = require("../utils");
10
- const utils_2 = require("../utils");
10
+ const tunnel_1 = require("../types/tunnel");
11
11
  class TunnelTcp extends events_1.default {
12
+ id;
13
+ host;
14
+ port;
15
+ stream;
16
+ socket;
12
17
  constructor(host, port, stream) {
13
18
  super();
14
19
  this.id = (0, uuid_1.v4)();
@@ -19,39 +24,47 @@ class TunnelTcp extends events_1.default {
19
24
  }
20
25
  end() {
21
26
  try {
22
- this.stream.unpipe();
23
- this.socket.unpipe();
27
+ if (this.stream)
28
+ this.stream.unpipe();
29
+ if (this.socket)
30
+ this.socket.unpipe();
24
31
  }
25
32
  catch {
26
33
  // do nothing
27
34
  }
28
- try {
29
- this.stream.removeAllListeners();
30
- this.stream.on('error', () => { });
31
- this.stream.end();
32
- }
33
- catch {
34
- // do nothing
35
+ if (this.stream) {
36
+ try {
37
+ this.stream.removeAllListeners();
38
+ this.stream.on('error', () => { });
39
+ this.stream.end();
40
+ }
41
+ catch {
42
+ // do nothing
43
+ }
35
44
  }
36
45
  const s1 = this.stream;
37
- try {
38
- this.socket.removeAllListeners();
39
- this.socket.once('error', () => { });
40
- this.socket.end();
41
- }
42
- catch {
43
- // do nothing
46
+ if (this.socket) {
47
+ try {
48
+ this.socket.removeAllListeners();
49
+ this.socket.once('error', () => { });
50
+ this.socket.end();
51
+ }
52
+ catch {
53
+ // do nothing
54
+ }
44
55
  }
45
56
  const s2 = this.socket;
46
57
  setTimeout(() => {
47
58
  try {
48
- s1.destroy();
59
+ if (s1)
60
+ s1.destroy();
49
61
  }
50
62
  catch {
51
63
  // do nothing
52
64
  }
53
65
  try {
54
- s2.destroy();
66
+ if (s2)
67
+ s2.destroy();
55
68
  }
56
69
  catch {
57
70
  // do nothing
@@ -61,33 +74,39 @@ class TunnelTcp extends events_1.default {
61
74
  this.stream = null;
62
75
  this.host = null;
63
76
  this.port = null;
64
- this.emit(utils_2.TCP_EVENT_CLOSED);
77
+ this.emit(tunnel_1.TUNNEL_EVENT_TCP.CLOSED);
65
78
  }
66
79
  pipe() {
67
- this.socket.on('error', () => {
68
- this.end();
69
- });
70
- this.socket.on('close', () => {
71
- this.end();
72
- });
73
- this.stream.on('error', () => {
74
- this.end();
75
- });
76
- this.stream.on('close', () => {
77
- this.end();
78
- });
79
- try {
80
- this.socket.connect({
81
- noDelay: true,
82
- keepAlive: true,
83
- host: (0, utils_1.getRealTargetHost)(this.host),
84
- port: this.port,
85
- }, () => {
86
- this.socket.pipe(this.stream).pipe(this.socket);
80
+ if (this.stream) {
81
+ this.stream.on('error', () => {
82
+ this.end();
83
+ });
84
+ this.stream.on('close', () => {
85
+ this.end();
87
86
  });
88
87
  }
89
- catch {
90
- this.end();
88
+ if (this.socket) {
89
+ this.socket.on('error', () => {
90
+ this.end();
91
+ });
92
+ this.socket.on('close', () => {
93
+ this.end();
94
+ });
95
+ try {
96
+ this.socket.connect({
97
+ noDelay: true,
98
+ keepAlive: true,
99
+ host: (0, utils_1.getRealTargetHost)(this.host),
100
+ port: this.port || 0,
101
+ }, () => {
102
+ if (this.socket && this.stream) {
103
+ this.socket.pipe(this.stream).pipe(this.socket);
104
+ }
105
+ });
106
+ }
107
+ catch {
108
+ this.end();
109
+ }
91
110
  }
92
111
  }
93
112
  }