Browse Source

Homogenize colors

master
Aeris 3 years ago
parent
commit
427b966e1d

+ 1
- 1
app/controllers/check_controller.rb View File

@@ -24,7 +24,7 @@ class CheckController < ApplicationController
24 24
 			refresh_allowed = @result.date + Rails.configuration.refresh_delay
25 25
 			if Time.now < refresh_allowed
26 26
 				flash[:warning] = "Merci d’attendre au moins #{l refresh_allowed} pour rafraîchir"
27
-				return redirect_to result_path @host
27
+				return redirect_to action: :show, id: @host
28 28
 			end
29 29
 			enqueue_host
30 30
 		end

+ 1
- 1
app/controllers/ssh_controller.rb View File

@@ -27,7 +27,7 @@ class SshController < ApplicationController
27 27
 			refresh_allowed = @result.date + Rails.configuration.refresh_delay
28 28
 			if Time.now < refresh_allowed
29 29
 				flash[:warning] = "Merci d’attendre au moins #{l refresh_allowed} pour rafraîchir"
30
-				return redirect_to result_path @host
30
+				return redirect_to action: :show, id: @host
31 31
 			end
32 32
 			enqueue_host
33 33
 		end

+ 31
- 32
app/helpers/check_helper.rb View File

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

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

@@ -1,2 +1,3 @@
1 1
 module SiteHelper
2
+	include CheckHelper
2 3
 end

+ 13
- 8
app/views/check/show.html.erb View File

@@ -53,15 +53,18 @@
53 53
 							<p>Diffie Hellman : <%= key_labels @result.dh %></p>
54 54
 						</td>
55 55
 					</tr>
56
-					<% { 'Bonnes pratiques' => ['success', 'success'],
57
-					 'Alertes' => ['warning', 'warning'],
58
-					 'Erreurs' => ['error', 'danger'] }.each do |name, v| %>
56
+					<% { 'Bonnes pratiques' => :success,
57
+					 'Alertes' => :warning,
58
+					 'Dangers' => :danger,
59
+					 'Erreurs' => :error }.each do |name, color|
60
+						names = @result.score[color]
61
+						next if names.nil? or names.empty?
62
+					%>
59 63
 					<tr>
60 64
 						<th><%= name %></th>
61 65
 						<td>
62
-							<% item, color = v
63
-							(@result.score[item] || []).each do |item| %>
64
-							<span class="label label-<%= color %>"><%= item.upcase %></span>
66
+							<% names.each do |name| %>
67
+							<span class="label label-<%= color %>"><%= name.upcase %></span>
65 68
 							<% end %>
66 69
 						</td>
67 70
 					</tr>
@@ -89,9 +92,11 @@
89 92
 					<tr>
90 93
 						<th colspan="3"><%= protocol_label protocol %></th>
91 94
 					</tr>
92
-							<% ciphers.each do |cipher| %>
95
+							<% ciphers.each do |cipher|
96
+								cipher = CryptCheck::Tls::Cipher.new protocol, [cipher.name, nil, cipher[:size]], cipher.dh
97
+							%>
93 98
 					<tr>
94
-						<td><%= cipher.name %></td>
99
+						<th><%= cipher_name_label cipher, cipher.state %></th>
95 100
 						<td><%= cipher_size_label cipher %></td>
96 101
 						<td><%= key_label cipher.dh if cipher.dh %></td>
97 102
 						<td><%= cipher_labels cipher %></td>

+ 1
- 0
app/workers/check_worker.rb View File

@@ -28,6 +28,7 @@ class CheckWorker
28 28
 									cipher_strengths: grade.cipher_strengths_score
29 29
 							},
30 30
 							error:   grade.error,
31
+							danger:  grade.danger,
31 32
 							warning: grade.warning,
32 33
 							success: grade.success
33 34
 					}

+ 0
- 5
config/environments/test.rb View File

@@ -26,11 +26,6 @@ Rails.application.configure do
26 26
   # Disable request forgery protection in test environment.
