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.

40 lines
954B

  1. class CheckController < ApplicationController
  2. before_action :check_host
  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 self.type, @idn
  12. end
  13. def show
  14. enqueue_host unless @result
  15. return render :processing if @result.pending
  16. return render :no_tls if @result.no_tls
  17. end
  18. def refresh
  19. unless @result.pending
  20. refresh_allowed = @result.date + Rails.configuration.refresh_delay
  21. if Time.now < refresh_allowed
  22. flash[:warning] = "Merci d’attendre au moins #{l refresh_allowed} pour rafraîchir"
  23. return redirect_to result_path @host
  24. end
  25. enqueue_host
  26. end
  27. redirect_to action: :show
  28. end
  29. protected
  30. def enqueue_host
  31. Datastore.pending self.type, @host
  32. self.worker.perform_async @idn
  33. @result = OpenStruct.new pending: true , date: Time.now
  34. end
  35. end