Module: Msf::DBManager::Task

Included in:
Msf::DBManager
Defined in:
lib/msf/core/db_manager/task.rb

Instance Method Summary collapse

Instance Method Details

#find_or_create_task(opts) ⇒ Object

Find or create a task matching this type/data



5
6
7
# File 'lib/msf/core/db_manager/task.rb', line 5

def find_or_create_task(opts)
  report_task(opts)
end

#report_task(opts) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/msf/core/db_manager/task.rb', line 9

def report_task(opts)
  return if not active
::ApplicationRecord.connection_pool.with_connection {
  wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
  opts = opts.clone()
  opts.delete(:workspace)
  path = opts.delete(:path) || (raise RuntimeError, "A task :path is required")

  ret = {}

  user      = opts.delete(:user)
  desc      = opts.delete(:desc)
  error     = opts.delete(:error)
  info      = opts.delete(:info)
  mod       = opts.delete(:mod)
  options   = opts.delete(:options)
  prog      = opts.delete(:prog)
  result    = opts.delete(:result)
  completed_at = opts.delete(:completed_at)
  task      = wspace.tasks.new

  task.created_by = user
  task.description = desc
  task.error = error if error
  task.info = info
  task.module = mod
  task.options = options
  task.path = path
  task.progress = prog
  task.result = result if result
  msf_import_timestamps(opts,task)
  # Having blank completed_ats, while accurate, will cause unstoppable tasks.
  if completed_at.nil? || completed_at.empty?
    task.completed_at = opts[:updated_at]
  else
    task.completed_at = completed_at
  end
  task.save!
  ret[:task] = task
}
end

#tasks(wspace = framework.db.workspace) ⇒ Object

This methods returns a list of all tasks in the database



54
55
56
57
58
# File 'lib/msf/core/db_manager/task.rb', line 54

def tasks(wspace=framework.db.workspace)
::ApplicationRecord.connection_pool.with_connection {
  wspace.tasks
}
end