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.

43 lines
984B

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