Browse Source

Refactor runner

master
Nicolas Vinot 4 years ago
parent
commit
a0a2dc8813
5 changed files with 29 additions and 22 deletions
  1. 2
    1
      Gemfile
  2. 22
    4
      lib/sslcheck.rb
  3. 2
    3
      sslcheck
  4. 1
    1
      sslcheck-alexa
  5. 2
    13
      sslcheck-all

+ 2
- 1
Gemfile View File

@@ -2,7 +2,8 @@ source 'https://rubygems.org'
2 2
 
3 3
 gem 'httparty'
4 4
 gem 'nokogiri'
5
-gem 'net-sftp'
5
+gem 'net-ssh', '>= 2.9.2.beta'
6
+gem 'net-scp'
6 7
 gem 'tcp_timeout'
7 8
 gem 'parallel'
8 9
 gem 'ruby-progressbar'

+ 22
- 4
lib/sslcheck.rb View File

@@ -2,6 +2,7 @@ require 'erb'
2 2
 require 'logging'
3 3
 require 'parallel'
4 4
 require 'thread'
5
+require 'yaml'
5 6
 
6 7
 module SSLCheck
7 8
 	module SSLLabs
@@ -10,10 +11,12 @@ module SSLCheck
10 11
 	autoload :Server, 'sslcheck/server'
11 12
 	autoload :Grade, 'sslcheck/grade'
12 13
 
14
+	PARALLEL_ANALYSIS = 20
15
+	SYN_TIMEOUT = 600
13 16
 	@@log = Logging.logger[SSLCheck]
14 17
 
15 18
 	def self.grade(hostname, port=443)
16
-		timeout 600 do
19
+		timeout SYN_TIMEOUT do
17 20
 			Grade.new Server.new hostname, port
18 21
 		end
19 22
 	rescue Exception => e
@@ -21,10 +24,11 @@ module SSLCheck
21 24
 		NoSslTlsGrade.new NoSslTlsServer.new hostname, port
22 25
 	end
23 26
 
24
-	def self.analyze(hosts, output)
27
+	def self.analyze(hosts, output, groups = nil)
25 28
 		results = {}
26 29
 		semaphore = Mutex.new
27
-		Parallel.each hosts, progress: 'Testing', in_threads: 10 do |description, host|
30
+		Parallel.each hosts, progress: 'Analysing', in_threads: PARALLEL_ANALYSIS,
31
+			finish: lambda { |item, _, _| puts item[1] } do |description, host|
28 32
 			result = SSLCheck.grade host.strip
29 33
 			semaphore.synchronize do
30 34
 				if results.include? description
@@ -35,6 +39,8 @@ module SSLCheck
35 39
 			end
36 40
 		end
37 41
 
42
+		results = Hash[groups.collect { |g| [g, results[g]] }] if groups
43
+
38 44
 		results.each do |d, _|
39 45
 			results[d].sort! do |a, b|
40 46
 				cmp = score(a) <=> score(b)
@@ -48,7 +54,19 @@ module SSLCheck
48 54
 			end
49 55
 		end
50 56
 
51
-		File.write "output/#{output}.html", ERB.new(File.read('output/sslcheck.erb')).result(binding)
57
+		File.write output, ERB.new(File.read('output/sslcheck.erb')).result(binding)
58
+	end
59
+
60
+	def self.analyze_from_file(file, output)
61
+		config = YAML.load_file file
62
+		hosts = []
63
+		groups = []
64
+		config.each do |c|
65
+			d, hs = c['description'], c['hostnames']
66
+			groups << d
67
+			hs.each { |host| hosts << [d, host] }
68
+		end
69
+		self.analyze hosts, output, groups
52 70
 	end
53 71
 
54 72
 	private

+ 2
- 3
sslcheck View File

@@ -1,11 +1,10 @@
1 1
 #!/usr/bin/env ruby
2
-ENV['LD_LIBRARY_PATH'] = '/home/aeris/Workspace/external/sslscan/openssl'
3
-require 'logging'
4 2
 $:.unshift 'lib'
3
+require 'logging'
5 4
 require 'sslcheck'
6 5
 
7 6
 Logging.logger.root.appenders = Logging.appenders.stdout
8 7
 Logging.logger.root.level = :warn
9 8
 
10
-p server = SSLCheck::Server.new(ARGV[0])
9
+server = SSLCheck::Server.new(ARGV[0], ARGV[1] || 443)
11 10
 p grade = SSLCheck::Grade.new(server)

+ 1
- 1
sslcheck-alexa View File

@@ -16,4 +16,4 @@ File.open('top-1m.csv', 'r') do |file|
16 16
 	end
17 17
 end
18 18
 
19
-SSLCheck.analyze hosts, 'alexa'
19
+SSLCheck.analyze hosts, 'output/alexa.html'

+ 2
- 13
sslcheck-all View File

@@ -1,16 +1,5 @@
1 1
 #!/usr/bin/env ruby
2
-require 'yaml'
3 2
 $:.unshift 'lib'
4 3
 require 'sslcheck'
5
-
6
-Logging.logger.root.appenders = Logging.appenders.stdout
7
-Logging.logger.root.level = :error
8
-
9
-config = YAML.load_file 'hosts.yml'
10
-hosts = []
11
-config.each do |c|
12
-	d, hs = c['description'], c['hostnames']
13
-	hs.each { |host| hosts << [d, host] }
14
-end
15
-
16
-SSLCheck.analyze hosts, 'results'
4
+name = ARGV[0] || 'index'
5
+SSLCheck.analyze_from_file "output/#{name}.yml", "output/#{name}.html"

Loading…
Cancel
Save