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.

92 satır
2.3KB

  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
  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_label(cipher)
  53. "<span class=\"label label-#{cipher_color cipher['size']} %>\">#{cipher['size']} bits</span>".html_safe
  54. end
  55. def color_key(key)
  56. case key.rsa_size
  57. when 0...1024 then :error
  58. when 1024...2048 then :danger
  59. when 2048...4096 then :warning
  60. else :success
  61. end
  62. end
  63. def cipher_color(key)
  64. case key
  65. when 0...112 then :error
  66. when 112...128 then :warning
  67. when 128...256 then :success
  68. else :primary
  69. end
  70. end
  71. def cipher_labels(cipher)
  72. { success: %i(pfs),
  73. warning: %i(des3 sha1),
  74. danger: %i(md5 psk srp anonymous null export des rc2 rc4)
  75. }.collect do |color, types|
  76. types.select { |t| CryptCheck::Tls::Cipher.send "#{t}?", cipher.name }
  77. .collect { |t| "<span class=\"label label-#{color}\">#{t.upcase}</span>" }
  78. end.flatten(1).join("\n").html_safe
  79. end
  80. end