Skip to content
This repository has been archived by the owner on Sep 29, 2022. It is now read-only.

Commit

Permalink
Merge 47d55ea into 94ff17a
Browse files Browse the repository at this point in the history
  • Loading branch information
fwininger committed Dec 5, 2017
2 parents 94ff17a + 47d55ea commit b8fab40
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 111 deletions.
3 changes: 0 additions & 3 deletions .document

This file was deleted.

11 changes: 0 additions & 11 deletions .project

This file was deleted.

54 changes: 0 additions & 54 deletions .rubocop_todo.yml
Expand Up @@ -6,11 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 4
Lint/AmbiguousOperator:
Exclude:
- 'lib/ruby-nessus/cli.rb'

# Offense count: 1
Lint/DuplicateMethods:
Exclude:
Expand All @@ -21,22 +16,6 @@ Lint/RescueWithoutErrorClass:
Exclude:
- 'lib/ruby-nessus/cli.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'lib/ruby-nessus/cli.rb'

# Offense count: 10
Lint/UselessAssignment:
Exclude:
- 'Rakefile'
- 'lib/ruby-nessus/Version1/host.rb'
- 'lib/ruby-nessus/Version1/version1.rb'
- 'lib/ruby-nessus/Version2/event.rb'
- 'lib/ruby-nessus/Version2/host.rb'

# Offense count: 8
Metrics/AbcSize:
Max: 70
Expand Down Expand Up @@ -85,39 +64,6 @@ Naming/FileName:
- 'lib/ruby-nessus/ruby-nessus.rb'
- 'spec/ruby-nessus_spec.rb'

# Offense count: 7
# Cop supports --auto-correct.
Performance/RedundantBlockCall:
Exclude:
- 'lib/ruby-nessus/Version1/host.rb'
- 'lib/ruby-nessus/Version1/version1.rb'
- 'lib/ruby-nessus/Version2/host.rb'
- 'lib/ruby-nessus/Version2/version2.rb'
- 'lib/ruby-nessus/parse.rb'

# Offense count: 9
# Cop supports --auto-correct.
Performance/StringReplacement:
Exclude:
- 'lib/ruby-nessus/Version1/host.rb'
- 'lib/ruby-nessus/Version1/version1.rb'
- 'lib/ruby-nessus/Version2/host.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: braces, no_braces, context_dependent
Style/BracesAroundHashParameters:
Exclude:
- 'examples/example.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/ClassMethods:
Exclude:
- 'lib/ruby-nessus/Version1/port.rb'
- 'lib/ruby-nessus/cli.rb'

# Offense count: 8
Style/DateTime:
Exclude:
Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Expand Up @@ -12,11 +12,11 @@ rescue LoadError => e
end

begin
gem 'rspec', '~> 2.4'
gem 'rspec', '~> 3.7'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new
rescue LoadError => e
rescue LoadError
task :spec do
abort 'Please run `gem install rspec` to install RSpec.'
end
Expand All @@ -30,7 +30,7 @@ begin
require 'yard'

YARD::Rake::YardocTask.new
rescue LoadError => e
rescue LoadError
task :yard do
abort 'Please run `gem install yard` to install YARD.'
end
Expand Down
2 changes: 1 addition & 1 deletion examples/example.rb
Expand Up @@ -40,6 +40,6 @@ def print_info(host)

# From a string:
puts '+ Using an XML string:'
Nessus::Parse.new(nil, { xml: File.read('example_v1.nessus') }) do |scan|
Nessus::Parse.new(nil, xml: File.read('example_v1.nessus')) do |scan|
scan.each_host(&method(:print_info))
end
12 changes: 6 additions & 6 deletions lib/ruby-nessus/Version1/host.rb
Expand Up @@ -34,7 +34,7 @@ def scan_start_time
if @host.at('startTime').inner_text.blank?
false
else
@host_scan_time = DateTime.strptime(@host.at('startTime').inner_text, fmt = '%a %b %d %H:%M:%S %Y')
@host_scan_time = DateTime.strptime(@host.at('startTime').inner_text, '%a %b %d %H:%M:%S %Y')
end
end

Expand All @@ -47,7 +47,7 @@ def scan_stop_time
if @host.at('stopTime').inner_text.blank?
false
else
@host_scan_time = DateTime.strptime(@host.at('stopTime').inner_text, fmt = '%a %b %d %H:%M:%S %Y')
@host_scan_time = DateTime.strptime(@host.at('stopTime').inner_text, '%a %b %d %H:%M:%S %Y')
end
end

Expand Down Expand Up @@ -237,7 +237,7 @@ def event_count
# end
def each_event(&block)
@host.xpath('ReportItem').each do |event|
block.call(Event.new(event)) if block
yield(Event.new(event)) if block
end
end

Expand All @@ -252,9 +252,9 @@ def events