27 27
   config.action_controller.allow_forgery_protection = false
28 28
 
29
-  # Tell Action Mailer not to deliver emails to the real world.
30
-  # The :test delivery method accumulates sent emails in the
31
-  # ActionMailer::Base.deliveries array.
32
-  config.action_mailer.delivery_method = :test
33
-
34 29
   # Randomize the order test cases are executed.
35 30
   config.active_support.test_order = :random
36 31
 

+ 0
- 4
config/routes.rb View File

@@ -1,8 +1,4 @@
1 1
 Rails.application.routes.draw do
2
-  get 'ssh/show'
3
-
4
-  get 'ssh/index'
5
-
6 2
 	namespace :https, id: /[^\/]*/ do
7 3
 		get ':id/', action: :show
8 4
 		get ':id/refresh', action: :refresh, as: :refresh

+ 0
- 10
test/controllers/check_controller_test.rb View File

@@ -1,14 +1,4 @@
1 1
 require 'test_helper'
2 2
 
3 3
 class CheckControllerTest < ActionController::TestCase
4
-  test "should get result" do
5
-    get :show
6
-    assert_response :success
7
-  end
8
-
9
-  test "should get refresh" do
10
-    get :refresh
11
-    assert_response :success
12
-  end
13
-
14 4
 end

+ 0
- 10
test/controllers/https_controller_test.rb View File

@@ -1,14 +1,4 @@
1 1
 require 'test_helper'
2 2
 
3 3
 class HttpsControllerTest < ActionController::TestCase
4
-  test "should get result" do
5
-    get :show
6
-    assert_response :success
7
-  end
8
-
9
-  test "should get refresh" do
10
-    get :refresh
11
-    assert_response :success
12
-  end
13
-
14 4
 end

+ 0
- 5
test/controllers/site_controller_test.rb View File

@@ -1,9 +1,4 @@
1 1
 require 'test_helper'
2 2
 
3 3
 class SiteControllerTest < ActionController::TestCase
4
-  test "should get index" do
5
-    get :index
6
-    assert_response :success
7
-  end
8
-
9 4
 end

+ 0
- 10
test/controllers/smtp_controller_test.rb View File

@@ -1,14 +1,4 @@
1 1
 require 'test_helper'
2 2
 
3 3
 class SmtpControllerTest < ActionController::TestCase
4
-  test "should get show" do
5
-    get :show
6
-    assert_response :success
7
-  end
8
-
9
-  test "should get refresh" do
10
-    get :refresh
11
-    assert_response :success
12
-  end
13
-
14 4
 end

+ 0
- 10
test/controllers/ssh_controller_test.rb View File

@@ -1,14 +1,4 @@
1 1
 require 'test_helper'
2 2
 
3 3
 class SshControllerTest < ActionController::TestCase
4
-  test "should get show" do
5
-    get :show
6
-    assert_response :success
7
-  end
8
-
9
-  test "should get index" do
10
-    get :index
11
-    assert_response :success
12
-  end
13
-
14 4
 end

+ 0
- 10
test/controllers/xmpp_controller_test.rb View File

@@ -1,14 +1,4 @@
1 1
 require 'test_helper'
2 2
 
3 3
 class XmppControllerTest < ActionController::TestCase
4
-  test "should get show" do
5
-    get :show
6
-    assert_response :success
7
-  end
8
-
9
-  test "should get refresh" do
10
-    get :refresh
11
-    assert_response :success
12
-  end
13
-
14 4
 end

+ 0
- 7
test/test_helper.rb View File

@@ -1,10 +1,3 @@
1 1
 ENV['RAILS_ENV'] ||= 'test'
2 2
 require File.expand_path('../../config/environment', __FILE__)
3 3
 require 'rails/test_help'
4
-
5
-class ActiveSupport::TestCase
6
-  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7
-  fixtures :all
8
-
9
-  # Add more helper methods to be used by all tests here...
10
-end

Loading…
Cancel
Save