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 line
2.4KB

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