weblink 1.0.0 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c268c95b2cdcec3669dbf5c90f0753bc28949b6098744bd7c9f9e42aac24bb97
4
- data.tar.gz: 44f0363bf19eae1f40a5a00fd962f60134a1db2a12e36aeda7bba04fe5090855
3
+ metadata.gz: d385e7232ce9202ce7b88e2ff864541243694f1b0a81fd40a8bb02b3ec0cc616
4
+ data.tar.gz: ae5d4588789bad44e61d29094cf9aa73c1e230bee61b32df9fa70e2a074fc3dd
5
5
  SHA512:
6
- metadata.gz: 72ba709dd3bbdc06582bb20a83ab50090d8a60859698f4a00576122b0cd9687ed348b24d4ddbadc99219011750b897e4596605369c46e75655a821c7a76c4716
7
- data.tar.gz: d729d225e330f6ab9714bd078893eeeecccb5d56e85f0f5d39c92f4b192a4fd9f94243789b94e0008b6264906d6a33c50f59682cb5afb215b0f21aa649202515
6
+ metadata.gz: 6a29a327435407af014c9bb887f4289536f5a28d6b1495dfd00e2892ee1396339efff8ae4b71b074ad256bab80808e22f41f1f9fa7857937a8fd61e08eabb3ad
7
+ data.tar.gz: 8d358c66cc2a55d79988f34b7e9997209e978e4d0828fa5ff3aa39a86f5c85be39fc9ff000c81ee900b009d0fda1118b46170b4c19ad03cdb3a404f90dc3738f
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 1.1.0
2
+
3
+ * Works on Windows
4
+ * HTTPS proxy support
5
+
1
6
  1.0.0
2
7
 
3
8
  * First public release
9
+ * SOCKS5 proxy support
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env -S ruby -w
2
- # frozen_string_literal: true
3
2
 
4
3
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
5
4
 
@@ -35,11 +34,16 @@ op = OptionParser.new do |op|
35
34
  opts[:port] = port
36
35
  end
37
36
 
37
+ op.on('--proxy-type TYPE', String, 'https or socks5 (default: https)') do |type|
38
+ raise OptionParser::InvalidArgument, type unless type == 'https' || type == 'socks5'
39
+ opts[:proxy_type] = type
40
+ end
41
+
38
42
  op.on('--proxy-host HOST', String, 'Address to bind proxy to(default: 0.0.0.0)') do |host|
39
43
  opts[:proxy_host] = host
40
44
  end
41
45
 
42
- op.on('--proxy-port PORT', Integer, 'Use proxy PORT (default: 1080)') do |port|
46
+ op.on('--proxy-port PORT', Integer, 'Use proxy PORT (default: 3128)') do |port|
43
47
  opts[:proxy_port] = port
44
48
  end
45
49
 
@@ -66,8 +70,9 @@ else
66
70
  end
67
71
  opts[:host] ||= '0.0.0.0'
68
72
  opts[:port] ||= 8000
73
+ opts[:proxy_type] ||= 'https'
69
74
  opts[:proxy_host] ||= '0.0.0.0'
70
- opts[:proxy_port] ||= 1080
75
+ opts[:proxy_port] ||= 3128
71
76
  end
72
77
 
73
78
  weblink = Weblink.new(opts)
@@ -3,6 +3,7 @@ require 'time'
3
3
 
4
4
  class Relay < EventMachine::Connection
5
5
  def initialize(tag, xff = nil)
6
+ super
6
7
  pause
7
8
  @tag = tag
8
9
  @xff = xff
@@ -7,7 +7,8 @@ require 'relay'
7
7
  class Weblink
8
8
  def initialize(opts)
9
9
  @opts = opts
10
- @proxxxy_socket = Tempfile.new('weblink')
10
+ @https = Tempfile.new('weblink')
11
+ @socks5 = Tempfile.new('weblink')
11
12
  @websockets = EventMachine::Queue.new
12
13
  end
13
14
 
@@ -16,7 +17,7 @@ class Weblink
16
17
 
17
18
  if @opts[:client]
18
19
  public = File.expand_path('../public', __dir__)
19
- spawn('ruby', '-run', '-ehttpd', '--', public, err: '/dev/null')
20
+ spawn('ruby', '-run', '-ehttpd', '--', public, err: IO::NULL)
20
21
 
21
22
  ip = Socket.getifaddrs.find { |ifa| ifa.addr.ipv4_private? }
