You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

68 lines
1.6 KiB

class CheckController < ApplicationController
before_action :check_host, except: %i(index)
helper_method :tls_type, :type
def show
enqueue_host unless @result
@host = SimpleIDN.to_unicode @host
respond_to do |format|
format.html do
return render :processing if @result[:pending]
@result = OpenStruct.deep @result
end
format.json do
render json: case
when @result[:pending] then
:pending
else
JSON.pretty_generate @result
end
end
end
end
def refresh
unless @result.pending
if Rails.env == 'production'
refresh_allowed = @result.date + Rails.configuration.refresh_delay
if Time.now < refresh_allowed
flash[:warning] = "Merci d’attendre au moins #{l refresh_allowed} pour rafraîchir"
return redirect_to action: :show, id: @host
end
end
enqueue_host
end
redirect_to action: :show
end
protected
def enqueue_host
Datastore.pending self.type, @host, @port
self.worker.perform_async *(@port.blank? ? [@host] : [@host, @port])
@result = OpenStruct.new pending: true, date: Time.now
end
def check_host
@id = params[:id]
if @id.end_with? '.json'
@id = @id.sub /\.json$/, ''
request.format = :json
end
@host, @port = @id.split ':'
@host = SimpleIDN.to_ascii @host.downcase
if /[^a-zA-Z0-9.-]/ =~ @host
flash[:danger] = "Hôte #{@host} invalide"
redirect_to action: :index
return false
end
@port = @port.to_i if @port
#@result = Datastore.host self.type, @host, @port
file = File.join Rails.root, 'config/host.yml'
#File.write file, YAML.dump(@result)
@result = YAML.load File.read file
end
end