Class: Nexpose::SiteConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose.rb

Overview

Description

Object that represents the configuration of a Site. This object is automatically created when a new Site object is instantiated.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSiteConfig

Returns a new instance of SiteConfig.



1181
1182
1183
1184
1185
1186
1187
# File 'lib/nexpose.rb', line 1181

def initialize()
	@xml_tag_stack = Array.new()
	@hosts = Array.new()
	@credentials = Array.new()
	@alerts = Array.new()
	@error = false
end

Instance Attribute Details

#alertsObject (readonly)

Array containing ((SmtpAlera|SnmpAlert|SyslogAlert)*)



1177
1178
1179
# File 'lib/nexpose.rb', line 1177

def alerts
  @alerts
end

#connectionObject (readonly)

The NSC Connection associated with this object



1163
1164
1165
# File 'lib/nexpose.rb', line 1163

def connection
  @connection
end

#credentialsObject (readonly)

Array containing (AdminCredentials*)



1175
1176
1177
# File 'lib/nexpose.rb', line 1175

def credentials
  @credentials
end

#descriptionObject (readonly)

A Description of the Site



1169
1170
1171
# File 'lib/nexpose.rb', line 1169

def description
  @description
end

#errorObject (readonly)

true if an error condition exists; false otherwise



1155
1156
1157
# File 'lib/nexpose.rb', line 1155

def error
  @error
end

#error_msgObject (readonly)

Error message string



1157
1158
1159
# File 'lib/nexpose.rb', line 1157

def error_msg
  @error_msg
end

#hostsObject (readonly)

Array containing ((IPRange|HostName)*)



1173
1174
1175
# File 'lib/nexpose.rb', line 1173

def hosts
  @hosts
end

#request_xmlObject (readonly)

The last XML request sent by this object



1159
1160
1161
# File 'lib/nexpose.rb', line 1159

def request_xml
  @request_xml
end

#response_xmlObject (readonly)

The last XML response received by this object



1161
1162
1163
# File 'lib/nexpose.rb', line 1161

def response_xml
  @response_xml
end

#riskfactorObject (readonly)

User assigned risk multiplier



1171
1172
1173
# File 'lib/nexpose.rb', line 1171

def riskfactor
  @riskfactor
end

#scanConfigObject (readonly)

ScanConfig object which holds Schedule and ScanTrigger Objects



1179
1180
1181
# File 'lib/nexpose.rb', line 1179

def scanConfig
  @scanConfig
end

#site_idObject (readonly)

The Site ID



1165
1166
1167
# File 'lib/nexpose.rb', line 1165

def site_id
  @site_id
end

#site_nameObject (readonly)

The Site Name



1167
1168
1169
# File 'lib/nexpose.rb', line 1167

def site_name
  @site_name
end

Instance Method Details

#_set_connection(connection) ⇒ Object



1233
1234
1235
# File 'lib/nexpose.rb', line 1233

def _set_connection(connection)
	@connection = connection
end

#_set_description(description) ⇒ Object



1221
1222
1223
# File 'lib/nexpose.rb', line 1221

def _set_description(description)
	@description = description
end

#_set_riskfactor(riskfactor) ⇒ Object



1225
1226
1227
# File 'lib/nexpose.rb', line 1225

def _set_riskfactor(riskfactor)
	@riskfactor = riskfactor
end

#_set_scanConfig(scanConfig) ⇒ Object



1229
1230
1231
# File 'lib/nexpose.rb', line 1229

def _set_scanConfig(scanConfig)
	@scanConfig = scanConfig
end

#_set_site_id(site_id) ⇒ Object



1213
1214
1215
# File 'lib/nexpose.rb', line 1213

def _set_site_id(site_id)
	@site_id = site_id
end

#_set_site_name(site_name) ⇒ Object



1217
1218
1219
# File 'lib/nexpose.rb', line 1217

def _set_site_name(site_name)
	@site_name = site_name
end

#addAlert(alert) ⇒ Object

Adds a new alert to the alerts array



1195
1196
1197
# File 'lib/nexpose.rb', line 1195

def addAlert(alert)
	@alerts.push(alert)
end

#addCredentials(credential) ⇒ Object

