5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 12:21:43 +00:00
panel/app/models/deploy_hidden_service.rb

38 lines
846 B
Ruby
Raw Normal View History

2020-07-18 19:26:54 +00:00
# frozen_string_literal: true
# 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
2020-07-18 19:26:54 +00:00
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
2020-07-18 19:26:54 +00:00
end
def url
2022-04-06 23:07:14 +00:00
"http://#{fqdn}"
2020-07-18 19:26:54 +00:00
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
2020-07-18 19:26:54 +00:00
end