5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-19 10:16:22 +00:00

feat: validar y agregar la dirección a la configuración del sitio

This commit is contained in:
f 2023-03-28 16:21:29 -03:00
parent f4264fe763
commit 9d09c3244f
2 changed files with 14 additions and 6 deletions

View file

@ -6,6 +6,8 @@ class DeployHiddenService < DeployWww
before_create :create_hidden_service!
ONION_RE = /\A[a-z0-9]{56}\.onion\z/.freeze
def fqdn
onion.tap do |onion|
raise ArgumentError, 'Aun no se generó la dirección .onion' if onion.blank?
@ -19,6 +21,15 @@ class DeployHiddenService < DeployWww
private
def create_hidden_service!
self.onion = HiddenServiceClient.new.create(site.name)
onion_address = HiddenServiceClient.new.create(site.name)
if onion_address =~ ONION_RE
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

View file

@ -62,14 +62,11 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
# Agregar una dirección oculta de Tor al DeployHiddenService y a la
# configuración del Site.
def add_onion
onion = params[:onion].strip
deploy = DeployHiddenService.find_by(site: site)
onion = params[:onion]
deploy = params[:deploy]
return false unless !onion.blank? && deploy
deploy.values[:onion] = onion
deploy.save
site.config['onion-location'] = onion
site.config.write