Browse Source

Homogenize colors

master
Aeris 4 years ago
parent
commit
427b966e1d

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

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

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

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

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

@@ -1,17 +1,27 @@
module CheckHelper
def label(value, color)
"<span class=\"label label-#{color} %>\">#{value}</span>".html_safe
end

def rank_color(rank)
case rank
when 'A+' then :primary
when 'A' then :success
when 'B' then :default
when 'C', 'D' then :warning
when 'E', 'F' then :danger
else :error
when 'A+' then
:primary
when 'A' then
:success
when 'B' then
:default
when 'C', 'D' then
:warning
when 'E', 'F' then
:danger
else
:error
end
end

def rank_label(rank)
"<span class=\"label label-#{rank_color rank}\">#{rank}</span>".html_safe
label rank, rank_color(rank)
end

def progress_color(percentage)
@@ -37,10 +47,10 @@ module CheckHelper
def protocol_label(protocol)
color = case protocol.to_s
when 'TLSv1_2' then :success
when 'SSLv3', 'SSLv2' then :danger
when 'SSLv3', 'SSLv2' then :error
else :default
end
"<span class=\"label label-#{color}\">#{protocol}</span>".html_safe
label protocol, color
end

def protocol_labels(protocols)
@@ -48,18 +58,18 @@ module CheckHelper
end

def key_label(key)
return '<span class="label label-error">Aucune</span>'.html_safe unless key
"<span class=\"label label-#{color_key key}\">#{key.type.upcase} #{key[:size]} bits</span>".html_safe
return label('Aucune', :error) unless key
label "#{key.type.upcase} #{key[:size]} bits", color_key(key)
end

def key_labels(keys)
return '<span class="label label-error">Aucune</span>'.html_safe if keys.empty?
keys.sort { |a, b| -1 * (a.rsa_size <=> b.rsa_size)} .collect { |k| key_label k }.join("\n").html_safe
return label('Aucune', :error) if keys.empty?
keys.sort { |a, b| -1 * (a.rsa_size <=> b.rsa_size) }.collect { |k| key_label k }.join("\n").html_safe
end

def cipher_size_label(cipher)
size = cipher.kind_of?(CryptCheck::Tls::Cipher) ? cipher.size : cipher['size']
"<span class=\"label label-#{cipher_color size} %>\">#{size} bits</span>".html_safe
size = cipher.size
label "#{size} bits", cipher_color(size)
end

def color_key(key)
@@ -73,8 +83,8 @@ module CheckHelper

def cipher_color(key)
case key
when 0...112 then :danger
when 112...128 then :warning
when 0...112 then :error
when 112...128 then :danger
when 128...256 then :success
else :primary
end
@@ -82,29 +92,18 @@ module CheckHelper

def cipher_name_label(cipher, state)
color = case
when !state[:error].empty? then :error
when !state[:danger].empty? then :danger
when !state[:warning].empty? then :warning
when !state[:success].empty? then :success
else :default
end
color = :primary if color == :success and cipher.size >= 256
"<span class=\"label label-#{color} %>\">#{cipher.name}</span>".html_safe
label("&nbsp;", color) + "&nbsp;#{cipher.name}".html_safe
end

def cipher_labels(cipher)
case cipher
when Hashie::Mash
{ success: %i(pfs),
warning: %i(des3 sha1),
danger: %i(dss md5 psk srp anonymous null export des rc2 rc4)
}.collect do |c, ts|
ts.select { |t| CryptCheck::Tls::Cipher.send "#{t}?", cipher.name }.collect { |t| [c, t] }
end
when Hash
cipher.collect { |c, ts| ts.collect { |t| [c, t] } }
end
.flatten(1)
.collect { |c, t| "<span class=\"label label-#{c}\">#{t.upcase}</span>" }
.join("\n").html_safe
cipher.state.collect { |c, ls| ls.collect { |l| label l.upcase, c } }
.flatten(1).join("\n").html_safe
end
end

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

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

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

@@ -53,15 +53,18 @@
<p>Diffie Hellman : <%= key_labels @result.dh %></p>
</td>
</tr>
<% { 'Bonnes pratiques' => ['success', 'success'],
'Alertes' => ['warning', 'warning'],
'Erreurs' => ['error', 'danger'] }.each do |name, v| %>
<% { 'Bonnes pratiques' => :success,
'Alertes' => :warning,
'Dangers' => :danger,
'Erreurs' => :error }.each do |name, color|
names = @result.score[color]
next if names.nil? or names.empty?
%>
<tr>
<th><%= name %></th>
<td>
<% item, color = v
(@result.score[item] || []).each do |item| %>
<span class="label label-<%= color %>"><%= item.upcase %></span>
<% names.each do |name| %>
<span class="label label-<%= color %>"><%= name.upcase %></span>
<% end %>
</td>
</tr>
@@ -89,9 +92,11 @@
<tr>
<th colspan="3"><%= protocol_label protocol %></th>
</tr>
<% ciphers.each do |cipher| %>
<% ciphers.each do |cipher|
cipher = CryptCheck::Tls::Cipher.new protocol, [cipher.name, nil, cipher[:size]], cipher.dh
%>
<tr>
<td><%= cipher.name %></td>
<th><%= cipher_name_label cipher, cipher.state %></th>
<td><%= cipher_size_label cipher %></td>
<td><%= key_label cipher.dh if cipher.dh %></td>
<td><%= cipher_labels cipher %></td>

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

@@ -28,6 +28,7 @@ class CheckWorker
cipher_strengths: grade.cipher_strengths_score
},
error: grade.error,
danger: grade.danger,
warning: grade.warning,
success: grade.success
}

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

@@ -26,11 +26,6 @@ Rails.application.configure do
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

# Randomize the order test cases are executed.
config.active_support.test_order = :random


+ 0
- 4
config/routes.rb View File

@@ -1,8 +1,4 @@
Rails.application.routes.draw do
get 'ssh/show'

get 'ssh/index'

namespace :https, id: /[^\/]*/ do
get ':id/', action: :show
get ':id/refresh', action: :refresh, as: :refresh

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

@@ -1,14 +1,4 @@
require 'test_helper'

class CheckControllerTest < ActionController::TestCase
test "should get result" do
get :show
assert_response :success
end

test "should get refresh" do
get :refresh
assert_response :success
end

end

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

@@ -1,14 +1,4 @@
require 'test_helper'

class HttpsControllerTest < ActionController::TestCase
test "should get result" do
get :show
assert_response :success
end

test "should get refresh" do
get :refresh
assert_response :success
end

end

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

@@ -1,9 +1,4 @@
require 'test_helper'

class SiteControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
end

end

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

@@ -1,14 +1,4 @@
require 'test_helper'

class SmtpControllerTest < ActionController::TestCase
test "should get show" do
get :show
assert_response :success
end

test "should get refresh" do
get :refresh
assert_response :success
end

end

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

@@ -1,14 +1,4 @@
require 'test_helper'

class SshControllerTest < ActionController::TestCase
test "should get show" do
get :show
assert_response :success
end

test "should get index" do
get :index
assert_response :success
end

end

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

@@ -1,14 +1,4 @@
require 'test_helper'

class XmppControllerTest < ActionController::TestCase
test "should get show" do
get :show
assert_response :success
end

test "should get refresh" do
get :refresh
assert_response :success
end

end

+ 0
- 7
test/test_helper.rb View File

@@ -1,10 +1,3 @@
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all

# Add more helper methods to be used by all tests here...
end

Loading…
Cancel
Save