No Description https://cryptcheck.fr/
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.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. render json: JSON.pretty_generate(JSON.parse @result.to_json)
  13. end
  14. end
  15. end
  16. def refresh
  17. unless @result.pending
  18. if Rails.env == 'production'
  19. refresh_allowed = @result.date + Rails.configuration.refresh_delay
  20. if Time.now < refresh_allowed
  21. flash[:warning] = "Merci d’attendre au moins #{l refresh_allowed} pour rafraîchir"
  22. return redirect_to action: :show, id: @host
  23. end
  24. end
  25. enqueue_host
  26. end
  27. redirect_to action: :show
  28. end
  29. protected
  30. def enqueue_host
  31. @result = Analysis.pending self.type, @host, @port
  32. self.worker.perform_async *(@port.blank? ? [@host] : [@host, @port])
  33. end
  34. def check_host
  35. @id = params[:id]
  36. if @id.end_with? '.json'
  37. @id = @id.sub /\.json$/, ''
  38. request.format = :json
  39. end
  40. @host, @port = @id.split ':'
  41. @host = SimpleIDN.to_ascii @host.downcase
  42. if /[^a-zA-Z0-9.-]/ =~ @host
  43. flash[:danger] = "Hôte #{@host} invalide"
  44. redirect_to action: :index
  45. return false
  46. end
  47. if @port
  48. @port = @port.to_i
  49. else
  50. @port = self.default_port
  51. end
  52. @result = Analysis[self.type, @host, @port]
  53. # file = File.join Rails.root, 'config/host.yml'
  54. # File.write file, YAML.dump(@result)
  55. # @result = YAML.load File.read file
  56. end
  57. end