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.

111 lines
2.9KB

  1. module SiteHelper
  2. def rank_color(rank)
  3. case rank
  4. when 'A+' then :primary
  5. when 'A' then :success
  6. when 'B' then :default
  7. when 'C', 'D' then :warning
  8. when 'E', 'F' then :danger
  9. else :error
  10. end
  11. end
  12. def rank_label(rank)
  13. "<span class=\"label label-#{rank_color rank}\">#{rank}</span>".html_safe
  14. end
  15. def progress_color(percentage)
  16. case percentage
  17. when 0...20 then :error
  18. when 20...40 then :danger
  19. when 40...60 then :warning
  20. when 60...80 then :default
  21. when 80...90 then :success
  22. else :primary
  23. end
  24. end
  25. def score_progress(score)
  26. %Q(<div class="progress">
  27. <div class="progress-bar progress-bar-striped progress-bar-#{progress_color score}"
  28. style="width: #{score}%">
  29. #{score} / 100
  30. </div>
  31. </div>).html_safe
  32. end
  33. def protocol_label(protocol)
  34. color = case protocol.to_s
  35. when 'TLSv1_2' then :success
  36. when 'SSLv3', 'SSLv2' then :danger
  37. else :default
  38. end
  39. "<span class=\"label label-#{color}\">#{protocol}</span>".html_safe
  40. end
  41. def protocol_labels(protocols)
  42. protocols.collect { |p| protocol_label p }.join("\n").html_safe
  43. end
  44. def key_label(key)
  45. return '<span class="label label-error">Aucune</span>'.html_safe unless key
  46. "<span class=\"label label-#{color_key key}\">#{key.type.upcase} #{key[:size]} bits</span>".html_safe
  47. end
  48. def key_labels(keys)
  49. return '<span class="label label-error">Aucune</span>'.html_safe if keys.empty?
  50. keys.sort { |a, b| -1 * (a.rsa_size <=> b.rsa_size)} .collect { |k| key_label k }.join("\n").html_safe
  51. end
  52. def cipher_size_label(cipher)
  53. size = cipher.kind_of?(CryptCheck::Tls::Cipher) ? cipher.size : cipher['size']
  54. "<span class=\"label label-#{cipher_color size} %>\">#{size} bits</span>".html_safe
  55. end
  56. def color_key(key)
  57. case key.rsa_size
  58. when 0...1024 then :error
  59. when 1024...2048 then :danger
  60. when 2048...4096 then :warning
  61. else :success
  62. end
  63. end
  64. def cipher_color(key)
  65. case key
  66. when 0...112 then :danger
  67. when 112...128 then :warning
  68. when 128...256 then :success
  69. else :primary
  70. end
  71. end
  72. def cipher_name_label(cipher, state)
  73. color = case
  74. when !state[:danger].empty? then :danger
  75. when !state[:warning].empty? then :warning
  76. when !state[:success].empty? then :success
  77. else :default
  78. end
  79. color = :primary if color == :success and cipher.size >= 256
  80. "<span class=\"label label-#{color} %>\">#{cipher.name}</span>".html_safe
  81. end
  82. def cipher_labels(cipher)
  83. case cipher
  84. when Hashie::Mash
  85. { success: %i(pfs),
  86. warning: %i(des3 sha1),
  87. danger: %i(md5 psk srp anonymous null export des rc2 rc4)
  88. }.collect do |c, ts|
  89. ts.select { |t| CryptCheck::Tls::Cipher.send "#{t}?", cipher.name }.collect { |t| [c, t] }
  90. end
  91. when Hash
  92. cipher.collect { |c, ts| ts.collect { |t| [c, t] } }
  93. end
  94. .flatten(1)
  95. .collect { |c, t| "<span class=\"label label-#{c}\">#{t.upcase}</span>" }
  96. .join("\n").html_safe
  97. end
  98. end