Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

check_controller.rb 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. respond_to do |format|
  8. format.html do
  9. return render :processing if @result.pending
  10. end
  11. format.json do
  12. ap @result
  13. render json: JSON.pretty_generate(JSON.parse @result.to_json)
  14. end
  15. end
  16. end
  17. def refresh
  18. unless @result.pending
  19. if Rails.env == 'production'
  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 action: :show, id: @host
  24. end
  25. end
  26. enqueue_host
  27. end
  28. redirect_to action: :show
  29. end
  30. protected
  31. def enqueue_host
  32. @result = Analysis.pending self.type, @host, @port
  33. self.worker.perform_async *(@port.blank? ? [@host] : [@host, @port])
  34. end
  35. def check_host
  36. @id = params[:id]
  37. if @id.end_with? '.json'
  38. @id = @id.sub /\.json$/, ''
  39. request.format = :json
  40. end
  41. @host, @port = @id.split ':'
  42. @host = SimpleIDN.to_ascii @host.downcase
  43. if /[^a-zA-Z0-9.-]/ =~ @host
  44. flash[:danger] = "Hôte #{@host} invalide"
  45. redirect_to action: :index
  46. return false
  47. end
  48. if @port
  49. @port = @port.to_i
  50. else
  51. @port = self.default_port
  52. end
  53. @result = Analysis[self.type, @host, @port]
  54. # file = File.join Rails.root, 'config/host.yml'
  55. # File.write file, YAML.dump(@result)
  56. # @result = YAML.load File.read file
  57. end
  58. end