Переглянути джерело

Restore non HTTPS TLS test

master
aeris 8 місяці тому
джерело
коміт
84a72139a6
12 змінених файлів з 72 додано та 69 видалено
  1. +6
    -13
      app/controllers/check_controller.rb
  2. +1
    -1
      app/controllers/https_controller.rb
  3. +0
    -4
      app/controllers/smtp_controller.rb
  4. +17
    -12
      app/controllers/xmpp_controller.rb
  5. +3
    -3
      app/helpers/ssh_helper.rb
  6. +8
    -8
      app/models/analysis.rb
  7. +8
    -8
      app/workers/check_worker.rb
  8. +8
    -8
      app/workers/https_worker.rb
  9. +1
    -1
      app/workers/smtp_worker.rb
  10. +2
    -8
      app/workers/xmpp_worker.rb
  11. +15
    -0
      db/migrate/20191201192510_convert_to_args.rb
  12. +3
    -3
      db/schema.rb

+ 6
- 13
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

+ 1
- 1
app/controllers/https_controller.rb Переглянути файл

@@ -12,7 +12,7 @@ class HttpsController < CheckController
'HTTPS'
end

def default_port
def default_args
443
end
end

+ 0
- 4
app/controllers/smtp_controller.rb Переглянути файл

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

def default_port
25
end
end

+ 17
- 12
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

+ 3
- 3
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

+ 8
- 8
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

+ 8
- 8
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

+ 8
- 8
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

+ 1
- 1
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


+ 2
- 8
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
- 0
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

+ 3
- 3
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

Завантаження…
Відмінити
Зберегти