Adds a new set of credentials to the credentials array



1200
1201
1202
# File 'lib/nexpose.rb', line 1200

def addCredentials(credential)
	@credentials.push(credential)
end

#addHost(host) ⇒ Object

Adds a new host to the hosts array



1190
1191
1192
# File 'lib/nexpose.rb', line 1190

def addHost(host)
	@hosts.push(host)
end

#getSiteConfig(connection, site_id) ⇒ Object

TODO



1205
1206
1207
1208
1209
1210
1211
# File 'lib/nexpose.rb', line 1205

def getSiteConfig(connection,site_id)
	@connection = connection
	@site_id = site_id

	r = APIRequest.execute(@connection.url,'<SiteConfigRequest session-id="' + @connection.session_id + '" site-id="' + @site_id + '"/>')
	parse(r.res)
end

#parse(response) ⇒ Object

<SiteConfigResponse success=‘1’> <Site name=‘Site1’ id=‘243’ description=” riskfactor=‘1.0’> <Hosts> <range from=‘127.0.0.1’/> </Hosts> <Credentials> </Credentials> <Alerting> </Alerting> <ScanConfig configID=‘243’ name=‘Full audit’ configVersion=‘3’ engineID=‘2’ templateID=‘full-audit’> <Schedules> </Schedules> <ScanTriggers> </ScanTriggers> </ScanConfig> </Site>



1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
# File 'lib/nexpose.rb', line 1256

def parse(response)
	response.elements.each('SiteConfigResponse/Site') do |s|
		@site_id = s.attributes['id']
		@site_name = s.attributes['name']
		@description = s.attributes['description']
		@riskfactor = s.attributes['riskfactor']
		s.elements.each('Hosts/range') do |r|
			@hosts.push(IPRange.new(r.attributes['from'],r.attributes['to']))
		end
		s.elements.each('ScanConfig') do |c|
			@scanConfig = ScanConfig.new(c.attributes['configID'],
										c.attributes['name'],
										c.attributes['configVersion'],
										c.attributes['templateID'])
			s.elements.each('Schedule') do |schedule|
				schedule = new Schedule(schedule.attributes["type"], schedule.attributes["interval"], schedule.attributes["start"], schedule.attributes["enabled"])
				@scanConfig.addSchedule(schedule)
			end
		end

		s.elements.each('Alerting/Alert') do |a|

			a.elements.each('smtpAlert') do |smtp|
				smtp_alert = SmtpAlert.new(a.attributes["name"], smtp.attributes["sender"], smtp.attributes["limitText"], a.attributes["enabled"])

				smtp.elements.each('recipient') do |recipient|
					smtp_alert.addRecipient(recipient.text)
				end
				@alerts.push(smtp_alert)
			end

			a.elements.each('snmpAlert') do |snmp|
				snmp_alert = SnmpAlert.new(a.attributes["name"], snmp.attributes["community"], snmp.attributes["server"], a.attributes["enabled"])
				@alerts.push(snmp_alert)
			end
			a.elements.each('syslogAlert') do |syslog|
				syslog_alert = SyslogAlert.new(a.attributes["name"], syslog.attributes["server"], a.attributes["enabled"])
				@alerts.push(syslog_alert)
			end

			a.elements.each('vulnFilter') do |vulnFilter|

				#vulnfilter = new VulnFilter.new(a.attributes["typemask"], a.attributes["severityThreshold"], $attrs["MAXALERTS"])
				# Pop off the top alert on the stack
				#$alert = @alerts.pop()
				# Add the new recipient string to the Alert Object
				#$alert.setVulnFilter($vulnfilter)
				# Push the alert back on to the alert stack
				#array_push($this->alerts, $alert)
			end

			a.elements.each('scanFilter') do |scanFilter|
				#<scanFilter scanStop='0' scanFailed='0' scanStart='1'/>
				#scanfilter = ScanFilter.new(scanFilter.attributes['scanStop'],scanFilter.attributes['scanFailed'],scanFilter.attributes['scanStart'])
				#alert = @alerts.pop()
				#alert.setScanFilter(scanfilter)
				#@alerts.push(alert)
			end
		end
	end
end