75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/voodoo/cli.rb', line 75
def template(path)
pwd = Dir.pwd
if File.directory? path
pwd = File.expand_path(File.join(pwd, path))
template = YAML.load_file(File.join(path, 'voodoo.yaml'))
else
pwd = File.expand_path(File.join(pwd, File.dirname(path)))
template = YAML.load_file(path)
end
browser_inst = template['browser'] || {}
browser = get_browser(options[:browser] || browser_inst['name'] || browser_inst['default'] || 'chrome')
if template['permissions']
browser.add_permissions template['permissions']
end
if template['host_permissions']
browser.add_host_permissions template['host_permissions']
end
output_format = options[:format]
is_default = output_format == 'none'
if is_default && template['format']
output_format = template['format']
end
output_handler = Output.new(file: options[:output], in_format: output_format, for_command: 'template')
template['scripts'].each do |script|
file = File.expand_path(File.join(pwd, script['file'])) if script['file']
content = script['content']
matches = script['matches'] || ['*://*/*']
background = script['background'] || false
if background
matches = nil
end
communication = true
if script.keys.include? 'communication'
communication = script['communication']
end
if output_handler.writable
browser.add_script(max_events: options[:max_events], matches: matches, file: file, content: content, options: options[:params], background: background, communication: communication) do |event|
output_handler.handle(event)
end
else
browser.add_script(matches: matches, content: content, file: file, options: options[:params], background: background)
end
end
urls = options[:urls]
if urls.length == 0 && browser_inst['urls']
urls = browser_inst['urls']
end
browser.hijack urls, flags: browser_inst['flags'] || ''
end
|