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

Commit

Permalink
Add gem update warnings/status
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Claudius committed Sep 20, 2016
1 parent 779ce9b commit c6367b1
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bin/ssh_scan
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ unless File.exists?(options[:policy])
exit 1
end

# Check to see if we're running the latest released version
update = SSHScan::Update.new
if update.newer_gem_available?
options[:logger].warn("You're NOT using the latest version of ssh_scan, try 'gem update ssh_scan' to get the latest")
else
options[:logger].info("You're using the latest version of ssh_scan #{SSHScan::VERSION}")
end

options[:policy_file] = SSHScan::Policy.from_file(options[:policy])

# Perform scan and get results
Expand Down
1 change: 1 addition & 0 deletions lib/ssh_scan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require 'ssh_scan/protocol'
require 'ssh_scan/scan_engine'
require 'ssh_scan/target_parser'
require 'ssh_scan/update'

#Monkey Patches
require 'string_ext'
64 changes: 64 additions & 0 deletions lib/ssh_scan/update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require 'ssh_scan/os'
require 'ssh_scan/ssh_lib'
require 'ssh_scan/version'
require 'net/http'

module SSHScan
class Update
def next_patch_version(version = SSHScan::VERSION)
major, minor, patch = version.split(".")
patch_num = patch.to_i
patch_num += 1

return [major, minor, patch_num.to_s].join(".")
end

def next_minor_version(version = SSHScan::VERSION)
major, minor, patch = version.split(".")
minor_num = minor.to_i
minor_num += 1

return [major, minor_num.to_s, "0"].join(".")
end

def next_major_version(version = SSHScan::VERSION)
major, minor, patch = version.split(".")
major_num = major.to_i
major_num += 1

return [major_num.to_s, "0", "0"].join(".")
end

def gem_exists?(version = SSHScan::VERSION)
uri = URI("https://rubygems.org/gems/ssh_scan/versions/#{version}")

begin
res = Net::HTTP.get_response(uri)
rescue
return false
end

if res.code != "200"
return false
else
return true
end
end

def newer_gem_available?(version = SSHScan::VERSION)
if gem_exists?(next_patch_version(version))
return true
end

if gem_exists?(next_minor_version(version))
return true
end

if gem_exists?(next_major_version(version))
return true
end

return false
end
end
end

0 comments on commit c6367b1

Please sign in to comment.