id
int32
0
24.9k
repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
18,800
2Checkout/2checkout-ruby
lib/twocheckout/option.rb
Twocheckout.Option.update
def update(opts) opts = opts.merge(:option_id => self.option_id) Twocheckout::API.request(:post, 'products/update_option', opts) response = Twocheckout::API.request(:get, 'products/detail_option', opts) Option.new(response['option'][0]) end
ruby
def update(opts) opts = opts.merge(:option_id => self.option_id) Twocheckout::API.request(:post, 'products/update_option', opts) response = Twocheckout::API.request(:get, 'products/detail_option', opts) Option.new(response['option'][0]) end
[ "def", "update", "(", "opts", ")", "opts", "=", "opts", ".", "merge", "(", ":option_id", "=>", "self", ".", "option_id", ")", "Twocheckout", "::", "API", ".", "request", "(", ":post", ",", "'products/update_option'", ",", "opts", ")", "response", "=", "Twocheckout", "::", "API", ".", "request", "(", ":get", ",", "'products/detail_option'", ",", "opts", ")", "Option", ".", "new", "(", "response", "[", "'option'", "]", "[", "0", "]", ")", "end" ]
Updates option and returns a new object
[ "Updates", "option", "and", "returns", "a", "new", "object" ]
e9447ed61ef33c6cbaee7defe9eac0e8f8252509
https://github.com/2Checkout/2checkout-ruby/blob/e9447ed61ef33c6cbaee7defe9eac0e8f8252509/lib/twocheckout/option.rb#L27-L32
18,801
2Checkout/2checkout-ruby
lib/twocheckout/sale.rb
Twocheckout.Sale.comment
def comment(opts) opts = opts.merge(:sale_id => self.sale_id) Twocheckout::API.request(:post, 'sales/create_comment', opts) end
ruby
def comment(opts) opts = opts.merge(:sale_id => self.sale_id) Twocheckout::API.request(:post, 'sales/create_comment', opts) end
[ "def", "comment", "(", "opts", ")", "opts", "=", "opts", ".", "merge", "(", ":sale_id", "=>", "self", ".", "sale_id", ")", "Twocheckout", "::", "API", ".", "request", "(", ":post", ",", "'sales/create_comment'", ",", "opts", ")", "end" ]
Add a sale comment
[ "Add", "a", "sale", "comment" ]
e9447ed61ef33c6cbaee7defe9eac0e8f8252509
https://github.com/2Checkout/2checkout-ruby/blob/e9447ed61ef33c6cbaee7defe9eac0e8f8252509/lib/twocheckout/sale.rb#L65-L68
18,802
2Checkout/2checkout-ruby
lib/twocheckout/sale.rb
Twocheckout.Sale.ship
def ship(opts) opts = opts.merge(:sale_id => self.sale_id) Twocheckout::API.request(:post, 'sales/mark_shipped', opts) end
ruby
def ship(opts) opts = opts.merge(:sale_id => self.sale_id) Twocheckout::API.request(:post, 'sales/mark_shipped', opts) end
[ "def", "ship", "(", "opts", ")", "opts", "=", "opts", ".", "merge", "(", ":sale_id", "=>", "self", ".", "sale_id", ")", "Twocheckout", "::", "API", ".", "request", "(", ":post", ",", "'sales/mark_shipped'", ",", "opts", ")", "end" ]
Mark tangible sale as shipped
[ "Mark", "tangible", "sale", "as", "shipped" ]
e9447ed61ef33c6cbaee7defe9eac0e8f8252509
https://github.com/2Checkout/2checkout-ruby/blob/e9447ed61ef33c6cbaee7defe9eac0e8f8252509/lib/twocheckout/sale.rb#L73-L76
18,803
2Checkout/2checkout-ruby
lib/twocheckout/lineitem.rb
Twocheckout.LineItem.update_recurring!
def update_recurring!(opts) opts = opts.merge(:lineitem_id => self.lineitem_id) Twocheckout::API.request(:post, 'sales/update_lineitem_recurring', opts) end
ruby
def update_recurring!(opts) opts = opts.merge(:lineitem_id => self.lineitem_id) Twocheckout::API.request(:post, 'sales/update_lineitem_recurring', opts) end
[ "def", "update_recurring!", "(", "opts", ")", "opts", "=", "opts", ".", "merge", "(", ":lineitem_id", "=>", "self", ".", "lineitem_id", ")", "Twocheckout", "::", "API", ".", "request", "(", ":post", ",", "'sales/update_lineitem_recurring'", ",", "opts", ")", "end" ]
Provide access to update existing recurring lineitems by allowing to lower the lineitem price and push the recurring billing date forward. This call is not currently documented in the 2Checkout API documentation. POST https://www.2checkout.com/api/sales/update_lineitem_recurring Parameters: * (required) lineitem_id: lineitem_id * (optional) comment: Optional comment added to sale * (optional) shift: days to shift next recurring payment forward * (optional) price: new recurring price (must be lower than previous price or else call will fail) The shift and price parameters are optional, but at least one of them must be provided for the call to be valid. Example Shift Date Next curl -X POST https://www.2checkout.com/api/sales/update_lineitem_recurring -u \ 'username:password' -d 'lineitem_id=1234567890' -d 'shift=7' -H 'Accept: application/json' Example Update Price curl -X POST https://www.2checkout.com/api/sales/update_lineitem_recurring -u \ 'username:password' -d 'lineitem_id=1234567890' -d 'price=1.00' -H 'Accept: application/json' Please note that this method cannot be used on PayPal sales as 2Checkout cannot alter the customer's billing agreement so this call can only update a recurring lineitem on credit card sales.
[ "Provide", "access", "to", "update", "existing", "recurring", "lineitems", "by", "allowing", "to", "lower", "the", "lineitem", "price", "and", "push", "the", "recurring", "billing", "date", "forward", ".", "This", "call", "is", "not", "currently", "documented", "in", "the", "2Checkout", "API", "documentation", "." ]
e9447ed61ef33c6cbaee7defe9eac0e8f8252509
https://github.com/2Checkout/2checkout-ruby/blob/e9447ed61ef33c6cbaee7defe9eac0e8f8252509/lib/twocheckout/lineitem.rb#L45-L48
18,804
2Checkout/2checkout-ruby
lib/twocheckout/product.rb
Twocheckout.Product.update
def update(opts) opts = opts.merge(:product_id => self.product_id) Twocheckout::API.request(:post, 'products/update_product', opts) response = Twocheckout::API.request(:get, 'products/detail_product', opts) Product.new(response['product']) end
ruby
def update(opts) opts = opts.merge(:product_id => self.product_id) Twocheckout::API.request(:post, 'products/update_product', opts) response = Twocheckout::API.request(:get, 'products/detail_product', opts) Product.new(response['product']) end
[ "def", "update", "(", "opts", ")", "opts", "=", "opts", ".", "merge", "(", ":product_id", "=>", "self", ".", "product_id", ")", "Twocheckout", "::", "API", ".", "request", "(", ":post", ",", "'products/update_product'", ",", "opts", ")", "response", "=", "Twocheckout", "::", "API", ".", "request", "(", ":get", ",", "'products/detail_product'", ",", "opts", ")", "Product", ".", "new", "(", "response", "[", "'product'", "]", ")", "end" ]
Updates product and returns a new Product object
[ "Updates", "product", "and", "returns", "a", "new", "Product", "object" ]
e9447ed61ef33c6cbaee7defe9eac0e8f8252509
https://github.com/2Checkout/2checkout-ruby/blob/e9447ed61ef33c6cbaee7defe9eac0e8f8252509/lib/twocheckout/product.rb#L27-L32
18,805
browserify-rails/browserify-rails
lib/browserify-rails/browserify_processor.rb
BrowserifyRails.BrowserifyProcessor.commonjs_module?
def commonjs_module? data.to_s.include?("module.exports") || data.present? && data.to_s.match(/(require\(.*\)|import)/) && dependencies.length > 0 end
ruby
def commonjs_module? data.to_s.include?("module.exports") || data.present? && data.to_s.match(/(require\(.*\)|import)/) && dependencies.length > 0 end
[ "def", "commonjs_module?", "data", ".", "to_s", ".", "include?", "(", "\"module.exports\"", ")", "||", "data", ".", "present?", "&&", "data", ".", "to_s", ".", "match", "(", "/", "\\(", "\\)", "/", ")", "&&", "dependencies", ".", "length", ">", "0", "end" ]
Is this a commonjs module? Be here as strict as possible, so that non-commonjs files are not preprocessed.
[ "Is", "this", "a", "commonjs", "module?" ]
fcf33879619bef124e7347c46fd303276073c5d4
https://github.com/browserify-rails/browserify-rails/blob/fcf33879619bef124e7347c46fd303276073c5d4/lib/browserify-rails/browserify_processor.rb#L120-L122
18,806
browserify-rails/browserify-rails
lib/browserify-rails/browserify_processor.rb
BrowserifyRails.BrowserifyProcessor.evaluate_dependencies
def evaluate_dependencies(asset_paths) return dependencies if config.evaluate_node_modules dependencies.select do |path| path.start_with?(*asset_paths) end end
ruby
def evaluate_dependencies(asset_paths) return dependencies if config.evaluate_node_modules dependencies.select do |path| path.start_with?(*asset_paths) end end
[ "def", "evaluate_dependencies", "(", "asset_paths", ")", "return", "dependencies", "if", "config", ".", "evaluate_node_modules", "dependencies", ".", "select", "do", "|", "path", "|", "path", ".", "start_with?", "(", "asset_paths", ")", "end", "end" ]
This primarily filters out required files from node modules @return [<String>] Paths of dependencies to evaluate
[ "This", "primarily", "filters", "out", "required", "files", "from", "node", "modules" ]
fcf33879619bef124e7347c46fd303276073c5d4
https://github.com/browserify-rails/browserify-rails/blob/fcf33879619bef124e7347c46fd303276073c5d4/lib/browserify-rails/browserify_processor.rb#L131-L137
18,807
rapid7/nexpose-client
lib/nexpose/manage.rb
Nexpose.Connection.console_command
def console_command(cmd_string) xml = make_xml('ConsoleCommandRequest', {}) cmd = REXML::Element.new('Command') cmd.text = cmd_string xml << cmd r = execute(xml) if r.success r.res.elements.each('//Output') do |out| return out.text.to_s end else false end end
ruby
def console_command(cmd_string) xml = make_xml('ConsoleCommandRequest', {}) cmd = REXML::Element.new('Command') cmd.text = cmd_string xml << cmd r = execute(xml) if r.success r.res.elements.each('//Output') do |out| return out.text.to_s end else false end end
[ "def", "console_command", "(", "cmd_string", ")", "xml", "=", "make_xml", "(", "'ConsoleCommandRequest'", ",", "{", "}", ")", "cmd", "=", "REXML", "::", "Element", ".", "new", "(", "'Command'", ")", "cmd", ".", "text", "=", "cmd_string", "xml", "<<", "cmd", "r", "=", "execute", "(", "xml", ")", "if", "r", ".", "success", "r", ".", "res", ".", "elements", ".", "each", "(", "'//Output'", ")", "do", "|", "out", "|", "return", "out", ".", "text", ".", "to_s", "end", "else", "false", "end", "end" ]
Execute an arbitrary console command that is supplied as text via the supplied parameter. Console commands are documented in the administrator's guide. If you use a command that is not listed in the administrator's guide, the application will return the XMLResponse.
[ "Execute", "an", "arbitrary", "console", "command", "that", "is", "supplied", "as", "text", "via", "the", "supplied", "parameter", ".", "Console", "commands", "are", "documented", "in", "the", "administrator", "s", "guide", ".", "If", "you", "use", "a", "command", "that", "is", "not", "listed", "in", "the", "administrator", "s", "guide", "the", "application", "will", "return", "the", "XMLResponse", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/manage.rb#L12-L26
18,808
rapid7/nexpose-client
lib/nexpose/manage.rb
Nexpose.Connection.system_information
def system_information r = execute(make_xml('SystemInformationRequest', {})) if r.success res = {} r.res.elements.each('//Statistic') do |stat| res[stat.attributes['name'].to_s] = stat.text.to_s end res else false end end
ruby
def system_information r = execute(make_xml('SystemInformationRequest', {})) if r.success res = {} r.res.elements.each('//Statistic') do |stat| res[stat.attributes['name'].to_s] = stat.text.to_s end res else false end end
[ "def", "system_information", "r", "=", "execute", "(", "make_xml", "(", "'SystemInformationRequest'", ",", "{", "}", ")", ")", "if", "r", ".", "success", "res", "=", "{", "}", "r", ".", "res", ".", "elements", ".", "each", "(", "'//Statistic'", ")", "do", "|", "stat", "|", "res", "[", "stat", ".", "attributes", "[", "'name'", "]", ".", "to_s", "]", "=", "stat", ".", "text", ".", "to_s", "end", "res", "else", "false", "end", "end" ]
Obtain system data, such as total RAM, free RAM, total disk space, free disk space, CPU speed, number of CPU cores, and other vital information.
[ "Obtain", "system", "data", "such", "as", "total", "RAM", "free", "RAM", "total", "disk", "space", "free", "disk", "space", "CPU", "speed", "number", "of", "CPU", "cores", "and", "other", "vital", "information", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/manage.rb#L32-L44
18,809
rapid7/nexpose-client
lib/nexpose/manage.rb
Nexpose.Connection.engine_versions
def engine_versions info = console_command('version engines') versions = [] engines = info.sub('VERSION INFORMATION\n', '').split(/\n\n/) engines.each do |eng| engdata = {} eng.split(/\n/).each do |kv| key, value = kv.split(/:\s*/) key = key.sub('Local Engine ', '').sub('Remote Engine ', '') engdata[key] = value end versions << engdata end versions end
ruby
def engine_versions info = console_command('version engines') versions = [] engines = info.sub('VERSION INFORMATION\n', '').split(/\n\n/) engines.each do |eng| engdata = {} eng.split(/\n/).each do |kv| key, value = kv.split(/:\s*/) key = key.sub('Local Engine ', '').sub('Remote Engine ', '') engdata[key] = value end versions << engdata end versions end
[ "def", "engine_versions", "info", "=", "console_command", "(", "'version engines'", ")", "versions", "=", "[", "]", "engines", "=", "info", ".", "sub", "(", "'VERSION INFORMATION\\n'", ",", "''", ")", ".", "split", "(", "/", "\\n", "\\n", "/", ")", "engines", ".", "each", "do", "|", "eng", "|", "engdata", "=", "{", "}", "eng", ".", "split", "(", "/", "\\n", "/", ")", ".", "each", "do", "|", "kv", "|", "key", ",", "value", "=", "kv", ".", "split", "(", "/", "\\s", "/", ")", "key", "=", "key", ".", "sub", "(", "'Local Engine '", ",", "''", ")", ".", "sub", "(", "'Remote Engine '", ",", "''", ")", "engdata", "[", "key", "]", "=", "value", "end", "versions", "<<", "engdata", "end", "versions", "end" ]
Obtain the version information for each scan engine. Includes Product, Content, and Java versions.
[ "Obtain", "the", "version", "information", "for", "each", "scan", "engine", ".", "Includes", "Product", "Content", "and", "Java", "versions", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/manage.rb#L49-L63
18,810
rapid7/nexpose-client
lib/nexpose/manage.rb
Nexpose.Connection.send_log
def send_log(uri = 'https://support.rapid7.com') url = REXML::Element.new('URL') url.text = uri tpt = REXML::Element.new('Transport') tpt.add_attribute('protocol', 'https') tpt << url xml = make_xml('SendLogRequest') xml << tpt execute(xml).success end
ruby
def send_log(uri = 'https://support.rapid7.com') url = REXML::Element.new('URL') url.text = uri tpt = REXML::Element.new('Transport') tpt.add_attribute('protocol', 'https') tpt << url xml = make_xml('SendLogRequest') xml << tpt execute(xml).success end
[ "def", "send_log", "(", "uri", "=", "'https://support.rapid7.com'", ")", "url", "=", "REXML", "::", "Element", ".", "new", "(", "'URL'", ")", "url", ".", "text", "=", "uri", "tpt", "=", "REXML", "::", "Element", ".", "new", "(", "'Transport'", ")", "tpt", ".", "add_attribute", "(", "'protocol'", ",", "'https'", ")", "tpt", "<<", "url", "xml", "=", "make_xml", "(", "'SendLogRequest'", ")", "xml", "<<", "tpt", "execute", "(", "xml", ")", ".", "success", "end" ]
Output diagnostic information into log files, zip the files, and encrypt the archive with a PGP public key that is provided as a parameter for the API call. Then upload the archive using HTTPS to a URL that is specified as an API parameter. @param uri Upload server to send the support log package to.
[ "Output", "diagnostic", "information", "into", "log", "files", "zip", "the", "files", "and", "encrypt", "the", "archive", "with", "a", "PGP", "public", "key", "that", "is", "provided", "as", "a", "parameter", "for", "the", "API", "call", ".", "Then", "upload", "the", "archive", "using", "HTTPS", "to", "a", "URL", "that", "is", "specified", "as", "an", "API", "parameter", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/manage.rb#L90-L100
18,811
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.scan_ips_with_schedule
def scan_ips_with_schedule(site_id, ip_addresses, schedules) xml = make_xml('SiteDevicesScanRequest', 'site-id' => site_id) hosts = REXML::Element.new('Hosts') ip_addresses.each do |ip| xml.add_element('range', 'from' => ip) end xml.add_element(hosts) scheds = REXML::Element.new('Schedules') schedules.each { |sched| scheds.add_element(sched.as_xml) } xml.add_element(scheds) _scan_ad_hoc_with_schedules(xml) end
ruby
def scan_ips_with_schedule(site_id, ip_addresses, schedules) xml = make_xml('SiteDevicesScanRequest', 'site-id' => site_id) hosts = REXML::Element.new('Hosts') ip_addresses.each do |ip| xml.add_element('range', 'from' => ip) end xml.add_element(hosts) scheds = REXML::Element.new('Schedules') schedules.each { |sched| scheds.add_element(sched.as_xml) } xml.add_element(scheds) _scan_ad_hoc_with_schedules(xml) end
[ "def", "scan_ips_with_schedule", "(", "site_id", ",", "ip_addresses", ",", "schedules", ")", "xml", "=", "make_xml", "(", "'SiteDevicesScanRequest'", ",", "'site-id'", "=>", "site_id", ")", "hosts", "=", "REXML", "::", "Element", ".", "new", "(", "'Hosts'", ")", "ip_addresses", ".", "each", "do", "|", "ip", "|", "xml", ".", "add_element", "(", "'range'", ",", "'from'", "=>", "ip", ")", "end", "xml", ".", "add_element", "(", "hosts", ")", "scheds", "=", "REXML", "::", "Element", ".", "new", "(", "'Schedules'", ")", "schedules", ".", "each", "{", "|", "sched", "|", "scheds", ".", "add_element", "(", "sched", ".", "as_xml", ")", "}", "xml", ".", "add_element", "(", "scheds", ")", "_scan_ad_hoc_with_schedules", "(", "xml", ")", "end" ]
Perform an ad hoc scan of a subset of IP addresses for a site at a specific time. Only IPs from a single site can be submitted per request, and IP addresses must already be included in the site configuration. Method is designed for scanning when the targets are coming from an external source that does not have access to internal identfiers. For example: to_scan = ['192.168.2.1', '192.168.2.107'] nsc.scan_ips(5, to_scan) @param [Fixnum] site_id Site ID that the assets belong to. @param [Array[String]] ip_addresses Array of IP addresses to scan. @return [Status] whether the request was successful
[ "Perform", "an", "ad", "hoc", "scan", "of", "a", "subset", "of", "IP", "addresses", "for", "a", "site", "at", "a", "specific", "time", ".", "Only", "IPs", "from", "a", "single", "site", "can", "be", "submitted", "per", "request", "and", "IP", "addresses", "must", "already", "be", "included", "in", "the", "site", "configuration", ".", "Method", "is", "designed", "for", "scanning", "when", "the", "targets", "are", "coming", "from", "an", "external", "source", "that", "does", "not", "have", "access", "to", "internal", "identfiers", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L157-L169
18,812
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.scan_ips
def scan_ips(site_id, ip_addresses) xml = make_xml('SiteDevicesScanRequest', 'site-id' => site_id) hosts = REXML::Element.new('Hosts') ip_addresses.each do |ip| xml.add_element('range', 'from' => ip) end xml.add_element(hosts) _scan_ad_hoc(xml) end
ruby
def scan_ips(site_id, ip_addresses) xml = make_xml('SiteDevicesScanRequest', 'site-id' => site_id) hosts = REXML::Element.new('Hosts') ip_addresses.each do |ip| xml.add_element('range', 'from' => ip) end xml.add_element(hosts) _scan_ad_hoc(xml) end
[ "def", "scan_ips", "(", "site_id", ",", "ip_addresses", ")", "xml", "=", "make_xml", "(", "'SiteDevicesScanRequest'", ",", "'site-id'", "=>", "site_id", ")", "hosts", "=", "REXML", "::", "Element", ".", "new", "(", "'Hosts'", ")", "ip_addresses", ".", "each", "do", "|", "ip", "|", "xml", ".", "add_element", "(", "'range'", ",", "'from'", "=>", "ip", ")", "end", "xml", ".", "add_element", "(", "hosts", ")", "_scan_ad_hoc", "(", "xml", ")", "end" ]
Perform an ad hoc scan of a subset of IP addresses for a site. Only IPs from a single site can be submitted per request, and IP addresses must already be included in the site configuration. Method is designed for scanning when the targets are coming from an external source that does not have access to internal identfiers. For example: to_scan = ['192.168.2.1', '192.168.2.107'] nsc.scan_ips(5, to_scan) @param [Fixnum] site_id Site ID that the assets belong to. @param [Array[String]] ip_addresses Array of IP addresses to scan. @return [Scan] Scan launch information.
[ "Perform", "an", "ad", "hoc", "scan", "of", "a", "subset", "of", "IP", "addresses", "for", "a", "site", ".", "Only", "IPs", "from", "a", "single", "site", "can", "be", "submitted", "per", "request", "and", "IP", "addresses", "must", "already", "be", "included", "in", "the", "site", "configuration", ".", "Method", "is", "designed", "for", "scanning", "when", "the", "targets", "are", "coming", "from", "an", "external", "source", "that", "does", "not", "have", "access", "to", "internal", "identfiers", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L185-L194
18,813
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.scan_site
def scan_site(site_id, blackout_override = false) xml = make_xml('SiteScanRequest', 'site-id' => site_id) xml.add_attributes({ 'force' => true }) if blackout_override response = execute(xml) Scan.parse(response.res) if response.success end
ruby
def scan_site(site_id, blackout_override = false) xml = make_xml('SiteScanRequest', 'site-id' => site_id) xml.add_attributes({ 'force' => true }) if blackout_override response = execute(xml) Scan.parse(response.res) if response.success end
[ "def", "scan_site", "(", "site_id", ",", "blackout_override", "=", "false", ")", "xml", "=", "make_xml", "(", "'SiteScanRequest'", ",", "'site-id'", "=>", "site_id", ")", "xml", ".", "add_attributes", "(", "{", "'force'", "=>", "true", "}", ")", "if", "blackout_override", "response", "=", "execute", "(", "xml", ")", "Scan", ".", "parse", "(", "response", ".", "res", ")", "if", "response", ".", "success", "end" ]
Initiate a site scan. @param [Fixnum] site_id Site ID to scan. @param [Boolean] blackout_override Optional. Given suffencent permissions, force bypass blackout and start scan. @return [Scan] Scan launch information.
[ "Initiate", "a", "site", "scan", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L202-L207
18,814
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.scan_assets_with_template_and_engine
def scan_assets_with_template_and_engine(site_id, assets, scan_template, scan_engine) uri = "/data/site/#{site_id}/scan" assets.size > 1 ? addresses = assets.join(',') : addresses = assets.first params = { 'addressList' => addresses, 'template' => scan_template, 'scanEngine' => scan_engine } scan_id = AJAX.form_post(self, uri, params) scan_id.to_i end
ruby
def scan_assets_with_template_and_engine(site_id, assets, scan_template, scan_engine) uri = "/data/site/#{site_id}/scan" assets.size > 1 ? addresses = assets.join(',') : addresses = assets.first params = { 'addressList' => addresses, 'template' => scan_template, 'scanEngine' => scan_engine } scan_id = AJAX.form_post(self, uri, params) scan_id.to_i end
[ "def", "scan_assets_with_template_and_engine", "(", "site_id", ",", "assets", ",", "scan_template", ",", "scan_engine", ")", "uri", "=", "\"/data/site/#{site_id}/scan\"", "assets", ".", "size", ">", "1", "?", "addresses", "=", "assets", ".", "join", "(", "','", ")", ":", "addresses", "=", "assets", ".", "first", "params", "=", "{", "'addressList'", "=>", "addresses", ",", "'template'", "=>", "scan_template", ",", "'scanEngine'", "=>", "scan_engine", "}", "scan_id", "=", "AJAX", ".", "form_post", "(", "self", ",", "uri", ",", "params", ")", "scan_id", ".", "to_i", "end" ]
Initiate an ad-hoc scan on a subset of site assets with a specific scan template and scan engine, which may differ from the site's defined scan template and scan engine. @param [Fixnum] site_id Site ID to scan. @param [Array[String]] assets Hostnames and/or IP addresses to scan. @param [String] scan_template The scan template ID. @param [Fixnum] scan_engine The scan engine ID. @return [Fixnum] Scan ID.
[ "Initiate", "an", "ad", "-", "hoc", "scan", "on", "a", "subset", "of", "site", "assets", "with", "a", "specific", "scan", "template", "and", "scan", "engine", "which", "may", "differ", "from", "the", "site", "s", "defined", "scan", "template", "and", "scan", "engine", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L219-L227
18,815
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection._append_asset!
def _append_asset!(xml, asset) if asset.is_a? Nexpose::IPRange xml.add_element('range', 'from' => asset.from, 'to' => asset.to) else # Assume HostName host = REXML::Element.new('host') host.text = asset xml.add_element(host) end end
ruby
def _append_asset!(xml, asset) if asset.is_a? Nexpose::IPRange xml.add_element('range', 'from' => asset.from, 'to' => asset.to) else # Assume HostName host = REXML::Element.new('host') host.text = asset xml.add_element(host) end end
[ "def", "_append_asset!", "(", "xml", ",", "asset", ")", "if", "asset", ".", "is_a?", "Nexpose", "::", "IPRange", "xml", ".", "add_element", "(", "'range'", ",", "'from'", "=>", "asset", ".", "from", ",", "'to'", "=>", "asset", ".", "to", ")", "else", "# Assume HostName", "host", "=", "REXML", "::", "Element", ".", "new", "(", "'host'", ")", "host", ".", "text", "=", "asset", "xml", ".", "add_element", "(", "host", ")", "end", "end" ]
Utility method for appending a HostName or IPRange object into an XML object, in preparation for ad hoc scanning. @param [REXML::Document] xml Prepared API call to execute. @param [HostName|IPRange] asset Asset to append to XML.
[ "Utility", "method", "for", "appending", "a", "HostName", "or", "IPRange", "object", "into", "an", "XML", "object", "in", "preparation", "for", "ad", "hoc", "scanning", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L235-L243
18,816
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection._scan_ad_hoc
def _scan_ad_hoc(xml) r = execute(xml, '1.1', timeout: 60) Scan.parse(r.res) end
ruby
def _scan_ad_hoc(xml) r = execute(xml, '1.1', timeout: 60) Scan.parse(r.res) end
[ "def", "_scan_ad_hoc", "(", "xml", ")", "r", "=", "execute", "(", "xml", ",", "'1.1'", ",", "timeout", ":", "60", ")", "Scan", ".", "parse", "(", "r", ".", "res", ")", "end" ]
Utility method for executing prepared XML and extracting Scan launch information. @param [REXML::Document] xml Prepared API call to execute. @return [Scan] Scan launch information.
[ "Utility", "method", "for", "executing", "prepared", "XML", "and", "extracting", "Scan", "launch", "information", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L251-L254
18,817
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.stop_scan
def stop_scan(scan_id, wait_sec = 0) r = execute(make_xml('ScanStopRequest', 'scan-id' => scan_id)) if r.success so_far = 0 while so_far < wait_sec status = scan_status(scan_id) return status if status == 'stopped' sleep 5 so_far += 5 end end r.success end
ruby
def stop_scan(scan_id, wait_sec = 0) r = execute(make_xml('ScanStopRequest', 'scan-id' => scan_id)) if r.success so_far = 0 while so_far < wait_sec status = scan_status(scan_id) return status if status == 'stopped' sleep 5 so_far += 5 end end r.success end
[ "def", "stop_scan", "(", "scan_id", ",", "wait_sec", "=", "0", ")", "r", "=", "execute", "(", "make_xml", "(", "'ScanStopRequest'", ",", "'scan-id'", "=>", "scan_id", ")", ")", "if", "r", ".", "success", "so_far", "=", "0", "while", "so_far", "<", "wait_sec", "status", "=", "scan_status", "(", "scan_id", ")", "return", "status", "if", "status", "==", "'stopped'", "sleep", "5", "so_far", "+=", "5", "end", "end", "r", ".", "success", "end" ]
Stop a running or paused scan. @param [Fixnum] scan_id ID of the scan to stop. @param [Fixnum] wait_sec Number of seconds to wait for status to be updated.
[ "Stop", "a", "running", "or", "paused", "scan", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L271-L283
18,818
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.scan_status
def scan_status(scan_id) r = execute(make_xml('ScanStatusRequest', 'scan-id' => scan_id)) r.success ? r.attributes['status'] : nil end
ruby
def scan_status(scan_id) r = execute(make_xml('ScanStatusRequest', 'scan-id' => scan_id)) r.success ? r.attributes['status'] : nil end
[ "def", "scan_status", "(", "scan_id", ")", "r", "=", "execute", "(", "make_xml", "(", "'ScanStatusRequest'", ",", "'scan-id'", "=>", "scan_id", ")", ")", "r", ".", "success", "?", "r", ".", "attributes", "[", "'status'", "]", ":", "nil", "end" ]
Retrieve the status of a scan. @param [Fixnum] scan_id The scan ID. @return [String] Current status of the scan. See Nexpose::Scan::Status.
[ "Retrieve", "the", "status", "of", "a", "scan", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L290-L293
18,819
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.resume_scan
def resume_scan(scan_id) r = execute(make_xml('ScanResumeRequest', 'scan-id' => scan_id), '1.1', timeout: 60) r.success ? r.attributes['success'] == '1' : false end
ruby
def resume_scan(scan_id) r = execute(make_xml('ScanResumeRequest', 'scan-id' => scan_id), '1.1', timeout: 60) r.success ? r.attributes['success'] == '1' : false end
[ "def", "resume_scan", "(", "scan_id", ")", "r", "=", "execute", "(", "make_xml", "(", "'ScanResumeRequest'", ",", "'scan-id'", "=>", "scan_id", ")", ",", "'1.1'", ",", "timeout", ":", "60", ")", "r", ".", "success", "?", "r", ".", "attributes", "[", "'success'", "]", "==", "'1'", ":", "false", "end" ]
Resumes a scan. @param [Fixnum] scan_id The scan ID.
[ "Resumes", "a", "scan", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L299-L302
18,820
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.pause_scan
def pause_scan(scan_id) r = execute(make_xml('ScanPauseRequest', 'scan-id' => scan_id)) r.success ? r.attributes['success'] == '1' : false end
ruby
def pause_scan(scan_id) r = execute(make_xml('ScanPauseRequest', 'scan-id' => scan_id)) r.success ? r.attributes['success'] == '1' : false end
[ "def", "pause_scan", "(", "scan_id", ")", "r", "=", "execute", "(", "make_xml", "(", "'ScanPauseRequest'", ",", "'scan-id'", "=>", "scan_id", ")", ")", "r", ".", "success", "?", "r", ".", "attributes", "[", "'success'", "]", "==", "'1'", ":", "false", "end" ]
Pauses a scan. @param [Fixnum] scan_id The scan ID.
[ "Pauses", "a", "scan", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L308-L311
18,821
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.activity
def activity r = execute(make_xml('ScanActivityRequest')) res = [] if r.success r.res.elements.each('//ScanSummary') do |scan| res << ScanData.parse(scan) end end res end
ruby
def activity r = execute(make_xml('ScanActivityRequest')) res = [] if r.success r.res.elements.each('//ScanSummary') do |scan| res << ScanData.parse(scan) end end res end
[ "def", "activity", "r", "=", "execute", "(", "make_xml", "(", "'ScanActivityRequest'", ")", ")", "res", "=", "[", "]", "if", "r", ".", "success", "r", ".", "res", ".", "elements", ".", "each", "(", "'//ScanSummary'", ")", "do", "|", "scan", "|", "res", "<<", "ScanData", ".", "parse", "(", "scan", ")", "end", "end", "res", "end" ]
Retrieve a list of current scan activities across all Scan Engines managed by Nexpose. This method returns lighter weight objects than scan_activity. @return [Array[ScanData]] Array of ScanData objects associated with each active scan on the engines.
[ "Retrieve", "a", "list", "of", "current", "scan", "activities", "across", "all", "Scan", "Engines", "managed", "by", "Nexpose", ".", "This", "method", "returns", "lighter", "weight", "objects", "than", "scan_activity", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L320-L329
18,822
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.scan_activity
def scan_activity r = execute(make_xml('ScanActivityRequest')) res = [] if r.success r.res.elements.each('//ScanSummary') do |scan| res << ScanSummary.parse(scan) end end res end
ruby
def scan_activity r = execute(make_xml('ScanActivityRequest')) res = [] if r.success r.res.elements.each('//ScanSummary') do |scan| res << ScanSummary.parse(scan) end end res end
[ "def", "scan_activity", "r", "=", "execute", "(", "make_xml", "(", "'ScanActivityRequest'", ")", ")", "res", "=", "[", "]", "if", "r", ".", "success", "r", ".", "res", ".", "elements", ".", "each", "(", "'//ScanSummary'", ")", "do", "|", "scan", "|", "res", "<<", "ScanSummary", ".", "parse", "(", "scan", ")", "end", "end", "res", "end" ]
Retrieve a list of current scan activities across all Scan Engines managed by Nexpose. @return [Array[ScanSummary]] Array of ScanSummary objects associated with each active scan on the engines.
[ "Retrieve", "a", "list", "of", "current", "scan", "activities", "across", "all", "Scan", "Engines", "managed", "by", "Nexpose", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L337-L346
18,823
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.scan_statistics
def scan_statistics(scan_id) r = execute(make_xml('ScanStatisticsRequest', 'scan-id' => scan_id)) if r.success ScanSummary.parse(r.res.elements['//ScanSummary']) else false end end
ruby
def scan_statistics(scan_id) r = execute(make_xml('ScanStatisticsRequest', 'scan-id' => scan_id)) if r.success ScanSummary.parse(r.res.elements['//ScanSummary']) else false end end
[ "def", "scan_statistics", "(", "scan_id", ")", "r", "=", "execute", "(", "make_xml", "(", "'ScanStatisticsRequest'", ",", "'scan-id'", "=>", "scan_id", ")", ")", "if", "r", ".", "success", "ScanSummary", ".", "parse", "(", "r", ".", "res", ".", "elements", "[", "'//ScanSummary'", "]", ")", "else", "false", "end", "end" ]
Get scan statistics, including node and vulnerability breakdowns. @param [Fixnum] scan_id Scan ID to retrieve statistics for. @return [ScanSummary] ScanSummary object providing statistics for the scan.
[ "Get", "scan", "statistics", "including", "node", "and", "vulnerability", "breakdowns", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L353-L360
18,824
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.past_scans
def past_scans(limit = nil) uri = '/data/scan/global/scan-history' rows = AJAX.row_pref_of(limit) params = { 'sort' => 'endTime', 'dir' => 'DESC', 'startIndex' => 0 } AJAX.preserving_preference(self, 'global-completed-scans') do data = DataTable._get_json_table(self, uri, params, rows, limit) data.map(&CompletedScan.method(:parse_json)) end end
ruby
def past_scans(limit = nil) uri = '/data/scan/global/scan-history' rows = AJAX.row_pref_of(limit) params = { 'sort' => 'endTime', 'dir' => 'DESC', 'startIndex' => 0 } AJAX.preserving_preference(self, 'global-completed-scans') do data = DataTable._get_json_table(self, uri, params, rows, limit) data.map(&CompletedScan.method(:parse_json)) end end
[ "def", "past_scans", "(", "limit", "=", "nil", ")", "uri", "=", "'/data/scan/global/scan-history'", "rows", "=", "AJAX", ".", "row_pref_of", "(", "limit", ")", "params", "=", "{", "'sort'", "=>", "'endTime'", ",", "'dir'", "=>", "'DESC'", ",", "'startIndex'", "=>", "0", "}", "AJAX", ".", "preserving_preference", "(", "self", ",", "'global-completed-scans'", ")", "do", "data", "=", "DataTable", ".", "_get_json_table", "(", "self", ",", "uri", ",", "params", ",", "rows", ",", "limit", ")", "data", ".", "map", "(", "CompletedScan", ".", "method", "(", ":parse_json", ")", ")", "end", "end" ]
Get a history of past scans for this console, sorted by most recent first. Please note that for consoles with a deep history of scanning, this method could return an excessive amount of data (and take quite a bit of time to retrieve). Consider limiting the amount of data with the optional argument. @param [Fixnum] limit The maximum number of records to return from this call. @return [Array[CompletedScan]] List of completed scans, ordered by most recently completed first.
[ "Get", "a", "history", "of", "past", "scans", "for", "this", "console", "sorted", "by", "most", "recent", "first", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L372-L380
18,825
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.paused_scans
def paused_scans(site_id = nil, limit = nil) if site_id uri = "/data/scan/site/#{site_id}?status=active" rows = AJAX.row_pref_of(limit) params = { 'sort' => 'endTime', 'dir' => 'DESC', 'startIndex' => 0 } AJAX.preserving_preference(self, 'site-active-scans') do data = DataTable._get_json_table(self, uri, params, rows, limit).select { |scan| scan['paused'] } data.map(&ActiveScan.method(:parse_json)) end else uri = '/data/site/scans/dyntable.xml?printDocType=0&tableID=siteScansTable&activeOnly=true' data = DataTable._get_dyn_table(self, uri).select { |scan| (scan['Status'].include? 'Paused') } data.map(&ActiveScan.method(:parse_dyntable)) end end
ruby
def paused_scans(site_id = nil, limit = nil) if site_id uri = "/data/scan/site/#{site_id}?status=active" rows = AJAX.row_pref_of(limit) params = { 'sort' => 'endTime', 'dir' => 'DESC', 'startIndex' => 0 } AJAX.preserving_preference(self, 'site-active-scans') do data = DataTable._get_json_table(self, uri, params, rows, limit).select { |scan| scan['paused'] } data.map(&ActiveScan.method(:parse_json)) end else uri = '/data/site/scans/dyntable.xml?printDocType=0&tableID=siteScansTable&activeOnly=true' data = DataTable._get_dyn_table(self, uri).select { |scan| (scan['Status'].include? 'Paused') } data.map(&ActiveScan.method(:parse_dyntable)) end end
[ "def", "paused_scans", "(", "site_id", "=", "nil", ",", "limit", "=", "nil", ")", "if", "site_id", "uri", "=", "\"/data/scan/site/#{site_id}?status=active\"", "rows", "=", "AJAX", ".", "row_pref_of", "(", "limit", ")", "params", "=", "{", "'sort'", "=>", "'endTime'", ",", "'dir'", "=>", "'DESC'", ",", "'startIndex'", "=>", "0", "}", "AJAX", ".", "preserving_preference", "(", "self", ",", "'site-active-scans'", ")", "do", "data", "=", "DataTable", ".", "_get_json_table", "(", "self", ",", "uri", ",", "params", ",", "rows", ",", "limit", ")", ".", "select", "{", "|", "scan", "|", "scan", "[", "'paused'", "]", "}", "data", ".", "map", "(", "ActiveScan", ".", "method", "(", ":parse_json", ")", ")", "end", "else", "uri", "=", "'/data/site/scans/dyntable.xml?printDocType=0&tableID=siteScansTable&activeOnly=true'", "data", "=", "DataTable", ".", "_get_dyn_table", "(", "self", ",", "uri", ")", ".", "select", "{", "|", "scan", "|", "(", "scan", "[", "'Status'", "]", ".", "include?", "'Paused'", ")", "}", "data", ".", "map", "(", "ActiveScan", ".", "method", "(", ":parse_dyntable", ")", ")", "end", "end" ]
Get paused scans. Provide a site ID to get paused scans for a site. With no site ID, all paused scans are returned. @param [Fixnum] site_id Site ID to retrieve paused scans for. @param [Fixnum] limit The maximum number of records to return from this call. @return [Array[ActiveScan]] List of paused scans.
[ "Get", "paused", "scans", ".", "Provide", "a", "site", "ID", "to", "get", "paused", "scans", "for", "a", "site", ".", "With", "no", "site", "ID", "all", "paused", "scans", "are", "returned", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L389-L403
18,826
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.export_scan
def export_scan(scan_id, zip_file = nil) http = AJAX.https(self) headers = { 'Cookie' => "nexposeCCSessionID=#{@session_id}", 'Accept-Encoding' => 'identity' } resp = http.get("/data/scan/#{scan_id}/export", headers) case resp when Net::HTTPSuccess if zip_file ::File.open(zip_file, 'wb') { |file| file.write(resp.body) } else resp.body end when Net::HTTPForbidden raise Nexpose::PermissionError.new(resp) else raise Nexpose::APIError.new(resp, "#{resp.class}: Unrecognized response.") end end
ruby
def export_scan(scan_id, zip_file = nil) http = AJAX.https(self) headers = { 'Cookie' => "nexposeCCSessionID=#{@session_id}", 'Accept-Encoding' => 'identity' } resp = http.get("/data/scan/#{scan_id}/export", headers) case resp when Net::HTTPSuccess if zip_file ::File.open(zip_file, 'wb') { |file| file.write(resp.body) } else resp.body end when Net::HTTPForbidden raise Nexpose::PermissionError.new(resp) else raise Nexpose::APIError.new(resp, "#{resp.class}: Unrecognized response.") end end
[ "def", "export_scan", "(", "scan_id", ",", "zip_file", "=", "nil", ")", "http", "=", "AJAX", ".", "https", "(", "self", ")", "headers", "=", "{", "'Cookie'", "=>", "\"nexposeCCSessionID=#{@session_id}\"", ",", "'Accept-Encoding'", "=>", "'identity'", "}", "resp", "=", "http", ".", "get", "(", "\"/data/scan/#{scan_id}/export\"", ",", "headers", ")", "case", "resp", "when", "Net", "::", "HTTPSuccess", "if", "zip_file", "::", "File", ".", "open", "(", "zip_file", ",", "'wb'", ")", "{", "|", "file", "|", "file", ".", "write", "(", "resp", ".", "body", ")", "}", "else", "resp", ".", "body", "end", "when", "Net", "::", "HTTPForbidden", "raise", "Nexpose", "::", "PermissionError", ".", "new", "(", "resp", ")", "else", "raise", "Nexpose", "::", "APIError", ".", "new", "(", "resp", ",", "\"#{resp.class}: Unrecognized response.\"", ")", "end", "end" ]
Export the data associated with a single scan, and optionally store it in a zip-compressed file under the provided name. @param [Fixnum] scan_id Scan ID to remove data for. @param [String] zip_file Filename to export scan data to. @return [Fixnum] On success, returned the number of bytes written to zip_file, if provided. Otherwise, returns raw ZIP binary data.
[ "Export", "the", "data", "associated", "with", "a", "single", "scan", "and", "optionally", "store", "it", "in", "a", "zip", "-", "compressed", "file", "under", "the", "provided", "name", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L413-L430
18,827
rapid7/nexpose-client
lib/nexpose/scan.rb
Nexpose.Connection.import_scan
def import_scan(site_id, zip_file) data = Rexlite::MIME::Message.new data.add_part(site_id.to_s, nil, nil, 'form-data; name="siteid"') data.add_part(session_id, nil, nil, 'form-data; name="nexposeCCSessionID"') ::File.open(zip_file, 'rb') do |scan| data.add_part(scan.read, 'application/zip', 'binary', "form-data; name=\"scan\"; filename=\"#{zip_file}\"") end post = Net::HTTP::Post.new('/data/scan/import') post.body = data.to_s post.set_content_type('multipart/form-data', boundary: data.bound) # Avoiding AJAX#request, because the data can cause binary dump on error. http = AJAX.https(self) AJAX.headers(self, post) response = http.request(post) case response when Net::HTTPOK response.body.empty? ? response.body : response.body.to_i when Net::HTTPUnauthorized raise Nexpose::PermissionError.new(response) else raise Nexpose::APIError.new(post, response.body) end end
ruby
def import_scan(site_id, zip_file) data = Rexlite::MIME::Message.new data.add_part(site_id.to_s, nil, nil, 'form-data; name="siteid"') data.add_part(session_id, nil, nil, 'form-data; name="nexposeCCSessionID"') ::File.open(zip_file, 'rb') do |scan| data.add_part(scan.read, 'application/zip', 'binary', "form-data; name=\"scan\"; filename=\"#{zip_file}\"") end post = Net::HTTP::Post.new('/data/scan/import') post.body = data.to_s post.set_content_type('multipart/form-data', boundary: data.bound) # Avoiding AJAX#request, because the data can cause binary dump on error. http = AJAX.https(self) AJAX.headers(self, post) response = http.request(post) case response when Net::HTTPOK response.body.empty? ? response.body : response.body.to_i when Net::HTTPUnauthorized raise Nexpose::PermissionError.new(response) else raise Nexpose::APIError.new(post, response.body) end end
[ "def", "import_scan", "(", "site_id", ",", "zip_file", ")", "data", "=", "Rexlite", "::", "MIME", "::", "Message", ".", "new", "data", ".", "add_part", "(", "site_id", ".", "to_s", ",", "nil", ",", "nil", ",", "'form-data; name=\"siteid\"'", ")", "data", ".", "add_part", "(", "session_id", ",", "nil", ",", "nil", ",", "'form-data; name=\"nexposeCCSessionID\"'", ")", "::", "File", ".", "open", "(", "zip_file", ",", "'rb'", ")", "do", "|", "scan", "|", "data", ".", "add_part", "(", "scan", ".", "read", ",", "'application/zip'", ",", "'binary'", ",", "\"form-data; name=\\\"scan\\\"; filename=\\\"#{zip_file}\\\"\"", ")", "end", "post", "=", "Net", "::", "HTTP", "::", "Post", ".", "new", "(", "'/data/scan/import'", ")", "post", ".", "body", "=", "data", ".", "to_s", "post", ".", "set_content_type", "(", "'multipart/form-data'", ",", "boundary", ":", "data", ".", "bound", ")", "# Avoiding AJAX#request, because the data can cause binary dump on error.", "http", "=", "AJAX", ".", "https", "(", "self", ")", "AJAX", ".", "headers", "(", "self", ",", "post", ")", "response", "=", "http", ".", "request", "(", "post", ")", "case", "response", "when", "Net", "::", "HTTPOK", "response", ".", "body", ".", "empty?", "?", "response", ".", "body", ":", "response", ".", "body", ".", "to_i", "when", "Net", "::", "HTTPUnauthorized", "raise", "Nexpose", "::", "PermissionError", ".", "new", "(", "response", ")", "else", "raise", "Nexpose", "::", "APIError", ".", "new", "(", "post", ",", "response", ".", "body", ")", "end", "end" ]
Import scan data into a site. This method is designed to work with export_scan to migrate scan data from one console to another. This method will import the data as if run from a local scan engine. Scan importing is restricted to only importing scans in chronological order. It assumes that it is the latest scan for a given site, and will abort if attempting to import an older scan. @param [Fixnum] site_id Site ID of the site to import the scan into. @param [String] zip_file Path to a previously exported scan archive. @return [Fixnum] The scan ID on success.
[ "Import", "scan", "data", "into", "a", "site", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan.rb#L446-L471
18,828
rapid7/nexpose-client
lib/nexpose/data_table.rb
Nexpose.DataTable._get_json_table
def _get_json_table(console, address, parameters = {}, page_size = 500, records = nil, post = true) parameters['dir'] = 'DESC' parameters['startIndex'] = -1 parameters['results'] = -1 if post request = lambda { |p| AJAX.form_post(console, address, p) } else request = lambda { |p| AJAX.get(console, address.dup, AJAX::CONTENT_TYPE::JSON, p) } end response = request.call(parameters) data = JSON.parse(response) # Don't attept to grab more records than there are. total = data['totalRecords'] return [] if total.zero? total = records.nil? ? total : [records, total].min rows = [] parameters['results'] = page_size while rows.length < total parameters['startIndex'] = rows.length data = JSON.parse(request.call(parameters)) rows.concat data['records'] end rows end
ruby
def _get_json_table(console, address, parameters = {}, page_size = 500, records = nil, post = true) parameters['dir'] = 'DESC' parameters['startIndex'] = -1 parameters['results'] = -1 if post request = lambda { |p| AJAX.form_post(console, address, p) } else request = lambda { |p| AJAX.get(console, address.dup, AJAX::CONTENT_TYPE::JSON, p) } end response = request.call(parameters) data = JSON.parse(response) # Don't attept to grab more records than there are. total = data['totalRecords'] return [] if total.zero? total = records.nil? ? total : [records, total].min rows = [] parameters['results'] = page_size while rows.length < total parameters['startIndex'] = rows.length data = JSON.parse(request.call(parameters)) rows.concat data['records'] end rows end
[ "def", "_get_json_table", "(", "console", ",", "address", ",", "parameters", "=", "{", "}", ",", "page_size", "=", "500", ",", "records", "=", "nil", ",", "post", "=", "true", ")", "parameters", "[", "'dir'", "]", "=", "'DESC'", "parameters", "[", "'startIndex'", "]", "=", "-", "1", "parameters", "[", "'results'", "]", "=", "-", "1", "if", "post", "request", "=", "lambda", "{", "|", "p", "|", "AJAX", ".", "form_post", "(", "console", ",", "address", ",", "p", ")", "}", "else", "request", "=", "lambda", "{", "|", "p", "|", "AJAX", ".", "get", "(", "console", ",", "address", ".", "dup", ",", "AJAX", "::", "CONTENT_TYPE", "::", "JSON", ",", "p", ")", "}", "end", "response", "=", "request", ".", "call", "(", "parameters", ")", "data", "=", "JSON", ".", "parse", "(", "response", ")", "# Don't attept to grab more records than there are.", "total", "=", "data", "[", "'totalRecords'", "]", "return", "[", "]", "if", "total", ".", "zero?", "total", "=", "records", ".", "nil?", "?", "total", ":", "[", "records", ",", "total", "]", ".", "min", "rows", "=", "[", "]", "parameters", "[", "'results'", "]", "=", "page_size", "while", "rows", ".", "length", "<", "total", "parameters", "[", "'startIndex'", "]", "=", "rows", ".", "length", "data", "=", "JSON", ".", "parse", "(", "request", ".", "call", "(", "parameters", ")", ")", "rows", ".", "concat", "data", "[", "'records'", "]", "end", "rows", "end" ]
Helper method to get the YUI tables into a consumable Ruby object. @param [Connection] console API connection to a Nexpose console. @param [String] address Controller address relative to https://host:port @param [Hash] parameters Parameters that need to be sent to the controller The following attributes may need to be provided: 'sort' Column to sort by 'table-id' The ID of the table to get from this controller @param [Fixnum] page_size Number of records to include per page. Value must conform to supported defaults: -1, 10, 25, 50, 100, 500. @param [Fixnum] records number of records to return, gets all if not specified. @param [Boolean] post Whether to use form post or get to retrieve data. @return [Array[Hash]] An array of hashes representing the requested table. Example usage: DataTable._get_json_table(@console, '/data/asset/site', { 'sort' => 'assetName', 'table-id' => 'site-assets', 'siteID' => site_id })
[ "Helper", "method", "to", "get", "the", "YUI", "tables", "into", "a", "consumable", "Ruby", "object", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/data_table.rb#L34-L58
18,829
rapid7/nexpose-client
lib/nexpose/data_table.rb
Nexpose.DataTable._get_dyn_table
def _get_dyn_table(console, address, payload = nil) if payload response = AJAX.post(console, address, payload) else response = AJAX.get(console, address) end response = REXML::Document.new(response) headers = _dyn_headers(response) rows = _dyn_rows(response) rows.map { |row| Hash[headers.zip(row)] } end
ruby
def _get_dyn_table(console, address, payload = nil) if payload response = AJAX.post(console, address, payload) else response = AJAX.get(console, address) end response = REXML::Document.new(response) headers = _dyn_headers(response) rows = _dyn_rows(response) rows.map { |row| Hash[headers.zip(row)] } end
[ "def", "_get_dyn_table", "(", "console", ",", "address", ",", "payload", "=", "nil", ")", "if", "payload", "response", "=", "AJAX", ".", "post", "(", "console", ",", "address", ",", "payload", ")", "else", "response", "=", "AJAX", ".", "get", "(", "console", ",", "address", ")", "end", "response", "=", "REXML", "::", "Document", ".", "new", "(", "response", ")", "headers", "=", "_dyn_headers", "(", "response", ")", "rows", "=", "_dyn_rows", "(", "response", ")", "rows", ".", "map", "{", "|", "row", "|", "Hash", "[", "headers", ".", "zip", "(", "row", ")", "]", "}", "end" ]
Helper method to get a Dyntable into a consumable Ruby object. @param [Connection] console API connection to a Nexpose console. @param [String] address Tag address with parameters relative to https://host:port @return [Array[Hash]] array of hashes representing the requested table. Example usage: DataTable._get_dyn_table(@console, '/data/asset/os/dyntable.xml?tableID=OSSynopsisTable')
[ "Helper", "method", "to", "get", "a", "Dyntable", "into", "a", "consumable", "Ruby", "object", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/data_table.rb#L70-L81
18,830
rapid7/nexpose-client
lib/nexpose/data_table.rb
Nexpose.DataTable._dyn_headers
def _dyn_headers(response) headers = [] response.elements.each('DynTable/MetaData/Column') do |header| headers << header.attributes['name'] end headers end
ruby
def _dyn_headers(response) headers = [] response.elements.each('DynTable/MetaData/Column') do |header| headers << header.attributes['name'] end headers end
[ "def", "_dyn_headers", "(", "response", ")", "headers", "=", "[", "]", "response", ".", "elements", ".", "each", "(", "'DynTable/MetaData/Column'", ")", "do", "|", "header", "|", "headers", "<<", "header", ".", "attributes", "[", "'name'", "]", "end", "headers", "end" ]
Parse headers out of a dyntable response.
[ "Parse", "headers", "out", "of", "a", "dyntable", "response", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/data_table.rb#L84-L90
18,831
rapid7/nexpose-client
lib/nexpose/data_table.rb
Nexpose.DataTable._dyn_rows
def _dyn_rows(response) rows = [] response.elements.each('DynTable/Data/tr') do |row| rows << _dyn_record(row) end rows end
ruby
def _dyn_rows(response) rows = [] response.elements.each('DynTable/Data/tr') do |row| rows << _dyn_record(row) end rows end
[ "def", "_dyn_rows", "(", "response", ")", "rows", "=", "[", "]", "response", ".", "elements", ".", "each", "(", "'DynTable/Data/tr'", ")", "do", "|", "row", "|", "rows", "<<", "_dyn_record", "(", "row", ")", "end", "rows", "end" ]
Parse rows out of a dyntable into an array of values.
[ "Parse", "rows", "out", "of", "a", "dyntable", "into", "an", "array", "of", "values", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/data_table.rb#L93-L99
18,832
rapid7/nexpose-client
lib/nexpose/data_table.rb
Nexpose.DataTable._dyn_record
def _dyn_record(row) record = [] row.elements.each('td') do |value| record << (value.text ? value.text.to_s : '') end record end
ruby
def _dyn_record(row) record = [] row.elements.each('td') do |value| record << (value.text ? value.text.to_s : '') end record end
[ "def", "_dyn_record", "(", "row", ")", "record", "=", "[", "]", "row", ".", "elements", ".", "each", "(", "'td'", ")", "do", "|", "value", "|", "record", "<<", "(", "value", ".", "text", "?", "value", ".", "text", ".", "to_s", ":", "''", ")", "end", "record", "end" ]
Parse records out of the row of a dyntable.
[ "Parse", "records", "out", "of", "the", "row", "of", "a", "dyntable", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/data_table.rb#L102-L108
18,833
rapid7/nexpose-client
lib/nexpose/report_template.rb
Nexpose.Connection.list_report_templates
def list_report_templates r = execute(make_xml('ReportTemplateListingRequest', {})) templates = [] if r.success r.res.elements.each('//ReportTemplateSummary') do |template| templates << ReportTemplateSummary.parse(template) end end templates end
ruby
def list_report_templates r = execute(make_xml('ReportTemplateListingRequest', {})) templates = [] if r.success r.res.elements.each('//ReportTemplateSummary') do |template| templates << ReportTemplateSummary.parse(template) end end templates end
[ "def", "list_report_templates", "r", "=", "execute", "(", "make_xml", "(", "'ReportTemplateListingRequest'", ",", "{", "}", ")", ")", "templates", "=", "[", "]", "if", "r", ".", "success", "r", ".", "res", ".", "elements", ".", "each", "(", "'//ReportTemplateSummary'", ")", "do", "|", "template", "|", "templates", "<<", "ReportTemplateSummary", ".", "parse", "(", "template", ")", "end", "end", "templates", "end" ]
Provide a list of all report templates the user can access on the Security Console. @return [Array[ReportTemplateSummary]] List of current report templates.
[ "Provide", "a", "list", "of", "all", "report", "templates", "the", "user", "can", "access", "on", "the", "Security", "Console", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/report_template.rb#L11-L20
18,834
rapid7/nexpose-client
lib/nexpose/report_template.rb
Nexpose.ReportTemplate.save
def save(connection) xml = %(<ReportTemplateSaveRequest session-id='#{connection.session_id}' scope='#{@scope}'>) xml << to_xml xml << '</ReportTemplateSaveRequest>' response = connection.execute(xml) if response.success @id = response.attributes['template-id'] end end
ruby
def save(connection) xml = %(<ReportTemplateSaveRequest session-id='#{connection.session_id}' scope='#{@scope}'>) xml << to_xml xml << '</ReportTemplateSaveRequest>' response = connection.execute(xml) if response.success @id = response.attributes['template-id'] end end
[ "def", "save", "(", "connection", ")", "xml", "=", "%(<ReportTemplateSaveRequest session-id='#{connection.session_id}' scope='#{@scope}'>)", "xml", "<<", "to_xml", "xml", "<<", "'</ReportTemplateSaveRequest>'", "response", "=", "connection", ".", "execute", "(", "xml", ")", "if", "response", ".", "success", "@id", "=", "response", ".", "attributes", "[", "'template-id'", "]", "end", "end" ]
Save the configuration for a report template.
[ "Save", "the", "configuration", "for", "a", "report", "template", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/report_template.rb#L128-L136
18,835
rapid7/nexpose-client
lib/nexpose/api.rb
Nexpose.APIObject.object_from_hash
def object_from_hash(nsc, hash) hash.each do |k, v| next if k == :url # Do not store self-referential URL. # Store resource URLs separately and create lazy accessors. if v.is_a?(Hash) && v.key?(:url) self.class.send(:define_method, k, proc { |conn = nsc| load_resource(conn, k, v[:url].gsub(/.*\/api/, '/api')) }) else # Convert timestamps. if v.is_a?(String) && v.match(/^\d{8}T\d{6}\.\d{3}/) instance_variable_set("@#{k}", ISO8601.to_time(v)) elsif v.is_a?(Array) && k == :attributes instance_variable_set("@#{k}", v.map { |h| { h[:key] => h[:value] } }) else instance_variable_set("@#{k}", v) end self.class.send(:define_method, k, proc { instance_variable_get("@#{k}") }) end end self end
ruby
def object_from_hash(nsc, hash) hash.each do |k, v| next if k == :url # Do not store self-referential URL. # Store resource URLs separately and create lazy accessors. if v.is_a?(Hash) && v.key?(:url) self.class.send(:define_method, k, proc { |conn = nsc| load_resource(conn, k, v[:url].gsub(/.*\/api/, '/api')) }) else # Convert timestamps. if v.is_a?(String) && v.match(/^\d{8}T\d{6}\.\d{3}/) instance_variable_set("@#{k}", ISO8601.to_time(v)) elsif v.is_a?(Array) && k == :attributes instance_variable_set("@#{k}", v.map { |h| { h[:key] => h[:value] } }) else instance_variable_set("@#{k}", v) end self.class.send(:define_method, k, proc { instance_variable_get("@#{k}") }) end end self end
[ "def", "object_from_hash", "(", "nsc", ",", "hash", ")", "hash", ".", "each", "do", "|", "k", ",", "v", "|", "next", "if", "k", "==", ":url", "# Do not store self-referential URL.", "# Store resource URLs separately and create lazy accessors.", "if", "v", ".", "is_a?", "(", "Hash", ")", "&&", "v", ".", "key?", "(", ":url", ")", "self", ".", "class", ".", "send", "(", ":define_method", ",", "k", ",", "proc", "{", "|", "conn", "=", "nsc", "|", "load_resource", "(", "conn", ",", "k", ",", "v", "[", ":url", "]", ".", "gsub", "(", "/", "\\/", "/", ",", "'/api'", ")", ")", "}", ")", "else", "# Convert timestamps.", "if", "v", ".", "is_a?", "(", "String", ")", "&&", "v", ".", "match", "(", "/", "\\d", "\\d", "\\.", "\\d", "/", ")", "instance_variable_set", "(", "\"@#{k}\"", ",", "ISO8601", ".", "to_time", "(", "v", ")", ")", "elsif", "v", ".", "is_a?", "(", "Array", ")", "&&", "k", "==", ":attributes", "instance_variable_set", "(", "\"@#{k}\"", ",", "v", ".", "map", "{", "|", "h", "|", "{", "h", "[", ":key", "]", "=>", "h", "[", ":value", "]", "}", "}", ")", "else", "instance_variable_set", "(", "\"@#{k}\"", ",", "v", ")", "end", "self", ".", "class", ".", "send", "(", ":define_method", ",", "k", ",", "proc", "{", "instance_variable_get", "(", "\"@#{k}\"", ")", "}", ")", "end", "end", "self", "end" ]
Populate object methods and attributes from a JSON-derived hash. @param [Nexpose::Connection] nsc Active connection to a console. @param [Hash] hash Result of running JSON#parse with the symbolize_names parameter to a 2.0 API response. Pass hash[:resources] if the response is pageable.
[ "Populate", "object", "methods", "and", "attributes", "from", "a", "JSON", "-", "derived", "hash", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/api.rb#L23-L42
18,836
rapid7/nexpose-client
lib/nexpose/api.rb
Nexpose.APIObject.load_resource
def load_resource(nsc, k, url) obj = class_from_string(k) resp = AJAX.get(nsc, url, AJAX::CONTENT_TYPE::JSON) hash = JSON.parse(resp, symbolize_names: true) if hash.is_a?(Array) resources = hash.map { |e| obj.method(:new).call.object_from_hash(nsc, e) } elsif hash.key?(:resources) resources = hash[:resources].map { |e| obj.method(:new).call.object_from_hash(nsc, e) } else resources = obj.method(:new).call.object_from_hash(nsc, hash) end instance_variable_set("@#{k}", resources) self.class.send(:define_method, k, proc { instance_variable_get("@#{k}") }) resources end
ruby
def load_resource(nsc, k, url) obj = class_from_string(k) resp = AJAX.get(nsc, url, AJAX::CONTENT_TYPE::JSON) hash = JSON.parse(resp, symbolize_names: true) if hash.is_a?(Array) resources = hash.map { |e| obj.method(:new).call.object_from_hash(nsc, e) } elsif hash.key?(:resources) resources = hash[:resources].map { |e| obj.method(:new).call.object_from_hash(nsc, e) } else resources = obj.method(:new).call.object_from_hash(nsc, hash) end instance_variable_set("@#{k}", resources) self.class.send(:define_method, k, proc { instance_variable_get("@#{k}") }) resources end
[ "def", "load_resource", "(", "nsc", ",", "k", ",", "url", ")", "obj", "=", "class_from_string", "(", "k", ")", "resp", "=", "AJAX", ".", "get", "(", "nsc", ",", "url", ",", "AJAX", "::", "CONTENT_TYPE", "::", "JSON", ")", "hash", "=", "JSON", ".", "parse", "(", "resp", ",", "symbolize_names", ":", "true", ")", "if", "hash", ".", "is_a?", "(", "Array", ")", "resources", "=", "hash", ".", "map", "{", "|", "e", "|", "obj", ".", "method", "(", ":new", ")", ".", "call", ".", "object_from_hash", "(", "nsc", ",", "e", ")", "}", "elsif", "hash", ".", "key?", "(", ":resources", ")", "resources", "=", "hash", "[", ":resources", "]", ".", "map", "{", "|", "e", "|", "obj", ".", "method", "(", ":new", ")", ".", "call", ".", "object_from_hash", "(", "nsc", ",", "e", ")", "}", "else", "resources", "=", "obj", ".", "method", "(", ":new", ")", ".", "call", ".", "object_from_hash", "(", "nsc", ",", "hash", ")", "end", "instance_variable_set", "(", "\"@#{k}\"", ",", "resources", ")", "self", ".", "class", ".", "send", "(", ":define_method", ",", "k", ",", "proc", "{", "instance_variable_get", "(", "\"@#{k}\"", ")", "}", ")", "resources", "end" ]
Load a resource from the security console. Once loaded, the value is cached so that it need not be loaded again. @param [Connection] nsc Active connection to the console. @param [Symbol] k Original key name, used to identify the class to load. @param [String] url Truncated URL to use to retrieve the resource. @return [Array[?]] Collection of "k" marshalled object.
[ "Load", "a", "resource", "from", "the", "security", "console", ".", "Once", "loaded", "the", "value", "is", "cached", "so", "that", "it", "need", "not", "be", "loaded", "again", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/api.rb#L54-L68
18,837
rapid7/nexpose-client
lib/nexpose/api.rb
Nexpose.APIObject.class_from_string
def class_from_string(field) str = field.to_s.split('_').map(&:capitalize!).join str = 'Vulnerability' if str == 'Vulnerabilities' str.chop! if str.end_with?('s') Object.const_get('Nexpose').const_get(str) end
ruby
def class_from_string(field) str = field.to_s.split('_').map(&:capitalize!).join str = 'Vulnerability' if str == 'Vulnerabilities' str.chop! if str.end_with?('s') Object.const_get('Nexpose').const_get(str) end
[ "def", "class_from_string", "(", "field", ")", "str", "=", "field", ".", "to_s", ".", "split", "(", "'_'", ")", ".", "map", "(", ":capitalize!", ")", ".", "join", "str", "=", "'Vulnerability'", "if", "str", "==", "'Vulnerabilities'", "str", ".", "chop!", "if", "str", ".", "end_with?", "(", "'s'", ")", "Object", ".", "const_get", "(", "'Nexpose'", ")", ".", "const_get", "(", "str", ")", "end" ]
Get the class referred to by a field name. For example, this method will translate a field name like "malware_kits" into to corresponding MalwareKit class. @param [String] field Snake-case name of a field. @return [Class] Class associated with the provided field.
[ "Get", "the", "class", "referred", "to", "by", "a", "field", "name", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/api.rb#L78-L83
18,838
rapid7/nexpose-client
lib/nexpose/dag.rb
Nexpose.DynamicAssetGroup.save
def save(nsc) # load includes admin users, but save will fail if they are included. admins = nsc.users.select { |u| u.is_admin }.map { |u| u.id } @users.reject! { |id| admins.member? id } params = @id ? { 'entityid' => @id, 'mode' => 'edit' } : { 'entityid' => false, 'mode' => false } uri = AJAX.parameterize_uri('/data/assetGroup/saveAssetGroup', params) data = JSON.parse(AJAX.post(nsc, uri, _to_entity_details, AJAX::CONTENT_TYPE::JSON)) data['response'] == 'success.' end
ruby
def save(nsc) # load includes admin users, but save will fail if they are included. admins = nsc.users.select { |u| u.is_admin }.map { |u| u.id } @users.reject! { |id| admins.member? id } params = @id ? { 'entityid' => @id, 'mode' => 'edit' } : { 'entityid' => false, 'mode' => false } uri = AJAX.parameterize_uri('/data/assetGroup/saveAssetGroup', params) data = JSON.parse(AJAX.post(nsc, uri, _to_entity_details, AJAX::CONTENT_TYPE::JSON)) data['response'] == 'success.' end
[ "def", "save", "(", "nsc", ")", "# load includes admin users, but save will fail if they are included.", "admins", "=", "nsc", ".", "users", ".", "select", "{", "|", "u", "|", "u", ".", "is_admin", "}", ".", "map", "{", "|", "u", "|", "u", ".", "id", "}", "@users", ".", "reject!", "{", "|", "id", "|", "admins", ".", "member?", "id", "}", "params", "=", "@id", "?", "{", "'entityid'", "=>", "@id", ",", "'mode'", "=>", "'edit'", "}", ":", "{", "'entityid'", "=>", "false", ",", "'mode'", "=>", "false", "}", "uri", "=", "AJAX", ".", "parameterize_uri", "(", "'/data/assetGroup/saveAssetGroup'", ",", "params", ")", "data", "=", "JSON", ".", "parse", "(", "AJAX", ".", "post", "(", "nsc", ",", "uri", ",", "_to_entity_details", ",", "AJAX", "::", "CONTENT_TYPE", "::", "JSON", ")", ")", "data", "[", "'response'", "]", "==", "'success.'", "end" ]
Save this dynamic asset group to the Nexpose console. Warning, saving this object does not set the id. It must be retrieved independently. @param [Connection] nsc Connection to a security console. @return [Boolean] Whether the group was successfully saved.
[ "Save", "this", "dynamic", "asset", "group", "to", "the", "Nexpose", "console", ".", "Warning", "saving", "this", "object", "does", "not", "set", "the", "id", ".", "It", "must", "be", "retrieved", "independently", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/dag.rb#L30-L38
18,839
rapid7/nexpose-client
lib/nexpose/pool.rb
Nexpose.Connection.list_engine_pools
def list_engine_pools response = execute(make_xml('EnginePoolListingRequest'), '1.2') arr = [] if response.success response.res.elements.each('EnginePoolListingResponse/EnginePoolSummary') do |pool| arr << EnginePoolSummary.new(pool.attributes['id'], pool.attributes['name'], pool.attributes['scope']) end end arr end
ruby
def list_engine_pools response = execute(make_xml('EnginePoolListingRequest'), '1.2') arr = [] if response.success response.res.elements.each('EnginePoolListingResponse/EnginePoolSummary') do |pool| arr << EnginePoolSummary.new(pool.attributes['id'], pool.attributes['name'], pool.attributes['scope']) end end arr end
[ "def", "list_engine_pools", "response", "=", "execute", "(", "make_xml", "(", "'EnginePoolListingRequest'", ")", ",", "'1.2'", ")", "arr", "=", "[", "]", "if", "response", ".", "success", "response", ".", "res", ".", "elements", ".", "each", "(", "'EnginePoolListingResponse/EnginePoolSummary'", ")", "do", "|", "pool", "|", "arr", "<<", "EnginePoolSummary", ".", "new", "(", "pool", ".", "attributes", "[", "'id'", "]", ",", "pool", ".", "attributes", "[", "'name'", "]", ",", "pool", ".", "attributes", "[", "'scope'", "]", ")", "end", "end", "arr", "end" ]
Retrieve a list of all Scan Engine Pools managed by the Security Console. @return [Array[EnginePoolSummary]] Array of EnginePoolSummary objects associated with each engine associated with this security console.
[ "Retrieve", "a", "list", "of", "all", "Scan", "Engine", "Pools", "managed", "by", "the", "Security", "Console", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/pool.rb#L11-L22
18,840
rapid7/nexpose-client
lib/nexpose/pool.rb
Nexpose.EnginePool.save
def save(connection) request = @id > 0 ? 'EnginePoolUpdateRequest' : 'EnginePoolCreateRequest' xml = %(<#{request} session-id="#{connection.session_id}">) xml << '<EnginePool' xml << %( id="#{@id}") if @id > 0 xml << %( name="#{@name}" scope="#{@scope}">) @engines.each do |engine| xml << %(<Engine name="#{engine.name}" />) end xml << '</EnginePool>' xml << %(</#{request}>) r = connection.execute(xml, '1.2') if r.success r.res.elements.each(request.gsub('Request', 'Response')) do |v| return @id = v.attributes['id'].to_i end end end
ruby
def save(connection) request = @id > 0 ? 'EnginePoolUpdateRequest' : 'EnginePoolCreateRequest' xml = %(<#{request} session-id="#{connection.session_id}">) xml << '<EnginePool' xml << %( id="#{@id}") if @id > 0 xml << %( name="#{@name}" scope="#{@scope}">) @engines.each do |engine| xml << %(<Engine name="#{engine.name}" />) end xml << '</EnginePool>' xml << %(</#{request}>) r = connection.execute(xml, '1.2') if r.success r.res.elements.each(request.gsub('Request', 'Response')) do |v| return @id = v.attributes['id'].to_i end end end
[ "def", "save", "(", "connection", ")", "request", "=", "@id", ">", "0", "?", "'EnginePoolUpdateRequest'", ":", "'EnginePoolCreateRequest'", "xml", "=", "%(<#{request} session-id=\"#{connection.session_id}\">)", "xml", "<<", "'<EnginePool'", "xml", "<<", "%( id=\"#{@id}\")", "if", "@id", ">", "0", "xml", "<<", "%( name=\"#{@name}\" scope=\"#{@scope}\">)", "@engines", ".", "each", "do", "|", "engine", "|", "xml", "<<", "%(<Engine name=\"#{engine.name}\" />)", "end", "xml", "<<", "'</EnginePool>'", "xml", "<<", "%(</#{request}>)", "r", "=", "connection", ".", "execute", "(", "xml", ",", "'1.2'", ")", "if", "r", ".", "success", "r", ".", "res", ".", "elements", ".", "each", "(", "request", ".", "gsub", "(", "'Request'", ",", "'Response'", ")", ")", "do", "|", "v", "|", "return", "@id", "=", "v", ".", "attributes", "[", "'id'", "]", ".", "to_i", "end", "end", "end" ]
Save an engine pool to a security console. @param [Connection] connection Connection to console where site exists.
[ "Save", "an", "engine", "pool", "to", "a", "security", "console", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/pool.rb#L129-L147
18,841
rapid7/nexpose-client
lib/nexpose/site.rb
Nexpose.Connection.list_sites
def list_sites r = execute(make_xml('SiteListingRequest')) arr = [] if r.success r.res.elements.each('SiteListingResponse/SiteSummary') do |site| arr << SiteSummary.new(site.attributes['id'].to_i, site.attributes['name'], site.attributes['description'], site.attributes['riskfactor'].to_f, site.attributes['riskscore'].to_f) end end arr end
ruby
def list_sites r = execute(make_xml('SiteListingRequest')) arr = [] if r.success r.res.elements.each('SiteListingResponse/SiteSummary') do |site| arr << SiteSummary.new(site.attributes['id'].to_i, site.attributes['name'], site.attributes['description'], site.attributes['riskfactor'].to_f, site.attributes['riskscore'].to_f) end end arr end
[ "def", "list_sites", "r", "=", "execute", "(", "make_xml", "(", "'SiteListingRequest'", ")", ")", "arr", "=", "[", "]", "if", "r", ".", "success", "r", ".", "res", ".", "elements", ".", "each", "(", "'SiteListingResponse/SiteSummary'", ")", "do", "|", "site", "|", "arr", "<<", "SiteSummary", ".", "new", "(", "site", ".", "attributes", "[", "'id'", "]", ".", "to_i", ",", "site", ".", "attributes", "[", "'name'", "]", ",", "site", ".", "attributes", "[", "'description'", "]", ",", "site", ".", "attributes", "[", "'riskfactor'", "]", ".", "to_f", ",", "site", ".", "attributes", "[", "'riskscore'", "]", ".", "to_f", ")", "end", "end", "arr", "end" ]
Retrieve a list of all sites the user is authorized to view or manage. @return [Array[SiteSummary]] Array of SiteSummary objects.
[ "Retrieve", "a", "list", "of", "all", "sites", "the", "user", "is", "authorized", "to", "view", "or", "manage", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/site.rb#L10-L23
18,842
rapid7/nexpose-client
lib/nexpose/site.rb
Nexpose.Connection.site_scan_history
def site_scan_history(site_id) r = execute(make_xml('SiteScanHistoryRequest', { 'site-id' => site_id })) scans = [] if r.success r.res.elements.each('SiteScanHistoryResponse/ScanSummary') do |scan_event| scans << ScanSummary.parse(scan_event) end end scans end
ruby
def site_scan_history(site_id) r = execute(make_xml('SiteScanHistoryRequest', { 'site-id' => site_id })) scans = [] if r.success r.res.elements.each('SiteScanHistoryResponse/ScanSummary') do |scan_event| scans << ScanSummary.parse(scan_event) end end scans end
[ "def", "site_scan_history", "(", "site_id", ")", "r", "=", "execute", "(", "make_xml", "(", "'SiteScanHistoryRequest'", ",", "{", "'site-id'", "=>", "site_id", "}", ")", ")", "scans", "=", "[", "]", "if", "r", ".", "success", "r", ".", "res", ".", "elements", ".", "each", "(", "'SiteScanHistoryResponse/ScanSummary'", ")", "do", "|", "scan_event", "|", "scans", "<<", "ScanSummary", ".", "parse", "(", "scan_event", ")", "end", "end", "scans", "end" ]
Retrieve a list of all previous scans of the site. @param [FixNum] site_id Site ID to request scan history for. @return [Array[ScanSummary]] Array of ScanSummary objects representing each scan run to date on the site provided.
[ "Retrieve", "a", "list", "of", "all", "previous", "scans", "of", "the", "site", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/site.rb#L42-L51
18,843
rapid7/nexpose-client
lib/nexpose/site.rb
Nexpose.Connection.completed_scans
def completed_scans(site_id) table = { 'table-id' => 'site-completed-scans' } data = DataTable._get_json_table(self, "/data/scan/site/#{site_id}", table) data.map(&CompletedScan.method(:parse_json)) end
ruby
def completed_scans(site_id) table = { 'table-id' => 'site-completed-scans' } data = DataTable._get_json_table(self, "/data/scan/site/#{site_id}", table) data.map(&CompletedScan.method(:parse_json)) end
[ "def", "completed_scans", "(", "site_id", ")", "table", "=", "{", "'table-id'", "=>", "'site-completed-scans'", "}", "data", "=", "DataTable", ".", "_get_json_table", "(", "self", ",", "\"/data/scan/site/#{site_id}\"", ",", "table", ")", "data", ".", "map", "(", "CompletedScan", ".", "method", "(", ":parse_json", ")", ")", "end" ]
Retrieve a history of the completed scans for a given site. @param [FixNum] site_id Site ID to find scans for. @return [CompletedScan] details of the completed scans for the site.
[ "Retrieve", "a", "history", "of", "the", "completed", "scans", "for", "a", "given", "site", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/site.rb#L70-L74
18,844
rapid7/nexpose-client
lib/nexpose/site.rb
Nexpose.Site.remove_included_ip_range
def remove_included_ip_range(from, to) from_ip = IPAddr.new(from) to_ip = IPAddr.new(to) (from_ip..to_ip) raise 'Invalid IP range specified' if (from_ip..to_ip).to_a.size.zero? @included_scan_targets[:addresses].reject! { |t| t.eql? IPRange.new(from, to) } rescue ArgumentError => e raise "#{e.message} in given IP range" end
ruby
def remove_included_ip_range(from, to) from_ip = IPAddr.new(from) to_ip = IPAddr.new(to) (from_ip..to_ip) raise 'Invalid IP range specified' if (from_ip..to_ip).to_a.size.zero? @included_scan_targets[:addresses].reject! { |t| t.eql? IPRange.new(from, to) } rescue ArgumentError => e raise "#{e.message} in given IP range" end
[ "def", "remove_included_ip_range", "(", "from", ",", "to", ")", "from_ip", "=", "IPAddr", ".", "new", "(", "from", ")", "to_ip", "=", "IPAddr", ".", "new", "(", "to", ")", "(", "from_ip", "..", "to_ip", ")", "raise", "'Invalid IP range specified'", "if", "(", "from_ip", "..", "to_ip", ")", ".", "to_a", ".", "size", ".", "zero?", "@included_scan_targets", "[", ":addresses", "]", ".", "reject!", "{", "|", "t", "|", "t", ".", "eql?", "IPRange", ".", "new", "(", "from", ",", "to", ")", "}", "rescue", "ArgumentError", "=>", "e", "raise", "\"#{e.message} in given IP range\"", "end" ]
Remove assets to this site by IP address range. @param [String] from Beginning IP address of a range. @param [String] to Ending IP address of a range.
[ "Remove", "assets", "to", "this", "site", "by", "IP", "address", "range", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/site.rb#L254-L262
18,845
rapid7/nexpose-client
lib/nexpose/site.rb
Nexpose.Site.exclude_ip_range
def exclude_ip_range(from, to) from_ip = IPAddr.new(from) to_ip = IPAddr.new(to) (from_ip..to_ip) raise 'Invalid IP range specified' if (from_ip..to_ip).to_a.size.zero? @excluded_scan_targets[:addresses] << IPRange.new(from, to) rescue ArgumentError => e raise "#{e.message} in given IP range" end
ruby
def exclude_ip_range(from, to) from_ip = IPAddr.new(from) to_ip = IPAddr.new(to) (from_ip..to_ip) raise 'Invalid IP range specified' if (from_ip..to_ip).to_a.size.zero? @excluded_scan_targets[:addresses] << IPRange.new(from, to) rescue ArgumentError => e raise "#{e.message} in given IP range" end
[ "def", "exclude_ip_range", "(", "from", ",", "to", ")", "from_ip", "=", "IPAddr", ".", "new", "(", "from", ")", "to_ip", "=", "IPAddr", ".", "new", "(", "to", ")", "(", "from_ip", "..", "to_ip", ")", "raise", "'Invalid IP range specified'", "if", "(", "from_ip", "..", "to_ip", ")", ".", "to_a", ".", "size", ".", "zero?", "@excluded_scan_targets", "[", ":addresses", "]", "<<", "IPRange", ".", "new", "(", "from", ",", "to", ")", "rescue", "ArgumentError", "=>", "e", "raise", "\"#{e.message} in given IP range\"", "end" ]
Adds assets to this site excluded scan targets by IP address range. @param [String] from Beginning IP address of a range. @param [String] to Ending IP address of a range.
[ "Adds", "assets", "to", "this", "site", "excluded", "scan", "targets", "by", "IP", "address", "range", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/site.rb#L286-L294
18,846
rapid7/nexpose-client
lib/nexpose/site.rb
Nexpose.Site.remove_included_asset_group
def remove_included_asset_group(asset_group_id) validate_asset_group(asset_group_id) @included_scan_targets[:asset_groups].reject! { |t| t.eql? asset_group_id.to_i } end
ruby
def remove_included_asset_group(asset_group_id) validate_asset_group(asset_group_id) @included_scan_targets[:asset_groups].reject! { |t| t.eql? asset_group_id.to_i } end
[ "def", "remove_included_asset_group", "(", "asset_group_id", ")", "validate_asset_group", "(", "asset_group_id", ")", "@included_scan_targets", "[", ":asset_groups", "]", ".", "reject!", "{", "|", "t", "|", "t", ".", "eql?", "asset_group_id", ".", "to_i", "}", "end" ]
Adds an asset group ID to this site included scan targets. @param [Integer] asset_group_id Identifier of an assetGroupID.
[ "Adds", "an", "asset", "group", "ID", "to", "this", "site", "included", "scan", "targets", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/site.rb#L341-L344
18,847
rapid7/nexpose-client
lib/nexpose/site.rb
Nexpose.Site.remove_excluded_asset_group
def remove_excluded_asset_group(asset_group_id) validate_asset_group(asset_group_id) @excluded_scan_targets[:asset_groups].reject! { |t| t.eql? asset_group_id.to_i } end
ruby
def remove_excluded_asset_group(asset_group_id) validate_asset_group(asset_group_id) @excluded_scan_targets[:asset_groups].reject! { |t| t.eql? asset_group_id.to_i } end
[ "def", "remove_excluded_asset_group", "(", "asset_group_id", ")", "validate_asset_group", "(", "asset_group_id", ")", "@excluded_scan_targets", "[", ":asset_groups", "]", ".", "reject!", "{", "|", "t", "|", "t", ".", "eql?", "asset_group_id", ".", "to_i", "}", "end" ]
Adds an asset group ID to this site excluded scan targets. @param [Integer] asset_group_id Identifier of an assetGroupID.
[ "Adds", "an", "asset", "group", "ID", "to", "this", "site", "excluded", "scan", "targets", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/site.rb#L359-L362
18,848
rapid7/nexpose-client
lib/nexpose/site.rb
Nexpose.Site.scan
def scan(connection, sync_id = nil, blackout_override = false) xml = REXML::Element.new('SiteScanRequest') xml.add_attributes({ 'session-id' => connection.session_id, 'site-id' => @id, 'sync-id' => sync_id }) xml.add_attributes({ 'force' => true }) if blackout_override response = connection.execute(xml, '1.1', timeout: connection.timeout) Scan.parse(response.res) if response.success end
ruby
def scan(connection, sync_id = nil, blackout_override = false) xml = REXML::Element.new('SiteScanRequest') xml.add_attributes({ 'session-id' => connection.session_id, 'site-id' => @id, 'sync-id' => sync_id }) xml.add_attributes({ 'force' => true }) if blackout_override response = connection.execute(xml, '1.1', timeout: connection.timeout) Scan.parse(response.res) if response.success end
[ "def", "scan", "(", "connection", ",", "sync_id", "=", "nil", ",", "blackout_override", "=", "false", ")", "xml", "=", "REXML", "::", "Element", ".", "new", "(", "'SiteScanRequest'", ")", "xml", ".", "add_attributes", "(", "{", "'session-id'", "=>", "connection", ".", "session_id", ",", "'site-id'", "=>", "@id", ",", "'sync-id'", "=>", "sync_id", "}", ")", "xml", ".", "add_attributes", "(", "{", "'force'", "=>", "true", "}", ")", "if", "blackout_override", "response", "=", "connection", ".", "execute", "(", "xml", ",", "'1.1'", ",", "timeout", ":", "connection", ".", "timeout", ")", "Scan", ".", "parse", "(", "response", ".", "res", ")", "if", "response", ".", "success", "end" ]
Scan this site. @param [Connection] connection Connection to console where scan will be launched. @param [String] sync_id Optional synchronization token. @param [Boolean] blackout_override Optional. Given suffencent permissions, force bypass blackout and start scan. @return [Scan] Scan launch information.
[ "Scan", "this", "site", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/site.rb#L546-L555
18,849
rapid7/nexpose-client
lib/nexpose/silo_profile.rb
Nexpose.SiloProfile.update
def update(connection) xml = connection.make_xml('SiloProfileUpdateRequest') xml.add_element(as_xml) r = connection.execute(xml, '1.2') @id = r.attributes['silo-profile-id'] if r.success end
ruby
def update(connection) xml = connection.make_xml('SiloProfileUpdateRequest') xml.add_element(as_xml) r = connection.execute(xml, '1.2') @id = r.attributes['silo-profile-id'] if r.success end
[ "def", "update", "(", "connection", ")", "xml", "=", "connection", ".", "make_xml", "(", "'SiloProfileUpdateRequest'", ")", "xml", ".", "add_element", "(", "as_xml", ")", "r", "=", "connection", ".", "execute", "(", "xml", ",", "'1.2'", ")", "@id", "=", "r", ".", "attributes", "[", "'silo-profile-id'", "]", "if", "r", ".", "success", "end" ]
Updates an existing silo profile on a Nexpose console. @param [Connection] connection Connection to console where this silo profile will be saved. @return [String] Silo Profile ID assigned to this configuration, if successful.
[ "Updates", "an", "existing", "silo", "profile", "on", "a", "Nexpose", "console", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/silo_profile.rb#L118-L123
18,850
rapid7/nexpose-client
lib/nexpose/report.rb
Nexpose.Connection.list_reports
def list_reports r = execute(make_xml('ReportListingRequest')) reports = [] if r.success r.res.elements.each('//ReportConfigSummary') do |report| reports << ReportConfigSummary.parse(report) end end reports end
ruby
def list_reports r = execute(make_xml('ReportListingRequest')) reports = [] if r.success r.res.elements.each('//ReportConfigSummary') do |report| reports << ReportConfigSummary.parse(report) end end reports end
[ "def", "list_reports", "r", "=", "execute", "(", "make_xml", "(", "'ReportListingRequest'", ")", ")", "reports", "=", "[", "]", "if", "r", ".", "success", "r", ".", "res", ".", "elements", ".", "each", "(", "'//ReportConfigSummary'", ")", "do", "|", "report", "|", "reports", "<<", "ReportConfigSummary", ".", "parse", "(", "report", ")", "end", "end", "reports", "end" ]
Provide a listing of all report definitions the user can access on the Security Console. @return [Array[ReportConfigSummary]] List of current report configuration.
[ "Provide", "a", "listing", "of", "all", "report", "definitions", "the", "user", "can", "access", "on", "the", "Security", "Console", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/report.rb#L11-L20
18,851
rapid7/nexpose-client
lib/nexpose/report.rb
Nexpose.Connection.generate_report
def generate_report(report_id, wait = false) xml = make_xml('ReportGenerateRequest', { 'report-id' => report_id }) response = execute(xml) if response.success response.res.elements.each('//ReportSummary') do |summary| summary = ReportSummary.parse(summary) # If not waiting or the report is finished, return now. return summary unless wait && summary.status == 'Started' end end so_far = 0 while wait summary = last_report(report_id) return summary unless summary.status == 'Started' sleep 5 so_far += 5 if (so_far % 60).zero? puts "Still waiting. Current status: #{summary.status}" end end nil end
ruby
def generate_report(report_id, wait = false) xml = make_xml('ReportGenerateRequest', { 'report-id' => report_id }) response = execute(xml) if response.success response.res.elements.each('//ReportSummary') do |summary| summary = ReportSummary.parse(summary) # If not waiting or the report is finished, return now. return summary unless wait && summary.status == 'Started' end end so_far = 0 while wait summary = last_report(report_id) return summary unless summary.status == 'Started' sleep 5 so_far += 5 if (so_far % 60).zero? puts "Still waiting. Current status: #{summary.status}" end end nil end
[ "def", "generate_report", "(", "report_id", ",", "wait", "=", "false", ")", "xml", "=", "make_xml", "(", "'ReportGenerateRequest'", ",", "{", "'report-id'", "=>", "report_id", "}", ")", "response", "=", "execute", "(", "xml", ")", "if", "response", ".", "success", "response", ".", "res", ".", "elements", ".", "each", "(", "'//ReportSummary'", ")", "do", "|", "summary", "|", "summary", "=", "ReportSummary", ".", "parse", "(", "summary", ")", "# If not waiting or the report is finished, return now.", "return", "summary", "unless", "wait", "&&", "summary", ".", "status", "==", "'Started'", "end", "end", "so_far", "=", "0", "while", "wait", "summary", "=", "last_report", "(", "report_id", ")", "return", "summary", "unless", "summary", ".", "status", "==", "'Started'", "sleep", "5", "so_far", "+=", "5", "if", "(", "so_far", "%", "60", ")", ".", "zero?", "puts", "\"Still waiting. Current status: #{summary.status}\"", "end", "end", "nil", "end" ]
Generate a new report using the specified report definition.
[ "Generate", "a", "new", "report", "using", "the", "specified", "report", "definition", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/report.rb#L25-L46
18,852
rapid7/nexpose-client
lib/nexpose/report.rb
Nexpose.Connection.last_report
def last_report(report_config_id) history = report_history(report_config_id) history.sort { |a, b| b.generated_on <=> a.generated_on }.first end
ruby
def last_report(report_config_id) history = report_history(report_config_id) history.sort { |a, b| b.generated_on <=> a.generated_on }.first end
[ "def", "last_report", "(", "report_config_id", ")", "history", "=", "report_history", "(", "report_config_id", ")", "history", ".", "sort", "{", "|", "a", ",", "b", "|", "b", ".", "generated_on", "<=>", "a", ".", "generated_on", "}", ".", "first", "end" ]
Get details of the last report generated with the specified report id.
[ "Get", "details", "of", "the", "last", "report", "generated", "with", "the", "specified", "report", "id", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/report.rb#L56-L59
18,853
rapid7/nexpose-client
lib/nexpose/report.rb
Nexpose.AdhocReportConfig.generate
def generate(connection, timeout = 300, raw = false) xml = %(<ReportAdhocGenerateRequest session-id="#{connection.session_id}">) xml << to_xml xml << '</ReportAdhocGenerateRequest>' response = connection.execute(xml, '1.1', timeout: timeout, raw: raw) if response.success content_type_response = response.raw_response.header['Content-Type'] if content_type_response =~ /multipart\/mixed;\s*boundary=([^\s]+)/ # Nexpose sends an incorrect boundary format which breaks parsing # e.g., 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" + response.raw_response_data doc = Rexlite::MIME::Message.new(data) doc.parts.each do |part| if /.*base64.*/ =~ part.header.to_s if @format =~ /(?:ht|x)ml/ if part.header.to_s =~ %r(text/xml) return part.content.unpack('m*')[0].to_s elsif part.header.to_s =~ %r(text/html) return part.content.unpack('m*')[0].to_s end else # text|pdf|csv|rtf return part.content.unpack('m*')[0] end end end end end end
ruby
def generate(connection, timeout = 300, raw = false) xml = %(<ReportAdhocGenerateRequest session-id="#{connection.session_id}">) xml << to_xml xml << '</ReportAdhocGenerateRequest>' response = connection.execute(xml, '1.1', timeout: timeout, raw: raw) if response.success content_type_response = response.raw_response.header['Content-Type'] if content_type_response =~ /multipart\/mixed;\s*boundary=([^\s]+)/ # Nexpose sends an incorrect boundary format which breaks parsing # e.g., 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" + response.raw_response_data doc = Rexlite::MIME::Message.new(data) doc.parts.each do |part| if /.*base64.*/ =~ part.header.to_s if @format =~ /(?:ht|x)ml/ if part.header.to_s =~ %r(text/xml) return part.content.unpack('m*')[0].to_s elsif part.header.to_s =~ %r(text/html) return part.content.unpack('m*')[0].to_s end else # text|pdf|csv|rtf return part.content.unpack('m*')[0] end end end end end end
[ "def", "generate", "(", "connection", ",", "timeout", "=", "300", ",", "raw", "=", "false", ")", "xml", "=", "%(<ReportAdhocGenerateRequest session-id=\"#{connection.session_id}\">)", "xml", "<<", "to_xml", "xml", "<<", "'</ReportAdhocGenerateRequest>'", "response", "=", "connection", ".", "execute", "(", "xml", ",", "'1.1'", ",", "timeout", ":", "timeout", ",", "raw", ":", "raw", ")", "if", "response", ".", "success", "content_type_response", "=", "response", ".", "raw_response", ".", "header", "[", "'Content-Type'", "]", "if", "content_type_response", "=~", "/", "\\/", "\\s", "\\s", "/", "# Nexpose sends an incorrect boundary format which breaks parsing", "# e.g., 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", "(", "/", "/", ")", ")", "content_type_response", "=", "content_type_response", "[", "0", ",", "last_semi_colon_index", "]", "data", "=", "'Content-Type: '", "+", "content_type_response", "+", "\"\\r\\n\\r\\n\"", "+", "response", ".", "raw_response_data", "doc", "=", "Rexlite", "::", "MIME", "::", "Message", ".", "new", "(", "data", ")", "doc", ".", "parts", ".", "each", "do", "|", "part", "|", "if", "/", "/", "=~", "part", ".", "header", ".", "to_s", "if", "@format", "=~", "/", "/", "if", "part", ".", "header", ".", "to_s", "=~", "%r(", ")", "return", "part", ".", "content", ".", "unpack", "(", "'m*'", ")", "[", "0", "]", ".", "to_s", "elsif", "part", ".", "header", ".", "to_s", "=~", "%r(", ")", "return", "part", ".", "content", ".", "unpack", "(", "'m*'", ")", "[", "0", "]", ".", "to_s", "end", "else", "# text|pdf|csv|rtf", "return", "part", ".", "content", ".", "unpack", "(", "'m*'", ")", "[", "0", "]", "end", "end", "end", "end", "end", "end" ]
Generate a report once using a simple configuration. For XML-based reports, only the textual report is returned and not any images. @param [Connection] connection Nexpose connection. @param [Fixnum] timeout How long, in seconds, to wait for the report to generate. Larger reports can take a significant amount of time. @param [Boolean] raw Whether to bypass response parsing an use the raw response. If this option is used, error will only be exposed by examining Connection#response_xml. @return Report in text format except for PDF, which returns binary data.
[ "Generate", "a", "report", "once", "using", "a", "simple", "configuration", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/report.rb#L247-L278
18,854
rapid7/nexpose-client
lib/nexpose/report.rb
Nexpose.ReportConfig.save
def save(connection, generate_now = false) xml = %(<ReportSaveRequest session-id="#{connection.session_id}" generate-now="#{generate_now ? 1 : 0}">) xml << to_xml xml << '</ReportSaveRequest>' response = connection.execute(xml) if response.success @id = response.attributes['reportcfg-id'].to_i end end
ruby
def save(connection, generate_now = false) xml = %(<ReportSaveRequest session-id="#{connection.session_id}" generate-now="#{generate_now ? 1 : 0}">) xml << to_xml xml << '</ReportSaveRequest>' response = connection.execute(xml) if response.success @id = response.attributes['reportcfg-id'].to_i end end
[ "def", "save", "(", "connection", ",", "generate_now", "=", "false", ")", "xml", "=", "%(<ReportSaveRequest session-id=\"#{connection.session_id}\" generate-now=\"#{generate_now ? 1 : 0}\">)", "xml", "<<", "to_xml", "xml", "<<", "'</ReportSaveRequest>'", "response", "=", "connection", ".", "execute", "(", "xml", ")", "if", "response", ".", "success", "@id", "=", "response", ".", "attributes", "[", "'reportcfg-id'", "]", ".", "to_i", "end", "end" ]
Save the configuration of this report definition.
[ "Save", "the", "configuration", "of", "this", "report", "definition", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/report.rb#L334-L342
18,855
rapid7/nexpose-client
lib/nexpose/vuln.rb
Nexpose.Connection.list_vulns
def list_vulns(full = false) xml = make_xml('VulnerabilityListingRequest') # TODO: Add a flag to do stream parsing of the XML to improve performance. response = execute(xml, '1.2') vulns = [] if response.success response.res.elements.each('VulnerabilityListingResponse/VulnerabilitySummary') do |vuln| if full vulns << XML::VulnerabilitySummary.parse(vuln) else vulns << XML::Vulnerability.new(vuln.attributes['id'], vuln.attributes['title'], vuln.attributes['severity'].to_i) end end end vulns end
ruby
def list_vulns(full = false) xml = make_xml('VulnerabilityListingRequest') # TODO: Add a flag to do stream parsing of the XML to improve performance. response = execute(xml, '1.2') vulns = [] if response.success response.res.elements.each('VulnerabilityListingResponse/VulnerabilitySummary') do |vuln| if full vulns << XML::VulnerabilitySummary.parse(vuln) else vulns << XML::Vulnerability.new(vuln.attributes['id'], vuln.attributes['title'], vuln.attributes['severity'].to_i) end end end vulns end
[ "def", "list_vulns", "(", "full", "=", "false", ")", "xml", "=", "make_xml", "(", "'VulnerabilityListingRequest'", ")", "# TODO: Add a flag to do stream parsing of the XML to improve performance.", "response", "=", "execute", "(", "xml", ",", "'1.2'", ")", "vulns", "=", "[", "]", "if", "response", ".", "success", "response", ".", "res", ".", "elements", ".", "each", "(", "'VulnerabilityListingResponse/VulnerabilitySummary'", ")", "do", "|", "vuln", "|", "if", "full", "vulns", "<<", "XML", "::", "VulnerabilitySummary", ".", "parse", "(", "vuln", ")", "else", "vulns", "<<", "XML", "::", "Vulnerability", ".", "new", "(", "vuln", ".", "attributes", "[", "'id'", "]", ",", "vuln", ".", "attributes", "[", "'title'", "]", ",", "vuln", ".", "attributes", "[", "'severity'", "]", ".", "to_i", ")", "end", "end", "end", "vulns", "end" ]
Retrieve summary details of all vulnerabilities. @param [Boolean] full Whether or not to gather the full summary. Without the flag, only id, title, and severity are returned. It can take twice a long to retrieve full summary information. @return [Array[Vulnerability|VulnerabilitySummary]] Collection of all known vulnerabilities.
[ "Retrieve", "summary", "details", "of", "all", "vulnerabilities", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln.rb#L12-L29
18,856
rapid7/nexpose-client
lib/nexpose/vuln.rb
Nexpose.Connection.vuln_details
def vuln_details(vuln_id) xml = make_xml('VulnerabilityDetailsRequest', { 'vuln-id' => vuln_id }) response = execute(xml, '1.2') if response.success response.res.elements.each('VulnerabilityDetailsResponse/Vulnerability') do |vuln| return XML::VulnerabilityDetail.parse(vuln) end end end
ruby
def vuln_details(vuln_id) xml = make_xml('VulnerabilityDetailsRequest', { 'vuln-id' => vuln_id }) response = execute(xml, '1.2') if response.success response.res.elements.each('VulnerabilityDetailsResponse/Vulnerability') do |vuln| return XML::VulnerabilityDetail.parse(vuln) end end end
[ "def", "vuln_details", "(", "vuln_id", ")", "xml", "=", "make_xml", "(", "'VulnerabilityDetailsRequest'", ",", "{", "'vuln-id'", "=>", "vuln_id", "}", ")", "response", "=", "execute", "(", "xml", ",", "'1.2'", ")", "if", "response", ".", "success", "response", ".", "res", ".", "elements", ".", "each", "(", "'VulnerabilityDetailsResponse/Vulnerability'", ")", "do", "|", "vuln", "|", "return", "XML", "::", "VulnerabilityDetail", ".", "parse", "(", "vuln", ")", "end", "end", "end" ]
Retrieve details for a vulnerability. @param [String] vuln_id Nexpose vulnerability ID, such as 'windows-duqu-cve-2011-3402'. @return [VulnerabilityDetail] Details of the requested vulnerability.
[ "Retrieve", "details", "for", "a", "vulnerability", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln.rb#L59-L67
18,857
rapid7/nexpose-client
lib/nexpose/vuln.rb
Nexpose.Connection.find_vuln_check
def find_vuln_check(search_term, partial_words = true, all_words = true) uri = "/data/vulnerability/vulnerabilities/dyntable.xml?tableID=VulnCheckSynopsis&phrase=#{URI.encode(search_term)}&allWords=#{all_words}" data = DataTable._get_dyn_table(self, uri) data.map do |vuln| XML::VulnCheck.new(vuln) end end
ruby
def find_vuln_check(search_term, partial_words = true, all_words = true) uri = "/data/vulnerability/vulnerabilities/dyntable.xml?tableID=VulnCheckSynopsis&phrase=#{URI.encode(search_term)}&allWords=#{all_words}" data = DataTable._get_dyn_table(self, uri) data.map do |vuln| XML::VulnCheck.new(vuln) end end
[ "def", "find_vuln_check", "(", "search_term", ",", "partial_words", "=", "true", ",", "all_words", "=", "true", ")", "uri", "=", "\"/data/vulnerability/vulnerabilities/dyntable.xml?tableID=VulnCheckSynopsis&phrase=#{URI.encode(search_term)}&allWords=#{all_words}\"", "data", "=", "DataTable", ".", "_get_dyn_table", "(", "self", ",", "uri", ")", "data", ".", "map", "do", "|", "vuln", "|", "XML", "::", "VulnCheck", ".", "new", "(", "vuln", ")", "end", "end" ]
Search for Vulnerability Checks. @param [String] search_term Search terms to search for. @param [Boolean] partial_words Allow partial word matches. @param [Boolean] all_words All words must be present. @return [Array[VulnCheck]] List of matching Vulnerability Checks.
[ "Search", "for", "Vulnerability", "Checks", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln.rb#L76-L82
18,858
rapid7/nexpose-client
lib/nexpose/vuln.rb
Nexpose.Connection.find_vulns_by_date
def find_vulns_by_date(from, to = nil) uri = "/data/vulnerability/synopsis/dyntable.xml?addedMin=#{from}" uri += "&addedMax=#{to}" if to DataTable._get_dyn_table(self, uri).map { |v| VulnSynopsis.new(v) } end
ruby
def find_vulns_by_date(from, to = nil) uri = "/data/vulnerability/synopsis/dyntable.xml?addedMin=#{from}" uri += "&addedMax=#{to}" if to DataTable._get_dyn_table(self, uri).map { |v| VulnSynopsis.new(v) } end
[ "def", "find_vulns_by_date", "(", "from", ",", "to", "=", "nil", ")", "uri", "=", "\"/data/vulnerability/synopsis/dyntable.xml?addedMin=#{from}\"", "uri", "+=", "\"&addedMax=#{to}\"", "if", "to", "DataTable", ".", "_get_dyn_table", "(", "self", ",", "uri", ")", ".", "map", "{", "|", "v", "|", "VulnSynopsis", ".", "new", "(", "v", ")", "}", "end" ]
Find vulnerabilities by date available in Nexpose. This is not the date the original vulnerability was published, but the date the check was made available in Nexpose. @param [String] from Vulnerability publish date in format YYYY-MM-DD. @param [String] to Vulnerability publish date in format YYYY-MM-DD. @return [Array[VulnSynopsis]] List of vulnerabilities published in Nexpose between the provided dates.
[ "Find", "vulnerabilities", "by", "date", "available", "in", "Nexpose", ".", "This", "is", "not", "the", "date", "the", "original", "vulnerability", "was", "published", "but", "the", "date", "the", "check", "was", "made", "available", "in", "Nexpose", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln.rb#L93-L97
18,859
rapid7/nexpose-client
lib/nexpose/ticket.rb
Nexpose.Connection.delete_tickets
def delete_tickets(tickets) # TODO: Take Ticket objects, too, and pull out IDs. xml = make_xml('TicketDeleteRequest') tickets.each do |id| xml.add_element('Ticket', { 'id' => id }) end (execute xml, '1.2').success end
ruby
def delete_tickets(tickets) # TODO: Take Ticket objects, too, and pull out IDs. xml = make_xml('TicketDeleteRequest') tickets.each do |id| xml.add_element('Ticket', { 'id' => id }) end (execute xml, '1.2').success end
[ "def", "delete_tickets", "(", "tickets", ")", "# TODO: Take Ticket objects, too, and pull out IDs.", "xml", "=", "make_xml", "(", "'TicketDeleteRequest'", ")", "tickets", ".", "each", "do", "|", "id", "|", "xml", ".", "add_element", "(", "'Ticket'", ",", "{", "'id'", "=>", "id", "}", ")", "end", "(", "execute", "xml", ",", "'1.2'", ")", ".", "success", "end" ]
Deletes a Nexpose ticket. @param [Array[Fixnum]] tickets Array of unique IDs of tickets to delete. @return [Boolean] Whether or not the ticket deletions succeeded.
[ "Deletes", "a", "Nexpose", "ticket", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ticket.rb#L36-L44
18,860
rapid7/nexpose-client
lib/nexpose/ticket.rb
Nexpose.Ticket.save
def save(connection) xml = connection.make_xml('TicketCreateRequest') xml.add_element(to_xml) response = connection.execute(xml, '1.2') @id = response.attributes['id'].to_i if response.success end
ruby
def save(connection) xml = connection.make_xml('TicketCreateRequest') xml.add_element(to_xml) response = connection.execute(xml, '1.2') @id = response.attributes['id'].to_i if response.success end
[ "def", "save", "(", "connection", ")", "xml", "=", "connection", ".", "make_xml", "(", "'TicketCreateRequest'", ")", "xml", ".", "add_element", "(", "to_xml", ")", "response", "=", "connection", ".", "execute", "(", "xml", ",", "'1.2'", ")", "@id", "=", "response", ".", "attributes", "[", "'id'", "]", ".", "to_i", "if", "response", ".", "success", "end" ]
Save this ticket to a Nexpose console. @param [Connection] connection Connection to console where ticket exists. @return [Fixnum] Unique ticket ID assigned to this ticket.
[ "Save", "this", "ticket", "to", "a", "Nexpose", "console", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ticket.rb#L147-L153
18,861
rapid7/nexpose-client
lib/nexpose/console.rb
Nexpose.Console.save
def save(connection) nsc = REXML::XPath.first(@xml, 'NeXposeSecurityConsole') nsc.attributes['scanThreadsLimit'] = @scan_threads_limit.to_i nsc.attributes['realtimeIntegration'] = @incremental_scan_results ? '1' : '0' web_server = REXML::XPath.first(nsc, 'WebServer') web_server.attributes['sessionTimeout'] = @session_timeout.to_i response = REXML::Document.new(Nexpose::AJAX.post(connection, '/data/admin/config/nsc', @xml)) saved = REXML::XPath.first(response, 'SaveConfig') saved.attributes['success'] == '1' end
ruby
def save(connection) nsc = REXML::XPath.first(@xml, 'NeXposeSecurityConsole') nsc.attributes['scanThreadsLimit'] = @scan_threads_limit.to_i nsc.attributes['realtimeIntegration'] = @incremental_scan_results ? '1' : '0' web_server = REXML::XPath.first(nsc, 'WebServer') web_server.attributes['sessionTimeout'] = @session_timeout.to_i response = REXML::Document.new(Nexpose::AJAX.post(connection, '/data/admin/config/nsc', @xml)) saved = REXML::XPath.first(response, 'SaveConfig') saved.attributes['success'] == '1' end
[ "def", "save", "(", "connection", ")", "nsc", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'NeXposeSecurityConsole'", ")", "nsc", ".", "attributes", "[", "'scanThreadsLimit'", "]", "=", "@scan_threads_limit", ".", "to_i", "nsc", ".", "attributes", "[", "'realtimeIntegration'", "]", "=", "@incremental_scan_results", "?", "'1'", ":", "'0'", "web_server", "=", "REXML", "::", "XPath", ".", "first", "(", "nsc", ",", "'WebServer'", ")", "web_server", ".", "attributes", "[", "'sessionTimeout'", "]", "=", "@session_timeout", ".", "to_i", "response", "=", "REXML", "::", "Document", ".", "new", "(", "Nexpose", "::", "AJAX", ".", "post", "(", "connection", ",", "'/data/admin/config/nsc'", ",", "@xml", ")", ")", "saved", "=", "REXML", "::", "XPath", ".", "first", "(", "response", ",", "'SaveConfig'", ")", "saved", ".", "attributes", "[", "'success'", "]", "==", "'1'", "end" ]
Save modifications to the Nexpose security console. @param [Connection] connection Nexpose connection. @return [Boolean] true if configuration successfully saved.
[ "Save", "modifications", "to", "the", "Nexpose", "security", "console", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/console.rb#L58-L69
18,862
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.Connection.list_scan_templates
def list_scan_templates templates = JSON.parse(AJAX.get(self, '/api/2.0/scan_templates')) templates['resources'].map { |t| ScanTemplateSummary.new(t) } end
ruby
def list_scan_templates templates = JSON.parse(AJAX.get(self, '/api/2.0/scan_templates')) templates['resources'].map { |t| ScanTemplateSummary.new(t) } end
[ "def", "list_scan_templates", "templates", "=", "JSON", ".", "parse", "(", "AJAX", ".", "get", "(", "self", ",", "'/api/2.0/scan_templates'", ")", ")", "templates", "[", "'resources'", "]", ".", "map", "{", "|", "t", "|", "ScanTemplateSummary", ".", "new", "(", "t", ")", "}", "end" ]
List the scan templates currently configured on the console. @return [Array[ScanTemplateSummary]] list of scan template summary objects.
[ "List", "the", "scan", "templates", "currently", "configured", "on", "the", "console", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L9-L12
18,863
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.name=
def name=(name) desc = REXML::XPath.first(@xml, 'ScanTemplate/templateDescription') if desc desc.attributes['title'] = replace_entities(name) else root = REXML::XPath.first(xml, 'ScanTemplate') desc = REXML::Element.new('templateDescription') desc.add_attribute('title', name) root.add_element(desc) end end
ruby
def name=(name) desc = REXML::XPath.first(@xml, 'ScanTemplate/templateDescription') if desc desc.attributes['title'] = replace_entities(name) else root = REXML::XPath.first(xml, 'ScanTemplate') desc = REXML::Element.new('templateDescription') desc.add_attribute('title', name) root.add_element(desc) end end
[ "def", "name", "=", "(", "name", ")", "desc", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/templateDescription'", ")", "if", "desc", "desc", ".", "attributes", "[", "'title'", "]", "=", "replace_entities", "(", "name", ")", "else", "root", "=", "REXML", "::", "XPath", ".", "first", "(", "xml", ",", "'ScanTemplate'", ")", "desc", "=", "REXML", "::", "Element", ".", "new", "(", "'templateDescription'", ")", "desc", ".", "add_attribute", "(", "'title'", ",", "name", ")", "root", ".", "add_element", "(", "desc", ")", "end", "end" ]
Assign name to this scan template. Required attribute. @param [String] name Title to assign.
[ "Assign", "name", "to", "this", "scan", "template", ".", "Required", "attribute", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L78-L88
18,864
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.description=
def description=(description) desc = REXML::XPath.first(@xml, 'ScanTemplate/templateDescription') if desc desc.text = replace_entities(description) else root = REXML::XPath.first(xml, 'ScanTemplate') desc = REXML::Element.new('templateDescription') desc.add_text(description) root.add_element(desc) end end
ruby
def description=(description) desc = REXML::XPath.first(@xml, 'ScanTemplate/templateDescription') if desc desc.text = replace_entities(description) else root = REXML::XPath.first(xml, 'ScanTemplate') desc = REXML::Element.new('templateDescription') desc.add_text(description) root.add_element(desc) end end
[ "def", "description", "=", "(", "description", ")", "desc", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/templateDescription'", ")", "if", "desc", "desc", ".", "text", "=", "replace_entities", "(", "description", ")", "else", "root", "=", "REXML", "::", "XPath", ".", "first", "(", "xml", ",", "'ScanTemplate'", ")", "desc", "=", "REXML", "::", "Element", ".", "new", "(", "'templateDescription'", ")", "desc", ".", "add_text", "(", "description", ")", "root", ".", "add_element", "(", "desc", ")", "end", "end" ]
Assign a description to this scan template. Require attribute. @param [String] description Description of the scan template.
[ "Assign", "a", "description", "to", "this", "scan", "template", ".", "Require", "attribute", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L98-L108
18,865
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.scan_threads=
def scan_threads=(threads) scan_threads = REXML::XPath.first(@xml, 'ScanTemplate/General/scanThreads') scan_threads.text = threads.to_s end
ruby
def scan_threads=(threads) scan_threads = REXML::XPath.first(@xml, 'ScanTemplate/General/scanThreads') scan_threads.text = threads.to_s end
[ "def", "scan_threads", "=", "(", "threads", ")", "scan_threads", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/General/scanThreads'", ")", "scan_threads", ".", "text", "=", "threads", ".", "to_s", "end" ]
Adjust the number of threads to use per scan engine for this template @param [Integer] threads the number of threads to use per engine
[ "Adjust", "the", "number", "of", "threads", "to", "use", "per", "scan", "engine", "for", "this", "template" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L167-L170
18,866
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.host_threads=
def host_threads=(threads) host_threads = REXML::XPath.first(@xml, 'ScanTemplate/General/hostThreads') host_threads.text = threads.to_s end
ruby
def host_threads=(threads) host_threads = REXML::XPath.first(@xml, 'ScanTemplate/General/hostThreads') host_threads.text = threads.to_s end
[ "def", "host_threads", "=", "(", "threads", ")", "host_threads", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/General/hostThreads'", ")", "host_threads", ".", "text", "=", "threads", ".", "to_s", "end" ]
Adjust the number of threads to use per asset for this template @param [Integer] threads the number of threads to use per asset
[ "Adjust", "the", "number", "of", "threads", "to", "use", "per", "asset", "for", "this", "template" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L174-L177
18,867
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.tcp_device_discovery_ports=
def tcp_device_discovery_ports=(ports) tcp = REXML::XPath.first(@xml, 'ScanTemplate/DeviceDiscovery/CheckHosts/TCPHostCheck') REXML::XPath.first(tcp, './portList').text = ports.join(',') end
ruby
def tcp_device_discovery_ports=(ports) tcp = REXML::XPath.first(@xml, 'ScanTemplate/DeviceDiscovery/CheckHosts/TCPHostCheck') REXML::XPath.first(tcp, './portList').text = ports.join(',') end
[ "def", "tcp_device_discovery_ports", "=", "(", "ports", ")", "tcp", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/DeviceDiscovery/CheckHosts/TCPHostCheck'", ")", "REXML", "::", "XPath", ".", "first", "(", "tcp", ",", "'./portList'", ")", ".", "text", "=", "ports", ".", "join", "(", "','", ")", "end" ]
Set custom TCP ports to scan for device discovery @param [Array] ports Ports to scan for device discovery
[ "Set", "custom", "TCP", "ports", "to", "scan", "for", "device", "discovery" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L210-L213
18,868
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.udp_device_discovery_ports=
def udp_device_discovery_ports=(ports) udp = REXML::XPath.first(@xml, 'ScanTemplate/DeviceDiscovery/CheckHosts/UDPHostCheck') REXML::XPath.first(udp, './portList').text = ports.join(',') end
ruby
def udp_device_discovery_ports=(ports) udp = REXML::XPath.first(@xml, 'ScanTemplate/DeviceDiscovery/CheckHosts/UDPHostCheck') REXML::XPath.first(udp, './portList').text = ports.join(',') end
[ "def", "udp_device_discovery_ports", "=", "(", "ports", ")", "udp", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/DeviceDiscovery/CheckHosts/UDPHostCheck'", ")", "REXML", "::", "XPath", ".", "first", "(", "udp", ",", "'./portList'", ")", ".", "text", "=", "ports", ".", "join", "(", "','", ")", "end" ]
Set custom UDP ports to scan for UDP device discovery @param [Array] ports Ports to scan for UDP device discovery
[ "Set", "custom", "UDP", "ports", "to", "scan", "for", "UDP", "device", "discovery" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L224-L227
18,869
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.tcp_service_discovery_ports=
def tcp_service_discovery_ports=(ports) service_ports = REXML::XPath.first(@xml, 'ScanTemplate/ServiceDiscovery/TCPPortScan') service_ports.attributes['mode'] = 'custom' service_ports.attributes['method'] = 'syn' REXML::XPath.first(service_ports, './portList').text = ports.join(',') end
ruby
def tcp_service_discovery_ports=(ports) service_ports = REXML::XPath.first(@xml, 'ScanTemplate/ServiceDiscovery/TCPPortScan') service_ports.attributes['mode'] = 'custom' service_ports.attributes['method'] = 'syn' REXML::XPath.first(service_ports, './portList').text = ports.join(',') end
[ "def", "tcp_service_discovery_ports", "=", "(", "ports", ")", "service_ports", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/ServiceDiscovery/TCPPortScan'", ")", "service_ports", ".", "attributes", "[", "'mode'", "]", "=", "'custom'", "service_ports", ".", "attributes", "[", "'method'", "]", "=", "'syn'", "REXML", "::", "XPath", ".", "first", "(", "service_ports", ",", "'./portList'", ")", ".", "text", "=", "ports", ".", "join", "(", "','", ")", "end" ]
Set custom TCP ports to scan for TCP service discovery @param [Array] ports Ports to scan for TCP service discovery
[ "Set", "custom", "TCP", "ports", "to", "scan", "for", "TCP", "service", "discovery" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L238-L243
18,870
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.exclude_tcp_service_discovery_ports=
def exclude_tcp_service_discovery_ports=(ports) service_ports = REXML::XPath.first(@xml, 'ScanTemplate/ServiceDiscovery/ExcludedTCPPortScan') REXML::XPath.first(service_ports, './portList').text = ports.join(',') end
ruby
def exclude_tcp_service_discovery_ports=(ports) service_ports = REXML::XPath.first(@xml, 'ScanTemplate/ServiceDiscovery/ExcludedTCPPortScan') REXML::XPath.first(service_ports, './portList').text = ports.join(',') end
[ "def", "exclude_tcp_service_discovery_ports", "=", "(", "ports", ")", "service_ports", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/ServiceDiscovery/ExcludedTCPPortScan'", ")", "REXML", "::", "XPath", ".", "first", "(", "service_ports", ",", "'./portList'", ")", ".", "text", "=", "ports", ".", "join", "(", "','", ")", "end" ]
Exclude TCP ports during TCP service discovery @param [Array] ports TCP ports to exclude from TCP service discovery
[ "Exclude", "TCP", "ports", "during", "TCP", "service", "discovery" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L247-L250
18,871
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.exclude_udp_service_discovery_ports=
def exclude_udp_service_discovery_ports=(ports) service_ports = REXML::XPath.first(@xml, 'ScanTemplate/ServiceDiscovery/ExcludedUDPPortScan') REXML::XPath.first(service_ports, './portList').text = ports.join(',') end
ruby
def exclude_udp_service_discovery_ports=(ports) service_ports = REXML::XPath.first(@xml, 'ScanTemplate/ServiceDiscovery/ExcludedUDPPortScan') REXML::XPath.first(service_ports, './portList').text = ports.join(',') end
[ "def", "exclude_udp_service_discovery_ports", "=", "(", "ports", ")", "service_ports", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/ServiceDiscovery/ExcludedUDPPortScan'", ")", "REXML", "::", "XPath", ".", "first", "(", "service_ports", ",", "'./portList'", ")", ".", "text", "=", "ports", ".", "join", "(", "','", ")", "end" ]
Exclude UDP ports when performing UDP service discovery @param [Array] ports UDP ports to exclude from UDP service discovery
[ "Exclude", "UDP", "ports", "when", "performing", "UDP", "service", "discovery" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L262-L265
18,872
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.enabled_vuln_checks
def enabled_vuln_checks checks = REXML::XPath.first(@xml, '//VulnerabilityChecks/Enabled') checks ? checks.elements.to_a('Check').map { |c| c.attributes['id'] } : [] end
ruby
def enabled_vuln_checks checks = REXML::XPath.first(@xml, '//VulnerabilityChecks/Enabled') checks ? checks.elements.to_a('Check').map { |c| c.attributes['id'] } : [] end
[ "def", "enabled_vuln_checks", "checks", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'//VulnerabilityChecks/Enabled'", ")", "checks", "?", "checks", ".", "elements", ".", "to_a", "(", "'Check'", ")", ".", "map", "{", "|", "c", "|", "c", ".", "attributes", "[", "'id'", "]", "}", ":", "[", "]", "end" ]
Get a list of the individual vuln checks enabled for this scan template. @return [Array[String]] List of enabled vulnerability checks.
[ "Get", "a", "list", "of", "the", "individual", "vuln", "checks", "enabled", "for", "this", "scan", "template", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L425-L428
18,873
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.enable_vuln_check
def enable_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Disabled/Check[@id='#{check_id}']") enabled_checks = checks.elements['Enabled'] || checks.add_element('Enabled') enabled_checks.add_element('Check', { 'id' => check_id }) end
ruby
def enable_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Disabled/Check[@id='#{check_id}']") enabled_checks = checks.elements['Enabled'] || checks.add_element('Enabled') enabled_checks.add_element('Check', { 'id' => check_id }) end
[ "def", "enable_vuln_check", "(", "check_id", ")", "checks", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'//VulnerabilityChecks'", ")", "checks", ".", "elements", ".", "delete", "(", "\"Disabled/Check[@id='#{check_id}']\"", ")", "enabled_checks", "=", "checks", ".", "elements", "[", "'Enabled'", "]", "||", "checks", ".", "add_element", "(", "'Enabled'", ")", "enabled_checks", ".", "add_element", "(", "'Check'", ",", "{", "'id'", "=>", "check_id", "}", ")", "end" ]
Enable individual check for this template. @param [String] check_id Unique identifier of vuln check.
[ "Enable", "individual", "check", "for", "this", "template", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L443-L448
18,874
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.disable_vuln_check
def disable_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Enabled/Check[@id='#{check_id}']") disabled_checks = checks.elements['Disabled'] || checks.add_element('Disabled') disabled_checks.add_element('Check', { 'id' => check_id }) end
ruby
def disable_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Enabled/Check[@id='#{check_id}']") disabled_checks = checks.elements['Disabled'] || checks.add_element('Disabled') disabled_checks.add_element('Check', { 'id' => check_id }) end
[ "def", "disable_vuln_check", "(", "check_id", ")", "checks", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'//VulnerabilityChecks'", ")", "checks", ".", "elements", ".", "delete", "(", "\"Enabled/Check[@id='#{check_id}']\"", ")", "disabled_checks", "=", "checks", ".", "elements", "[", "'Disabled'", "]", "||", "checks", ".", "add_element", "(", "'Disabled'", ")", "disabled_checks", ".", "add_element", "(", "'Check'", ",", "{", "'id'", "=>", "check_id", "}", ")", "end" ]
Disable individual check for this template. @param [String] check_id Unique identifier of vuln check.
[ "Disable", "individual", "check", "for", "this", "template", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L454-L459
18,875
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.remove_vuln_check
def remove_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Disabled/Check[@id='#{check_id}']") checks.elements.delete("Enabled/Check[@id='#{check_id}']") end
ruby
def remove_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Disabled/Check[@id='#{check_id}']") checks.elements.delete("Enabled/Check[@id='#{check_id}']") end
[ "def", "remove_vuln_check", "(", "check_id", ")", "checks", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'//VulnerabilityChecks'", ")", "checks", ".", "elements", ".", "delete", "(", "\"Disabled/Check[@id='#{check_id}']\"", ")", "checks", ".", "elements", ".", "delete", "(", "\"Enabled/Check[@id='#{check_id}']\"", ")", "end" ]
Remove individual check for this template. Removes both enabled and disabled checks. @param [String] check_id Unique identifier of vuln check.
[ "Remove", "individual", "check", "for", "this", "template", ".", "Removes", "both", "enabled", "and", "disabled", "checks", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L466-L470
18,876
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.save
def save(nsc) root = REXML::XPath.first(@xml, 'ScanTemplate') if root.attributes['id'] == '#NewScanTemplate#' response = JSON.parse(AJAX.post(nsc, '/data/scan/templates', xml)) root.attributes['id'] = response['value'] else response = JSON.parse(AJAX.put(nsc, "/data/scan/templates/#{URI.encode(id)}", xml)) end response['value'] end
ruby
def save(nsc) root = REXML::XPath.first(@xml, 'ScanTemplate') if root.attributes['id'] == '#NewScanTemplate#' response = JSON.parse(AJAX.post(nsc, '/data/scan/templates', xml)) root.attributes['id'] = response['value'] else response = JSON.parse(AJAX.put(nsc, "/data/scan/templates/#{URI.encode(id)}", xml)) end response['value'] end
[ "def", "save", "(", "nsc", ")", "root", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate'", ")", "if", "root", ".", "attributes", "[", "'id'", "]", "==", "'#NewScanTemplate#'", "response", "=", "JSON", ".", "parse", "(", "AJAX", ".", "post", "(", "nsc", ",", "'/data/scan/templates'", ",", "xml", ")", ")", "root", ".", "attributes", "[", "'id'", "]", "=", "response", "[", "'value'", "]", "else", "response", "=", "JSON", ".", "parse", "(", "AJAX", ".", "put", "(", "nsc", ",", "\"/data/scan/templates/#{URI.encode(id)}\"", ",", "xml", ")", ")", "end", "response", "[", "'value'", "]", "end" ]
Save this scan template configuration to a Nexpose console. @param [Connection] nsc API connection to a Nexpose console.
[ "Save", "this", "scan", "template", "configuration", "to", "a", "Nexpose", "console", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L476-L485
18,877
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.aces_level=
def aces_level=(level) return if level.nil? return unless ['full', 'default', 'none'].include? level.downcase logging = REXML::XPath.first(@xml, 'ScanTemplate/Logging') if logging.nil? logging = REXML::Element.new('Logging') @xml.add_element(logging) end aces = REXML::XPath.first(logging, 'aces') if aces.nil? aces = REXML::Element.new('aces') logging.add_element(aces) end aces.attributes['level'] = level end
ruby
def aces_level=(level) return if level.nil? return unless ['full', 'default', 'none'].include? level.downcase logging = REXML::XPath.first(@xml, 'ScanTemplate/Logging') if logging.nil? logging = REXML::Element.new('Logging') @xml.add_element(logging) end aces = REXML::XPath.first(logging, 'aces') if aces.nil? aces = REXML::Element.new('aces') logging.add_element(aces) end aces.attributes['level'] = level end
[ "def", "aces_level", "=", "(", "level", ")", "return", "if", "level", ".", "nil?", "return", "unless", "[", "'full'", ",", "'default'", ",", "'none'", "]", ".", "include?", "level", ".", "downcase", "logging", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/Logging'", ")", "if", "logging", ".", "nil?", "logging", "=", "REXML", "::", "Element", ".", "new", "(", "'Logging'", ")", "@xml", ".", "add_element", "(", "logging", ")", "end", "aces", "=", "REXML", "::", "XPath", ".", "first", "(", "logging", ",", "'aces'", ")", "if", "aces", ".", "nil?", "aces", "=", "REXML", "::", "Element", ".", "new", "(", "'aces'", ")", "logging", ".", "add_element", "(", "aces", ")", "end", "aces", ".", "attributes", "[", "'level'", "]", "=", "level", "end" ]
Enable or disable asset configuration scanning for this template. If the level is not "full", "default" or "none", this is a no-op. @param [String] "full" to enable asset configuration logging, and "default" or "none" to disable it.
[ "Enable", "or", "disable", "asset", "configuration", "scanning", "for", "this", "template", ".", "If", "the", "level", "is", "not", "full", "default", "or", "none", "this", "is", "a", "no", "-", "op", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L531-L545
18,878
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.enable_debug_logging=
def enable_debug_logging=(enable) return if enable.nil? logging = REXML::XPath.first(@xml, 'ScanTemplate/Logging') if logging.nil? logging = REXML::Element.new('Logging') @xml.add_element(logging) end debug_logging = REXML::XPath.first(logging, 'debugLogging') if debug_logging.nil? debug_logging = REXML::Element.new('debugLogging') logging.add_element(debug_logging) end debug_logging.attributes['enabled'] = (enable ? 1 : 0) end
ruby
def enable_debug_logging=(enable) return if enable.nil? logging = REXML::XPath.first(@xml, 'ScanTemplate/Logging') if logging.nil? logging = REXML::Element.new('Logging') @xml.add_element(logging) end debug_logging = REXML::XPath.first(logging, 'debugLogging') if debug_logging.nil? debug_logging = REXML::Element.new('debugLogging') logging.add_element(debug_logging) end debug_logging.attributes['enabled'] = (enable ? 1 : 0) end
[ "def", "enable_debug_logging", "=", "(", "enable", ")", "return", "if", "enable", ".", "nil?", "logging", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/Logging'", ")", "if", "logging", ".", "nil?", "logging", "=", "REXML", "::", "Element", ".", "new", "(", "'Logging'", ")", "@xml", ".", "add_element", "(", "logging", ")", "end", "debug_logging", "=", "REXML", "::", "XPath", ".", "first", "(", "logging", ",", "'debugLogging'", ")", "if", "debug_logging", ".", "nil?", "debug_logging", "=", "REXML", "::", "Element", ".", "new", "(", "'debugLogging'", ")", "logging", ".", "add_element", "(", "debug_logging", ")", "end", "debug_logging", ".", "attributes", "[", "'enabled'", "]", "=", "(", "enable", "?", "1", ":", "0", ")", "end" ]
Enable or disable the debug logging. @param [Boolean] enable Enable or disable the debug logging.
[ "Enable", "or", "disable", "the", "debug", "logging", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L565-L578
18,879
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.windows_service_editor=
def windows_service_editor=(enable) cifs_scanner = REXML::XPath.first(@xml, 'ScanTemplate/Plugins/Plugin[@name="java/CifsScanner"]') param = REXML::XPath.first(cifs_scanner, './param[@name="windowsServiceEditor"]') if param param.text = (enable ? '1' : '0') else param = REXML::Element.new('param') param.attributes['name'] = 'windowsServiceEditor' param.text = (enable ? '1' : '0') cifs_scanner.add_element(param) end param.text end
ruby
def windows_service_editor=(enable) cifs_scanner = REXML::XPath.first(@xml, 'ScanTemplate/Plugins/Plugin[@name="java/CifsScanner"]') param = REXML::XPath.first(cifs_scanner, './param[@name="windowsServiceEditor"]') if param param.text = (enable ? '1' : '0') else param = REXML::Element.new('param') param.attributes['name'] = 'windowsServiceEditor' param.text = (enable ? '1' : '0') cifs_scanner.add_element(param) end param.text end
[ "def", "windows_service_editor", "=", "(", "enable", ")", "cifs_scanner", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/Plugins/Plugin[@name=\"java/CifsScanner\"]'", ")", "param", "=", "REXML", "::", "XPath", ".", "first", "(", "cifs_scanner", ",", "'./param[@name=\"windowsServiceEditor\"]'", ")", "if", "param", "param", ".", "text", "=", "(", "enable", "?", "'1'", ":", "'0'", ")", "else", "param", "=", "REXML", "::", "Element", ".", "new", "(", "'param'", ")", "param", ".", "attributes", "[", "'name'", "]", "=", "'windowsServiceEditor'", "param", ".", "text", "=", "(", "enable", "?", "'1'", ":", "'0'", ")", "cifs_scanner", ".", "add_element", "(", "param", ")", "end", "param", ".", "text", "end" ]
Enable or disable windows service editor. @param [Boolean] enable Enable or disable windows service editor.
[ "Enable", "or", "disable", "windows", "service", "editor", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L589-L601
18,880
rapid7/nexpose-client
lib/nexpose/role.rb
Nexpose.Connection.role_listing
def role_listing xml = make_xml('RoleListingRequest') r = execute(xml, '1.2') roles = [] if r.success r.res.elements.each('RoleListingResponse/RoleSummary') do |summary| roles << RoleSummary.parse(summary) end end roles end
ruby
def role_listing xml = make_xml('RoleListingRequest') r = execute(xml, '1.2') roles = [] if r.success r.res.elements.each('RoleListingResponse/RoleSummary') do |summary| roles << RoleSummary.parse(summary) end end roles end
[ "def", "role_listing", "xml", "=", "make_xml", "(", "'RoleListingRequest'", ")", "r", "=", "execute", "(", "xml", ",", "'1.2'", ")", "roles", "=", "[", "]", "if", "r", ".", "success", "r", ".", "res", ".", "elements", ".", "each", "(", "'RoleListingResponse/RoleSummary'", ")", "do", "|", "summary", "|", "roles", "<<", "RoleSummary", ".", "parse", "(", "summary", ")", "end", "end", "roles", "end" ]
Returns a summary list of all roles.
[ "Returns", "a", "summary", "list", "of", "all", "roles", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/role.rb#L53-L63
18,881
rapid7/nexpose-client
lib/nexpose/role.rb
Nexpose.Role.save
def save(nsc) if @existing xml = nsc.make_xml('RoleUpdateRequest') else xml = nsc.make_xml('RoleCreateRequest') end xml.add_element(as_xml) response = APIRequest.execute(nsc.url, xml, '1.2', { timeout: nsc.timeout, open_timeout: nsc.open_timeout }) xml = REXML::XPath.first(response.res, 'RoleCreateResponse') @id = xml.attributes['id'].to_i unless @existing @existing = true response.success end
ruby
def save(nsc) if @existing xml = nsc.make_xml('RoleUpdateRequest') else xml = nsc.make_xml('RoleCreateRequest') end xml.add_element(as_xml) response = APIRequest.execute(nsc.url, xml, '1.2', { timeout: nsc.timeout, open_timeout: nsc.open_timeout }) xml = REXML::XPath.first(response.res, 'RoleCreateResponse') @id = xml.attributes['id'].to_i unless @existing @existing = true response.success end
[ "def", "save", "(", "nsc", ")", "if", "@existing", "xml", "=", "nsc", ".", "make_xml", "(", "'RoleUpdateRequest'", ")", "else", "xml", "=", "nsc", ".", "make_xml", "(", "'RoleCreateRequest'", ")", "end", "xml", ".", "add_element", "(", "as_xml", ")", "response", "=", "APIRequest", ".", "execute", "(", "nsc", ".", "url", ",", "xml", ",", "'1.2'", ",", "{", "timeout", ":", "nsc", ".", "timeout", ",", "open_timeout", ":", "nsc", ".", "open_timeout", "}", ")", "xml", "=", "REXML", "::", "XPath", ".", "first", "(", "response", ".", "res", ",", "'RoleCreateResponse'", ")", "@id", "=", "xml", ".", "attributes", "[", "'id'", "]", ".", "to_i", "unless", "@existing", "@existing", "=", "true", "response", ".", "success", "end" ]
Create or save a Role to the Nexpose console. @param [Connection] nsc Nexpose connection.
[ "Create", "or", "save", "a", "Role", "to", "the", "Nexpose", "console", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/role.rb#L174-L187
18,882
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.get
def get(nsc, uri, content_type = CONTENT_TYPE::XML, options = {}) parameterize_uri(uri, options) get = Net::HTTP::Get.new(uri) get.set_content_type(content_type) request(nsc, get) end
ruby
def get(nsc, uri, content_type = CONTENT_TYPE::XML, options = {}) parameterize_uri(uri, options) get = Net::HTTP::Get.new(uri) get.set_content_type(content_type) request(nsc, get) end
[ "def", "get", "(", "nsc", ",", "uri", ",", "content_type", "=", "CONTENT_TYPE", "::", "XML", ",", "options", "=", "{", "}", ")", "parameterize_uri", "(", "uri", ",", "options", ")", "get", "=", "Net", "::", "HTTP", "::", "Get", ".", "new", "(", "uri", ")", "get", ".", "set_content_type", "(", "content_type", ")", "request", "(", "nsc", ",", "get", ")", "end" ]
GET call to a Nexpose controller. @param [Connection] nsc API connection to a Nexpose console. @param [String] uri Controller address relative to https://host:port @param [String] content_type Content type to use when issuing the GET. @param [Hash] options Parameter options to the call. @return [String|REXML::Document|Hash] The response from the call.
[ "GET", "call", "to", "a", "Nexpose", "controller", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L31-L36
18,883
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.put
def put(nsc, uri, payload = nil, content_type = CONTENT_TYPE::XML) put = Net::HTTP::Put.new(uri) put.set_content_type(content_type) put.body = payload.to_s if payload request(nsc, put) end
ruby
def put(nsc, uri, payload = nil, content_type = CONTENT_TYPE::XML) put = Net::HTTP::Put.new(uri) put.set_content_type(content_type) put.body = payload.to_s if payload request(nsc, put) end
[ "def", "put", "(", "nsc", ",", "uri", ",", "payload", "=", "nil", ",", "content_type", "=", "CONTENT_TYPE", "::", "XML", ")", "put", "=", "Net", "::", "HTTP", "::", "Put", ".", "new", "(", "uri", ")", "put", ".", "set_content_type", "(", "content_type", ")", "put", ".", "body", "=", "payload", ".", "to_s", "if", "payload", "request", "(", "nsc", ",", "put", ")", "end" ]
PUT call to a Nexpose controller. @param [Connection] nsc API connection to a Nexpose console. @param [String] uri Controller address relative to https://host:port @param [String|REXML::Document] payload XML document required by the call. @param [String] content_type Content type to use when issuing the PUT. @return [String] The response from the call.
[ "PUT", "call", "to", "a", "Nexpose", "controller", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L46-L51
18,884
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.post
def post(nsc, uri, payload = nil, content_type = CONTENT_TYPE::XML, timeout = nil) post = Net::HTTP::Post.new(uri) post.set_content_type(content_type) post.body = payload.to_s if payload request(nsc, post, timeout) end
ruby
def post(nsc, uri, payload = nil, content_type = CONTENT_TYPE::XML, timeout = nil) post = Net::HTTP::Post.new(uri) post.set_content_type(content_type) post.body = payload.to_s if payload request(nsc, post, timeout) end
[ "def", "post", "(", "nsc", ",", "uri", ",", "payload", "=", "nil", ",", "content_type", "=", "CONTENT_TYPE", "::", "XML", ",", "timeout", "=", "nil", ")", "post", "=", "Net", "::", "HTTP", "::", "Post", ".", "new", "(", "uri", ")", "post", ".", "set_content_type", "(", "content_type", ")", "post", ".", "body", "=", "payload", ".", "to_s", "if", "payload", "request", "(", "nsc", ",", "post", ",", "timeout", ")", "end" ]
POST call to a Nexpose controller. @param [Connection] nsc API connection to a Nexpose console. @param [String] uri Controller address relative to https://host:port @param [String|REXML::Document] payload XML document required by the call. @param [String] content_type Content type to use when issuing the POST. @param [Fixnum] timeout Set an explicit timeout for the HTTP request. @return [String|REXML::Document|Hash] The response from the call.
[ "POST", "call", "to", "a", "Nexpose", "controller", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L62-L67
18,885
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.patch
def patch(nsc, uri, payload = nil, content_type = CONTENT_TYPE::XML) patch = Net::HTTP::Patch.new(uri) patch.set_content_type(content_type) patch.body = payload.to_s if payload request(nsc, patch) end
ruby
def patch(nsc, uri, payload = nil, content_type = CONTENT_TYPE::XML) patch = Net::HTTP::Patch.new(uri) patch.set_content_type(content_type) patch.body = payload.to_s if payload request(nsc, patch) end
[ "def", "patch", "(", "nsc", ",", "uri", ",", "payload", "=", "nil", ",", "content_type", "=", "CONTENT_TYPE", "::", "XML", ")", "patch", "=", "Net", "::", "HTTP", "::", "Patch", ".", "new", "(", "uri", ")", "patch", ".", "set_content_type", "(", "content_type", ")", "patch", ".", "body", "=", "payload", ".", "to_s", "if", "payload", "request", "(", "nsc", ",", "patch", ")", "end" ]
PATCH call to a Nexpose controller. @param [Connection] nsc API connection to a Nexpose console. @param [String] uri Controller address relative to https://host:port @param [String|REXML::Document] payload XML document required by the call. @param [String] content_type Content type to use when issuing the PATCH. @return [String] The response from the call.
[ "PATCH", "call", "to", "a", "Nexpose", "controller", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L77-L82
18,886
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.form_post
def form_post(nsc, uri, parameters, content_type = CONTENT_TYPE::FORM) post = Net::HTTP::Post.new(uri) post.set_content_type(content_type) post.set_form_data(parameters) request(nsc, post) end
ruby
def form_post(nsc, uri, parameters, content_type = CONTENT_TYPE::FORM) post = Net::HTTP::Post.new(uri) post.set_content_type(content_type) post.set_form_data(parameters) request(nsc, post) end
[ "def", "form_post", "(", "nsc", ",", "uri", ",", "parameters", ",", "content_type", "=", "CONTENT_TYPE", "::", "FORM", ")", "post", "=", "Net", "::", "HTTP", "::", "Post", ".", "new", "(", "uri", ")", "post", ".", "set_content_type", "(", "content_type", ")", "post", ".", "set_form_data", "(", "parameters", ")", "request", "(", "nsc", ",", "post", ")", "end" ]
POST call to a Nexpose controller that uses a form-post model. This is here to support legacy use of POST in old controllers. @param [Connection] nsc API connection to a Nexpose console. @param [String] uri Controller address relative to https://host:port @param [Hash] parameters Hash of attributes that need to be sent to the controller. @param [String] content_type Content type to use when issuing the POST. @return [Hash] The parsed JSON response from the call.
[ "POST", "call", "to", "a", "Nexpose", "controller", "that", "uses", "a", "form", "-", "post", "model", ".", "This", "is", "here", "to", "support", "legacy", "use", "of", "POST", "in", "old", "controllers", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L94-L99
18,887
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.delete
def delete(nsc, uri, content_type = CONTENT_TYPE::XML) delete = Net::HTTP::Delete.new(uri) delete.set_content_type(content_type) request(nsc, delete) end
ruby
def delete(nsc, uri, content_type = CONTENT_TYPE::XML) delete = Net::HTTP::Delete.new(uri) delete.set_content_type(content_type) request(nsc, delete) end
[ "def", "delete", "(", "nsc", ",", "uri", ",", "content_type", "=", "CONTENT_TYPE", "::", "XML", ")", "delete", "=", "Net", "::", "HTTP", "::", "Delete", ".", "new", "(", "uri", ")", "delete", ".", "set_content_type", "(", "content_type", ")", "request", "(", "nsc", ",", "delete", ")", "end" ]
DELETE call to a Nexpose controller. @param [Connection] nsc API connection to a Nexpose console. @param [String] uri Controller address relative to https://host:port @param [String] content_type Content type to use when issuing the DELETE.
[ "DELETE", "call", "to", "a", "Nexpose", "controller", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L106-L110
18,888
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.get_error_message
def get_error_message(request, response) version = get_request_api_version(request) data_request = use_response_error_message?(request, response) return_response = (version >= 2.1 || data_request) (return_response && response.body) ? "response body: #{response.body}" : "request body: #{request.body}" end
ruby
def get_error_message(request, response) version = get_request_api_version(request) data_request = use_response_error_message?(request, response) return_response = (version >= 2.1 || data_request) (return_response && response.body) ? "response body: #{response.body}" : "request body: #{request.body}" end
[ "def", "get_error_message", "(", "request", ",", "response", ")", "version", "=", "get_request_api_version", "(", "request", ")", "data_request", "=", "use_response_error_message?", "(", "request", ",", "response", ")", "return_response", "=", "(", "version", ">=", "2.1", "||", "data_request", ")", "(", "return_response", "&&", "response", ".", "body", ")", "?", "\"response body: #{response.body}\"", ":", "\"request body: #{request.body}\"", "end" ]
Get an error message from the response body if the request url api version is 2.1 or greater otherwise use the request body
[ "Get", "an", "error", "message", "from", "the", "response", "body", "if", "the", "request", "url", "api", "version", "is", "2", ".", "1", "or", "greater", "otherwise", "use", "the", "request", "body" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L194-L199
18,889
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.use_response_error_message?
def use_response_error_message?(request, response) if (request.path.include?('/data/') && !response.content_type.nil?) response.content_type.include? 'text/plain' else false end end
ruby
def use_response_error_message?(request, response) if (request.path.include?('/data/') && !response.content_type.nil?) response.content_type.include? 'text/plain' else false end end
[ "def", "use_response_error_message?", "(", "request", ",", "response", ")", "if", "(", "request", ".", "path", ".", "include?", "(", "'/data/'", ")", "&&", "!", "response", ".", "content_type", ".", "nil?", ")", "response", ".", "content_type", ".", "include?", "'text/plain'", "else", "false", "end", "end" ]
Code cleanup to allow for cleaner get_error_message method
[ "Code", "cleanup", "to", "allow", "for", "cleaner", "get_error_message", "method" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L203-L209
18,890
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.preserving_preference
def preserving_preference(nsc, pref) orig = get_rows(nsc, pref) yield ensure set_rows(nsc, pref, orig) end
ruby
def preserving_preference(nsc, pref) orig = get_rows(nsc, pref) yield ensure set_rows(nsc, pref, orig) end
[ "def", "preserving_preference", "(", "nsc", ",", "pref", ")", "orig", "=", "get_rows", "(", "nsc", ",", "pref", ")", "yield", "ensure", "set_rows", "(", "nsc", ",", "pref", ",", "orig", ")", "end" ]
Execute a block of code while presenving the preferences for any underlying table being accessed. Use this method when accessing data tables which are present in the UI to prevent existing row preferences from being set to 500. This is an internal utility method, not subject to backward compatibility concerns. @param [Connection] nsc Live connection to a Nepose console. @param [String] pref Preference key value to preserve.
[ "Execute", "a", "block", "of", "code", "while", "presenving", "the", "preferences", "for", "any", "underlying", "table", "being", "accessed", ".", "Use", "this", "method", "when", "accessing", "data", "tables", "which", "are", "present", "in", "the", "UI", "to", "prevent", "existing", "row", "preferences", "from", "being", "set", "to", "500", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L222-L227
18,891
rapid7/nexpose-client
lib/nexpose/filter.rb
Nexpose.Connection.filter
def filter(field, operator, value = '') criterion = Criterion.new(field, operator, value) criteria = Criteria.new(criterion) search(criteria) end
ruby
def filter(field, operator, value = '') criterion = Criterion.new(field, operator, value) criteria = Criteria.new(criterion) search(criteria) end
[ "def", "filter", "(", "field", ",", "operator", ",", "value", "=", "''", ")", "criterion", "=", "Criterion", ".", "new", "(", "field", ",", "operator", ",", "value", ")", "criteria", "=", "Criteria", ".", "new", "(", "criterion", ")", "search", "(", "criteria", ")", "end" ]
Perform an asset filter search that will locate assets matching the provided conditions. For example, the following call will return assets with Java installed: nsc.filter(Search::Field::SOFTWARE, Search::Operator::CONTAINS, 'java') @param [String] field Constant from Search::Field @param [String] operator Constant from Search::Operator @param [String] value Search term or constant from Search::Value @return [Array[FilteredAsset]] List of matching assets.
[ "Perform", "an", "asset", "filter", "search", "that", "will", "locate", "assets", "matching", "the", "provided", "conditions", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/filter.rb#L15-L19
18,892
rapid7/nexpose-client
lib/nexpose/filter.rb
Nexpose.Connection.search
def search(criteria) results = DataTable._get_json_table(self, '/data/asset/filterAssets', criteria._to_payload) results.map { |a| FilteredAsset.new(a) } end
ruby
def search(criteria) results = DataTable._get_json_table(self, '/data/asset/filterAssets', criteria._to_payload) results.map { |a| FilteredAsset.new(a) } end
[ "def", "search", "(", "criteria", ")", "results", "=", "DataTable", ".", "_get_json_table", "(", "self", ",", "'/data/asset/filterAssets'", ",", "criteria", ".", "_to_payload", ")", "results", ".", "map", "{", "|", "a", "|", "FilteredAsset", ".", "new", "(", "a", ")", "}", "end" ]
Perform a search that will match the criteria provided. For example, the following call will return assets with Java and .NET: java_criterion = Criterion.new(Search::Field::SOFTWARE, Search::Operator::CONTAINS, 'java') dot_net_criterion = Criterion.new(Search::Field::SOFTWARE, Search::Operator::CONTAINS, '.net') criteria = Criteria.new([java_criterion, dot_net_criterion]) results = nsc.search(criteria) @param [Criteria] criteria Criteria search object. @return [Array[FilteredAsset]] List of matching assets.
[ "Perform", "a", "search", "that", "will", "match", "the", "criteria", "provided", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/filter.rb#L36-L39
18,893
rapid7/nexpose-client
lib/nexpose/connection.rb
Nexpose.Connection.login
def login login_hash = { 'sync-id' => 0, 'password' => @password, 'user-id' => @username, 'token' => @token } login_hash['silo-id'] = @silo_id if @silo_id r = execute(make_xml('LoginRequest', login_hash)) if r.success @session_id = r.sid true end rescue APIError raise AuthenticationFailed.new(r) end
ruby
def login login_hash = { 'sync-id' => 0, 'password' => @password, 'user-id' => @username, 'token' => @token } login_hash['silo-id'] = @silo_id if @silo_id r = execute(make_xml('LoginRequest', login_hash)) if r.success @session_id = r.sid true end rescue APIError raise AuthenticationFailed.new(r) end
[ "def", "login", "login_hash", "=", "{", "'sync-id'", "=>", "0", ",", "'password'", "=>", "@password", ",", "'user-id'", "=>", "@username", ",", "'token'", "=>", "@token", "}", "login_hash", "[", "'silo-id'", "]", "=", "@silo_id", "if", "@silo_id", "r", "=", "execute", "(", "make_xml", "(", "'LoginRequest'", ",", "login_hash", ")", ")", "if", "r", ".", "success", "@session_id", "=", "r", ".", "sid", "true", "end", "rescue", "APIError", "raise", "AuthenticationFailed", ".", "new", "(", "r", ")", "end" ]
A constructor for Connection @param [String] ip The IP address or hostname/FQDN of the Nexpose console. @param [String] user The username for Nexpose sessions. @param [String] pass The password for Nexpose sessions. @param [Fixnum] port The port number of the Nexpose console. @param [String] silo_id The silo identifier for Nexpose sessions. @param [String] token The two-factor authentication (2FA) token for Nexpose sessions. @param [String] trust_cert The PEM-formatted web certificate of the Nexpose console. Used for SSL validation. Establish a new connection and Session ID
[ "A", "constructor", "for", "Connection" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/connection.rb#L99-L109
18,894
rapid7/nexpose-client
lib/nexpose/connection.rb
Nexpose.Connection.logout
def logout r = execute(make_xml('LogoutRequest', { 'sync-id' => 0 })) return true if r.success raise APIError.new(r, 'Logout failed') end
ruby
def logout r = execute(make_xml('LogoutRequest', { 'sync-id' => 0 })) return true if r.success raise APIError.new(r, 'Logout failed') end
[ "def", "logout", "r", "=", "execute", "(", "make_xml", "(", "'LogoutRequest'", ",", "{", "'sync-id'", "=>", "0", "}", ")", ")", "return", "true", "if", "r", ".", "success", "raise", "APIError", ".", "new", "(", "r", ",", "'Logout failed'", ")", "end" ]
Logout of the current connection
[ "Logout", "of", "the", "current", "connection" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/connection.rb#L112-L116
18,895
rapid7/nexpose-client
lib/nexpose/connection.rb
Nexpose.Connection.execute
def execute(xml, version = '1.1', options = {}) options.store(:timeout, @timeout) unless options.key?(:timeout) options.store(:open_timeout, @open_timeout) @request_xml = xml.to_s @api_version = version response = APIRequest.execute(@url, @request_xml, @api_version, options, @trust_store) @response_xml = response.raw_response_data response end
ruby
def execute(xml, version = '1.1', options = {}) options.store(:timeout, @timeout) unless options.key?(:timeout) options.store(:open_timeout, @open_timeout) @request_xml = xml.to_s @api_version = version response = APIRequest.execute(@url, @request_xml, @api_version, options, @trust_store) @response_xml = response.raw_response_data response end
[ "def", "execute", "(", "xml", ",", "version", "=", "'1.1'", ",", "options", "=", "{", "}", ")", "options", ".", "store", "(", ":timeout", ",", "@timeout", ")", "unless", "options", ".", "key?", "(", ":timeout", ")", "options", ".", "store", "(", ":open_timeout", ",", "@open_timeout", ")", "@request_xml", "=", "xml", ".", "to_s", "@api_version", "=", "version", "response", "=", "APIRequest", ".", "execute", "(", "@url", ",", "@request_xml", ",", "@api_version", ",", "options", ",", "@trust_store", ")", "@response_xml", "=", "response", ".", "raw_response_data", "response", "end" ]
Execute an API request
[ "Execute", "an", "API", "request" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/connection.rb#L119-L127
18,896
rapid7/nexpose-client
lib/nexpose/connection.rb
Nexpose.Connection.download
def download(url, file_name = nil) return nil if (url.nil? || url.empty?) uri = URI.parse(url) http = Net::HTTP.new(@host, @port) http.use_ssl = true if @trust_store.nil? http.verify_mode = OpenSSL::SSL::VERIFY_NONE # XXX: security issue else http.cert_store = @trust_store end headers = { 'Cookie' => "nexposeCCSessionID=#{@session_id}" } if file_name http.request_get(uri.to_s, headers) do |resp| ::File.open(file_name, 'wb') do |file| resp.read_body { |chunk| file.write(chunk) } end end else resp = http.get(uri.to_s, headers) resp.body end end
ruby
def download(url, file_name = nil) return nil if (url.nil? || url.empty?) uri = URI.parse(url) http = Net::HTTP.new(@host, @port) http.use_ssl = true if @trust_store.nil? http.verify_mode = OpenSSL::SSL::VERIFY_NONE # XXX: security issue else http.cert_store = @trust_store end headers = { 'Cookie' => "nexposeCCSessionID=#{@session_id}" } if file_name http.request_get(uri.to_s, headers) do |resp| ::File.open(file_name, 'wb') do |file| resp.read_body { |chunk| file.write(chunk) } end end else resp = http.get(uri.to_s, headers) resp.body end end
[ "def", "download", "(", "url", ",", "file_name", "=", "nil", ")", "return", "nil", "if", "(", "url", ".", "nil?", "||", "url", ".", "empty?", ")", "uri", "=", "URI", ".", "parse", "(", "url", ")", "http", "=", "Net", "::", "HTTP", ".", "new", "(", "@host", ",", "@port", ")", "http", ".", "use_ssl", "=", "true", "if", "@trust_store", ".", "nil?", "http", ".", "verify_mode", "=", "OpenSSL", "::", "SSL", "::", "VERIFY_NONE", "# XXX: security issue", "else", "http", ".", "cert_store", "=", "@trust_store", "end", "headers", "=", "{", "'Cookie'", "=>", "\"nexposeCCSessionID=#{@session_id}\"", "}", "if", "file_name", "http", ".", "request_get", "(", "uri", ".", "to_s", ",", "headers", ")", "do", "|", "resp", "|", "::", "File", ".", "open", "(", "file_name", ",", "'wb'", ")", "do", "|", "file", "|", "resp", ".", "read_body", "{", "|", "chunk", "|", "file", ".", "write", "(", "chunk", ")", "}", "end", "end", "else", "resp", "=", "http", ".", "get", "(", "uri", ".", "to_s", ",", "headers", ")", "resp", ".", "body", "end", "end" ]
Download a specific URL, typically a report. Include an optional file_name parameter to write the output to a file. Note: XML and HTML reports have charts not downloaded by this method. Would need to do something more sophisticated to grab all the associated image files.
[ "Download", "a", "specific", "URL", "typically", "a", "report", ".", "Include", "an", "optional", "file_name", "parameter", "to", "write", "the", "output", "to", "a", "file", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/connection.rb#L135-L157
18,897
rapid7/nexpose-client
lib/nexpose/device.rb
Nexpose.Connection.find_device_by_address
def find_device_by_address(address, site_id = nil) r = execute(make_xml('SiteDeviceListingRequest', { 'site-id' => site_id })) if r.success device = REXML::XPath.first(r.res, "SiteDeviceListingResponse/SiteDevices/device[@address='#{address}']") if device return Device.new(device.attributes['id'].to_i, device.attributes['address'], device.parent.attributes['site-id'], device.attributes['riskfactor'].to_f, device.attributes['riskscore'].to_f) end end nil end
ruby
def find_device_by_address(address, site_id = nil) r = execute(make_xml('SiteDeviceListingRequest', { 'site-id' => site_id })) if r.success device = REXML::XPath.first(r.res, "SiteDeviceListingResponse/SiteDevices/device[@address='#{address}']") if device return Device.new(device.attributes['id'].to_i, device.attributes['address'], device.parent.attributes['site-id'], device.attributes['riskfactor'].to_f, device.attributes['riskscore'].to_f) end end nil end
[ "def", "find_device_by_address", "(", "address", ",", "site_id", "=", "nil", ")", "r", "=", "execute", "(", "make_xml", "(", "'SiteDeviceListingRequest'", ",", "{", "'site-id'", "=>", "site_id", "}", ")", ")", "if", "r", ".", "success", "device", "=", "REXML", "::", "XPath", ".", "first", "(", "r", ".", "res", ",", "\"SiteDeviceListingResponse/SiteDevices/device[@address='#{address}']\"", ")", "if", "device", "return", "Device", ".", "new", "(", "device", ".", "attributes", "[", "'id'", "]", ".", "to_i", ",", "device", ".", "attributes", "[", "'address'", "]", ",", "device", ".", "parent", ".", "attributes", "[", "'site-id'", "]", ",", "device", ".", "attributes", "[", "'riskfactor'", "]", ".", "to_f", ",", "device", ".", "attributes", "[", "'riskscore'", "]", ".", "to_f", ")", "end", "end", "nil", "end" ]
Find a Device by its address. This is a convenience method for finding a single device from a SiteDeviceListing. If no site_id is provided, the first matching device will be returned when a device occurs across multiple sites. @param [String] address Address of the device to find. Usually the IP address. @param [FixNum] site_id Site ID to restrict search to. @return [Device] The first matching Device with the provided address, if found.
[ "Find", "a", "Device", "by", "its", "address", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/device.rb#L17-L30
18,898
rapid7/nexpose-client
lib/nexpose/device.rb
Nexpose.Connection.list_site_devices
def list_site_devices(site_id = nil) r = execute(make_xml('SiteDeviceListingRequest', { 'site-id' => site_id })) devices = [] if r.success r.res.elements.each('SiteDeviceListingResponse/SiteDevices') do |site| site_id = site.attributes['site-id'].to_i site.elements.each('device') do |device| devices << Device.new(device.attributes['id'].to_i, device.attributes['address'], site_id, device.attributes['riskfactor'].to_f, device.attributes['riskscore'].to_f) end end end devices end
ruby
def list_site_devices(site_id = nil) r = execute(make_xml('SiteDeviceListingRequest', { 'site-id' => site_id })) devices = [] if r.success r.res.elements.each('SiteDeviceListingResponse/SiteDevices') do |site| site_id = site.attributes['site-id'].to_i site.elements.each('device') do |device| devices << Device.new(device.attributes['id'].to_i, device.attributes['address'], site_id, device.attributes['riskfactor'].to_f, device.attributes['riskscore'].to_f) end end end devices end
[ "def", "list_site_devices", "(", "site_id", "=", "nil", ")", "r", "=", "execute", "(", "make_xml", "(", "'SiteDeviceListingRequest'", ",", "{", "'site-id'", "=>", "site_id", "}", ")", ")", "devices", "=", "[", "]", "if", "r", ".", "success", "r", ".", "res", ".", "elements", ".", "each", "(", "'SiteDeviceListingResponse/SiteDevices'", ")", "do", "|", "site", "|", "site_id", "=", "site", ".", "attributes", "[", "'site-id'", "]", ".", "to_i", "site", ".", "elements", ".", "each", "(", "'device'", ")", "do", "|", "device", "|", "devices", "<<", "Device", ".", "new", "(", "device", ".", "attributes", "[", "'id'", "]", ".", "to_i", ",", "device", ".", "attributes", "[", "'address'", "]", ",", "site_id", ",", "device", ".", "attributes", "[", "'riskfactor'", "]", ".", "to_f", ",", "device", ".", "attributes", "[", "'riskscore'", "]", ".", "to_f", ")", "end", "end", "end", "devices", "end" ]
Retrieve a list of all of the assets in a site. If no site-id is specified, then return all of the assets for the Nexpose console, grouped by site-id. @param [FixNum] site_id Site ID to request device listing for. Optional. @return [Array[Device]] Array of devices associated with the site, or all devices on the console if no site is provided.
[ "Retrieve", "a", "list", "of", "all", "of", "the", "assets", "in", "a", "site", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/device.rb#L43-L60
18,899
rapid7/nexpose-client
lib/nexpose/device.rb
Nexpose.Connection.group_assets
def group_assets(group_id) payload = { 'sort' => 'assetName', 'table-id' => 'group-assets', 'groupID' => group_id } results = DataTable._get_json_table(self, '/data/asset/group', payload) results.map { |a| FilteredAsset.new(a) } end
ruby
def group_assets(group_id) payload = { 'sort' => 'assetName', 'table-id' => 'group-assets', 'groupID' => group_id } results = DataTable._get_json_table(self, '/data/asset/group', payload) results.map { |a| FilteredAsset.new(a) } end
[ "def", "group_assets", "(", "group_id", ")", "payload", "=", "{", "'sort'", "=>", "'assetName'", ",", "'table-id'", "=>", "'group-assets'", ",", "'groupID'", "=>", "group_id", "}", "results", "=", "DataTable", ".", "_get_json_table", "(", "self", ",", "'/data/asset/group'", ",", "payload", ")", "results", ".", "map", "{", "|", "a", "|", "FilteredAsset", ".", "new", "(", "a", ")", "}", "end" ]
Get a list of all assets currently associated with a group. @param [Fixnum] group_id Unique identifier of an asset group. @return [Array[FilteredAsset]] List of group assets.
[ "Get", "a", "list", "of", "all", "assets", "currently", "associated", "with", "a", "group", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/device.rb#L72-L78