22
23
  puts "Open http://#{ip.addr.ip_address}:8080/ on your other device." if ip
@@ -24,7 +25,7 @@ class Weblink
24
25
 
25
26
  if @opts[:server]
26
27
  begin
27
- spawn('proxxxy', "socks5://#{@proxxxy_socket.path}")
28
+ spawn('proxxxy', "https://#{@https.path}", "socks5://#{@socks5.path}")
28
29
  rescue Errno::ENOENT
29
30
  abort('Please install proxxxy v2 to run weblink server')
30
31
  end
@@ -38,8 +39,10 @@ class Weblink
38
39
  puts 'Ready'
39
40
  when '/client'
40
41
  @websockets.push(ws)
41
- when '/server'
42
- proxy(ws, handshake)
42
+ when '/proxy/socks5'
43
+ proxy(ws, handshake, @socks5.path)
44
+ when '/proxy/https'
45
+ proxy(ws, handshake, @https.path)
43
46
  else
44
47
  warn("Unexpected request: #{handshake.path.inspect}")
45
48
  end
@@ -53,20 +56,20 @@ class Weblink
53
56
  host, port = @opts.values_at(:proxy_host, :proxy_port)
54
57
  sig = EventMachine.start_server(host, port, Relay, 'client') do |rel|
55
58
  # Dogpile effect
56
- control_ws.send_text('more_ws') if @websockets.size < min_ws_num
59
+ control_ws.send_text(@opts[:proxy_type]) if @websockets.size < min_ws_num
57
60
  @websockets.pop { |ws| rel.start(ws) }
58
61
  end
59
62
  control_ws.onclose { EventMachine.stop_server(sig) }
60
63
  end
61
64
 
62
- def proxy(ws, handshake)
65
+ def proxy(ws, handshake, socket)
63
66
  unless @opts[:server]
64
67
  warn 'weblink server is disabled'
65
68
  return
66
69
  end
67
70
  xff = handshake.headers_downcased['x-forwarded-for']
68
71
  with_retry(3) do
69
- EventMachine.connect(@proxxxy_socket.path, Relay, 'server', xff) do |rel|
72
+ EventMachine.connect(socket, Relay, 'server', xff) do |rel|
70
73
  rel.start(ws)
71
74
  end
72
75
  end
@@ -1,67 +1,73 @@
1
+ <!DOCTYPE html>
1
2
  <html>
2
3
  <head>
3
4
  <meta charset="utf-8" />
4
5
  <title>weblink</title>
5
6
  <link rel="manifest" href="/weblink.webmanifest">
6
7
  <style>
8
+ html, body {
9
+ height: 100%;
10
+ }
7
11
  body {
12
+ align-items: center;
8
13
  background-color: #3f9cff;
9
14
  color: white;
15
+ display: flex;
16
+ justify-content: center;
10
17
  }
11
18
  h1 {
12
- align-items: center;
13
- display: flex;
14
19
  font-family: sans-serif;
15
20
  font-size: 8em;
16
- justify-content: center;
17
- height: 100%;
18
21
  }
19
22
  </style>
20
23
  </head>
21
24
  <body>
22
25
  <h1>weblink</h1>
23
26
  <script>
