Commit 585e1b10 authored by Ad Schellevis's avatar Ad Schellevis

(ids) obey configured output filename is source is different

parent 0d7e02e7
...@@ -62,18 +62,19 @@ class Downloader(object): ...@@ -62,18 +62,19 @@ class Downloader(object):
output.append(line) output.append(line)
return '\n'.join(output) return '\n'.join(output)
def download(self, proto, url, input_filter): def download(self, proto, url, filename, input_filter):
""" download ruleset file """ download ruleset file
:param proto: protocol (http,https) :param proto: protocol (http,https)
:param url: download url :param url: download url
:param filename: target filename
:param input_filter: filter to use on received data before save :param input_filter: filter to use on received data before save
""" """
if proto in ('http', 'https'): if proto in ('http', 'https'):
frm_url = url.replace('//', '/').replace(':/', '://') frm_url = url.replace('//', '/').replace(':/', '://')
req = requests.get(url=frm_url) req = requests.get(url=frm_url)
if req.status_code == 200: if req.status_code == 200:
target_filename = ('%s/%s' % (self._target_dir, frm_url.split('/')[-1])).replace('//', '/')
try: try:
target_filename = '%s/%s' % (self._target_dir, filename)
save_data = self.filter(req.text, input_filter) save_data = self.filter(req.text, input_filter)
open(target_filename, 'wb').write(save_data) open(target_filename, 'wb').write(save_data)
except IOError: except IOError:
......
...@@ -62,6 +62,7 @@ if __name__ == '__main__': ...@@ -62,6 +62,7 @@ if __name__ == '__main__':
else: else:
enabled_rulefiles[section.strip()]['filter'] = "" enabled_rulefiles[section.strip()]['filter'] = ""
# download / remove rules # download / remove rules
md = metadata.Metadata() md = metadata.Metadata()
dl = downloader.Downloader(target_dir=rule_source_directory) dl = downloader.Downloader(target_dir=rule_source_directory)
...@@ -77,4 +78,5 @@ if __name__ == '__main__': ...@@ -77,4 +78,5 @@ if __name__ == '__main__':
pass pass
else: else:
input_filter = enabled_rulefiles[rule['filename']]['filter'] input_filter = enabled_rulefiles[rule['filename']]['filter']
dl.download(proto=download_proto, url=rule['url'], input_filter=input_filter) dl.download(proto=download_proto, url=rule['url'],
filename=rule['filename'], input_filter=input_filter)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment