Detectar cuando el servicio oculto es opcional
This commit is contained in:
parent
45559ad58f
commit
70c8bcbcd1
4 changed files with 22 additions and 7 deletions
|
@ -16,7 +16,7 @@ module Api
|
||||||
#
|
#
|
||||||
# @return [Array] lista de nombres de sitios sin onion aun
|
# @return [Array] lista de nombres de sitios sin onion aun
|
||||||
def hidden_services
|
def hidden_services
|
||||||
render json: DeployHiddenService.where(values: nil).includes(:site).pluck(:name)
|
render json: DeployHiddenService.temporary.includes(:site).pluck(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Tor va a enviar el onion junto con el nombre del sitio y tenemos
|
# Tor va a enviar el onion junto con el nombre del sitio y tenemos
|
||||||
|
@ -28,7 +28,7 @@ module Api
|
||||||
site = Site.find_by(name: params[:name])
|
site = Site.find_by(name: params[:name])
|
||||||
|
|
||||||
if site
|
if site
|
||||||
usuarie = GitAuthor.new email: 'tor@' + Site.domain, name: 'Tor'
|
usuarie = GitAuthor.new email: "tor@#{Site.domain}", name: 'Tor'
|
||||||
service = SiteService.new site: site, usuarie: usuarie,
|
service = SiteService.new site: site, usuarie: usuarie,
|
||||||
params: params
|
params: params
|
||||||
service.add_onion
|
service.add_onion
|
||||||
|
|
|
@ -5,6 +5,12 @@
|
||||||
class DeployHiddenService < DeployWww
|
class DeployHiddenService < DeployWww
|
||||||
validates :hostname, format: { with: /\A[a-z2-7]{56}.onion\z/ }
|
validates :hostname, format: { with: /\A[a-z2-7]{56}.onion\z/ }
|
||||||
|
|
||||||
|
# Sufijo para todos los dominios temporales.
|
||||||
|
TEMPORARY_SUFFIX = 'temporary'
|
||||||
|
|
||||||
|
# Traer todos los servicios ocultos temporales.
|
||||||
|
scope :temporary, -> { where("hostname not like '#{TEMPORARY_SUFFIX}%'") }
|
||||||
|
|
||||||
# Los servicios ocultos son su propio transporte cifrado y
|
# Los servicios ocultos son su propio transporte cifrado y
|
||||||
# autenticado.
|
# autenticado.
|
||||||
#
|
#
|
||||||
|
@ -19,7 +25,14 @@ class DeployHiddenService < DeployWww
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def default_hostname
|
def default_hostname
|
||||||
"temporal#{random_base32}.onion"
|
"#{TEMPORARY_SUFFIX}#{random_base32}.onion"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Detecta si es una dirección temporal.
|
||||||
|
#
|
||||||
|
# @return [Boolean]
|
||||||
|
def temporary?
|
||||||
|
hostname.start_with? TEMPORARY_SUFFIX
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -32,8 +45,9 @@ class DeployHiddenService < DeployWww
|
||||||
#
|
#
|
||||||
# @see {https://github.com/stesla/base32/blob/master/lib/base32.rb}
|
# @see {https://github.com/stesla/base32/blob/master/lib/base32.rb}
|
||||||
# @see {https://github.com/stesla/base32/blob/master/LICENSE}
|
# @see {https://github.com/stesla/base32/blob/master/LICENSE}
|
||||||
def random_base32(length = 48)
|
def random_base32(length = nil)
|
||||||
table = 'abcdefghijklmnopqrstuvwxyz234567'
|
table = 'abcdefghijklmnopqrstuvwxyz234567'
|
||||||
|
length ||= 56 - TEMPORARY_SUFFIX.length
|
||||||
|
|
||||||
OpenSSL::Random.random_bytes(length).each_byte.map do |b|
|
OpenSSL::Random.random_bytes(length).each_byte.map do |b|
|
||||||
table[b % 32]
|
table[b % 32]
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
= sanitize_markdown t('.help', public_url: site.deploy_local.url),
|
= sanitize_markdown t('.help', public_url: site.deploy_local.url),
|
||||||
tags: %w[p strong em a]
|
tags: %w[p strong em a]
|
||||||
|
|
||||||
= sanitize_markdown t('.help_2', url: deploy.object.url),
|
- unless deploy.object.temporary?
|
||||||
tags: %w[p strong em a]
|
= sanitize_markdown t('.help_2', url: deploy.object.url),
|
||||||
|
tags: %w[p strong em a]
|
||||||
%hr/
|
%hr/
|
||||||
|
|
|
@ -20,7 +20,7 @@ class DeployHiddenServiceTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'los hostnames pueden ser temporales' do
|
test 'los hostnames pueden ser temporales' do
|
||||||
assert @deploy_hidden.hostname.start_with? 'temporal'
|
assert @deploy_hidden.hostname.start_with? 'temporary'
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'el hostname tiene que ser único' do
|
test 'el hostname tiene que ser único' do
|
||||||
|
|
Loading…
Reference in a new issue