class OpenvasCli::VasTask

Attributes

comment[R]
config_id[R]
last_report_id[RW]
name[R]
schedule_id[R]
status[RW]
target_id[R]
times_run[RW]

Public Class Methods

from_xml_node(node) click to toggle source
# File lib/openvas-cli/vas_task.rb, line 203
def self.from_xml_node(node)
  t                = VasTask.new
  t.id             = extract_value_from("@id", node)
  t.name           = extract_value_from("name", node)
  t.comment        = extract_value_from("comment", node)
  t.status         = extract_value_from("status", node)
  if node.at_xpath("progress")
    t.progress = VasTaskProgress.from_xml_node(node.at_xpath("progress"))
  end
  t.times_run      = extract_value_from("report_count/finished", node).to_i
  t.last_report_id = extract_value_from("last_report/report/@id", node)
  t.config_id      = extract_value_from("config/@id", node)
  t.target_id      = extract_value_from("target/@id", node)
  node.xpath("reports/report").each { |xr|
    t.reports << VasReport.new({
      :id => extract_value_from("@id", xr),
      :started_at => extract_value_from("timestamp", xr)
    })
  }  
  
  t.reset_changes
  
  t
end
get_all(options = {}) click to toggle source
# File lib/openvas-cli/vas_task.rb, line 184
def self.get_all(options = {})
  params = {:apply_overrides => 0, :sort_field => "name"}
  
  params[:task_id] = options[:id] if options[:id]

  req = Nokogiri::XML::Builder.new { |xml|
    xml.get_tasks(params)
  }
  
  tasks = connection.send_receive(req.doc)
  
  ret = []
  tasks.xpath('//task').each { |t|
    ret << from_xml_node(t)
  }
  
  ret
end

Public Instance Methods

comment=(val) click to toggle source
# File lib/openvas-cli/vas_task.rb, line 28
def comment=(val)
  comment_will_change! unless @comment == val
  @comment = val
end
config() click to toggle source
# File lib/openvas-cli/vas_task.rb, line 57
def config
  @config ||= pull_my_config
end
config=(val) click to toggle source
# File lib/openvas-cli/vas_task.rb, line 61
def config=(val)
  @config = val
  config_id = val.id if val
end
config_id=(v) click to toggle source
# File lib/openvas-cli/vas_task.rb, line 33
def config_id=(v)
  config_id_will_change! unless @config_id == v
  @config_id = v
end
create_or_update() click to toggle source
# File lib/openvas-cli/vas_task.rb, line 79
def create_or_update
      
  if schedule && schedule.changed?
    return unless schedule.save
    schedule_id = schedule.id
  end
  
  if config && config.changed?
    return unless config.save
    config_id = config.id
  end
   
  req = Nokogiri::XML::Builder.new { |xml|
    if @id
      xml.modify_task(:id => @id) {
        xml.name    { xml.text(@name) }    if name_changed?
        xml.comment { xml.text(@comment) } if comment_changed?
        xml.schedule(:id => @schedule_id)  if schedule_id && !schedule_id.blank? && schedule_id_changed?
      }
    else
      xml.create_task {
        xml.name    { xml.text(@name) }    if @name
        xml.comment { xml.text(@comment) } if @comment
        xml.config(:id => @config_id)
        xml.target(:id => @target_id)
        xml.schedule(:id => @schedule_id)  if @schedule_id && !@schedule_id.blank?
      }
    end
  }
  
  begin
    resp = VasTask.connection.send_receive(req.doc)
    @id = VasTask.extract_value_from("/create_task_response/@id", resp) unless @id
    reset_changes
    
    true
  rescue VasExceptions::CommandException => e
    errors[:command_failure] << e.message
    
    nil
  end
  
  
