Browse Source

Restore non HTTPS TLS test

master
aeris 3 years ago
parent
commit
84a72139a6
  1. 19
      app/controllers/check_controller.rb
  2. 2
      app/controllers/https_controller.rb
  3. 4
      app/controllers/smtp_controller.rb
  4. 29
      app/controllers/xmpp_controller.rb
  5. 6
      app/helpers/ssh_helper.rb
  6. 16
      app/models/analysis.rb
  7. 16
      app/workers/check_worker.rb
  8. 16
      app/workers/https_worker.rb
  9. 2
      app/workers/smtp_worker.rb
  10. 10
      app/workers/xmpp_worker.rb
  11. 15
      db/migrate/20191201192510_convert_to_args.rb
  12. 6
      db/schema.rb

19
app/controllers/check_controller.rb

@ -29,12 +29,12 @@ class CheckController < ApplicationController
end
protected
def default_port
def default_args
end
def enqueue_host
@analysis = Analysis.pending! self.type, @host, (@port || self.default_port)
self.worker.perform_async @analysis.host, @analysis.port
@analysis = Analysis.pending! self.type, @host, @args
self.worker.perform_async @analysis.host, *@analysis.args
end
def check_host
@ -45,22 +45,15 @@ class CheckController < ApplicationController
request.format = :json
end
@host, @port = @id.split ':'
@host, @args = @id.split ':'
@host = SimpleIDN.to_ascii @host.downcase
if /[^a-zA-Z0-9.-]/ =~ @host
flash[:danger] = "Hôte #{@host} invalide"
redirect_to action: :index
return false
end
if @port
@port = @port.to_i
else
@port = self.default_port
end
@args ||= default_args
@analysis = Analysis[self.type, @host, @port]
# file = File.join Rails.root, 'config/host.yml'
# File.write file, YAML.dump(@result)
# @result = YAML.load File.read file
@analysis = Analysis[self.type, @host, @args]
end
end

2
app/controllers/https_controller.rb

@ -12,7 +12,7 @@ class HttpsController < CheckController
'HTTPS'
end
def default_port
def default_args
443
end
end

4
app/controllers/smtp_controller.rb

@ -11,8 +11,4 @@ class SmtpController < CheckController
def tls_type
'STARTTLS'
end
def default_port
25
end
end

29
app/controllers/xmpp_controller.rb

@ -1,14 +1,19 @@
class XmppController < CheckController
protected
def type
:xmpp
end
def worker
XMPPWorker
end
def tls_type
'STARTTLS'
end
protected
def type
:xmpp
end
def worker
XMPPWorker
end
def tls_type
'STARTTLS'
end
def default_args
:c2s
end
end

6
app/helpers/ssh_helper.rb

@ -22,7 +22,7 @@ module SshHelper
end
private
def label(name, color)
"<span class=\"label label-#{color}\">&nbsp;</span>&nbsp;#{name}".html_safe
end
#def label(name, color)
# "<span class=\"label label-#{color}\">&nbsp;</span>&nbsp;#{name}".html_safe
#end
end

16
app/models/analysis.rb

@ -3,13 +3,13 @@ class Analysis < ApplicationRecord
validates :service, presence: true
validates :host, presence: true
def self.[](service, host, port)
key = self.key service, host, port
def self.[](service, host, args)
key = self.key service, host, args
self.find_by key
end
def self.pending!(service, host, port)
key = self.key service, host, port
def self.pending!(service, host, args)
key = self.key service, host, args
analysis = self.find_or_create_by! key
analysis.pending!
end
@ -19,8 +19,8 @@ class Analysis < ApplicationRecord
self
end
def self.post!(service, host, port, result)
analysis = self[service, host, port]
def self.post!(service, host, args, result)
analysis = self[service, host, args]
analysis.post! result
end
@ -30,7 +30,7 @@ class Analysis < ApplicationRecord
private
def self.key(service, host, port)
{ service: service, host: host, port: port }
def self.key(service, host, args)
{ service: service, host: host, args: args }
end
end

16
app/workers/check_worker.rb

@ -1,11 +1,11 @@
class CheckWorker
include Sidekiq::Worker
sidekiq_options retry: false
include Sidekiq::Worker
sidekiq_options retry: false
def perform(host, port)
# analysis = Analysis.pending self.type, host, port
host = SimpleIDN.to_ascii host.downcase
result = self.analyze host, port
Analysis.post! self.type, host, port, result
end
def perform(host, *args)
host = SimpleIDN.to_ascii host.downcase
result = self.analyze host, *args
args = nil if args.empty?
Analysis.post! self.type, host, args, result
end
end

16
app/workers/https_worker.rb

@ -1,12 +1,12 @@
class HTTPSWorker < CheckWorker
sidekiq_options retry: false
sidekiq_options retry: false
protected
def analyze(host, port=443)
CryptCheck::Tls::Https.analyze host, port
end
protected
def analyze(host, port)
CryptCheck::Tls::Https.analyze host, port
end
def type
:https
end
def type
:https
end
end

2
app/workers/smtp_worker.rb

@ -3,7 +3,7 @@ class SMTPWorker < CheckWorker
protected
def analyze(host)
CryptCheck::Tls::Smtp.analyze_domain host
CryptCheck::Tls::Smtp.analyze host
end
def type

10
app/workers/xmpp_worker.rb

@ -2,17 +2,11 @@ class XMPPWorker < CheckWorker
sidekiq_options retry: false
protected
def analyze(host)
CryptCheck::Tls::Xmpp.analyze_domain host
def analyze(host, type)
CryptCheck::Tls::Xmpp.analyze host, type
end
def type
:xmpp
end
def to_json(server)
result = super
result[:required] = server.required?
result
end
end

15
db/migrate/20191201192510_convert_to_args.rb

@ -0,0 +1,15 @@
class ConvertToArgs < ActiveRecord::Migration[5.2]
def self.up
add_column :analyses, :args, :jsonb, after: :host
Analysis.all.each { |a| a.update! args: { port: a.port }.compact }
add_index :analyses, %i[service host args], unique: true
remove_column :analyses, :port
end
def self.down
add_column :analyses, :port, :integer
Analysis.all.each { |a| a.update! port: a.args }
remove_column :analyses, :args
add_index :analyses, %i[service host port], unique: true
end
end

6
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_09_13_211227) do
ActiveRecord::Schema.define(version: 2019_12_01_192510) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
@ -19,12 +19,12 @@ ActiveRecord::Schema.define(version: 2019_09_13_211227) do
create_table "analyses", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "service", null: false
t.string "host", null: false
t.integer "port"
t.boolean "pending", default: true, null: false
t.jsonb "result"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["service", "host", "port"], name: "index_analyses_on_service_and_host_and_port", unique: true
t.jsonb "args"
t.index ["service", "host", "args"], name: "index_analyses_on_service_and_host_and_args", unique: true
end
end

Loading…
Cancel
Save