Browse Source

Remove global helpers

master
Aeris 3 years ago
parent
commit
ac60a22f86
3 changed files with 109 additions and 108 deletions
  1. 108
    0
      app/helpers/check_helper.rb
  2. 0
    108
      app/helpers/site_helper.rb
  3. 1
    0
      config/application.rb

+ 108
- 0
app/helpers/check_helper.rb View File

@@ -1,2 +1,110 @@
1 1
 module CheckHelper
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
+
13
+	def rank_label(rank)
14
+		"<span class=\"label label-#{rank_color rank}\">#{rank}</span>".html_safe
15
+	end
16
+
17
+	def progress_color(percentage)
18
+		case percentage
19
+			when 0...20 then :error
20
+			when 20...40 then :danger
21
+			when 40...60 then :warning
22
+			when 60...80 then :default
23
+			when 80...90 then :success
24
+			else :primary
25
+		end
26
+	end
27
+
28
+	def score_progress(score)
29
+		%Q(<div class="progress">
30
+			 <div class="progress-bar progress-bar-striped progress-bar-#{progress_color score}"
31
+						style="width: #{score}%">
32
+				#{score} / 100
33
+			</div>
34
+		</div>).html_safe
35
+	end
36
+
37
+	def protocol_label(protocol)
38
+		color = case protocol.to_s
39
+					when 'TLSv1_2' then :success
40
+					when 'SSLv3', 'SSLv2' then :danger
41
+					else :default
42
+				end
43
+		"<span class=\"label label-#{color}\">#{protocol}</span>".html_safe
44
+	end
45
+
46
+	def protocol_labels(protocols)
47
+		protocols.collect { |p| protocol_label p }.join("\n").html_safe
48
+	end
49
+
50
+	def key_label(key)
51
+		return '<span class="label label-error">Aucune</span>'.html_safe unless key
52
+		"<span class=\"label label-#{color_key key}\">#{key.type.upcase} #{key[:size]} bits</span>".html_safe
53
+	end
54
+
55
+	def key_labels(keys)
56
+		return '<span class="label label-error">Aucune</span>'.html_safe if keys.empty?
57
+		keys.sort { |a, b| -1 * (a.rsa_size <=> b.rsa_size)} .collect { |k| key_label k }.join("\n").html_safe
58
+	end
59
+
60
+	def cipher_size_label(cipher)
61
+		size = cipher.kind_of?(CryptCheck::Tls::Cipher) ? cipher.size : cipher['size']
62
+		"<span class=\"label label-#{cipher_color size} %>\">#{size} bits</span>".html_safe
63
+	end
64
+
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
+
74
+	def cipher_color(key)
75
+		case key
76
+			when 0...112 then :danger
77
+			when 112...128 then :warning
78
+			when 128...256 then :success
79
+			else :primary
80
+		end
81
+	end
82
+
83
+	def cipher_name_label(cipher, state)
84
+		color = case
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
+		"<span class=\"label label-#{color} %>\">#{cipher.name}</span>".html_safe
92
+	end
93
+
94
+	def cipher_labels(cipher)
95
+		case cipher
96
+			when Hashie::Mash
97
+				{ success: %i(pfs),
98
+				  warning: %i(des3 sha1),
99
+				  danger: %i(dss md5 psk srp anonymous null export des rc2 rc4)
100
+				}.collect do |c, ts|
101
+					ts.select { |t| CryptCheck::Tls::Cipher.send "#{t}?", cipher.name }.collect { |t| [c, t] }
102
+				end
103
+			when Hash
104
+				cipher.collect { |c, ts| ts.collect { |t| [c, t] } }
105
+		end
106
+				.flatten(1)
107
+				.collect { |c, t| "<span class=\"label label-#{c}\">#{t.upcase}</span>" }
108
+				.join("\n").html_safe
109
+	end
2 110
 end

+ 0
- 108
app/helpers/site_helper.rb View File

@@ -1,110 +1,2 @@
1 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
-
13
-	def rank_label(rank)
14
-		"<span class=\"label label-#{rank_color rank}\">#{rank}</span>".html_safe
15
-	end
16
-
17
-	def progress_color(percentage)
18
-		case percentage
19
-			when 0...20 then :error
20
-			when 20...40 then :danger
21
-			when 40...60 then :warning
22
-			when 60...80 then :default
23
-			when 80...90 then :success
24
-			else :primary
25
-		end
26
-	end
27
-
28
-	def score_progress(score)
29
-		%Q(<div class="progress">
30
-			 <div class="progress-bar progress-bar-striped progress-bar-#{progress_color score}"
31
-						style="width: #{score}%">
32
-				#{score} / 100
33
-			</div>
34
-		</div>).html_safe
35
-	end
36
-
37
-	def protocol_label(protocol)
38
-		color = case protocol.to_s
39
-			when 'TLSv1_2' then :success
40
-			when 'SSLv3', 'SSLv2' then :danger
41
-			else :default
42
-		end
43
-		"<span class=\"label label-#{color}\">#{protocol}</span>".html_safe
44
-	end
45
-
46
-	def protocol_labels(protocols)
47
-		protocols.collect { |p| protocol_label p }.join("\n").html_safe
48
-	end
49
-
50
-	def key_label(key)
51
-		return '<span class="label label-error">Aucune</span>'.html_safe unless key
52
-		"<span class=\"label label-#{color_key key}\">#{key.type.upcase} #{key[:size]} bits</span>".html_safe
53
-	end
54
-
55
-	def key_labels(keys)
56
-		return '<span class="label label-error">Aucune</span>'.html_safe if keys.empty?
57
-		keys.sort { |a, b| -1 * (a.rsa_size <=> b.rsa_size)} .collect { |k| key_label k }.join("\n").html_safe
58
-	end
59
-
60
-	def cipher_size_label(cipher)
61
-		size = cipher.kind_of?(CryptCheck::Tls::Cipher) ? cipher.size : cipher['size']
62
-		"<span class=\"label label-#{cipher_color size} %>\">#{size} bits</span>".html_safe
63
-	end
64
-
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
-
74
-	def cipher_color(key)
75
-		case key
76
-			when 0...112 then :danger
77
-			when 112...128 then :warning
78
-			when 128...256 then :success
79
-			else :primary
80
-		end
81
-	end
82
-
83
-	def cipher_name_label(cipher, state)
84
-		color = case
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
-		"<span class=\"label label-#{color} %>\">#{cipher.name}</span>".html_safe
92
-	end
93
-
94
-	def cipher_labels(cipher)
95
-		case cipher
96
-			when Hashie::Mash
97
-				{ success: %i(pfs),
98
-				  warning: %i(des3 sha1),
99
-				  danger: %i(dss md5 psk srp anonymous null export des rc2 rc4)
100
-				}.collect do |c, ts|
101
-					ts.select { |t| CryptCheck::Tls::Cipher.send "#{t}?", cipher.name }.collect { |t| [c, t] }
102
-				end
103
-			when Hash
104
-				cipher.collect { |c, ts| ts.collect { |t| [c, t] } }
105
-		end
106
-		.flatten(1)
107
-		.collect { |c, t| "<span class=\"label label-#{c}\">#{t.upcase}</span>" }
108
-		.join("\n").html_safe
109
-	end
110 2
 end

+ 1
- 0
config/application.rb View File

@@ -39,6 +39,7 @@ module CryptcheckRails
39 39
 		# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
40 40
 		# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
41 41
 		config.i18n.default_locale = :fr
42
+		config.action_controller.include_all_helpers = false
42 43
 
43 44
 		config.refresh_delay = 1.hour
44 45
 	end

Loading…
Cancel
Save