parent
11c86006b7
commit
02e6367d17
@ -0,0 +1,16 @@ |
||||
$ -> |
||||
ssh_submit = -> |
||||
host = $('#ssh_check_host').val() |
||||
port = $('#ssh_check_port').val() |
||||
port = 22 if port == '' |
||||
window.location.href = "<%= Rails.configuration.relative_url_root %>/ssh/#{host}:#{port}" |
||||
|
||||
$('#ssh_check_host').keypress (e) -> |
||||
ssh_submit() if e.which == 13 |
||||
return |
||||
$('#ssh_check_port').keypress (e) -> |
||||
ssh_submit() if e.which == 13 |
||||
return |
||||
$('#ssh_check_submit').click -> |
||||
ssh_submit() |
||||
return |
@ -0,0 +1,3 @@ |
||||
// Place all the styles related to the ssh controller here. |
||||
// They will automatically be included in application.css. |
||||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
@ -0,0 +1,43 @@ |
||||
class SshController < ApplicationController |
||||
before_action :check_host, except: %i(index) |
||||
|
||||
def check_host |
||||
@host, @port = params[:id].split ':' |
||||
@idn = SimpleIDN.to_ascii @host |
||||
if /[^a-zA-Z0-9.-]/.match @idn |
||||
flash[:danger] = "Hôte #{@host} invalide" |
||||
redirect_to :index |
||||
return false |
||||
end |
||||
@host = "#{@idn}:#{@port}" |
||||
@result = Datastore.host :ssh, @host |
||||
end |
||||
|
||||
def index |
||||
end |
||||
|
||||
def show |
||||
enqueue_host unless @result |
||||
return render :processing if @result.pending |
||||
return render :no_ssh if @result.no_ssh |
||||
end |
||||
|
||||
def refresh |
||||
unless @result.pending |
||||
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 |
||||
end |
||||
enqueue_host |
||||
end |
||||
redirect_to action: :show |
||||
end |
||||
|
||||
protected |
||||
def enqueue_host |
||||
Datastore.pending :ssh, @host |
||||
SSHWorker.perform_async @idn, @port |
||||
@result = OpenStruct.new pending: true, date: Time.now |
||||
end |
||||
end |
@ -0,0 +1,28 @@ |
||||
module SshHelper |
||||
COLORS = { green: :success, yellow: :warning, red: :danger, nil => :default } |
||||
|
||||
def kex_label(key) |
||||
label key, COLORS[CryptCheck::Ssh::Server::KEX[key]] |
||||
end |
||||
|
||||
def cipher_label(cipher) |
||||
label cipher, COLORS[CryptCheck::Ssh::Server::ENCRYPTION[cipher]] |
||||
end |
||||
|
||||
def hmac_label(hmac) |
||||
label hmac, COLORS[CryptCheck::Ssh::Server::HMAC[hmac]] |
||||
end |
||||
|
||||
def compression_label(compression) |
||||
label compression, COLORS[CryptCheck::Ssh::Server::COMPRESSION[compression]] |
||||
end |
||||
|
||||
def key_label(key) |
||||
label key, COLORS[CryptCheck::Ssh::Server::KEY[key]] |
||||
end |
||||
|
||||
private |
||||
def label(name, color) |
||||
"<span class=\"label label-#{color}\"> </span> #{name}".html_safe |
||||
end |
||||
end |
@ -0,0 +1,12 @@ |
||||
<div id="check" class="container"> |
||||
<div class="row"> |
||||
<div class="col-sm-8 col-sm-offset-2"> |
||||
<h1> |
||||
<%= @host %> ne supporte pas SSH |
||||
</h1> |
||||
<% if Time.now - @result.date >= Rails.configuration.refresh_delay %> |
||||
<%= link_to 'Rafraîchir', {action: :refresh}, class: %i(btn btn-default pull-right) %> |
||||
<% end %> |
||||
</div> |
||||
</div> |
||||
</div> |
@ -0,0 +1,67 @@ |
||||
<div class="container"> |
||||
<div class="row"> |
||||
<div class="col-sm-11"> |
||||
<h1> |
||||
[SSH] <%= @host %> <span class="small">(<%= l @result.date %>)</span> |
||||
</h1> |
||||
</div> |
||||
<% if Time.now - @result.date >= Rails.configuration.refresh_delay %> |
||||
<div class="col-sm-1"> |
||||
<%= link_to 'Rafraîchir', {action: :refresh}, class: %i(btn btn-default) %> |
||||
</div> |
||||
<% end %> |
||||
</div> |
||||
<br/> |
||||
<div class="row"> |
||||
<div class="col-sm-12"> |
||||
<table class="table table-bordered table-condensed table-striped"> |
||||
<tbody> |
||||
<tr> |
||||
<th>Échange de clef</th> |
||||
</tr> |
||||
<% @result.kex.each do |kex| %> |
||||
<tr> |
||||
<td><%= kex_label kex %></td> |
||||
</tr> |
||||
<% end %> |
||||
|
||||
<tr> |
||||
<th>Chiffrement</th> |
||||
</tr> |
||||
<% @result.encryption.each do |cipher| %> |
||||
<tr> |
||||
<td><%= cipher_label cipher %></td> |
||||
</tr> |
||||
<% end %> |
||||
|
||||
<tr> |
||||
<th>HMAC</th> |
||||
</tr> |
||||
<% @result.hmac.each do |hmac| %> |
||||
<tr> |
||||
<td><%= hmac_label hmac %></td> |
||||
</tr> |
||||
<% end %> |
||||
|
||||
<tr> |
||||
<th>Compression</th> |
||||
</tr> |
||||
<% @result.compression.each do |compression| %> |
||||
<tr> |
||||
<td><%= compression_label compression %></td> |
||||
</tr> |
||||
<% end %> |
||||
|
||||
<tr> |
||||
<th>Clefs</th> |
||||
</tr> |
||||
<% @result['key'].each do |key| %> |
||||
<tr> |
||||
<td><%= key_label key %></td> |
||||
</tr> |
||||
<% end %> |
||||
</tbody> |
||||
</table> |
||||
</div> |
||||
</div> |
||||
</div> |
@ -0,0 +1,24 @@ |
||||
require 'simpleidn' |
||||
require 'cryptcheck' |
||||
|
||||
class SSHWorker |
||||
include Sidekiq::Worker |
||||
sidekiq_options retry: false |
||||
|
||||
def perform(host, port) |
||||
idn = SimpleIDN.to_ascii host |
||||
result = begin |
||||
server = CryptCheck::Ssh::Server.new idn, port |
||||
{ |
||||
kex: server.kex, |
||||
encryption: server.encryption, |
||||
hmac: server.hmac, |
||||
compression: server.compression, |
||||
key: server.key |
||||
} |
||||
rescue CryptCheck::Ssh::Server::SshNotAvailableException |
||||
{ no_ssh: true } |
||||
end |
||||
Datastore.post :ssh, "#{host}:#{port}", result |
||||
end |
||||
end |
@ -0,0 +1,14 @@ |
||||
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 |
Loading…
Reference in new issue