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.
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 |
# File 'lib/nexpose.rb', line 1311 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
1294 1295 1296 |
# File 'lib/nexpose.rb', line 1294 def connection @connection end |
#error ⇒ Object (readonly)
true if an error condition exists; false otherwise
1286 1287 1288 |
# File 'lib/nexpose.rb', line 1286 def error @error end |
#error_msg ⇒ Object (readonly)
Error message string
1288 1289 1290 |
# File 'lib/nexpose.rb', line 1288 def error_msg @error_msg end |
#request_xml ⇒ Object (readonly)
The last XML request sent by this object
1290 1291 1292 |
# File 'lib/nexpose.rb', line 1290 def request_xml @request_xml end |
#response_xml ⇒ Object (readonly)
The last XML response received by this object
1292 1293 1294 |
# File 'lib/nexpose.rb', line 1292 def response_xml @response_xml end |
#site_config ⇒ Object (readonly)
The configuration of this site SiteConfig Object
1303 1304 1305 |
# File 'lib/nexpose.rb', line 1303 def site_config @site_config end |
#site_device_listing ⇒ Object (readonly)
The device listing for this site SiteDeviceListing Object
1306 1307 1308 |
# File 'lib/nexpose.rb', line 1306 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.
1297 1298 1299 |
# File 'lib/nexpose.rb', line 1297 def site_id @site_id end |
#site_scan_history ⇒ Object (readonly)
The scan history of this site SiteScanHistory Object
1309 1310 1311 |
# File 'lib/nexpose.rb', line 1309 def site_scan_history @site_scan_history end |
#site_summary ⇒ Object (readonly)
A summary overview of this site SiteSummary Object
1300 1301 1302 |
# File 'lib/nexpose.rb', line 1300 def site_summary @site_summary end |
Instance Method Details
#deleteSite ⇒ Object
1386 1387 1388 1389 |
# File 'lib/nexpose.rb', line 1386 def deleteSite() r = @connection.execute('<SiteDeleteRequest session-id="' + @connection.session_id.to_s + '" site-id="' + @site_id + '"/>') r.success end |
#getSiteXML ⇒ Object
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 |
# File 'lib/nexpose.rb', line 1399 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
1392 1393 1394 1395 1396 1397 |
# File 'lib/nexpose.rb', line 1392 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
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 |
# File 'lib/nexpose.rb', line 1373 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.
1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 |
# File 'lib/nexpose.rb', line 1358 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
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 |
# File 'lib/nexpose.rb', line 1345 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
1339 1340 1341 1342 |
# File 'lib/nexpose.rb', line 1339 def setSiteSummary(site_name, description, riskfactor = 1) @site_summary = SiteSummary.new(-1,site_name,description,riskfactor) end |