etunnel 1.6.6 → 1.6.8
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 +4 -4
- data/lib/etunnel.rb +52 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f7038b340c5731a62ba3f241b54201d982ba09fe9da34c38285cb419cb39cf65
|
|
4
|
+
data.tar.gz: 58bd384e529a3a9b2abcc44d3b3fc2914a10d1b8f827cac0fc3e594ae1754e44
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d1b6181c1edbefd657110c4e23497e403f4a53629a9fda2384fd1945cb52eb6d9906c6efcf21fd072c6d44883c63cfc8906484a0b0cb579bbecf182a28429c8c
|
|
7
|
+
data.tar.gz: 0c32aca0517d3cf5c365053a52c4a41309a82e33e5373dc41b1fd15f6cb6c91cca560c3b5a53dd2714a782ae72d6c7b1e856e4e6535ef4a3fe726375f62ceb39
|
data/lib/etunnel.rb
CHANGED
|
@@ -277,3 +277,55 @@ def Etunnel.main(argv = ARGV)
|
|
|
277
277
|
end
|
|
278
278
|
end
|
|
279
279
|
Etunnel.main if $PROGRAM_NAME == __FILE__
|
|
280
|
+
|
|
281
|
+
# --- CLI loopback login (RFC 8252 style; server /auth/cli/* endpoints) ---
|
|
282
|
+
# creds = Etunnel.login('https://t.etun.uk') # opens the browser
|
|
283
|
+
# # -> { 'api_token' => ..., 'subdomains' => [...], 'plan' => ..., 'expires_at' => 0 }
|
|
284
|
+
# Binds a random 127.0.0.1 port, waits for the one-time code on /callback
|
|
285
|
+
# (10-minute budget), exchanges it. Persist the result and pass api_token
|
|
286
|
+
# as token: on future Etunnel.connect calls.
|
|
287
|
+
def self.login(server, open_browser: nil, timeout: 600)
|
|
288
|
+
require 'socket'
|
|
289
|
+
require 'net/http'
|
|
290
|
+
require 'json'
|
|
291
|
+
require 'uri'
|
|
292
|
+
base = server.to_s.sub(%r{/+\z}, '')
|
|
293
|
+
raise ArgumentError, 'etunnel: login: server required' if base.empty?
|
|
294
|
+
|
|
295
|
+
server_sock = TCPServer.new('127.0.0.1', 0)
|
|
296
|
+
port = server_sock.addr[1]
|
|
297
|
+
|
|
298
|
+
th = Thread.new do
|
|
299
|
+
# Accept exactly one request: the browser's redirect to /callback?code=...
|
|
300
|
+
client = server_sock.accept
|
|
301
|
+
req = client.recv(4096)
|
|
302
|
+
path = req.split(' ')[1].to_s
|
|
303
|
+
code = path[/[?&]code=([^&\s]+)/, 1].to_s
|
|
304
|
+
body = '<!doctype html><p>Authorized. You can close this tab and return to the terminal.</p>'
|
|
305
|
+
client.write("HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: #{body.bytesize}\r\nConnection: close\r\n\r\n#{body}")
|
|
306
|
+
client.close
|
|
307
|
+
code
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
uri = URI(base + '/auth/cli/start')
|
|
311
|
+
start = JSON.parse(Net::HTTP.post(uri, { redirect_uri: "http://127.0.0.1:#{port}/callback" }.to_json, 'Content-Type' => 'application/json').body)
|
|
312
|
+
raise 'etunnel: login: empty start payload' if start['auth_url'].to_s.empty? || start['device_code'].to_s.empty?
|
|
313
|
+
|
|
314
|
+
opened = false
|
|
315
|
+
begin
|
|
316
|
+
opener = open_browser || ->(u) { system(RUBY_PLATFORM =~ /darwin/ ? 'open' : 'xdg-open', u) }
|
|
317
|
+
opened = opener.call(start['auth_url'])
|
|
318
|
+
rescue StandardError
|
|
319
|
+
opened = false
|
|
320
|
+
end
|
|
321
|
+
$stderr.puts "etunnel: authorize in your browser: #{start['auth_url']}" unless opened
|
|
322
|
+
|
|
323
|
+
code = th.value(timeout)
|
|
324
|
+
server_sock.close
|
|
325
|
+
raise 'etunnel: login: callback without code' if code.empty?
|
|
326
|
+
|
|
327
|
+
ex = URI(base + '/auth/cli/exchange')
|
|
328
|
+
creds = JSON.parse(Net::HTTP.post(ex, { device_code: start['device_code'], code: code }.to_json, 'Content-Type' => 'application/json').body)
|
|
329
|
+
raise 'etunnel: login: no api_token in exchange response' if creds['api_token'].to_s.empty?
|
|
330
|
+
creds
|
|
331
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: etunnel
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.6.
|
|
4
|
+
version: 1.6.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- etunnel authors
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faye-websocket
|