proxy_chain_rb 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +16 -16
- data/README.md +14 -5
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/.yarn-integrity +23 -0
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/README.md +1 -1
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.js +254 -121
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.min.js +3 -3
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.js +284 -129
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.min.js +4 -4
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/async.js +3 -48
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/debuggability.js +145 -27
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/join.js +4 -7
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/map.js +10 -3
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/promise.js +58 -28
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/promise_array.js +1 -0
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/reduce.js +16 -5
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/settle.js +4 -0
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/util.js +39 -7
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/package.json +39 -63
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/commander/CHANGELOG.md +11 -0
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/commander/index.js +1 -1
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/commander/package.json +20 -52
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/debug/package.json +21 -60
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/ms/package.json +19 -51
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/portastic/node_modules/bluebird/package.json +41 -66
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/portastic/package.json +23 -51
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/CHANGELOG.md +18 -0
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/README.md +8 -0
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/anonymize_proxy.js +5 -0
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_base.js +86 -53
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_forward.js +23 -5
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_chain.js +3 -7
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_direct.js +1 -1
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/index.js +3 -5
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/server.js +3 -1
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel.js +245 -115
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel_tools.js +138 -0
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/node_modules/.bin/portastic +1 -0
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/package.json +41 -68
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/underscore/package.json +27 -58
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/package.json +1 -1
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/server.js +4 -2
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/yarn.lock +53 -0
- data/lib/proxy_chain_rb/server.rb +8 -6
- data/lib/proxy_chain_rb/version.rb +1 -1
- data/proxy_chain_rb.gemspec +3 -3
- metadata +16 -14
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_tcp_chain.js +0 -271
- data/lib/proxy_chain_rb/node_js/proxy-chain-server/package-lock.json +0 -63
@@ -1,16 +1,18 @@
|
|
1
1
|
module ProxyChainRb
|
2
2
|
class Server
|
3
|
-
attr_accessor :script_path, :instance_id, :
|
3
|
+
attr_accessor :script_path, :instance_id, :pid_command, :pid, :generated_proxy_url
|
4
4
|
|
5
5
|
def initialize(instance_id = nil)
|
6
6
|
self.script_path = File.expand_path("../node_js/proxy-chain-server/server.js", __FILE__)
|
7
7
|
self.instance_id = instance_id.to_s.empty? ? SecureRandom.hex : instance_id
|
8
|
-
self.
|
8
|
+
self.pid_command = "ps aux | grep \"[n]ode\" | awk '/proxy-chain-instance-id-#{self.instance_id}/'"
|
9
9
|
self.generated_proxy_url = nil
|
10
10
|
end
|
11
|
-
|
12
|
-
def start(proxy_url, wait: 3)
|
13
|
-
|
11
|
+
|
12
|
+
def start(proxy_url, tag: "default", started_at: Time.now, wait: 3)
|
13
|
+
command = "((node #{self.script_path} \"#{proxy_url}\" proxy-chain-instance-id-#{self.instance_id} tag-#{tag} started-#{started_at.to_i} &)&)"
|
14
|
+
|
15
|
+
IO.popen(command) do |io|
|
14
16
|
self.generated_proxy_url = io.gets&.strip
|
15
17
|
end
|
16
18
|
|
@@ -23,7 +25,7 @@ module ProxyChainRb
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def identify_pid
|
26
|
-
process = `#{self.
|
28
|
+
process = `#{self.pid_command}`.split("\n")&.select { |p| p =~ /proxy-chain-instance-id-#{self.instance_id}/i }&.first
|
27
29
|
parts = process&.split(' ')
|
28
30
|
pid = parts && parts.any? ? parts[1] : nil
|
29
31
|
self.pid = !pid.to_s.empty? ? pid.to_i : nil
|
data/proxy_chain_rb.gemspec
CHANGED
@@ -23,9 +23,9 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
-
spec.add_development_dependency "bundler", "
|
27
|
-
spec.add_development_dependency "rake",
|
28
|
-
spec.add_development_dependency "rspec",
|
26
|
+
spec.add_development_dependency "bundler", ">= 1.17.2"
|
27
|
+
spec.add_development_dependency "rake", ">= 12.3.2"
|
28
|
+
spec.add_development_dependency "rspec", ">= 3.0"
|
29
29
|
|
30
30
|
spec.add_development_dependency "pry", "~> 0.12.2"
|
31
31
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proxy_chain_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Johnsson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.17.2
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.17.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- bin/setup
|
87
87
|
- lib/proxy_chain_rb.rb
|
88
88
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/.bin/portastic
|
89
|
+
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/.yarn-integrity
|
89
90
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/LICENSE
|
90
91
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/README.md
|
91
92
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/changelog.md
|
@@ -220,13 +221,14 @@ files:
|
|
220
221
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_forward.js
|
221
222
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_chain.js
|
222
223
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_direct.js
|
223
|
-
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_tcp_chain.js
|
224
224
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/index.js
|
225
225
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/run_locally.js
|
226
226
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/server.js
|
227
227
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel.js
|
228
|
+
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel_tools.js
|
228
229
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/testing_tcp_service.js
|
229
230
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/tools.js
|
231
|
+
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/node_modules/.bin/portastic
|
230
232
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/package.json
|
231
233
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/underscore/LICENSE
|
232
234
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/underscore/README.md
|
@@ -234,9 +236,9 @@ files:
|
|
234
236
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/underscore/underscore-min.js
|
235
237
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/underscore/underscore-min.js.map
|
236
238
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/underscore/underscore.js
|
237
|
-
- lib/proxy_chain_rb/node_js/proxy-chain-server/package-lock.json
|
238
239
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/package.json
|
239
240
|
- lib/proxy_chain_rb/node_js/proxy-chain-server/server.js
|
241
|
+
- lib/proxy_chain_rb/node_js/proxy-chain-server/yarn.lock
|
240
242
|
- lib/proxy_chain_rb/server.rb
|
241
243
|
- lib/proxy_chain_rb/version.rb
|
242
244
|
- proxy_chain_rb.gemspec
|
@@ -1,271 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
|
7
|
-
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
8
|
-
|
9
|
-
var _http = require('http');
|
10
|
-
|
11
|
-
var _http2 = _interopRequireDefault(_http);
|
12
|
-
|
13
|
-
var _tools = require('./tools');
|
14
|
-
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
16
|
-
|
17
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
18
|
-
|
19
|
-
/* globals Buffer */
|
20
|
-
|
21
|
-
// TODO: please rename this class to something else than "Handler", it makes it look like the class inherits from HandlerBase, which it doesn't
|
22
|
-
|
23
|
-
/**
|
24
|
-
* Represents a connection from source client to an external proxy using HTTP CONNECT tunnel, allows TCP connection.
|
25
|
-
*/
|
26
|
-
var HandlerTunnelTcpChain = function () {
|
27
|
-
function HandlerTunnelTcpChain(_ref) {
|
28
|
-
var srcSocket = _ref.srcSocket,
|
29
|
-
trgParsed = _ref.trgParsed,
|
30
|
-
upstreamProxyUrlParsed = _ref.upstreamProxyUrlParsed,
|
31
|
-
log = _ref.log;
|
32
|
-
|
33
|
-
_classCallCheck(this, HandlerTunnelTcpChain);
|
34
|
-
|
35
|
-
this.log = log;
|
36
|
-
|
37
|
-
// Bind all event handlers to this instance
|
38
|
-
this.bindHandlersToThis(['onSrcSocketClose', 'onSrcSocketEnd', 'onSrcSocketError', 'onTrgSocket', 'onTrgSocketClose', 'onTrgSocketEnd', 'onTrgSocketError', 'onTrgRequestConnect', 'onTrgRequestAbort', 'onTrgRequestError']);
|
39
|
-
|
40
|
-
if (!trgParsed.hostname) throw new Error('The "trgParsed.hostname" option is required');
|
41
|
-
if (!trgParsed.port) throw new Error('The "trgParsed.port" option is required');
|
42
|
-
|
43
|
-
this.trgRequest = null;
|
44
|
-
this.trgSocket = null;
|
45
|
-
this.trgParsed = trgParsed;
|
46
|
-
this.trgParsed.port = this.trgParsed.port || DEFAULT_TARGET_PORT;
|
47
|
-
|
48
|
-
this.srcSocket = srcSocket;
|
49
|
-
this.srcSocket.once('close', this.onSrcSocketClose);
|
50
|
-
this.srcSocket.once('end', this.onSrcSocketEnd);
|
51
|
-
this.srcSocket.once('error', this.onSrcSocketError);
|
52
|
-
|
53
|
-
this.upstreamProxyUrlParsed = upstreamProxyUrlParsed;
|
54
|
-
|
55
|
-
this.isClosed = false;
|
56
|
-
}
|
57
|
-
|
58
|
-
_createClass(HandlerTunnelTcpChain, [{
|
59
|
-
key: 'bindHandlersToThis',
|
60
|
-
value: function bindHandlersToThis(handlerNames) {
|
61
|
-
var _this = this;
|
62
|
-
|
63
|
-
handlerNames.forEach(function (evt) {
|
64
|
-
_this[evt] = _this[evt].bind(_this);
|
65
|
-
});
|
66
|
-
}
|
67
|
-
}, {
|
68
|
-
key: 'run',
|
69
|
-
value: function run() {
|
70
|
-
this.log('Connecting to upstream proxy...');
|
71
|
-
|
72
|
-
var options = {
|
73
|
-
method: 'CONNECT',
|
74
|
-
hostname: this.upstreamProxyUrlParsed.hostname,
|
75
|
-
port: this.upstreamProxyUrlParsed.port,
|
76
|
-
path: this.trgParsed.hostname + ':' + this.trgParsed.port,
|
77
|
-
headers: {}
|
78
|
-
};
|
79
|
-
|
80
|
-
(0, _tools.maybeAddProxyAuthorizationHeader)(this.upstreamProxyUrlParsed, options.headers);
|
81
|
-
|
82
|
-
this.trgRequest = _http2.default.request(options);
|
83
|
-
|
84
|
-
this.trgRequest.once('connect', this.onTrgRequestConnect);
|
85
|
-
this.trgRequest.once('abort', this.onTrgRequestAbort);
|
86
|
-
this.trgRequest.once('error', this.onTrgRequestError);
|
87
|
-
this.trgRequest.on('socket', this.onTrgSocket);
|
88
|
-
|
89
|
-
// Send the data
|
90
|
-
this.trgRequest.end();
|
91
|
-
}
|
92
|
-
|
93
|
-
// If the client closes the connection prematurely,
|
94
|
-
// then immediately destroy the upstream socket, there's nothing we can do with it
|
95
|
-
|
96
|
-
}, {
|
97
|
-
key: 'onSrcSocketClose',
|
98
|
-
value: function onSrcSocketClose() {
|
99
|
-
if (this.isClosed) return;
|
100
|
-
this.log('Source socket closed');
|
101
|
-
this.close();
|
102
|
-
}
|
103
|
-
}, {
|
104
|
-
key: 'onSrcSocketEnd',
|
105
|
-
value: function onSrcSocketEnd() {
|
106
|
-
if (this.isClosed) return;
|
107
|
-
this.log('Source socket ended');
|
108
|
-
this.close();
|
109
|
-
}
|
110
|
-
}, {
|
111
|
-
key: 'onSrcSocketError',
|
112
|
-
value: function onSrcSocketError(err) {
|
113
|
-
if (this.isClosed) return;
|
114
|
-
this.log('Source socket failed: ' + (err.stack || err));
|
115
|
-
this.close();
|
116
|
-
}
|
117
|
-
}, {
|
118
|
-
key: 'onTrgSocket',
|
119
|
-
value: function onTrgSocket(socket) {
|
120
|
-
if (this.isClosed) return;
|
121
|
-
|
122
|
-
this.log('Target socket assigned');
|
123
|
-
|
124
|
-
this.trgSocket = socket;
|
125
|
-
|
126
|
-
socket.once('close', this.onTrgSocketClose);
|
127
|
-
socket.once('end', this.onTrgSocketEnd);
|
128
|
-
socket.once('error', this.onTrgSocketError);
|
129
|
-
}
|
130
|
-
|
131
|
-
// Once target socket closes, we need to give time
|
132
|
-
// to source socket to receive pending data, so we only call end()
|
133
|
-
|
134
|
-
}, {
|
135
|
-
key: 'onTrgSocketClose',
|
136
|
-
value: function onTrgSocketClose() {
|
137
|
-
var _this2 = this;
|
138
|
-
|
139
|
-
if (this.isClosed) return;
|
140
|
-
this.log('Target socket closed');
|
141
|
-
setTimeout(function () {
|
142
|
-
if (_this2.srcSocket) _this2.srcSocket.end();
|
143
|
-
}, 100);
|
144
|
-
}
|
145
|
-
}, {
|
146
|
-
key: 'onTrgSocketEnd',
|
147
|
-
value: function onTrgSocketEnd() {
|
148
|
-
var _this3 = this;
|
149
|
-
|
150
|
-
if (this.isClosed) return;
|
151
|
-
this.log('Target socket ended');
|
152
|
-
setTimeout(function () {
|
153
|
-
if (_this3.srcSocket) _this3.srcSocket.end();
|
154
|
-
}, 100);
|
155
|
-
}
|
156
|
-
}, {
|
157
|
-
key: 'onTrgSocketError',
|
158
|
-
value: function onTrgSocketError(err) {
|
159
|
-
if (this.isClosed) return;
|
160
|
-
this.log('Target socket failed: ' + (err.stack || err));
|
161
|
-
this.fail(err);
|
162
|
-
}
|
163
|
-
}, {
|
164
|
-
key: 'onTrgRequestConnect',
|
165
|
-
value: function onTrgRequestConnect(response) {
|
166
|
-
if (this.isClosed) return;
|
167
|
-
this.log('Connected to upstream proxy');
|
168
|
-
|
169
|
-
if (this.checkUpstreamProxy407(response)) return;
|
170
|
-
|
171
|
-
// Setup bi-directional tunnel
|
172
|
-
this.trgSocket.pipe(this.srcSocket);
|
173
|
-
this.srcSocket.pipe(this.trgSocket);
|
174
|
-
|
175
|
-
this.srcSocket.resume();
|
176
|
-
}
|
177
|
-
}, {
|
178
|
-
key: 'onTrgRequestAbort',
|
179
|
-
value: function onTrgRequestAbort() {
|
180
|
-
if (this.isClosed) return;
|
181
|
-
this.log('Target aborted');
|
182
|
-
this.close();
|
183
|
-
}
|
184
|
-
}, {
|
185
|
-
key: 'onTrgRequestError',
|
186
|
-
value: function onTrgRequestError(err) {
|
187
|
-
if (this.isClosed) return;
|
188
|
-
this.log('Target request failed: ' + (err.stack || err));
|
189
|
-
this.fail(err);
|
190
|
-
}
|
191
|
-
|
192
|
-
/**
|
193
|
-
* Checks whether response from upstream proxy is 407 Proxy Authentication Required
|
194
|
-
* and if so, responds 502 Bad Gateway to client.
|
195
|
-
* @param response
|
196
|
-
* @return {boolean}
|
197
|
-
*/
|
198
|
-
|
199
|
-
}, {
|
200
|
-
key: 'checkUpstreamProxy407',
|
201
|
-
value: function checkUpstreamProxy407(response) {
|
202
|
-
if (this.upstreamProxyUrlParsed && response.statusCode === 407) {
|
203
|
-
this.fail('Invalid credentials provided for the upstream proxy.', 502);
|
204
|
-
return true;
|
205
|
-
}
|
206
|
-
return false;
|
207
|
-
}
|
208
|
-
}, {
|
209
|
-
key: 'fail',
|
210
|
-
value: function fail(err, statusCode) {
|
211
|
-
if (this.srcGotResponse) {
|
212
|
-
this.log('Source already received a response, just destroying the socket...');
|
213
|
-
this.close();
|
214
|
-
} else if (statusCode) {
|
215
|
-
// Manual error
|
216
|
-
this.log(err + ', responding with custom status code ' + statusCode + ' to client');
|
217
|
-
} else if (err.code === 'ENOTFOUND' && !this.upstreamProxyUrlParsed) {
|
218
|
-
this.log('Target server not found, sending 404 to client');
|
219
|
-
} else if (err.code === 'ENOTFOUND' && this.upstreamProxyUrlParsed) {
|
220
|
-
this.log('Upstream proxy not found, sending 502 to client');
|
221
|
-
} else if (err.code === 'ECONNREFUSED') {
|
222
|
-
this.log('Upstream proxy refused connection, sending 502 to client');
|
223
|
-
} else if (err.code === 'ETIMEDOUT') {
|
224
|
-
this.log('Connection timed out, sending 502 to client');
|
225
|
-
} else if (err.code === 'ECONNRESET') {
|
226
|
-
this.log('Connection lost, sending 502 to client');
|
227
|
-
} else if (err.code === 'EPIPE') {
|
228
|
-
this.log('Socket closed before write, sending 502 to client');
|
229
|
-
} else {
|
230
|
-
this.log('Unknown error, sending 500 to client');
|
231
|
-
}
|
232
|
-
}
|
233
|
-
/**
|
234
|
-
* Detaches all listeners and destroys all sockets.
|
235
|
-
*/
|
236
|
-
|
237
|
-
}, {
|
238
|
-
key: 'close',
|
239
|
-
value: function close() {
|
240
|
-
if (!this.isClosed) {
|
241
|
-
this.log('Closing handler');
|
242
|
-
|
243
|
-
if (this.srcRequest) {
|
244
|
-
this.srcRequest.destroy();
|
245
|
-
this.srcRequest = null;
|
246
|
-
}
|
247
|
-
|
248
|
-
if (this.srcSocket) {
|
249
|
-
this.srcSocket.destroy();
|
250
|
-
this.srcSocket = null;
|
251
|
-
}
|
252
|
-
|
253
|
-
if (this.trgRequest) {
|
254
|
-
this.trgRequest.abort();
|
255
|
-
this.trgRequest = null;
|
256
|
-
}
|
257
|
-
|
258
|
-
if (this.trgSocket) {
|
259
|
-
this.trgSocket.destroy();
|
260
|
-
this.trgSocket = null;
|
261
|
-
}
|
262
|
-
|
263
|
-
this.isClosed = true;
|
264
|
-
}
|
265
|
-
}
|
266
|
-
}]);
|
267
|
-
|
268
|
-
return HandlerTunnelTcpChain;
|
269
|
-
}();
|
270
|
-
|
271
|
-
exports.default = HandlerTunnelTcpChain;
|
@@ -1,63 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "proxy-chain-server",
|
3
|
-
"version": "1.0.0",
|
4
|
-
"lockfileVersion": 1,
|
5
|
-
"requires": true,
|
6
|
-
"dependencies": {
|
7
|
-
"bluebird": {
|
8
|
-
"version": "3.5.5",
|
9
|
-
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz",
|
10
|
-
"integrity": "sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w=="
|
11
|
-
},
|
12
|
-
"commander": {
|
13
|
-
"version": "2.20.0",
|
14
|
-
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz",
|
15
|
-
"integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ=="
|
16
|
-
},
|
17
|
-
"debug": {
|
18
|
-
"version": "2.6.9",
|
19
|
-
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
20
|
-
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
21
|
-
"requires": {
|
22
|
-
"ms": "2.0.0"
|
23
|
-
}
|
24
|
-
},
|
25
|
-
"ms": {
|
26
|
-
"version": "2.0.0",
|
27
|
-
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
28
|
-
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
29
|
-
},
|
30
|
-
"portastic": {
|
31
|
-
"version": "1.0.1",
|
32
|
-
"resolved": "https://registry.npmjs.org/portastic/-/portastic-1.0.1.tgz",
|
33
|
-
"integrity": "sha1-HJgF1D+uj2pAzw28d5QJGi6dDSo=",
|
34
|
-
"requires": {
|
35
|
-
"bluebird": "^2.9.34",
|
36
|
-
"commander": "^2.8.1",
|
37
|
-
"debug": "^2.2.0"
|
38
|
-
},
|
39
|
-
"dependencies": {
|
40
|
-
"bluebird": {
|
41
|
-
"version": "2.11.0",
|
42
|
-
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-2.11.0.tgz",
|
43
|
-
"integrity": "sha1-U0uQM8AiyVecVro7Plpcqvu2UOE="
|
44
|
-
}
|
45
|
-
}
|
46
|
-
},
|
47
|
-
"proxy-chain": {
|
48
|
-
"version": "0.2.7",
|
49
|
-
"resolved": "https://registry.npmjs.org/proxy-chain/-/proxy-chain-0.2.7.tgz",
|
50
|
-
"integrity": "sha512-e0s94WDfooeC3zQkvIJ/Eudiy/AywTQK4K6PMYbZdBE2m/eug54ThgCPdBE4txHvzi0A0gAVbX04Kt4RygTlRQ==",
|
51
|
-
"requires": {
|
52
|
-
"bluebird": "^3.5.1",
|
53
|
-
"portastic": "^1.0.1",
|
54
|
-
"underscore": "^1.9.1"
|
55
|
-
}
|
56
|
-
},
|
57
|
-
"underscore": {
|
58
|
-
"version": "1.9.1",
|
59
|
-
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.9.1.tgz",
|
60
|
-
"integrity": "sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg=="
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|