Class: Nexpose::ReportAdHoc
- Inherits:
-
Object
- Object
- Nexpose::ReportAdHoc
- Includes:
- XMLUtils
- Defined in:
- lib/nexpose/report.rb
Overview
Description
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#error_msg ⇒ Object
readonly
Returns the value of attribute error_msg.
-
#filters ⇒ Object
readonly
Array of (ReportFilter)*.
-
#format ⇒ Object
readonly
pdf|html|xml|text|csv|raw-xml.
-
#report_decoded ⇒ Object
readonly
Returns the value of attribute report_decoded.
-
#request_xml ⇒ Object
readonly
Returns the value of attribute request_xml.
-
#response_xml ⇒ Object
readonly
Returns the value of attribute response_xml.
-
#template_id ⇒ Object
readonly
Report Template ID strong e.g.
Instance Method Summary collapse
- #addFilter(filter_type, id) ⇒ Object
- #generate ⇒ Object
-
#initialize(connection, template_id = 'full-audit', format = 'raw-xml') ⇒ ReportAdHoc
constructor
A new instance of ReportAdHoc.
Methods included from XMLUtils
Constructor Details
#initialize(connection, template_id = 'full-audit', format = 'raw-xml') ⇒ ReportAdHoc
Returns a new instance of ReportAdHoc.
208 209 210 211 212 213 214 215 216 |
# File 'lib/nexpose/report.rb', line 208 def initialize(connection, template_id = 'full-audit', format = 'raw-xml') @error = false @connection = connection @filters = [] @template_id = template_id @format = format end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
196 197 198 |
# File 'lib/nexpose/report.rb', line 196 def connection @connection end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
194 195 196 |
# File 'lib/nexpose/report.rb', line 194 def error @error end |
#error_msg ⇒ Object (readonly)
Returns the value of attribute error_msg.
195 196 197 |
# File 'lib/nexpose/report.rb', line 195 def error_msg @error_msg end |
#filters ⇒ Object (readonly)
Array of (ReportFilter)*
202 203 204 |
# File 'lib/nexpose/report.rb', line 202 def filters @filters end |
#format ⇒ Object (readonly)
pdf|html|xml|text|csv|raw-xml
200 201 202 |
# File 'lib/nexpose/report.rb', line 200 def format @format end |
#report_decoded ⇒ Object (readonly)
Returns the value of attribute report_decoded.
205 206 207 |
# File 'lib/nexpose/report.rb', line 205 def report_decoded @report_decoded end |
#request_xml ⇒ Object (readonly)
Returns the value of attribute request_xml.
203 204 205 |
# File 'lib/nexpose/report.rb', line 203 def request_xml @request_xml end |
#response_xml ⇒ Object (readonly)
Returns the value of attribute response_xml.
204 205 206 |
# File 'lib/nexpose/report.rb', line 204 def response_xml @response_xml end |
#template_id ⇒ Object (readonly)
Report Template ID strong e.g. full-audit
198 199 200 |
# File 'lib/nexpose/report.rb', line 198 def template_id @template_id end |
Instance Method Details
#addFilter(filter_type, id) ⇒ Object
218 219 220 221 222 223 224 225 |
# File 'lib/nexpose/report.rb', line 218 def addFilter(filter_type, id) # filter_type can be site|group|device|scan # id is the ID number. For scan, you can use 'last' for the most recently run scan filter = ReportFilter.new(filter_type, id) filters.push(filter) end |
#generate ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/nexpose/report.rb', line 227 def generate() request_xml = '<ReportAdhocGenerateRequest session-id="' + @connection.session_id + '">' request_xml += '<AdhocReportConfig template-id="' + @template_id + '" format="' + @format + '">' request_xml += '<Filters>' @filters.each do |f| request_xml += '<filter type="' + f.type + '" id="'+ f.id.to_s + '"/>' end request_xml += '</Filters>' request_xml += '</AdhocReportConfig>' request_xml += '</ReportAdhocGenerateRequest>' ad_hoc_request = APIRequest.new(request_xml, @connection.url) ad_hoc_request.execute() content_type_response = ad_hoc_request.raw_response.header['Content-Type'] if content_type_response =~ /multipart\/mixed;\s*boundary=([^\s]+)/ # NeXpose sends an incorrect boundary format which breaks parsing # Eg: boundary=XXX; charset=XXX # Fix by removing everything from the last semi-colon onward last_semi_colon_index = content_type_response.index(/;/, content_type_response.index(/boundary/)) content_type_response = content_type_response[0, last_semi_colon_index] data = "Content-Type: " + content_type_response + "\r\n\r\n" + ad_hoc_request.raw_response_data doc = Rex::MIME::Message.new data doc.parts.each do |part| if /.*base64.*/ =~ part.header.to_s if (@format == "text") or (@format == "pdf") or (@format == "csv") return part.content.unpack("m*")[0] else return parse_xml(part.content.unpack("m*")[0]) end end end end end |