From 1043ad3e293493838b46a0377f46e764c230f89c Mon Sep 17 00:00:00 2001 From: Aeris Date: Thu, 10 Sep 2015 00:31:01 +0200 Subject: [PATCH] Generic TLS checker --- .gitignore | 16 +++++---- app/assets/javascripts/tls.coffee.erb | 18 ++++++++++ app/assets/stylesheets/application.scss | 6 ++++ app/assets/stylesheets/site.scss | 3 -- app/assets/stylesheets/smtp.scss | 3 -- app/assets/stylesheets/ssh.scss | 3 -- app/assets/stylesheets/tls.scss | 0 app/controllers/check_controller.rb | 26 ++++++++------ app/controllers/site_controller.rb | 3 -- app/controllers/ssh_controller.rb | 45 +++++------------------- app/controllers/tls_controller.rb | 14 ++++++++ app/helpers/tls_helper.rb | 2 ++ app/views/application/_headers.erb | 1 + app/views/{site => https}/index.html.erb | 0 app/views/ssh/no_ssh.html.erb | 12 ------- app/views/ssh/processing.html.erb | 20 ----------- app/views/tls/index.html.erb | 18 ++++++++++ app/workers/check_worker.rb | 8 ++--- app/workers/https_worker.rb | 7 ++-- app/workers/smtp_worker.rb | 7 ++-- app/workers/ssh_worker.rb | 4 +-- app/workers/tls_worker.rb | 15 ++++++++ app/workers/xmpp_worker.rb | 7 ++-- config/routes.rb | 16 ++++++--- test/controllers/tls_controller_test.rb | 19 ++++++++++ 25 files changed, 157 insertions(+), 116 deletions(-) create mode 100644 app/assets/javascripts/tls.coffee.erb create mode 100644 app/assets/stylesheets/tls.scss create mode 100644 app/controllers/tls_controller.rb create mode 100644 app/helpers/tls_helper.rb rename app/views/{site => https}/index.html.erb (100%) delete mode 100644 app/views/ssh/no_ssh.html.erb delete mode 100644 app/views/ssh/processing.html.erb create mode 100644 app/views/tls/index.html.erb create mode 100644 app/workers/tls_worker.rb create mode 100644 test/controllers/tls_controller_test.rb diff --git a/.gitignore b/.gitignore index acaa469..33ccb4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,14 @@ -/.bundle/ +.bundle/ +.generators +.rakeTasks +*.iml +Gemfile.lock + /db/*.sqlite3 /db/*.sqlite3-journal /log/* !/log/.keep -/tmp +/tmp/ /public/assets/ -*.iml -Gemfile.lock -.generators -.rakeTasks - +/deploy.sh +/.excluded diff --git a/app/assets/javascripts/tls.coffee.erb b/app/assets/javascripts/tls.coffee.erb new file mode 100644 index 0000000..cc6f575 --- /dev/null +++ b/app/assets/javascripts/tls.coffee.erb @@ -0,0 +1,18 @@ +$ -> + tls_submit = -> + host = $('#tls_check_host').val() + port = $('#tls_check_port').val() + if port == '' + alert 'Veuillez saisir un port' + return + window.location.href = "<%= Rails.configuration.relative_url_root %>/tls/#{host}:#{port}" + + $('#tls_check_host').keypress (e) -> + tls_submit() if e.which == 13 + return + $('#tls_check_port').keypress (e) -> + tls_submit() if e.which == 13 + return + $('#tls_check_submit').click -> + tls_submit() + return diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 8d94831..8f807f2 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -44,3 +44,9 @@ body { .progress { margin: 0; } + +#check, +#ssh_check, +#tls_check { + margin-top: 100px; +} diff --git a/app/assets/stylesheets/site.scss b/app/assets/stylesheets/site.scss index 1d8795d..e69de29 100644 --- a/app/assets/stylesheets/site.scss +++ b/app/assets/stylesheets/site.scss @@ -1,3 +0,0 @@ -#check { - margin-top: 100px; -} diff --git a/app/assets/stylesheets/smtp.scss b/app/assets/stylesheets/smtp.scss index b32f95d..e69de29 100644 --- a/app/assets/stylesheets/smtp.scss +++ b/app/assets/stylesheets/smtp.scss @@ -1,3 +0,0 @@ -// Place all the styles related to the Smtp controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/ssh.scss b/app/assets/stylesheets/ssh.scss index 1a72257..e69de29 100644 --- a/app/assets/stylesheets/ssh.scss +++ b/app/assets/stylesheets/ssh.scss @@ -1,3 +0,0 @@ -// 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/ diff --git a/app/assets/stylesheets/tls.scss b/app/assets/stylesheets/tls.scss new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/check_controller.rb b/app/controllers/check_controller.rb index 8ab3698..61a7ec5 100644 --- a/app/controllers/check_controller.rb +++ b/app/controllers/check_controller.rb @@ -1,16 +1,8 @@ class CheckController < ApplicationController - before_action :check_host + before_action :check_host, except: %i(index) helper_method :tls_type, :type - def check_host - @host = params[:id] - @idn = SimpleIDN.to_ascii @host - if /[^a-zA-Z0-9.-]/.match @idn - flash[:danger] = "Hôte #{@host} invalide" - redirect_to :root - return false - end - @result = Datastore.host self.type, @idn + def index end def show @@ -34,7 +26,19 @@ class CheckController < ApplicationController protected def enqueue_host Datastore.pending self.type, @host - self.worker.perform_async @idn + self.worker.perform_async *(@port ? [@idn, @port] : [@idn]) @result = OpenStruct.new pending: true , date: Time.now end + + 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 action: :index + return false + end + @host = "#{@idn}:#{@port}" if @port + @result = Datastore.host self.type, @host + end end diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index 4b0a771..a119eb4 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -1,7 +1,4 @@ class SiteController < ApplicationController - def index - end - def ciphers end end diff --git a/app/controllers/ssh_controller.rb b/app/controllers/ssh_controller.rb index 2290c4c..c97a18e 100644 --- a/app/controllers/ssh_controller.rb +++ b/app/controllers/ssh_controller.rb @@ -1,43 +1,14 @@ -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 +class SshController < CheckController + protected + def type + :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 action: :show, id: @host - end - enqueue_host - end - redirect_to action: :show + def worker + SSHWorker end - protected - def enqueue_host - Datastore.pending :ssh, @host - SSHWorker.perform_async @idn, @port - @result = OpenStruct.new pending: true, date: Time.now + def tls_type + 'SSH' end end diff --git a/app/controllers/tls_controller.rb b/app/controllers/tls_controller.rb new file mode 100644 index 0000000..3c07312 --- /dev/null +++ b/app/controllers/tls_controller.rb @@ -0,0 +1,14 @@ +class TlsController < CheckController + protected + def type + :tls + end + + def worker + TLSWorker + end + + def tls_type + 'TLS' + end +end diff --git a/app/helpers/tls_helper.rb b/app/helpers/tls_helper.rb new file mode 100644 index 0000000..b7fed60 --- /dev/null +++ b/app/helpers/tls_helper.rb @@ -0,0 +1,2 @@ +module TlsHelper +end diff --git a/app/views/application/_headers.erb b/app/views/application/_headers.erb index de4661f..5fe40c0 100644 --- a/app/views/application/_headers.erb +++ b/app/views/application/_headers.erb @@ -6,6 +6,7 @@