選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

check_controller.rb 1.1KB

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