2019-09-05 18:56:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
# API para sitios
|
|
|
|
class SitesController < BaseController
|
2020-02-06 16:11:17 +00:00
|
|
|
http_basic_authenticate_with name: ENV['HTTP_BASIC_USER'],
|
|
|
|
password: ENV['HTTP_BASIC_PASSWORD']
|
|
|
|
|
2020-05-29 15:42:39 +00:00
|
|
|
# Lista de nombres de dominios a emitir certificados
|
2019-09-06 23:40:33 +00:00
|
|
|
def index
|
2021-08-09 00:55:22 +00:00
|
|
|
render json: Deploy.all.pluck(:hostname)
|
2019-09-06 23:40:33 +00:00
|
|
|
end
|
|
|
|
|
2020-07-18 19:26:54 +00:00
|
|
|
# Sitios con hidden service de Tor
|
|
|
|
#
|
|
|
|
# @return [Array] lista de nombres de sitios sin onion aun
|
|
|
|
def hidden_services
|
2021-08-07 21:59:23 +00:00
|
|
|
render json: DeployHiddenService.temporary.includes(:site).pluck(:name)
|
2020-07-18 19:26:54 +00:00
|
|
|
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
|
2021-08-09 00:55:22 +00:00
|
|
|
if (site = Site.find_by_name(params[:name]))
|
2021-08-07 21:59:23 +00:00
|
|
|
usuarie = GitAuthor.new email: "tor@#{Site.domain}", name: 'Tor'
|
2020-07-18 19:26:54 +00:00
|
|
|
service = SiteService.new site: site, usuarie: usuarie,
|
|
|
|
params: params
|
|
|
|
service.add_onion
|
|
|
|
end
|
|
|
|
|
|
|
|
head :ok
|
|
|
|
end
|
2019-09-05 18:56:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|