def get_runtime
if scan_start_time && scan_stop_time
h = (Time.parse(scan_stop_time.to_s).strftime('%H').to_i - Time.parse(scan_start_time.to_s).strftime('%H').to_i).to_s.gsub('-', '')
m = (Time.parse(scan_stop_time.to_s).strftime('%M').to_i - Time.parse(scan_start_time.to_s).strftime('%M').to_i).to_s.gsub('-', '')
s = (Time.parse(scan_stop_time.to_s).strftime('%S').to_i - Time.parse(scan_start_time.to_s).strftime('%S').to_i).to_s.gsub('-', '')
h = (Time.parse(scan_stop_time.to_s).strftime('%H').to_i - Time.parse(scan_start_time.to_s).strftime('%H').to_i).to_s.delete('-')
m = (Time.parse(scan_stop_time.to_s).strftime('%M').to_i - Time.parse(scan_start_time.to_s).strftime('%M').to_i).to_s.delete('-')
s = (Time.parse(scan_stop_time.to_s).strftime('%S').to_i - Time.parse(scan_start_time.to_s).strftime('%S').to_i).to_s.delete('-')
"#{h} hours #{m} minutes and #{s} seconds"
else
false
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-nessus/Version1/port.rb
Expand Up @@ -29,7 +29,7 @@ def initialize(service, number, protocol, raw_string)
# New Port Object
# @example
# Port.parse(port)
def Port.parse(str)
def self.parse(str)
@full_port = str
components = str.match(/^([^\(]+)\((\d+)\/([^\)]+)\)/)

Expand Down
30 changes: 15 additions & 15 deletions lib/ruby-nessus/Version1/version1.rb
Expand Up @@ -58,7 +58,7 @@ def title
#
def time
datetime = @xml.xpath('//NessusClientData//Report//ReportName').inner_text.split(' - ').first
@report_time ||= DateTime.strptime(datetime, fmt = '%y/%m/%d %I:%M:%S %p')
@report_time ||= DateTime.strptime(datetime, '%y/%m/%d %I:%M:%S %p')
end

#
Expand All @@ -71,7 +71,7 @@ def time
# scan.start_time #=> 'Fri Nov 11 23:36:54 1985'
#
def start_time
@start_time = DateTime.strptime(@xml.xpath('//NessusClientData//Report//StartTime').inner_text, fmt = '%a %b %d %H:%M:%S %Y')
@start_time = DateTime.strptime(@xml.xpath('//NessusClientData//Report//StartTime').inner_text, '%a %b %d %H:%M:%S %Y')
end

#
Expand All @@ -84,7 +84,7 @@ def start_time
# scan.stop_time #=> 'Mon Nov 11 23:36:54 1985'
#
def stop_time
@stop_time = DateTime.strptime(@xml.xpath('//NessusClientData//Report//StopTime').inner_text, fmt = '%a %b %d %H:%M:%S %Y')
@stop_time = DateTime.strptime(@xml.xpath('//NessusClientData//Report//StopTime').inner_text, '%a %b %d %H:%M:%S %Y')
end

#
Expand All @@ -97,9 +97,9 @@ def stop_time
# scan.runtime #=> '2 hours 5 minutes and 16 seconds'
#
def runtime
h = (Time.parse(stop_time.to_s).strftime('%H').to_i - Time.parse(start_time.to_s).strftime('%H').to_i).to_s.gsub('-', '')
m = (Time.parse(stop_time.to_s).strftime('%M').to_i - Time.parse(start_time.to_s).strftime('%M').to_i).to_s.gsub('-', '')
s = (Time.parse(stop_time.to_s).strftime('%S').to_i - Time.parse(start_time.to_s).strftime('%S').to_i).to_s.gsub('-', '')
h = (Time.parse(stop_time.to_s).strftime('%H').to_i - Time.parse(start_time.to_s).strftime('%H').to_i).to_s.delete('-')
m = (Time.parse(stop_time.to_s).strftime('%M').to_i - Time.parse(start_time.to_s).strftime('%M').to_i).to_s.delete('-')
s = (Time.parse(stop_time.to_s).strftime('%S').to_i - Time.parse(start_time.to_s).strftime('%S').to_i).to_s.delete('-')
"#{h} hours #{m} minutes and #{s} seconds"
end

Expand Down Expand Up @@ -201,7 +201,7 @@ def each_host(&block)
hosts = []
@xml.xpath('//ReportHost').each do |host|
hosts << host.at('HostName').inner_text if host.at('HostName').inner_text
block.call(Host.new(host)) if block
yield(Host.new(host)) if block
end
hosts
end
Expand Down Expand Up @@ -238,14 +238,14 @@ def host_count
# scan.unique_ports #=> 234
#
def unique_ports
unless @unique_ports
@unique_ports = []
@xml.xpath('//ReportItem//port').each do |port|
@unique_ports << port.inner_text
end
@unique_ports.uniq!
@unique_ports.sort!
return if @unique_ports

@unique_ports = []
@xml.xpath('//ReportItem//port').each do |port|
@unique_ports << port.inner_text
end
@unique_ports.uniq!
@unique_ports.sort!
end

