25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

56 satır
1.3KB

  1. require 'erb'
  2. require 'logging'
  3. require 'parallel'
  4. module CryptCheck
  5. module Tls
  6. module Xmpp
  7. MAX_ANALYSIS_DURATION = 600
  8. PARALLEL_ANALYSIS = 10
  9. @@log = ::Logging.logger[Https]
  10. def self.grade(hostname, type=:s2s)
  11. timeout MAX_ANALYSIS_DURATION do
  12. Grade.new Server.new hostname, type
  13. end
  14. rescue ::Exception => e
  15. @@log.error { "Error during #{hostname}:#{type} analysis : #{e}" }
  16. TlsNotSupportedGrade.new TlsNotSupportedServer.new hostname, type
  17. end
  18. def self.analyze(hosts, output)
  19. servers = []
  20. semaphore = ::Mutex.new
  21. ::Parallel.each hosts, progress: 'Analysing', in_threads: PARALLEL_ANALYSIS, finish: lambda { |item, _, _| puts item } do |host|
  22. result = grade host.strip
  23. semaphore.synchronize { servers << result }
  24. end
  25. servers.sort! do |a, b|
  26. cmp = score(a) <=> score(b)
  27. if cmp == 0
  28. cmp = b.score <=> a.score
  29. if cmp == 0
  30. cmp = a.server.hostname <=> b.server.hostname
  31. end
  32. end
  33. cmp
  34. end
  35. ::File.write output, ::ERB.new(::File.read('output/xmpp.erb')).result(binding)
  36. end
  37. def self.analyze_from_file(file, output)
  38. hosts = ::YAML.load_file file
  39. self.analyze hosts, output
  40. end
  41. private
  42. SCORES = %w(A+ A A- B C D E F T M X)
  43. def self.score(a)
  44. SCORES.index a.grade
  45. end
  46. end
  47. end
  48. end