end
delete_record() click to toggle source
# File lib/openvas-cli/vas_task.rb, line 124
def delete_record
  req = Nokogiri::XML::Builder.new { |xml|
    xml.delete_task(:task_id => @id)
  }
  
  begin
    VasTask.connection.send_receive(req.doc)
    
    true
  rescue VasExceptions::CommandException => e
    errors[:command_failure] << e.message
    
    nil
  end
end
name=(val) click to toggle source
# File lib/openvas-cli/vas_task.rb, line 23
def name=(val)
  name_will_change! unless @name == val
  @name = val
end
pause() click to toggle source
# File lib/openvas-cli/vas_task.rb, line 168
def pause
  req = Nokogiri::XML::Builder.new { |xml|
    xml.pause_task(:task_id => @id)
  }
  
  VasTask.connection.send_receive(req.doc)
end
progress(refresh=false) click to toggle source
# File lib/openvas-cli/vas_task.rb, line 152
def progress(refresh=false)
  if refresh == true || @progress == nil
    params = {:apply_overrides => 0, :sort_field => "name"}
    params[:task_id] = options[:task_id] if options[:task_id]
  
    req = Nokogiri::XML::Builder.new { |xml|
      xml.get_tasks
    }
    
    task = VasTask.connection.send_receive(req.doc)
  
    @progress = VasTaskProgress.from_xml_node task.at_xpath('/get_tasks_response/task/progress')
  end
  @progress
end
progress=(val) click to toggle source
# File lib/openvas-cli/vas_task.rb, line 148
def progress=(val)
  @progress = val
end
reports() click to toggle source
# File lib/openvas-cli/vas_task.rb, line 75
def reports
  @reports ||= []
end
schedule() click to toggle source
# File lib/openvas-cli/vas_task.rb, line 48
def schedule
  @schedule ||= pull_my_schedule
end
schedule=(v) click to toggle source
# File lib/openvas-cli/vas_task.rb, line 52
def schedule=(v)
  @schedule = v
  schedule_id = v ? v.id : nil 
end
schedule_id=(v) click to toggle source
# File lib/openvas-cli/vas_task.rb, line 43
def schedule_id=(v)
  schedule_id_will_change! unless @schedule_id == v
  @schedule_id = v
end
start() click to toggle source
# File lib/openvas-cli/vas_task.rb, line 140
def start
  req = Nokogiri::XML::Builder.new { |xml|
    xml.resume_or_start_task(:task_id => @id)
  }
  
  VasTask.connection.send_receive(req.doc)
end
stop() click to toggle source
# File lib/openvas-cli/vas_task.rb, line 176
def stop
  req = Nokogiri::XML::Builder.new { |xml|
    xml.stop_task(:task_id => @id)
  }
  
  VasTask.connection.send_receive(req.doc)
end
target() click to toggle source
# File lib/openvas-cli/vas_task.rb, line 66
def target
  @target ||= pull_my_target
end
target=(val) click to toggle source
# File lib/openvas-cli/vas_task.rb, line 70
def target=(val)
  @target = val
  target_id = val.id if val
end
target_id=(v) click to toggle source
# File lib/openvas-cli/vas_task.rb, line 38
def target_id=(v)
  target_id_will_change! unless @target_id == v
  @target_id = v
end

Private Instance Methods

pull_my_config() click to toggle source
# File lib/openvas-cli/vas_task.rb, line 229
def pull_my_config
  if @config_id && !@config_id.empty?
    VasConfig.get_all(:id => @config_id)[0]
  else
    nil
  end
end
pull_my_schedule() click to toggle source
# File lib/openvas-cli/vas_task.rb, line 245
def pull_my_schedule
  if @schedule_id && !@schedule_id.empty?
    VasSchedule.get_all(:id => @schedule_id)[0]
  else
    nil
  end
end
pull_my_target() click to toggle source
# File lib/openvas-cli/vas_task.rb, line 237
def pull_my_target
  if @target_id && !@target_id.empty?
    VasTarget.get_all(:id => @target_id)[0]
  else
    nil
  end
end