Skip to content

Commit

Permalink
Statistics pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Norore authored and aeris committed Jul 31, 2022
1 parent e7bf963 commit c117131
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--require spec_helper
--format progress
--format html --out tmp/rspec.html
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ gem 'http_accept_language'
gem 'recursive-open-struct'
gem 'ruby-progressbar'
gem 'public_suffix'
gem 'amazing_print'

gem 'uglifier'
gem 'sass-rails'
Expand Down Expand Up @@ -46,7 +47,6 @@ end

group :development, :test do
gem 'pry-byebug'
gem 'amazing_print'
end

group :test do
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class StatsController < ApplicationController
end
69 changes: 69 additions & 0 deletions app/javascript/css/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ td.error {
$color-critical: #d9534f;
$color-error: #e4804e;
$color-warning: #f0ad4e;
$color-effort: #6c757d;
$color-good: #beb052;
$color-best: #8db457;
$color-great: #5cb85c;
Expand Down Expand Up @@ -195,3 +196,71 @@ table.scoring img {
max-width: 140px;
}
}

/** Navigation tabs */
.tab-content {
border: 1px solid $nav-pills-link-active-bg;
border-bottom-left-radius: .3rem;
border-bottom-right-radius: .3rem;
}

.nav-pills .nav-link {
border-radius: .3rem;
font-weight: bold;
}

.nav-pills .nav-link.active {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
font-weight: bolder;
}

/** Chart CSS */
.cumulative-datas {
position: relative;
display: flex;
flex-direction: row;
width: 100%;

&-content {
position: absolute;
height: 2rem;
}
}

.cumulative-data {
height: 2rem;
line-height: 2rem;
display: inline-block;
white-space: nowrap;
text-overflow: ellipsis;
margin-right: .1rem;
padding-left: .3rem;
}

/** Progress bar */
.progress {
box-shadow: 0 0 .1rem $dark;
height: 1.4rem;
}
.progress-critical {
background-color: $color-critical;
}
.progress-error {
background-color: $color-error;
}
.progress-warning {
background-color: $color-warning;
}
.progress-effort {
background-color: $color-effort;
}
.progress-good {
background-color: $color-good;
}
.progress-best {
background-color: $color-best;
}
.progress-great {
background-color: $color-great;
}
1 change: 1 addition & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import 'css/application'
import 'bootstrap/js/dist/tab'
167 changes: 167 additions & 0 deletions app/views/stats/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<% colors = {
"A+" => 'great',
"good" => 'great',
"A" => 'great',
"B+" => 'best',
"B" => 'best',
"C+" => 'good',
"C" => 'good',
"D" => 'effort',
"E" => 'warning',
"F" => 'error',
"G" => 'critical',
"bad" => 'critical',
"ssl" => 'critical',
"tls" => 'error',
"tls1_2" => 'effort',
"tls1_2_only" => 'great'
} %>

<ul class="nav nav-pills nav-fill" id="pills-tab" role="Navigation stats list">
<% %i[https smtp tls xmpp].each do |service| %>
<li class="nav-item" role="presentation">
<button class="nav-link<%= " active btn-dark" if service.to_s == "https" %>"
id="nav-<%= service %>-pill" data-bs-toggle="pill"
data-bs-target="#nav-<%= service %>" type="button" role="Button to show <%= service %> stats" aria-controls="nav-<%= service %>" aria-selected="true">
<%= service.to_s.upcase %>
</button>
</li>
<% end %>
</ul>

<div class="tab-content p-2 mb-4" id="nav-pillsContent">
<% %i[https smtp tls xmpp].each do |service| %>
<div class="tab-pane fade show <%= "active" if service.to_s == "https" %>"
id="nav-<%= service %>" role="<%= service.to_s %>> stats"
aria-labelledby="nav-<%= service %>-pill">
<h2>Grades for service <%= service.to_s.upcase %></h2>

<%
grades = Stat["grades_for_#{service}"]
total = grades.data.collect { _2 }.sum
%>

<p>Over <%= total %> URL tested with a grade.</p>

<table class="table table-bordered table-striped">
<thead class="bg-dark text-light">
<tr>
<th>Grade</th>
<th>Count</th>
<th></th>
</tr>
</thead>
<tbody>
<% sorted_grades = grades.data.keys.sort &CryptCheck::Grade.method(:compare)
sorted_grades.each do |grade|
unless %w(T V).include?(grade)
count = grades.data[grade].to_i
percent = (count.to_f / total.to_f) * 100.0
color = CryptCheck::Grade::GRADE_STATUS.fetch grade.to_sym %>
<tr>
<td class="col-4"><%= grade.capitalize %></td>
<td class="col-4"><%= count %>
(<%= percent.round %>%)
</td>
<td class="col-4">
<div class="progress bg-light">
<div class="progress-bar progress-<%= color %> border-dark"
style="width: <%= percent.round %>%" role="progressbar"
aria-valuenow="<%= percent.round %>" aria-valuemin="0"
aria-valuemax="100"></div>
</div>
</td>
</tr>
<% end
end %>
</tbody>
</table>

<h2>Ciphers for service <%= service.to_s.upcase %></h2>

<%
name = "ciphers_for_#{service}"
ciphers = Stat[name]
total = ciphers.data.collect { _2 }.sum
%>
<p>Over <%= total %> URL tested with a cipher.</p>

<table class="table table-bordered table-striped">
<thead class="bg-dark text-light">
<tr>
<%= content_tag :th, t(:'.ciphers.title') %>
<th>Count</th>
<th></th>
</tr>
</thead>
<tbody>
<%
ciphers = ciphers.data
%w[good bad].each do |grade|
count = ciphers.fetch grade
percent = (count.to_f / total.to_f) * 100.0
color = colors[grade]
%>
<tr>
<td class="col-4"><%= t ".ciphers.#{grade}" %></td>
<td class="col-4"><%= count %> (<%= percent.round %>
%)
</td>
<td class="col-4">
<div class="progress bg-light">
<div class="progress-bar progress-<%= color %>"
style="width: <%= percent.round %>%" role="progressbar"
aria-valuenow="<%= percent.round %>" aria-valuemin="0"
aria-valuemax="100"></div>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>

<h2>TLS for service <%= service.to_s.upcase %></h2>

<%
name = "tls_for_#{service}"
tls = Stat[name]
total = tls.data.collect { _2 }.sum
%>
<p>Over <%= total %> URL tested with TLS.</p>

<table class="table table-bordered table-striped">
<thead class="bg-dark text-light">
<tr>
<%= content_tag :th, t(:'.tls.title') %>
<th>Count</th>
<th></th>
</tr>
</thead>
<tbody>
<%
tls = tls.data
%w[tls1_2_only tls1_2 tls ssl].each do |grade|
count = tls.fetch grade
percent = (count.to_f / total.to_f) * 100.0
color = colors[grade]
%>
<tr>
<td class="col-4"><%= t ".tls.#{grade}" %></td>
<td class="col-4"><%= count %> (<%= percent.round %>
%)
</td>
<td class="col-4">
<div class="progress bg-light">
<div class="progress-bar progress-<%= color %>"
style="width: <%= percent.round %>%" role="progressbar"
aria-valuenow="<%= percent.round %>" aria-valuemin="0"
aria-valuemax="100"></div>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% end %>
</div>
29 changes: 29 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
Loading

0 comments on commit c117131

Please sign in to comment.