5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-05-19 08:50:49 +00:00

feat: generar direcciones tor a demanda #12773

This commit is contained in:
f 2023-03-28 15:28:46 -03:00
parent 252652c94b
commit 718463f0ea
2 changed files with 33 additions and 1 deletions

View file

@ -0,0 +1,13 @@
# frozen_string_literal: true
require 'httparty'
class HiddenServiceClient
include HTTParty
base_uri ENV.fetch('HIDDEN_SERVICE', 'http://tor:3000')
def create(name)
self.class.get("/#{name}").body
end
end

View file

@ -2,8 +2,12 @@
# Genera una versión onion
class DeployHiddenService < DeployWww
store :values, accessors: %i[onion], coder: JSON
before_create :create_hidden_service!
def fqdn
values[:onion].tap do |onion|
onion.tap do |onion|
raise ArgumentError, 'Aun no se generó la dirección .onion' if onion.blank?
end
end
@ -11,4 +15,19 @@ class DeployHiddenService < DeployWww
def url
"http://#{fqdn}"
end
private
def create_hidden_service!
onion_address = HiddenServiceClient.new.create(site.name)
if ONION_RE =~ onion_address
self.onion = onion_address
usuarie = GitAuthor.new email: "tor@#{Site.domain}", name: 'Tor'
params = { onion: onion_address, deploy: self }
SiteService.new(site: site, usuarie: usuarie, params: params).add_onion
end
end
end