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.

check_controller.rb 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. class CheckController < ApplicationController
  2. before_action :check_host, except: %i(index)
  3. helper_method :tls_type, :type
  4. def show
  5. enqueue_host unless @result
  6. @host = SimpleIDN.to_unicode @host
  7. return render :processing if @result.pending
  8. return render :no_tls if @result.no_tls
  9. end
  10. def refresh
  11. unless @result.pending
  12. refresh_allowed = @result.date + Rails.configuration.refresh_delay
  13. if Time.now < refresh_allowed
  14. flash[:warning] = "Merci d’attendre au moins #{l refresh_allowed} pour rafraîchir"
  15. return redirect_to action: :show, id: @host
  16. end
  17. enqueue_host
  18. end
  19. redirect_to action: :show
  20. end
  21. protected
  22. def enqueue_host
  23. Datastore.pending self.type, @id, @port
  24. self.worker.perform_async *(@port.blank? ? [@host] : [@host, @port])
  25. @result = OpenStruct.new pending: true , date: Time.now
  26. end
  27. def check_host
  28. @id = params[:id]
  29. @host, @port = @id.split ':'
  30. @host = SimpleIDN.to_ascii @host.downcase
  31. if /[^a-zA-Z0-9.-]/.match @host
  32. flash[:danger] = "Hôte #{@host} invalide"
  33. redirect_to action: :index
  34. return false
  35. end
  36. @result = Datastore.host self.type, @host, @port
  37. end
  38. end