mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 06:31:42 +00:00
Merge branch 'issue-12773' into 'rails'
generar hidden services a demandab Closes #12410, #12753, #10467, #10506, and #10509 See merge request sutty/sutty!132
This commit is contained in:
commit
9e6ba61ab9
6 changed files with 39 additions and 41 deletions
|
@ -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)
|
||||
|
|
13
app/lib/hidden_service_client.rb
Normal file
13
app/lib/hidden_service_client.rb
Normal 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
|
|
@ -2,8 +2,16 @@
|
|||
|
||||
# Genera una versión onion
|
||||
class DeployHiddenService < DeployWww
|
||||
store :values, accessors: %i[onion], coder: JSON
|
||||
|
||||
before_create :create_hidden_service!
|
||||
|
||||
ONION_RE = /\A[a-z0-9]{56}\.onion\z/.freeze
|
||||
|
||||
def fqdn
|
||||
values[:onion].tap do |onion|
|
||||
create_hidden_service! if onion.blank?
|
||||
|
||||
onion.tap do |onion|
|
||||
raise ArgumentError, 'Aun no se generó la dirección .onion' if onion.blank?
|
||||
end
|
||||
end
|
||||
|
@ -11,4 +19,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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue