nexpose-functions 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,124 @@
1
+ # Nexpose functions
2
+
3
+ require "nexpose"
4
+
5
+ # Log into a Nexpose console. Returns a connection object.
6
+ #
7
+ # @param consoleIP [String] the IP address of the Nexpose console.
8
+ # @return [Connection] the connection object.
9
+ def NexposeLogin(consoleIP)
10
+ require "io/console"
11
+
12
+ print "Username: "
13
+ username = $stdin.gets.chomp
14
+ print "Password: "
15
+ password = STDIN.noecho(&:gets).chomp
16
+ puts ""
17
+
18
+ # Create connection and login.
19
+ nsc = Nexpose::Connection.new(consoleIP, username, password)
20
+ nsc.login
21
+ return nsc
22
+ end
23
+
24
+ class Nexpose::Connection
25
+ # Check if an input is a valid engine id.
26
+ #
27
+ # @param engID [Fixnum] an id to check against the list of valid engine ids.
28
+ # @return [Boolean] true if engID is valid.
29
+ def validate_engineid(engID)
30
+ # Create array of engine ids for validation
31
+ engine_ids = []
32
+ for eng in self.list_engines do
33
+ engine_ids << eng.id
34
+ end
35
+
36
+ return engine_ids.include?(engID.to_i)
37
+ end
38
+
39
+ # Get the ID for a site name.
40
+ #
41
+ # @param sitename [String] the site name to look up.
42
+ # @return [Fixnum] the id for the site name.
43
+ def sitename_to_id(sitename)
44
+ self.list_sites.each { |site|
45
+ if site.name == sitename
46
+ return site.id
47
+ end
48
+ }
49
+ end
50
+
51
+ # Get the name for a site ID.
52
+ #
53
+ # @param siteid [Fixnum] a site id to look up.
54
+ # @return [String] the name of the site.
55
+ def siteid_to_name(siteid)
56
+ self.list_sites.each { |site|
57
+ if site.id == siteid
58
+ return site.name
59
+ end
60
+ }
61
+ end
62
+
63
+ # Get a Hash object containing pairs of site ids/names where the Hash key is the site id.
64
+ #
65
+ # @return [Hash] object with site ids as the keys and site names as the values.
66
+ def getSitesInfobyId()
67
+ sitesinfo = {}
68
+ self.list_sites.each { |site|
69
+ sitesinfo[site.id] = site.name
70
+ }
71
+ return sitesinfo
72
+ end
73
+
74
+ # Get a Hash object containing pairs of site names/ids where the Hash key is the site name.
75
+ #
76
+ # @return [Hash] object with site names as the keys and site ids as the values.
77
+ def getSitesInfobyName()
78
+ sitesinfo = {}
79
+ self.list_sites.each { |site|
80
+ sitesinfo[site.name] = sites.id
81
+ }
82
+ end
83
+
84
+ # Get an Asset object for the specified host IP.
85
+ #
86
+ # @param host [String] the hostname to get an Asset object for.
87
+ # @return [Asset] the Asset object for the host.
88
+ def getAsset(host)
89
+ return self.filter(Nexpose::Search::Field::ASSET, Nexpose::Search::Operator::IS, host)
90
+ end
91
+
92
+ # Get an array of Asset objects for hosts that have not been scanned in 'X' days.
93
+ #
94
+ # @param days [Fixnum] the number of days back to check for unscanned hosts.
95
+ # @return [Array[Asset]] array of Asset objects for the hosts.
96
+ def notScannedSince(days)
97
+ return self.filter(Nexpose::Search::Field::SCAN_DATE, Nexpose::Search::Operator::EARLIER_THAN, days.to_i)
98
+ end
99
+ end
100
+
101
+ class Nexpose::Site
102
+
103
+ # Load asset hostnames from a CSV file.
104
+ #
105
+ # @param nsc [Connection] an active connection to a Nexpose console.
106
+ # @param csvfile [String] path to a CSV file to load hostnames from. (The first column will be used.)
107
+ def load_csv_hostnames(nsc, csvfile)
108
+ puts "Loading site..."
109
+ @site = Site.load(@nsc, self.id)
110
+
111
+ puts "Building hostname/asset list..."
112
+ @hostnames = []
113
+ CSV.foreach(@csvfile) do |line|
114
+ @hostnames << HostName.new(line[0])
115
+ end
116
+
117
+ puts "Saving site assets..."
118
+ @site.assets = @hostnames
119
+ @site.save(@nsc)
120
+ puts "Done."
121
+ puts "Site #{self.id} now has #{@hostnames.length} assets."
122
+ end
123
+
124
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nexpose-functions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Red5d
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Additional useful functions for use with the Nexpose API.
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - doc/Nexpose/Connection.html
20
+ - doc/Nexpose/Site.html
21
+ - doc/_index.html
22
+ - doc/class_list.html
23
+ - doc/css/common.css
24
+ - doc/css/full_list.css
25
+ - doc/css/style.css
26
+ - doc/file_list.html
27
+ - doc/frames.html
28
+ - doc/index.html
29
+ - doc/js/app.js
30
+ - doc/js/full_list.js
31
+ - doc/js/jquery.js
32
+ - doc/method_list.html
33
+ - doc/top-level-namespace.html
34
+ - lib/nexpose-functions.rb
35
+ homepage: http://rubygems.org/gems/nexpose-functions
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.4.1
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Additional Nexpose API functions.
59
+ test_files: []
60
+ has_rdoc: