From 252652c94b2bff95ad0304422b73d7c19a6efa13 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 15 Mar 2022 16:03:16 -0300 Subject: [PATCH 1/5] poder ver la salida si lo ejecutamos desde la terminal --- app/models/deploy_local.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/models/deploy_local.rb b/app/models/deploy_local.rb index 71c23b36..bfde29f7 100644 --- a/app/models/deploy_local.rb +++ b/app/models/deploy_local.rb @@ -117,14 +117,6 @@ class DeployLocal < Deploy run %(gem install bundler --no-document), output: output end - def pnpm_lock - File.join(site.path, 'pnpm-lock.yaml') - end - - def pnpm_lock? - File.exist? pnpm_lock - end - # Corre yarn dentro del repositorio def yarn(output: false) return true unless yarn_lock? From 718463f0eae2255e7cb33cddb72a6ab4364b6405 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 28 Mar 2023 15:28:46 -0300 Subject: [PATCH 2/5] feat: generar direcciones tor a demanda #12773 --- app/lib/hidden_service_client.rb | 13 +++++++++++++ app/models/deploy_hidden_service.rb | 21 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 app/lib/hidden_service_client.rb diff --git a/app/lib/hidden_service_client.rb b/app/lib/hidden_service_client.rb new file mode 100644 index 00000000..5715a869 --- /dev/null +++ b/app/lib/hidden_service_client.rb @@ -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 diff --git a/app/models/deploy_hidden_service.rb b/app/models/deploy_hidden_service.rb index 79ff1bae..aa495baf 100644 --- a/app/models/deploy_hidden_service.rb +++ b/app/models/deploy_hidden_service.rb @@ -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 From 487765f7d88356b4d33242ca95c4487bb6488917 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 28 Mar 2023 16:21:29 -0300 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20validar=20y=20agregar=20la=20direcc?= =?UTF-8?q?i=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 | 2 ++ app/services/site_service.rb | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/deploy_hidden_service.rb b/app/models/deploy_hidden_service.rb index aa495baf..3356e815 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? diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 848f3cfc..8ecc3f56 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -64,14 +64,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 From 0002ed53a940f69da649ab3ebe4c1b90bb8c3433 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 28 Mar 2023 16:22:02 -0300 Subject: [PATCH 4/5] BREAKING CHANGE: deprecar la api de onion --- app/controllers/api/v1/sites_controller.rb | 25 ---------------------- config/routes.rb | 2 -- 2 files changed, 27 deletions(-) diff --git a/app/controllers/api/v1/sites_controller.rb b/app/controllers/api/v1/sites_controller.rb index 10a92907..ae64cf74 100644 --- a/app/controllers/api/v1/sites_controller.rb +++ b/app/controllers/api/v1/sites_controller.rb @@ -12,31 +12,6 @@ module Api render json: sites_names + alternative_names + api_names + www_names end - # Sitios con hidden service de Tor - # - # @return [Array] lista de nombres de sitios sin onion aun - def hidden_services - render json: DeployHiddenService.where(values: nil).includes(:site).pluck(:name) - end - - # Tor va a enviar el onion junto con el nombre del sitio y tenemos - # que guardarlo en su deploy_hidden_service. - # - # @params [String] name - # @params [String] onion - def add_onion - site = Site.find_by(name: params[:name]) - - if site - usuarie = GitAuthor.new email: "tor@#{Site.domain}", name: 'Tor' - service = SiteService.new site: site, usuarie: usuarie, - params: params - service.add_onion - end - - head :ok - end - private def canonicalize(name) diff --git a/config/routes.rb b/config/routes.rb index a132135a..511ca654 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,8 +11,6 @@ Rails.application.routes.draw do namespace :v1 do resources :csp_reports, only: %i[create] - get :'sites/hidden_services', to: 'sites#hidden_services' - post :'sites/add_onion', to: 'sites#add_onion' resources :sites, only: %i[index], constraints: { site_id: /[a-z0-9\-.]+/, id: /[a-z0-9\-.]+/ } do get :'invitades/cookie', to: 'invitades#cookie' post :'posts/:layout', to: 'posts#create', as: :posts From 2f745886f5240a7b4f524155f505900ef54932fd Mon Sep 17 00:00:00 2001 From: f Date: Tue, 28 Mar 2023 16:22:58 -0300 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20reintentar=20si=20fall=C3=B3=20la=20?= =?UTF-8?q?generaci=C3=B3n=20en=20el=20pasado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/deploy_hidden_service.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/deploy_hidden_service.rb b/app/models/deploy_hidden_service.rb index 3356e815..25c0c217 100644 --- a/app/models/deploy_hidden_service.rb +++ b/app/models/deploy_hidden_service.rb @@ -9,6 +9,8 @@ class DeployHiddenService < DeployWww ONION_RE = /\A[a-z0-9]{56}\.onion\z/.freeze def fqdn + create_hidden_service! if onion.blank? + onion.tap do |onion| raise ArgumentError, 'Aun no se generó la dirección .onion' if onion.blank? end