Repository navigation
Expand file tree
/
Copy pathhelpers.rb
More file actions
92 lines (75 loc) · 2.91 KB
/
Copy pathhelpers.rb
File metadata and controls
92 lines (75 loc) · 2.91 KB
1
2
3
4
5
6
7
8
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module Intrigue
module Task
module Helper
def entity_exists?(project, entity_type, entity_name)
entities = Intrigue::Model::Entity.scope_by_project_and_type(project.name, entity_type)
return entities.first(:name => entity_name) if entities
false
end
###
### Helper method for starting a task run
###
def start_task(queue, project, existing_scan_result_id, task_name, entity, depth,
options=[], handlers=[], machine_name="external_discovery_light_active", auto_enrich=true, auto_scope=false)
# Create the task result, and associate our entity and options
logger = Intrigue::Model::Logger.create(:project_id => project.id)
task_result = Intrigue::Model::TaskResult.create({
:project_id => project.id,
:logger_id => logger.id,
:name => "#{task_name}_on_#{entity.name}",
:task_name => task_name,
:options => options,
:handlers => [],
:base_entity => entity,
:autoscheduled => (queue == "task_autoscheduled" || queue == "task_enrichment"),
:auto_enrich => auto_enrich,
:auto_scope => auto_scope,
:depth => depth
})
# cancel any new tasks if the project has been cancelled
if project.cancelled
task_result.cancel!
end
# only assign handlers if this isn't a scan (in that case, we want to send the whole scan)
task_result.handlers = handlers unless (!existing_scan_result_id && depth > 1)
# if we were passed a scan result, we know this new task
# belongs to it, and we should associate those
if existing_scan_result_id
# we are in the middle of a change, let's preserve the recursive trail
task_result.scan_result_id = existing_scan_result_id
task_result.save_changes
# lets also add one to the incomplete task count, so we can determine if we're actually done
#existing_scan_result.increment_task_count
end
# If the depth is greater than 1, AND we don't have a
# prexisting scan id, start a new scan
if !existing_scan_result_id && depth > 1
logger = Intrigue::Model::Logger.create(:project => project)
new_scan_result = Intrigue::Model::ScanResult.create({
:name => "#{machine_name}_on_#{entity.name}",
:project => project,
:base_entity_id => entity.id,
:logger_id => logger.id,
:depth => depth,
:machine => machine_name,
:whitelist_strings => ["#{entity.name}"], # this is a list of strings that we know are good
:blacklist_strings => [],
:handlers => handlers,
:incomplete_task_count => 0
})
# Add the scan result
task_result.scan_result_id = new_scan_result.id
task_result.save_changes
# Add the task result
new_scan_result.add_task_result(task_result)
# Start it
new_scan_result.start(queue)
else
# otherwise, we're a task, and we're ready to go
task_result.start(queue)
end
task_result
end
end
end
end