#
Expand Down Expand Up @@ -361,7 +361,7 @@ def find_by_hostname(hostname, &block)
raise "Error: hostname can't be blank." if hostname.blank?
@xml.xpath('//ReportHost[HostName]').each do |host|
next unless host.inner_text.match(hostname)
block.call(Host.new(host)) if block
yield(Host.new(host)) if block
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-nessus/Version2/event.rb
Expand Up @@ -230,7 +230,7 @@ def see_also
#
def patch_publication_date
@patch_publication_date ||= if @event.at('patch_publication_date')
DateTime.strptime(@event.at('patch_publication_date').inner_text, fmt = '%Y/%m/%d')
DateTime.strptime(@event.at('patch_publication_date').inner_text, '%Y/%m/%d')
end
end

Expand Down
12 changes: 6 additions & 6 deletions lib/ruby-nessus/Version2/host.rb
Expand Up @@ -63,7 +63,7 @@ def ip
#
def start_time
if (start_time = @host.at('tag[name=HOST_START]'))
DateTime.strptime(start_time.inner_text, fmt = '%a %b %d %H:%M:%S %Y')
DateTime.strptime(start_time.inner_text, '%a %b %d %H:%M:%S %Y')
else
false
end
Expand All @@ -80,7 +80,7 @@ def start_time
#
def stop_time
if (stop_time = @host.at('tag[name=HOST_END]'))
DateTime.strptime(stop_time.inner_text, fmt = '%a %b %d %H:%M:%S %Y')
DateTime.strptime(stop_time.inner_text, '%a %b %d %H:%M:%S %Y')
else
false
end
Expand Down Expand Up @@ -343,7 +343,7 @@ def event_count
#
def each_event(&block)
@host.xpath('ReportItem').each do |event|
block.call(Event.new(event)) if block
yield(Event.new(event)) if block
end
end

Expand Down Expand Up @@ -532,9 +532,9 @@ def event_percentage_for(type, round_percentage = false)

def get_runtime
if stop_time && start_time
h = (Time.parse(stop_time.to_s).strftime('%H').to_i - Time.parse(start_time.to_s).strftime('%H').to_i).to_s.gsub('-', '')
m = (Time.parse(stop_time.to_s).strftime('%M').to_i - Time.parse(start_time.to_s).strftime('%M').to_i).to_s.gsub('-', '')
s = (Time.parse(stop_time.to_s).strftime('%S').to_i - Time.parse(start_time.to_s).strftime('%S').to_i).to_s.gsub('-', '')
h = (Time.parse(stop_time.to_s).strftime('%H').to_i - Time.parse(start_time.to_s).strftime('%H').to_i).to_s.delete('-')
m = (Time.parse(stop_time.to_s).strftime('%M').to_i - Time.parse(start_time.to_s).strftime('%M').to_i).to_s.delete('-')
s = (Time.parse(stop_time.to_s).strftime('%S').to_i - Time.parse(start_time.to_s).strftime('%S').to_i).to_s.delete('-')
"#{h} hours #{m} minutes and #{s} seconds"
else
false
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby-nessus/Version2/version2.rb
Expand Up @@ -97,7 +97,7 @@ def each_host(&block)
hosts = []
@xml.xpath('//ReportHost').each do |host|
hosts << host['name'] if host['name']
block.call(Host.new(host)) if block
yield(Host.new(host)) if block
end
hosts
end
Expand Down Expand Up @@ -328,7 +328,7 @@ def find_by_hostname(hostname, &block)
raise "Error: hostname can't be blank." if hostname.blank?
@xml.xpath('//ReportHost').each do |host|
next unless host['name'].match(hostname)
block.call(Host.new(host)) if block
yield(Host.new(host)) if block
end
end

Expand Down
14 changes: 7 additions & 7 deletions lib/ruby-nessus/cli.rb
Expand Up @@ -13,7 +13,7 @@ def initialize
@args = []
end

def CLI.run
def self.run
new.run(*ARGV)
end

Expand Down Expand Up @@ -95,16 +95,16 @@ def optparse(*args)
@file = file
end

opts.on('-h', '--help', 'This help summary page.') do |help|
opts.on('-h', '--help', 'This help summary page.') do |_help|
Log.it opts
Log.it
exit -1
exit(-1)
end

opts.on('-v', '--version', 'Recess Version.') do |version|
opts.on('-v', '--version', 'Recess Version.') do |_version|
Log.it RubyNessus::VERSION
Log.it
exit -1
exit(-1)
end

begin
Expand All @@ -113,13 +113,13 @@ def optparse(*args)
if @file.nil?
Log.it opts
Log.it
exit -1
exit(-1)
end
rescue => e
Log.error e.message
Log.it opts
Log.it
exit -1
exit(-1)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-nessus/parse.rb
Expand Up @@ -23,7 +23,7 @@ def initialize(file = nil, options = {}, &block)
raise 'Error: Supported .Nessus Version are 1 and 2.'
end

block.call(@xml_parser) if block
yield(@xml_parser) if block
end

# Retrive scan from file
Expand Down

0 comments on commit b8fab40

Please sign in to comment.