idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
8,500
def diagonalColumnRow ( d , i ) { 'column' => ( d . to_i < 0 ? i : d . to_i + i ) . to_i , 'row' => ( d . to_i < 0 ? d . to_i . abs + i : i ) . to_i } end
Get the column and row based on the diagonal hash created using diagonalLines .
8,501
def getSobel ( x , y ) if ! defined? ( @sobels ) @sobel_x ||= [ [ - 1 , 0 , 1 ] , [ - 2 , 0 , 2 ] , [ - 1 , 0 , 1 ] ] @sobel_y ||= [ [ - 1 , - 2 , - 1 ] , [ 0 , 0 , 0 ] , [ 1 , 2 , 1 ] ] return 0 if x . zero? || ( x == ( @width - 1 ) ) || y . zero? || ( y == ( @height - 1 ) ) t1 = @grey [ y - 1 ] [ x - 1 ] t2 = @grey [...
Retrieve Sobel value for a given pixel .
8,502
def getSobels unless defined? ( @sobels ) l = [ ] ( 0 ... ( @width * @height ) ) . each do | xy | s = getSobel ( xy % @width , ( xy / @width ) . floor ) l . push ( s ) end @sobels = l end @sobels end
Retrieve the Sobel values for every pixel and set it as
8,503
def build_call_chain ( stack ) stack . reverse . inject ( EMPTY_MIDDLEWARE ) do | next_middleware , current_middleware | klass , args , block = current_middleware args ||= [ ] if klass . is_a? ( Class ) klass . new ( next_middleware , * args , & block ) elsif klass . respond_to? ( :call ) lambda do | env | next_middlew...
This takes a stack of middlewares and initializes them in a way that each middleware properly calls the next middleware .
8,504
def insert_before_each ( middleware , * args , & block ) self . stack = stack . reduce ( [ ] ) do | carry , item | carry . push ( [ middleware , args , block ] , item ) end end
Inserts a middleware before each middleware object
8,505
def delete ( index ) index = self . index ( index ) unless index . is_a? ( Integer ) stack . delete_at ( index ) end
Deletes the given middleware object or index
8,506
def to_hash doc = :: Nokogiri :: XML ( self . response ) hash = { } doc . at_css ( "Response" ) . element_children . each do | attribute | hash [ attribute . name . underscore . to_sym ] = attribute . inner_text end hash [ :valid ] = doc . at_css ( "Response" ) [ 'valid' ] hash end
Return the response as a hash
8,507
def valid_target_url? return false unless cloud_info = cloud_info ( ) return false unless cloud_info [ :name ] return false unless cloud_info [ :build ] return false unless cloud_info [ :support ] return false unless cloud_info [ :version ] true rescue false end
Checks if the target_url is a valid CloudFoundry target .
8,508
def result case @type when :anime iter { | i | Jikan :: AnimeResult . new ( i ) } when :manga iter { | i | Jikan :: MangaResult . new ( i ) } when :character iter { | i | Jikan :: CharacterResult . new ( i ) } when :person iter { | i | Jikan :: PersonResult . new ( i ) } end end
returns each result items wrapped in their respective objects
8,509
def parse_url ( url ) uri = URI ( url ) if URI . split ( url ) [ 3 ] . nil? uri . port = uri . scheme == 'https' ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT end raise ArgumentError , "URL #{url} has invalid scheme" unless uri . scheme =~ / / parsed_url = { ssl : uri . scheme == 'https' , host : uri . host , port : uri . p...
Parse a URL to determine hostname port number and whether or not SSL is used .
8,510
def resources build raise OctocatalogDiff :: Errors :: CatalogError , 'Catalog does not appear to have been built' if ! valid? && error_message . nil? raise OctocatalogDiff :: Errors :: CatalogError , error_message unless valid? return @catalog [ 'data' ] [ 'resources' ] if @catalog [ 'data' ] . is_a? ( Hash ) && @cata...
This is a compatibility layer for the resources which are in a different place in Puppet 3 . x and Puppet 4 . x
8,511
def facts ( node = @node , timestamp = false ) raise "Expected @facts to be a hash but it is a #{@facts.class}" unless @facts . is_a? ( Hash ) raise "Expected @facts['values'] to be a hash but it is a #{@facts['values'].class}" unless @facts [ 'values' ] . is_a? ( Hash ) f = @facts . dup f [ 'name' ] = node unless node...
Facts - returned the cleansed facts . Clean up facts by setting name to the node if given and deleting _timestamp and expiration which may cause Puppet catalog compilation to fail if the facts are old .
8,512
def without ( remove ) r = remove . is_a? ( Array ) ? remove : [ remove ] obj = dup r . each { | fact | obj . remove_fact_from_list ( fact ) } obj end
Facts - remove one or more facts from the list .
8,513
def facts_to_yaml ( node = @node ) f = facts ( node ) fact_file = f . to_yaml . split ( / \n / ) fact_file [ 0 ] = '--- !ruby/object:Puppet::Node::Facts' if fact_file [ 0 ] =~ / / fact_file . join ( "\n" ) end
Turn hash of facts into appropriate YAML for Puppet
8,514
def parameter_value_of ( param ) _String = Rjb :: import 'java.lang.String' if param . class . parent == Rjb param else _String . new ( param . to_s , "UTF-8" ) end end
Returns the value without conversion when it s converted to Java Types . When isn t a Rjb class returns a Java String of it .
8,515
def schedule! options = { } options = options . dup if run_every = options . delete ( :run_every ) options [ :run_interval ] = serialize_duration ( run_every ) end @schedule_options = options . reverse_merge ( @schedule_options || { } ) . reverse_merge ( run_at : self . class . run_at , timezone : self . class . timezo...
Schedule this repeating job
8,516
def create_methods_from_instance ( instance ) instance . public_methods ( false ) . each do | method_name | add_method ( instance , method_name ) end end
Loop through all of the endpoint instances public singleton methods to add the method to client
8,517
def add_method ( instance , method_name ) define_singleton_method ( method_name ) do | * args | instance . public_send ( method_name , * args ) end end
Define the method on the client and send it to the endpoint instance with the args passed in
8,518
def auth_keys AUTH_KEYS . inject ( { } ) do | keys_hash , key | keys_hash [ key ] = send ( key ) keys_hash end end
Creates the configuration
8,519
def write_to_disk ( path ) filename = File . basename ( path ) path . dirname . mkpath unless path . dirname . exist? yaml = to_link_yaml File . open ( path , 'w' ) { | f | f . write ( yaml ) } self . defined_in_file = path end
Hook the Podfile . lock file generation to allow us to filter out the links added to the Podfile . lock . The logic here is to replace the new Podfile . lock link content with what existed before the link was added . Currently this is called for both Podfile . lock and Manifest . lock file so we only want to alter the ...
8,520
def to_link_hash after_hash = to_hash unless File . exists? ( PODFILE_LOCK ) return after_hash end before_hash = YAML . load ( File . read ( PODFILE_LOCK ) ) links = Pod :: Command :: Links . installed_links after_hash [ 'PODS' ] = merge_pods links , before_hash [ 'PODS' ] , after_hash [ 'PODS' ] after_hash [ 'DEPENDEN...
Will get the Podfile . lock contents hash after replacing the linked content with its previous Podfile . lock information keeping the Podfile and Podfile . lock in sync and clear of any link data
8,521
def merge_dependencies ( links , before , after ) links . each do | link | before_index = find_dependency_index before , link after_index = find_dependency_index after , link unless before_index . nil? || after_index . nil? after [ after_index ] = before [ before_index ] end end return after end
Will merge the DEPENDENCIES of the Podfile . lock before a link and after a link
8,522
def merge_hashes ( links , before , after ) if before . nil? return after end links . each do | link | if before . has_key? ( link ) after [ link ] = before [ link ] else if after . has_key? ( link ) after . delete ( link ) end end end return after end
Will merge the hashes of the Podfile . lock before a link and after a link
8,523
def perform ( campaign , subscription ) subscriber = subscription . subscriber return if subscriber . blank? mailer = campaign . prepare_mail_to ( subscription ) response = mailer . deliver message_id = response . message_id . gsub ( "@email.amazonses.com" , "" ) campaign . metrics . create ( trackable : subscription ,...
send to ses
8,524
def clean_inline_css ( url ) premailer = Premailer . new ( url , :adapter => :nokogiri , :escape_url_attributes => false ) premailer . to_inline_css . gsub ( "Drop Content Blocks Here" , "" ) end
will remove content blocks text
8,525
def perform ( campaign ) campaign . apply_premailer campaign . list . subscriptions . availables . each do | s | campaign . push_notification ( s ) end end
send to all list with state passive & subscribed
8,526
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
8,527
def comment ( opts ) opts = opts . merge ( :sale_id => self . sale_id ) Twocheckout :: API . request ( :post , 'sales/create_comment' , opts ) end
Add a sale comment
8,528
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
8,529
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 .
8,530
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
8,531
def commonjs_module? data . to_s . include? ( "module.exports" ) || data . present? && data . to_s . match ( / \( \) / ) && dependencies . length > 0 end
Is this a commonjs module?
8,532
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
8,533
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 .
8,534
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 .
8,535
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 ...
Obtain the version information for each scan engine . Includes Product Content and Java versions .
8,536
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 .
8,537
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 ( 'Sc...
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 ...
8,538
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 identfi...
8,539
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 .
8,540
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 = ...
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 .
8,541
def _append_asset! ( xml , asset ) if asset . is_a? Nexpose :: IPRange xml . add_element ( 'range' , 'from' => asset . from , 'to' => asset . to ) else 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 .
8,542
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 .
8,543
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 .
8,544
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 .
8,545
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 .
8,546
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 .
8,547
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 .
8,548
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 .
8,549
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 .
8,550
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 ) d...
Get a history of past scans for this console sorted by most recent first .
8,551
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...
Get paused scans . Provide a site ID to get paused scans for a site . With no site ID all paused scans are returned .
8,552
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' ) { | fi...
Export the data associated with a single scan and optionally store it in a zip - compressed file under the provided name .
8,553
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 , 'a...
Import scan data into a site .
8,554
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 . g...
Helper method to get the YUI tables into a consumable Ruby object .
8,555
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 [ he...
Helper method to get a Dyntable into a consumable Ruby object .
8,556
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 .
8,557
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 .
8,558
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 .
8,559
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 .
8,560
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 .
8,561
def object_from_hash ( nsc , hash ) hash . each do | k , v | next if k == :url 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 if v . is_a? ( String ) && v . match ( / \d \d \. \d / ) ...
Populate object methods and attributes from a JSON - derived hash .
8,562
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? ...
Load a resource from the security console . Once loaded the value is cached so that it need not be loaded again .
8,563
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 .
8,564
def save ( nsc ) 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 ) da...
Save this dynamic asset group to the Nexpose console . Warning saving this object does not set the id . It must be retrieved independently .
8,565
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 . ...
Retrieve a list of all Scan Engine Pools managed by the Security Console .
8,566
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...
Save an engine pool to a security console .
8,567
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 [ 'r...
Retrieve a list of all sites the user is authorized to view or manage .
8,568
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 .
8,569
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 .
8,570
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...
Remove assets to this site by IP address range .
8,571
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...
Adds assets to this site excluded scan targets by IP address range .
8,572
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 .
8,573
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 .
8,574
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 . ...
Scan this site .
8,575
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 .
8,576
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 .
8,577
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 ) return summary unless wait && summ...
Generate a new report using the specified report definition .
8,578
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 .
8,579
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 = respons...
Generate a report once using a simple configuration .
8,580
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 .
8,581
def list_vulns ( full = false ) xml = make_xml ( 'VulnerabilityListingRequest' ) 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 vu...
Retrieve summary details of all vulnerabilities .
8,582
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 .
8,583
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 )...
Search for Vulnerability Checks .
8,584
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 .
8,585
def delete_tickets ( tickets ) 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 .
8,586
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 .
8,587
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 . attribut...
Save modifications to the Nexpose security console .
8,588
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 .
8,589
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 ) ro...
Assign name to this scan template . Required attribute .
8,590
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 . ...
Assign a description to this scan template . Require attribute .
8,591
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
8,592
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
8,593
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
8,594
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
8,595
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 ( ',' )...
Set custom TCP ports to scan for TCP service discovery
8,596
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
8,597
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
8,598
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 .
8,599
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 } ) ...
Enable individual check for this template .