browsed 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gemfile.lock +2 -2
  4. data/README.md +12 -17
  5. data/bin/browse +13 -10
  6. data/lib/browsed.rb +9 -2
  7. data/lib/browsed/browser.rb +82 -0
  8. data/lib/browsed/chrome.rb +21 -12
  9. data/lib/browsed/client.rb +48 -130
  10. data/lib/browsed/constants.rb +7 -1
  11. data/lib/browsed/errors.rb +1 -0
  12. data/lib/browsed/extensions/hash.rb +27 -0
  13. data/lib/browsed/firefox.rb +18 -17
  14. data/lib/browsed/manager.rb +5 -5
  15. data/lib/browsed/{poltergeist.rb → phantomjs.rb} +2 -2
  16. data/lib/browsed/proxies.rb +26 -0
  17. data/lib/browsed/{extensions → proxies}/chrome/proxy_authentication.rb +3 -3
  18. data/lib/browsed/proxies/proxy-chain-server/node_modules/.bin/portastic +1 -0
  19. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/LICENSE +21 -0
  20. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/README.md +57 -0
  21. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/changelog.md +1 -0
  22. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.js +3824 -0
  23. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.min.js +31 -0
  24. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.js +5666 -0
  25. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.min.js +31 -0
  26. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/any.js +21 -0
  27. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/assert.js +55 -0
  28. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/async.js +165 -0
  29. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bind.js +67 -0
  30. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bluebird.js +11 -0
  31. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/call_get.js +123 -0
  32. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/cancel.js +129 -0
  33. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/catch_filter.js +42 -0
  34. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/context.js +69 -0
  35. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/debuggability.js +934 -0
  36. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/direct_resolve.js +46 -0
  37. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/each.js +30 -0
  38. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/errors.js +116 -0
  39. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/es5.js +80 -0
  40. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/filter.js +12 -0
  41. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/finally.js +146 -0
  42. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/generators.js +223 -0
  43. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/join.js +168 -0
  44. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/map.js +168 -0
  45. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/method.js +55 -0
  46. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeback.js +51 -0
  47. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeify.js +58 -0
  48. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise.js +789 -0
  49. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise_array.js +185 -0
  50. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promisify.js +314 -0
  51. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/props.js +118 -0
  52. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/queue.js +73 -0
  53. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/race.js +49 -0
  54. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/reduce.js +172 -0
  55. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/schedule.js +62 -0
  56. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/settle.js +43 -0
  57. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/some.js +148 -0
  58. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/synchronous_inspection.js +103 -0
  59. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/thenables.js +86 -0
  60. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/timers.js +93 -0
  61. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/using.js +226 -0
  62. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/util.js +389 -0
  63. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/package.json +102 -0
  64. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/CHANGELOG.md +408 -0
  65. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/LICENSE +22 -0
  66. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/Readme.md +428 -0
  67. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/index.js +1224 -0
  68. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/package.json +70 -0
  69. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/typings/index.d.ts +310 -0
  70. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.coveralls.yml +1 -0
  71. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.eslintrc +11 -0
  72. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.npmignore +9 -0
  73. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.travis.yml +14 -0
  74. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/CHANGELOG.md +362 -0
  75. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/LICENSE +19 -0
  76. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/Makefile +50 -0
  77. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/README.md +312 -0
  78. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/component.json +19 -0
  79. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/karma.conf.js +70 -0
  80. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/node.js +1 -0
  81. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/package.json +88 -0
  82. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/browser.js +185 -0
  83. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/debug.js +202 -0
  84. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/index.js +10 -0
  85. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/inspector-log.js +15 -0
  86. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/node.js +248 -0
  87. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/index.js +152 -0
  88. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/license.md +21 -0
  89. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/package.json +69 -0
  90. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/readme.md +51 -0
  91. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/LICENSE +13 -0
  92. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/README.md +148 -0
  93. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/bin/portastic +65 -0
  94. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/history.md +7 -0
  95. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/index.js +4 -0
  96. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/monitor.js +59 -0
  97. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/portastic.js +167 -0
  98. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/LICENSE +21 -0
  99. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/README.md +677 -0
  100. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/changelog.md +1730 -0
  101. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.js +4892 -0
  102. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.min.js +31 -0
  103. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/any.js +21 -0
  104. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/assert.js +55 -0
  105. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/async.js +150 -0
  106. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bind.js +72 -0
  107. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bluebird.js +11 -0
  108. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/call_get.js +123 -0
  109. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/cancel.js +48 -0
  110. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/captured_trace.js +493 -0
  111. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/catch_filter.js +66 -0
  112. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/context.js +38 -0
  113. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/debuggability.js +162 -0
  114. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/direct_resolve.js +63 -0
  115. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/each.js +12 -0
  116. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/errors.js +111 -0
  117. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/es5.js +80 -0
  118. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/filter.js +12 -0
  119. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/finally.js +98 -0
  120. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/generators.js +136 -0
  121. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/join.js +107 -0
  122. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/map.js +133 -0
  123. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/method.js +44 -0
  124. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js +59 -0
  125. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/progress.js +76 -0
  126. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise.js +759 -0
  127. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_array.js +142 -0
  128. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_resolver.js +123 -0
  129. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promisify.js +307 -0
  130. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/props.js +79 -0
  131. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/queue.js +90 -0
  132. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/race.js +47 -0
  133. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/reduce.js +148 -0
  134. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/schedule.js +35 -0
  135. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/settle.js +40 -0
  136. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/some.js +125 -0
  137. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/synchronous_inspection.js +94 -0
  138. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/thenables.js +84 -0
  139. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/timers.js +64 -0
  140. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/using.js +213 -0
  141. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/util.js +321 -0
  142. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/package.json +103 -0
  143. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/package.json +69 -0
  144. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/CHANGELOG.md +109 -0
  145. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/LICENSE +201 -0
  146. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/README.md +278 -0
  147. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/anonymize_proxy.js +100 -0
  148. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_base.js +319 -0
  149. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_custom_response.js +96 -0
  150. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_forward.js +173 -0
  151. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_chain.js +132 -0
  152. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_direct.js +89 -0
  153. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_tcp_chain.js +271 -0
  154. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/index.js +26 -0
  155. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/run_locally.js +66 -0
  156. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/server.js +595 -0
  157. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel.js +138 -0
  158. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/testing_tcp_service.js +37 -0
  159. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tools.js +220 -0
  160. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/package.json +104 -0
  161. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/LICENSE +23 -0
  162. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/README.md +28 -0
  163. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/package.json +81 -0
  164. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js +5 -0
  165. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js.map +1 -0
  166. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore.js +1692 -0
  167. data/lib/browsed/proxies/proxy-chain-server/package-lock.json +63 -0
  168. data/lib/browsed/proxies/proxy-chain-server/package.json +15 -0
  169. data/lib/browsed/proxies/proxy-chain-server/server.js +25 -0
  170. data/lib/browsed/proxies/proxy_chain.rb +36 -0
  171. data/lib/browsed/version.rb +1 -1
  172. metadata +160 -4
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8
+
9
+ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
10
+
11
+ exports.createTunnel = createTunnel;
12
+ exports.closeTunnel = closeTunnel;
13
+
14
+ var _bluebird = require('bluebird');
15
+
16
+ var _bluebird2 = _interopRequireDefault(_bluebird);
17
+
18
+ var _net = require('net');
19
+
20
+ var _net2 = _interopRequireDefault(_net);
21
+
22
+ var _handler_tunnel_tcp_chain = require('./handler_tunnel_tcp_chain');
23
+
24
+ var _handler_tunnel_tcp_chain2 = _interopRequireDefault(_handler_tunnel_tcp_chain);
25
+
26
+ var _tools = require('./tools');
27
+
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
+
30
+ var runningServers = {};
31
+
32
+ function createTunnel(proxyUrl, targetHost) {
33
+ var providedOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
34
+ var callback = arguments[3];
35
+
36
+ // TODO: More and better validations - yeah, make sure targetHost is really a hostname
37
+ var _targetHost$split = targetHost.split(':'),
38
+ _targetHost$split2 = _slicedToArray(_targetHost$split, 2),
39
+ trgHostname = _targetHost$split2[0],
40
+ trgPort = _targetHost$split2[1];
41
+
42
+ if (!trgHostname || !trgPort) throw new Error('target needs to include both hostname and port.');
43
+
44
+ var parsedProxyUrl = (0, _tools.parseUrl)(proxyUrl);
45
+ if (!parsedProxyUrl.hostname) throw new Error('proxyUrl needs to include atleast hostname');
46
+ if (parsedProxyUrl.scheme !== 'http') throw new Error('Currently only "http" scheme is supported');
47
+
48
+ var options = _extends({
49
+ verbose: false,
50
+ hostname: 'localhost',
51
+ port: null
52
+ }, providedOptions);
53
+
54
+ return new _bluebird2.default(function (resolve, reject) {
55
+ if (options.port) return resolve(options.port);
56
+ (0, _tools.findFreePort)().then(resolve).catch(reject);
57
+ }).then(function (port) {
58
+ var server = _net2.default.createServer();
59
+
60
+ var log = function log() {
61
+ var _console;
62
+
63
+ if (options.verbose) (_console = console).log.apply(_console, arguments);
64
+ };
65
+
66
+ server.on('connection', function (srcSocket) {
67
+ runningServers[port].connections = srcSocket;
68
+ var remoteAddress = srcSocket.remoteAddress + ':' + srcSocket.remotePort;
69
+ log('new client connection from %s', remoteAddress);
70
+
71
+ srcSocket.pause();
72
+
73
+ var tunnel = new _handler_tunnel_tcp_chain2.default({
74
+ srcSocket: srcSocket,
75
+ upstreamProxyUrlParsed: parsedProxyUrl,
76
+ trgParsed: {
77
+ hostname: trgHostname,
78
+ port: trgPort
79
+ },
80
+ log: log
81
+ });
82
+
83
+ tunnel.run();
84
+
85
+ srcSocket.on('data', onConnData);
86
+ srcSocket.once('close', onConnClose);
87
+ srcSocket.on('error', onConnError);
88
+
89
+ function onConnData(d) {
90
+ log('connection data from %s: %j', remoteAddress, d);
91
+ }
92
+
93
+ function onConnClose() {
94
+ log('connection from %s closed', remoteAddress);
95
+ }
96
+
97
+ function onConnError(err) {
98
+ log('Connection %s error: %s', remoteAddress, err.message);
99
+ }
100
+ });
101
+
102
+ return new _bluebird2.default(function (resolve) {
103
+ server.listen(port, function (err) {
104
+ if (err) return reject(err);
105
+ log('server listening to ', server.address());
106
+ runningServers[port] = { server: server, connections: [] };
107
+ resolve(options.hostname + ':' + port);
108
+ });
109
+ });
110
+ }).nodeify(callback);
111
+ }
112
+
113
+ function closeTunnel(serverPath, closeConnections, callback) {
114
+ var _serverPath$split = serverPath.split(':'),
115
+ _serverPath$split2 = _slicedToArray(_serverPath$split, 2),
116
+ hostname = _serverPath$split2[0],
117
+ port = _serverPath$split2[1];
118
+
119
+ if (!hostname) throw new Error('serverPath must contain hostname');
120
+ if (!port) throw new Error('serverPath must contain port');
121
+
122
+ return new _bluebird2.default(function (resolve) {
123
+ if (!runningServers[port]) return resolve(false);
124
+ if (!closeConnections) return resolve();
125
+ runningServers[port].connections.forEach(function (connection) {
126
+ return connection.destroy();
127
+ });
128
+ resolve();
129
+ }).then(function (serverExists) {
130
+ return new _bluebird2.default(function (resolve) {
131
+ if (!serverExists) return resolve(false);
132
+ runningServers[port].close(function () {
133
+ delete runningServers[port];
134
+ resolve(true);
135
+ });
136
+ });
137
+ }).nodeify(callback);
138
+ }
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var net = require('net');
4
+
5
+ // TODO: please move this into ./test dir
6
+
7
+ var server = net.createServer();
8
+
9
+ server.on('connection', handleConnection);
10
+
11
+ server.listen(9112, function () {
12
+ console.log('server listening to %j', server.address());
13
+ });
14
+
15
+ function handleConnection(conn) {
16
+ var remoteAddress = conn.remoteAddress + ':' + conn.remotePort;
17
+ console.log('new client connection from %s', remoteAddress);
18
+
19
+ conn.setEncoding('utf8');
20
+
21
+ conn.on('data', onConnData);
22
+ conn.once('close', onConnClose);
23
+ conn.on('error', onConnError);
24
+
25
+ function onConnData(d) {
26
+ console.log('connection data from %s: %j', remoteAddress, d);
27
+ conn.write(d);
28
+ }
29
+
30
+ function onConnClose() {
31
+ console.log('connection from %s closed', remoteAddress);
32
+ }
33
+
34
+ function onConnError(err) {
35
+ console.log('Connection %s error: %s', remoteAddress, err.message);
36
+ }
37
+ }
@@ -0,0 +1,220 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.maybeAddProxyAuthorizationHeader = exports.findFreePort = exports.PORT_SELECTION_CONFIG = exports.addHeader = exports.parseProxyAuthorizationHeader = exports.redactParsedUrl = exports.redactUrl = exports.parseUrl = exports.isInvalidHeader = exports.isHopByHopHeader = exports.parseHostHeader = undefined;
7
+
8
+ var _url = require('url');
9
+
10
+ var _url2 = _interopRequireDefault(_url);
11
+
12
+ var _http_common = require('_http_common');
13
+
14
+ var _portastic = require('portastic');
15
+
16
+ var _portastic2 = _interopRequireDefault(_portastic);
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ // import through from 'through';
21
+
22
+
23
+ var HOST_HEADER_REGEX = /^((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9]))(:([0-9]+))?$/;
24
+
25
+ /**
26
+ * Parsed the 'Host' HTTP header and returns an object with { host: String, port: Number }.
27
+ * For example, for 'www.example.com:80' it returns { host: 'www.example.com', port: 80 }.
28
+ * If port is not present, the function
29
+ * If the header is invalid, returns null.
30
+ * @param hostHeader
31
+ * @return {*}
32
+ */
33
+ // eslint-disable-line
34
+ var parseHostHeader = exports.parseHostHeader = function parseHostHeader(hostHeader) {
35
+ var matches = HOST_HEADER_REGEX.exec(hostHeader || '');
36
+ if (!matches) return null;
37
+
38
+ var hostname = matches[1];
39
+ if (hostname.length > 255) return null;
40
+
41
+ var port = null;
42
+ if (matches[5]) {
43
+ port = parseInt(matches[6], 10);
44
+ if (!(port > 0 && port <= 65535)) return null;
45
+ }
46
+
47
+ return { hostname: hostname, port: port };
48
+ };
49
+
50
+ var HOP_BY_HOP_HEADERS = ['Connection', 'Keep-Alive', 'Proxy-Authenticate', 'Proxy-Authorization', 'TE', 'Trailers', 'Transfer-Encoding', 'Upgrade'];
51
+
52
+ var HOP_BY_HOP_HEADERS_REGEX = new RegExp('^(' + HOP_BY_HOP_HEADERS.join('|') + ')$', 'i');
53
+
54
+ var isHopByHopHeader = exports.isHopByHopHeader = function isHopByHopHeader(header) {
55
+ return HOP_BY_HOP_HEADERS_REGEX.test(header);
56
+ };
57
+
58
+ // This code is based on Node.js' validateHeader() function from _http_outgoing.js module
59
+ // (see https://github.com/nodejs/node/blob/189d29f39e6de9ccf10682bfd1341819b4a2291f/lib/_http_outgoing.js#L485)
60
+ var isInvalidHeader = exports.isInvalidHeader = function isInvalidHeader(name, value) {
61
+ // NOTE: These are internal Node.js functions, they might stop working in the future!
62
+ return typeof name !== 'string' || !name || !(0, _http_common._checkIsHttpToken)(name) || value === undefined || (0, _http_common._checkInvalidHeaderChar)(value);
63
+ };
64
+
65
+ /**
66
+ * Sames are Node's url.parse() just adds the 'username', 'password' and 'scheme' fields.
67
+ * Also this method makes sure "port" is a number rather than a string.
68
+ * Note that `scheme` is always lower-cased (e.g. `ftp`).
69
+ * @param url
70
+ * @ignore
71
+ */
72
+ var parseUrl = exports.parseUrl = function parseUrl(url) {
73
+ var parsed = _url2.default.parse(url);
74
+
75
+ parsed.username = null;
76
+ parsed.password = null;
77
+ parsed.scheme = null;
78
+
79
+ if (parsed.auth) {
80
+ var matches = /^([^:]+)(:?)(.*)$/.exec(parsed.auth);
81
+ if (matches && matches.length === 4) {
82
+ parsed.username = matches[1];
83
+ if (matches[2] === ':') parsed.password = matches[3];
84
+ }
85
+ }
86
+
87
+ if (parsed.protocol) {
88
+ var _matches = /^([a-z0-9]+):$/i.exec(parsed.protocol);
89
+ if (_matches && _matches.length === 2) {
90
+ parsed.scheme = _matches[1];
91
+ }
92
+ }
93
+
94
+ if (parsed.port) {
95
+ parsed.port = parseInt(parsed.port, 10);
96
+ }
97
+
98
+ return parsed;
99
+ };
100
+
101
+ /**
102
+ * Redacts password from a URL, so that it can be shown in logs, results etc.
103
+ * For example, converts URL such as
104
+ * 'https://username:password@www.example.com/path#hash'
105
+ * to 'https://username:<redacted>@www.example.com/path#hash'
106
+ * @param url URL, it must contain at least protocol and hostname
107
+ * @param passwordReplacement The string that replaces password, by default it is '<redacted>'
108
+ * @returns {string}
109
+ * @ignore
110
+ */
111
+ var redactUrl = exports.redactUrl = function redactUrl(url, passwordReplacement) {
112
+ return redactParsedUrl(parseUrl(url), passwordReplacement);
113
+ };
114
+
115
+ var redactParsedUrl = exports.redactParsedUrl = function redactParsedUrl(parsedUrl) {
116
+ var passwordReplacement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '<redacted>';
117
+
118
+ var p = parsedUrl;
119
+ var auth = null;
120
+ if (p.username) {
121
+ if (p.password) {
122
+ auth = p.username + ':' + passwordReplacement;
123
+ } else {
124
+ auth = '' + p.username;
125
+ }
126
+ }
127
+ return p.protocol + '//' + (auth || '') + (auth ? '@' : '') + p.host + (p.path || '') + (p.hash || '');
128
+ };
129
+
130
+ var PROXY_AUTH_HEADER_REGEX = /^([a-z0-9-]+) ([a-z0-9+/=]+)$/i;
131
+
132
+ /**
133
+ * Parses the content of the Proxy-Authorization HTTP header.
134
+ * @param header
135
+ * @returns {*} Object with fields { type: String, username: String, password: String }
136
+ * or null if string parsing failed. Note that password and username might be empty strings.
137
+ */
138
+ var parseProxyAuthorizationHeader = exports.parseProxyAuthorizationHeader = function parseProxyAuthorizationHeader(header) {
139
+ var matches = PROXY_AUTH_HEADER_REGEX.exec(header);
140
+ if (!matches) return null;
141
+
142
+ var auth = Buffer.from(matches[2], 'base64').toString();
143
+ if (!auth) return null;
144
+
145
+ var index = auth.indexOf(':');
146
+ return {
147
+ type: matches[1],
148
+ username: index >= 0 ? auth.substr(0, index) : auth,
149
+ password: index >= 0 ? auth.substr(index + 1) : ''
150
+ };
151
+ };
152
+
153
+ /**
154
+ * Works like Bash tee, but instead of passing output to file,
155
+ * passes output to log
156
+ *
157
+ * @param {String} name identifier
158
+ * @param {Boolean} initialOnly log only initial chunk of data
159
+ * @return {through} duplex stream (pipe)
160
+
161
+ export const tee = (name, initialOnly = true) => {
162
+ console.log('tee');
163
+ let maxChunks = 2;
164
+ const duplex = through((chunk) => {
165
+ if (maxChunks || !initialOnly) {
166
+ // let msg = chunk.toString();
167
+ // msg += '';
168
+ maxChunks--;
169
+ console.log(`pipe: ${JSON.stringify({
170
+ context: name,
171
+ chunkHead: chunk.toString().slice(0, 100),
172
+ })}`);
173
+ }
174
+ duplex.queue(chunk);
175
+ });
176
+
177
+ return duplex;
178
+ };
179
+ */
180
+
181
+ var addHeader = exports.addHeader = function addHeader(headers, name, value) {
182
+ if (headers[name] === undefined) {
183
+ headers[name] = value;
184
+ } else if (Array.isArray(headers[name])) {
185
+ headers[name].push(value);
186
+ } else {
187
+ headers[name] = [headers[name], value];
188
+ }
189
+ };
190
+
191
+ var PORT_SELECTION_CONFIG = exports.PORT_SELECTION_CONFIG = {
192
+ FROM: 20000,
193
+ TO: 60000,
194
+ RETRY_COUNT: 10
195
+ };
196
+
197
+ var findFreePort = exports.findFreePort = function findFreePort() {
198
+ // Let 'min' be a random value in the first half of the PORT_FROM-PORT_TO range,
199
+ // to reduce a chance of collision if other ProxyChain is started at the same time.
200
+ var half = Math.floor((PORT_SELECTION_CONFIG.TO - PORT_SELECTION_CONFIG.FROM) / 2);
201
+
202
+ var opts = {
203
+ min: PORT_SELECTION_CONFIG.FROM + Math.floor(Math.random() * half),
204
+ max: PORT_SELECTION_CONFIG.TO,
205
+ retrieve: 1
206
+ };
207
+
208
+ return _portastic2.default.find(opts).then(function (ports) {
209
+ if (ports.length < 1) throw new Error('There are no more free ports in range from ' + PORT_SELECTION_CONFIG.FROM + ' to ' + PORT_SELECTION_CONFIG.TO); // eslint-disable-line max-len
210
+ return ports[0];
211
+ });
212
+ };
213
+
214
+ var maybeAddProxyAuthorizationHeader = exports.maybeAddProxyAuthorizationHeader = function maybeAddProxyAuthorizationHeader(parsedUrl, headers) {
215
+ if (parsedUrl && parsedUrl.username) {
216
+ var auth = parsedUrl.username;
217
+ if (parsedUrl.password || parsedUrl.password === '') auth += ':' + parsedUrl.password;
218
+ headers['Proxy-Authorization'] = 'Basic ' + Buffer.from(auth).toString('base64');
219
+ }
220
+ };
@@ -0,0 +1,104 @@
1
+ {
2
+ "_from": "proxy-chain",
3
+ "_id": "proxy-chain@0.2.7",
4
+ "_inBundle": false,
5
+ "_integrity": "sha512-e0s94WDfooeC3zQkvIJ/Eudiy/AywTQK4K6PMYbZdBE2m/eug54ThgCPdBE4txHvzi0A0gAVbX04Kt4RygTlRQ==",
6
+ "_location": "/proxy-chain",
7
+ "_phantomChildren": {},
8
+ "_requested": {
9
+ "type": "tag",
10
+ "registry": true,
11
+ "raw": "proxy-chain",
12
+ "name": "proxy-chain",
13
+ "escapedName": "proxy-chain",
14
+ "rawSpec": "",
15
+ "saveSpec": null,
16
+ "fetchSpec": "latest"
17
+ },
18
+ "_requiredBy": [
19
+ "#USER",
20
+ "/"
21
+ ],
22
+ "_resolved": "https://registry.npmjs.org/proxy-chain/-/proxy-chain-0.2.7.tgz",
23
+ "_shasum": "3c24d1a487e37838b0c9fe34317c276f3401e0ec",
24
+ "_spec": "proxy-chain",
25
+ "_where": "/Users/sebastianjohnsson/Programming/Javascript/proxy-chain-server",
26
+ "author": {
27
+ "name": "Apify",
28
+ "email": "support@apify.com",
29
+ "url": "https://www.apify.com"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/apifytech/proxy-chain/issues"
33
+ },
34
+ "bundleDependencies": false,
35
+ "contributors": [
36
+ {
37
+ "name": "Jan Curn",
38
+ "email": "jan@apify.com"
39
+ }
40
+ ],
41
+ "dependencies": {
42
+ "bluebird": "^3.5.1",
43
+ "portastic": "^1.0.1",
44
+ "underscore": "^1.9.1"
45
+ },
46
+ "deprecated": false,
47
+ "description": "Node.js implementation of a proxy server (think Squid) with support for SSL, authentication, upstream proxy chaining, and protocol tunneling.",
48
+ "devDependencies": {
49
+ "babel-cli": "^6.6.5",
50
+ "babel-core": "^6.1.21",
51
+ "babel-eslint": "^8.2.6",
52
+ "babel-preset-es2015": "^6.1.18",
53
+ "babel-preset-stage-0": "^6.1.18",
54
+ "basic-auth": "^2.0.0",
55
+ "body-parser": "^1.18.2",
56
+ "chai": "^4.0.2",
57
+ "eslint": "^3.19.0",
58
+ "eslint-config-airbnb": "^15.0.1",
59
+ "eslint-config-airbnb-base": "^11.1.0",
60
+ "eslint-plugin-import": "^2.2.0",
61
+ "eslint-plugin-jsx-a11y": "^5.0.3",
62
+ "eslint-plugin-promise": "^3.4.2",
63
+ "eslint-plugin-react": "^7.0.1",
64
+ "express": "^4.16.2",
65
+ "https-proxy-agent": "^2.1.0",
66
+ "isparta": "^4.0.0",
67
+ "mocha": "^3.2.0",
68
+ "phantomjs-prebuilt": "^2.1.16",
69
+ "proxy": "^0.2.4",
70
+ "request": "^2.83.0",
71
+ "sinon": "^6.1.4",
72
+ "sinon-stub-promise": "^4.0.0",
73
+ "through": "^2.3.8",
74
+ "ws": "^6.0.0"
75
+ },
76
+ "files": [
77
+ "build"
78
+ ],
79
+ "homepage": "https://blog.apify.com/how-to-make-headless-chrome-and-puppeteer-use-a-proxy-server-with-authentication-249a21a79212",
80
+ "keywords": [
81
+ "proxy",
82
+ "squid",
83
+ "apify",
84
+ "tunnel"
85
+ ],
86
+ "license": "Apache-2.0",
87
+ "main": "build/index.js",
88
+ "name": "proxy-chain",
89
+ "optionalDependencies": {},
90
+ "repository": {
91
+ "type": "git",
92
+ "url": "git+https://github.com/apifytech/proxy-chain.git"
93
+ },
94
+ "scripts": {
95
+ "build": "rm -rf ./build && babel src --out-dir build",
96
+ "clean": "rm -rf build",
97
+ "lint": "npm run build && eslint src",
98
+ "local-proxy": "npm run build && node ./build/run_locally.js",
99
+ "prepare": "npm run build",
100
+ "prepublishOnly": "(test $RUNNING_FROM_SCRIPT || (echo \"You must use publish.sh instead of 'npm publish' directly!\"; exit 1)) && npm test && npm run lint",
101
+ "test": "npm run build && mocha --compilers js:babel-core/register --recursive"
102
+ },
103
+ "version": "0.2.7"
104
+ }