63 lines
1.7 KiB
Ruby
63 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Api
|
|
module V1
|
|
# API para sitios
|
|
class SitesController < BaseController
|
|
http_basic_authenticate_with name: ENV['HTTP_BASIC_USER'],
|
|
password: ENV['HTTP_BASIC_PASSWORD']
|
|
|
|
# Lista de nombres de dominios a emitir certificados
|
|
def index
|
|
render json: sites_names + alternative_names + api_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
|
|
|
|
# Nombres de los sitios
|
|
def sites_names
|
|
Site.all.order(:name).pluck(:name)
|
|
end
|
|
|
|
# Dominios alternativos
|
|
def alternative_names
|
|
DeployAlternativeDomain.all.map(&:hostname)
|
|
end
|
|
|
|
# Obtener todos los sitios con API habilitada, es decir formulario
|
|
# de contacto y/o colaboración anónima.
|
|
#
|
|
# TODO: Optimizar
|
|
def api_names
|
|
Site.where(contact: true)
|
|
.or(Site.where(colaboracion_anonima: true))
|
|
.select("'api.' || name as name").map(&:name)
|
|
end
|
|
end
|
|
end
|
|
end
|