24
- function connect({ client_addr, server_addr }) {
25
- const client = new WebSocket(client_addr + "/client");
26
- const server = new WebSocket(server_addr + "/server");
27
+ function connect(client_addr, server_addr, proxy) {
28
+ var client, server = new WebSocket(server_addr + "/proxy/" + proxy);
27
29
 
28
30
  server.onerror = function(event) { console.error("server/error"); };
29
- client.onerror = function(event) { console.error("client/error"); };
30
31
 
31
- client.onopen = function() {
32
- server.onopen = function() {
32
+ server.onopen = function() {
33
+ client = new WebSocket(client_addr + "/client");
34
+
35
+ client.onerror = function(event) { console.error("client/error"); };
36
+
37
+ client.onopen = function() {
33
38
  client.onmessage = function(msg) { server.send(msg.data); };
34
39
  server.onmessage = function(msg) { client.send(msg.data); };
35
40
  };
41
+
42
+ client.onclose = function(event) {
43
+ console.log("client/close", event.code, event.reason);
44
+ if (server.readyState === WebSocket.OPEN) server.close();
45
+ };
36
46
  };
37
47
 
38
48
  server.onclose = function(event) {
39
49
  console.log("server/close", event.code, event.reason);
40
-
41
50
  if (client.readyState === WebSocket.OPEN) client.close();
42
51
  };
43
-
44
- client.onclose = function(event) {
45
- console.log("client/close", event.code, event.reason);
46
-
47
- if (server.readyState === WebSocket.OPEN) server.close();
48
- };
49
52
  }
50
53
 
51
- const url = new URL(location.href);
52
- const client_addr = `ws://${location.hostname}:8000`;
53
- const server_addr = url.searchParams.get("server") || "wss://weblinkapp.herokuapp.com";
54
- const batch_size = Number(url.searchParams.get("batch")) || 4
55
- const control = new WebSocket(client_addr + "/control");
54
+ var params = {};
55
+ window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/g, function(m, key, value) {
56
+ params[key] = decodeURIComponent(value);
57
+ });
58
+
59
+ var client_addr = "ws://" + location.hostname + ":8000";
60
+ var server_addr = params.server || "wss://weblinkapp.herokuapp.com";
61
+ var batch_size = Number(params.batch) || 4;
62
+ var control = new WebSocket(client_addr + "/control");
56
63
 
57
64
  control.onerror = function(event) { console.error("control/error"); };
58
65
  control.onclose = function(event) { console.log("control/close"); };
59
66
  control.onmessage = function(msg) {
60
67
  for (var i = 0; i < batch_size; i++) {
61
- connect({ client_addr, server_addr });
68
+ connect(client_addr, server_addr, msg.data);
62
69
  }
63
70
  };
64
- control.onmessage();
65
71
  </script>
66
72
  </body>
67
73
  </html>
@@ -0,0 +1,59 @@
1
+ function connect(client_addr, server_addr) {
2
+ var client = new WebSocket(client_addr + "/client");
3
+ var server = new WebSocket(server_addr + "/server");
4
+
5
+ server.onerror = function(event) {
6
+ console.error("server/error");
7
+ };
8
+ client.onerror = function(event) {
9
+ console.error("client/error");
10
+ };
11
+
12
+ client.onopen = function() {
13
+ server.onopen = function() {
14
+ client.onmessage = function(msg) {
15
+ server.send(msg.data);
16
+ };
17
+ server.onmessage = function(msg) {
18
+ client.send(msg.data);
19
+ };
20
+ };
21
+ };
22
+
23
+ server.onclose = function(event) {
24
+ console.log("server/close", event.code, event.reason);
25
+
26
+ if (client.readyState === WebSocket.OPEN) client.close();
27
+ };
28
+
29
+ client.onclose = function(event) {
30
+ console.log("client/close", event.code, event.reason);
31
+
32
+ if (server.readyState === WebSocket.OPEN) server.close();
33
+ };
34
+ }
35
+
36
+ var params = {};
37
+ window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/g, function(m, key, value) {
38
+ params[key] = value;
39
+ });
40
+
41
+ var client_addr = "ws://" + location.hostname + ":8000";
42
+ var server_addr = params.server || "wss://weblinkapp.herokuapp.com";
43
+ var batch_size = Number(params.batch) || 4;
44
+ var control = new WebSocket(client_addr + "/control");
45
+
46
+ control.onerror = function(event) {
47
+ console.error("control/error");
48
+ };
49
+ control.onclose = function(event) {
50
+ console.log("control/close");
51
+ };
52
+ control.onmessage = function(msg) {
53
+ for (var i = 0; i < batch_size; i++)
54
+ connect(
55
+ client_addr,
56
+ server_addr
57
+ );
58
+ };
59
+ control.onmessage();
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weblink
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - soylent
@@ -28,7 +28,7 @@ cert_chain:
28
28
  VIAqJBK/gwFlRxVYjmi2w4Ouc4wL8HtX104yQqOuD9gVPN6PJecue66As7i2I/2q
29
29
  EARmnubhy24GUdxEooHV6pOs1mLLRuFepMgBnHfs
30
30
  -----END CERTIFICATE-----
31
- date: 2020-12-23 00:00:00.000000000 Z
31
+ date: 2020-12-26 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: em-websocket
@@ -63,6 +63,7 @@ files:
63
63
  - public/favicon-32x32.png
64
64
  - public/favicon.ico
65
65
  - public/index.html
66
+ - public/weblink.js
66
67
  - public/weblink.webmanifest
67
68
  homepage: https://github.com/soylent/weblink
68
69
  licenses: []
metadata.gz.sig CHANGED
Binary file