Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed mistake in blocklist script, added error on missing config #67

Merged
merged 3 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# EDIT THIS TITLE BEFORE POSTING. Use this template for bug reports. If you'd like to request a feature, please be as descriptive as possible and delete the template except the first section (Request Type)

### Request Type
(select Bug or Feature Request and **remove this line**)
Bug / Feature Request
(select Bug, Analyzer or Feature and **remove this line**)
Bug / Analyzer / Feature

### Work Environment
(replace with N/A if not applicable)

| Question | Answer
|---------------------------|--------------------
Expand All @@ -16,10 +17,11 @@ Bug / Feature Request
| Browser type & version | If applicable


### Problem Description
Describe the problem/bug as clearly as possible.
### Description
Describe your request as clearly as possible.

### Steps to Reproduce
(keep this section only if the issue relates to a bug)
1. step 1
1. step 2
1. step 3...
Expand Down
14 changes: 8 additions & 6 deletions analyzers/FireHOLBlocklists/firehol_blocklists.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self):
Analyzer.__init__(self)

# Get config parameters
self.path = self.getParam('config.blocklistpath', '/tmp/fireholblocklists')
self.path = self.getParam('config.blocklistpath', None, 'No path to blocklists provided.')
self.ignoreolderthandays = self.getParam('config.ignoreolderthandays', 365)
self.utc = pytz.UTC
self.now = dt.datetime.now(tz=self.utc)
Expand Down Expand Up @@ -65,7 +65,7 @@ def _check_ip(self, ip):
with open('{}/{}'.format(self.path, ipset)) as afile:
ipsetname = ipset.split('.')[0]
description.update({ipsetname: ''})
file_date.update({ipsetname : ''})
file_date.update({ipsetname: ''})
for l in afile:
if l[0] == '#':
# Check for date and break if too old
Expand All @@ -80,30 +80,32 @@ def _check_ip(self, ip):
else:
if ip in l:
# On match append to hits and break; next file!
hits.append({'list': ipsetname, 'description': description.get(ipsetname), 'file_date': file_date.get(ipsetname)})
hits.append({'list': ipsetname, 'description': description.get(ipsetname),
'file_date': file_date.get(ipsetname)})
break

# Second: check the netsets
for netset in self.netsets:
with open('{}/{}'.format(self.path, netset)) as afile:
netsetname = netset.split('.')[0]
description.update({netsetname: ''})
file_date.update({ipsetname : ''})
file_date.update({netsetname: ''})
for l in afile:
if l[0] == '#':
# Check for date and break if too old
if '# Source File Date: ' in l:
datestr = re.sub('# Source File Date: ', '', l.rstrip('\n'))
date = parse(datestr)
file_date[ipsetname] = str(date)
file_date[netsetname] = str(date)
if (self.now - date).days > self.ignoreolderthandays:
break
description[netsetname] += re.sub(r'^\[.*\] \(.*\) [a-zA-Z0-9.\- ]*$', '', l.lstrip('# '))\
.replace('\n\n', '\n')
else:
try:
if ipaddress.ip_address(ip) in ipaddress.ip_network(u'{}'.format(l.split('\n')[0])):
hits.append({'list': netsetname, 'description': description.get(netsetname), 'file_date': file_date.get(ipsetname)})
hits.append({'list': netsetname, 'description': description.get(netsetname),
'file_date': file_date.get(netsetname)})
break
except ValueError as e:
self.error('ValueError occured. Used values: ipnetwork {}, ip to check {}, file {}.'
Expand Down