From 9d09c3244f98ab1ab77bcf7aff4aa93957a1e18f Mon Sep 17 00:00:00 2001 From: f Date: Tue, 28 Mar 2023 16:21:29 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20validar=20y=20agregar=20la=20direcci?= =?UTF-8?q?=C3=B3n=20a=20la=20configuraci=C3=B3n=20del=20sitio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/deploy_hidden_service.rb | 13 ++++++++++++- app/services/site_service.rb | 7 ++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/models/deploy_hidden_service.rb b/app/models/deploy_hidden_service.rb index 6b84752f..ec6ed08c 100644 --- a/app/models/deploy_hidden_service.rb +++ b/app/models/deploy_hidden_service.rb @@ -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 diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 0ecccba4..378bcec0 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -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