Class: Nexpose::Site
- Inherits:
-
Object
- Object
- Nexpose::Site
- Defined in:
- lib/nexpose.rb
Overview
Description
Object that represents a site, including the site configuration, scan history, and device listing.
Example
# Create a new Nexpose Connection on the default port and Login
nsc = Connection.new("10.1.40.10","nxadmin","password")
nsc.login()
# Get an Existing Site
site_existing = Site.new(nsc,184)
# Create a New Site, add some hosts, and save it to the NSC
site = Site.new(nsc)
site.setSiteConfig("New Site", "New Site Created in the API")
# Add the hosts
site.site_config.addHost(HostName.new("localhost"))
site.site_config.addHost(IPRange.new("192.168.7.1","192.168.7.255"))
site.site_config.addHost(IPRange.new("10.1.20.30"))
status = site.saveSite()
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
The NSC Connection associated with this object.
-
#error ⇒ Object
readonly
true if an error condition exists; false otherwise.
-
#error_msg ⇒ Object
readonly
Error message string.
-
#request_xml ⇒ Object
readonly
The last XML request sent by this object.
-
#response_xml ⇒ Object
readonly
The last XML response received by this object.
-
#site_config ⇒ Object
readonly
The configuration of this site SiteConfig Object.
-
#site_device_listing ⇒ Object
readonly
The device listing for this site SiteDeviceListing Object.
-
#site_id ⇒ Object
readonly
The Site ID site_id = -1 means create a new site.
-
#site_scan_history ⇒ Object
readonly
The scan history of this site SiteScanHistory Object.
-
#site_summary ⇒ Object
readonly
A summary overview of this site SiteSummary Object.
Instance Method Summary collapse
- #deleteSite ⇒ Object
- #getSiteXML ⇒ Object
-
#initialize(connection, site_id = -1)) ⇒ Site
constructor
A new instance of Site.
- #printSite ⇒ Object
-
#saveSite ⇒ Object
Saves this site in the NSC.
-
#scanSite ⇒ Object
Initiates a scan of this site.
-
#setSiteConfig(site_name, description, riskfactor = 1) ⇒ Object
Creates a new site configuration.
-
#setSiteSummary(site_name, description, riskfactor = 1) ⇒ Object
Creates a new site summary.
Constructor Details
#initialize(connection, site_id = -1)) ⇒ Site
Returns a new instance of Site.
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 |
# File 'lib/nexpose.rb', line 1089 def initialize(connection, site_id = -1) @error = false @connection = connection @site_id = site_id # If site_id > 0 then get SiteConfig if (@site_id.to_i > 0) # Create new SiteConfig object @site_config = SiteConfig.new() # Populate SiteConfig Obect with Data from the NSC @site_config.getSiteConfig(@connection,@site_id) @site_summary = SiteSummary.new(@site_id, @site_config.site_name, @site_config.description, @site_config.riskfactor) @site_scan_history = SiteScanHistory.new(@connection,@site_id) @site_device_listing = SiteDeviceListing.new(@connection,@site_id) else # Just in case user enters a number > -1 or = 0 @site_id = -1 @site_config = SiteConfig.new() setSiteConfig("New Site " + rand(999999999999).to_s,"") @site_summary = nil end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
The NSC Connection associated with this object
1072 1073 1074 |
# File 'lib/nexpose.rb', line 1072 def connection @connection end |
#error ⇒ Object (readonly)
true if an error condition exists; false otherwise
1064 1065 1066 |
# File 'lib/nexpose.rb', line 1064 def error @error end |
#error_msg ⇒ Object (readonly)
Error message string
1066 1067 1068 |
# File 'lib/nexpose.rb', line 1066 def error_msg @error_msg end |
#request_xml ⇒ Object (readonly)
The last XML request sent by this object
1068 1069 1070 |
# File 'lib/nexpose.rb', line 1068 def request_xml @request_xml end |
#response_xml ⇒ Object (readonly)
The last XML response received by this object
1070 1071 1072 |
# File 'lib/nexpose.rb', line 1070 def response_xml @response_xml end |
#site_config ⇒ Object (readonly)
The configuration of this site SiteConfig Object
1081 1082 1083 |
# File 'lib/nexpose.rb', line 1081 def site_config @site_config end |
#site_device_listing ⇒ Object (readonly)
The device listing for this site SiteDeviceListing Object
1084 1085 1086 |
# File 'lib/nexpose.rb', line 1084 def site_device_listing @site_device_listing end |
#site_id ⇒ Object (readonly)
The Site ID site_id = -1 means create a new site. The NSC will assign a new site_id on SiteSave.
1075 1076 1077 |
# File 'lib/nexpose.rb', line 1075 def site_id @site_id end |
#site_scan_history ⇒ Object (readonly)
The scan history of this site SiteScanHistory Object
1087 1088 1089 |
# File 'lib/nexpose.rb', line 1087 def site_scan_history @site_scan_history end |
#site_summary ⇒ Object (readonly)
A summary overview of this site SiteSummary Object
1078 1079 1080 |
# File 'lib/nexpose.rb', line 1078 def site_summary @site_summary end |
Instance Method Details
#deleteSite ⇒ Object
1164 1165 1166 1167 |
# File 'lib/nexpose.rb', line 1164 def deleteSite() r = @connection.execute('<SiteDeleteRequest session-id="' + @connection.session_id.to_s + '" site-id="' + @site_id + '"/>') r.success end |
#getSiteXML ⇒ Object
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 |
# File 'lib/nexpose.rb', line 1177 def getSiteXML() xml = '<Site id="' + "#{@site_config.site_id}" + '" name="' + "#{@site_config.site_name}" + '" description="' + "#{@site_config.description}" + '" riskfactor="' + "#{@site_config.riskfactor}" + '">' xml << ' <Hosts>' @site_config.hosts.each do |h| xml << h.to_xml if h.respond_to? :to_xml end xml << '</Hosts>' xml << '<Credentials>' @site_config.credentials.each do |c| xml << c.to_xml if c.respond_to? :to_xml end xml << ' </Credentials>' xml << ' <Alerting>' @site_config.alerts.each do |a| xml << a.to_xml if a.respond_to? :to_xml end xml << ' </Alerting>' xml << ' <ScanConfig configID="' + "#{@site_config.scanConfig.configID}" + '" name="' + "#{@site_config.scanConfig.name}" + '" templateID="' + "#{@site_config.scanConfig.templateID}" + '" configVersion="' + "#{@site_config.scanConfig.configVersion}" + '">' xml << ' <Schedules>' @site_config.scanConfig.schedules.each do |s| xml << ' <Schedule enabled="' + s.enabled + '" type="' + s.type + '" interval="' + s.interval + '" start="' + s.start + '"/>' end xml << ' </Schedules>' xml << ' <ScanTriggers>' @site_config.scanConfig.scanTriggers.each do |s| if (s.class.to_s == "Nexpose::AutoUpdate") xml << ' <autoUpdate enabled="' + s.enabled + '" incremental="' + s.incremental + '"/>' end end xml << ' </ScanTriggers>' xml << ' </ScanConfig>' xml << ' </Site>' return xml end |
#printSite ⇒ Object
1170 1171 1172 1173 1174 1175 |
# File 'lib/nexpose.rb', line 1170 def printSite() puts "Site ID: " + @site_summary.id puts "Site Name: " + @site_summary.site_name puts "Site Description: " + @site_summary.description puts "Site Risk Factor: " + @site_summary.riskfactor end |
#saveSite ⇒ Object
Saves this site in the NSC
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 |
# File 'lib/nexpose.rb', line 1151 def saveSite() r = @connection.execute('<SiteSaveRequest session-id="' + @connection.session_id + '">' + getSiteXML() + ' </SiteSaveRequest>') if (r.success) @site_id = r.attributes['site-id'] @site_config._set_site_id(@site_id) @site_config.scanConfig._set_configID(@site_id) @site_config.scanConfig._set_name(@site_id) return true else return false end end |
#scanSite ⇒ Object
Initiates a scan of this site. If successful returns scan_id and engine_id in an associative array. Returns false if scan is unsuccessful.
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 |
# File 'lib/nexpose.rb', line 1136 def scanSite() r = @connection.execute('<SiteScanRequest session-id="' + "#{@connection.session_id}" + '" site-id="' + "#{@site_id}" + '"/>') if(r.success) res = {} r.res.elements.each('//Scan/') do |s| res[:scan_id] = s.attributes['scan-id'] res[:engine_id] = s.attributes['engine-id'] end return res else return false end end |
#setSiteConfig(site_name, description, riskfactor = 1) ⇒ Object
Creates a new site configuration
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 |
# File 'lib/nexpose.rb', line 1123 def setSiteConfig(site_name, description, riskfactor = 1) setSiteSummary(site_name,description,riskfactor) @site_config = SiteConfig.new() @site_config._set_site_id(-1) @site_config._set_site_name(site_name) @site_config._set_description(description) @site_config._set_riskfactor(riskfactor) @site_config._set_scanConfig(ScanConfig.new(-1,"tmp","full-audit")) @site_config._set_connection(@connection) end |
#setSiteSummary(site_name, description, riskfactor = 1) ⇒ Object
Creates a new site summary
1117 1118 1119 1120 |
# File 'lib/nexpose.rb', line 1117 def setSiteSummary(site_name, description, riskfactor = 1) @site_summary = SiteSummary.new(-1,site_name,description,riskfactor) end |