Skip to content

Commit

Permalink
Fix bug in relation with feeds caching files
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jul 17, 2018
1 parent 704c04d commit c022d4c
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 48 deletions.
13 changes: 7 additions & 6 deletions feeds/alienvault.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
##
# -*- coding: utf-8 -*-

import requests, string, re, ipaddress
import os, requests, string, re, ipaddress

class alienvault:
def __init__(self, log, group, agent, timeout):
Expand All @@ -15,6 +15,7 @@ def __init__(self, log, group, agent, timeout):
self.session = requests.Session()
self.session.headers.update({"User-Agent": agent})
self.timeout = timeout
self.cache = str("assets/cache/{}.txt").format(self.__class__.__name__)

def refresh(self):
data = []
Expand All @@ -26,12 +27,12 @@ def refresh(self):
data = data + response.text.splitlines()
except:
self.log.error(str("Request error in '{}' = '{}'").format(self.__class__.__name__, element))
if len(data) == 0:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "r+") as fp:
data = fp.read().splitlines()
else:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "w+") as fp:
if len(data) != 0:
with open(self.cache, "w+") as fp:
fp.write(str("\n").join(data))
if len(data) == 0 and os.path.isfile(self.cache):
with open(self.cache, "r+") as fp:
data = fp.read().splitlines()
for element in data:
try:
content, revlookup = self.parse(element)
Expand Down
13 changes: 7 additions & 6 deletions feeds/blocklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
##
# -*- coding: utf-8 -*-

import requests, string, re, ipaddress
import os, requests, string, re, ipaddress

class blocklist:
def __init__(self, log, group, agent, timeout):
Expand All @@ -15,6 +15,7 @@ def __init__(self, log, group, agent, timeout):
self.session = requests.Session()
self.session.headers.update({"User-Agent": agent})
self.timeout = timeout
self.cache = str("assets/cache/{}.txt").format(self.__class__.__name__)

def refresh(self):
data = []
Expand All @@ -26,12 +27,12 @@ def refresh(self):
data = data + response.text.splitlines()
except:
self.log.error(str("Request error in '{}' = '{}'").format(self.__class__.__name__, element))
if len(data) == 0:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "r+") as fp:
data = fp.read().splitlines()
else:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "w+") as fp:
if len(data) != 0:
with open(self.cache, "w+") as fp:
fp.write(str("\n").join(data))
if len(data) == 0 and os.path.isfile(self.cache):
with open(self.cache, "r+") as fp:
data = fp.read().splitlines()
for element in data:
try:
content, revlookup = self.parse(element)
Expand Down
13 changes: 7 additions & 6 deletions feeds/ciarmy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
##
# -*- coding: utf-8 -*-

import requests, string, re, ipaddress
import os, requests, string, re, ipaddress

class ciarmy:
def __init__(self, log, group, agent, timeout):
Expand All @@ -15,6 +15,7 @@ def __init__(self, log, group, agent, timeout):
self.session = requests.Session()
self.session.headers.update({"User-Agent": agent})
self.timeout = timeout
self.cache = str("assets/cache/{}.txt").format(self.__class__.__name__)

def refresh(self):
data = []
Expand All @@ -26,12 +27,12 @@ def refresh(self):
data = data + response.text.splitlines()
except:
self.log.error(str("Request error in '{}' = '{}'").format(self.__class__.__name__, element))
if len(data) == 0:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "r+") as fp:
data = fp.read().splitlines()
else:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "w+") as fp:
if len(data) != 0:
with open(self.cache, "w+") as fp:
fp.write(str("\n").join(data))
if len(data) == 0 and os.path.isfile(self.cache):
with open(self.cache, "r+") as fp:
data = fp.read().splitlines()
for element in data:
try:
content, revlookup = self.parse(element)
Expand Down
13 changes: 7 additions & 6 deletions feeds/greensnow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
##
# -*- coding: utf-8 -*-

import requests, string, re, ipaddress
import os, requests, string, re, ipaddress

class greensnow:
def __init__(self, log, group, agent, timeout):
Expand All @@ -15,6 +15,7 @@ def __init__(self, log, group, agent, timeout):
self.session = requests.Session()
self.session.headers.update({"User-Agent": agent})
self.timeout = timeout
self.cache = str("assets/cache/{}.txt").format(self.__class__.__name__)

def refresh(self):
data = []
Expand All @@ -26,12 +27,12 @@ def refresh(self):
data = data + response.text.splitlines()
except:
self.log.error(str("Request error in '{}' = '{}'").format(self.__class__.__name__, element))
if len(data) == 0:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "r+") as fp:
data = fp.read().splitlines()
else:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "w+") as fp:
if len(data) != 0:
with open(self.cache, "w+") as fp:
fp.write(str("\n").join(data))
if len(data) == 0 and os.path.isfile(self.cache):
with open(self.cache, "r+") as fp:
data = fp.read().splitlines()
for element in data:
try:
content, revlookup = self.parse(element)
Expand Down
13 changes: 7 additions & 6 deletions feeds/openphish.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
##
# -*- coding: utf-8 -*-

import requests, string, re, ipaddress
import os, requests, string, re, ipaddress

class openphish:
def __init__(self, log, group, agent, timeout):
Expand All @@ -15,6 +15,7 @@ def __init__(self, log, group, agent, timeout):
self.session = requests.Session()
self.session.headers.update({"User-Agent": agent})
self.timeout = timeout
self.cache = str("assets/cache/{}.txt").format(self.__class__.__name__)

def refresh(self):
data = []
Expand All @@ -26,12 +27,12 @@ def refresh(self):
data = data + response.text.splitlines()
except:
self.log.error(str("Request error in '{}' = '{}'").format(self.__class__.__name__, element))
if len(data) == 0:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "r+") as fp:
data = fp.read().splitlines()
else:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "w+") as fp:
if len(data) != 0:
with open(self.cache, "w+") as fp:
fp.write(str("\n").join(data))
if len(data) == 0 and os.path.isfile(self.cache):
with open(self.cache, "r+") as fp:
data = fp.read().splitlines()
for element in data:
try:
content, revlookup = self.parse(element)
Expand Down
13 changes: 7 additions & 6 deletions feeds/phishtank.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
##
# -*- coding: utf-8 -*-

import requests, string, re, ipaddress
import os, requests, string, re, ipaddress

class phishtank:
def __init__(self, log, group, agent, timeout):
Expand All @@ -15,6 +15,7 @@ def __init__(self, log, group, agent, timeout):
self.session = requests.Session()
self.session.headers.update({"User-Agent": agent})
self.timeout = timeout
self.cache = str("assets/cache/{}.txt").format(self.__class__.__name__)

def refresh(self):
data = []
Expand All @@ -26,12 +27,12 @@ def refresh(self):
data = data + response.text.splitlines()
except:
self.log.error(str("Request error in '{}' = '{}'").format(self.__class__.__name__, element))
if len(data) == 0:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "r+") as fp:
data = fp.read().splitlines()
else:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "w+") as fp:
if len(data) != 0:
with open(self.cache, "w+") as fp:
fp.write(str("\n").join(data))
if len(data) == 0 and os.path.isfile(self.cache):
with open(self.cache, "r+") as fp:
data = fp.read().splitlines()
for element in data:
try:
content, revlookup = self.parse(element)
Expand Down
13 changes: 7 additions & 6 deletions feeds/ransomware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
##
# -*- coding: utf-8 -*-

import requests, string, re, ipaddress
import os, requests, string, re, ipaddress

class ransomware:
def __init__(self, log, group, agent, timeout):
Expand All @@ -16,6 +16,7 @@ def __init__(self, log, group, agent, timeout):
self.session = requests.Session()
self.session.headers.update({"User-Agent": agent})
self.timeout = timeout
self.cache = str("assets/cache/{}.txt").format(self.__class__.__name__)

def refresh(self):
data = []
Expand All @@ -27,12 +28,12 @@ def refresh(self):
data = data + response.text.splitlines()
except:
self.log.error(str("Request error in '{}' = '{}'").format(self.__class__.__name__, element))
if len(data) == 0:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "r+") as fp:
data = fp.read().splitlines()
else:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "w+") as fp:
if len(data) != 0:
with open(self.cache, "w+") as fp:
fp.write(str("\n").join(data))
if len(data) == 0 and os.path.isfile(self.cache):
with open(self.cache, "r+") as fp:
data = fp.read().splitlines()
for element in data:
try:
content, revlookup = self.parse(element)
Expand Down
13 changes: 7 additions & 6 deletions feeds/spamhaus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
##
# -*- coding: utf-8 -*-

import requests, string, re, ipaddress
import os, requests, string, re, ipaddress

class spamhaus:
def __init__(self, log, group, agent, timeout):
Expand All @@ -16,6 +16,7 @@ def __init__(self, log, group, agent, timeout):
self.session = requests.Session()
self.session.headers.update({"User-Agent": agent})
self.timeout = timeout
self.cache = str("assets/cache/{}.txt").format(self.__class__.__name__)

def refresh(self):
data = []
Expand All @@ -27,12 +28,12 @@ def refresh(self):
data = data + response.text.splitlines()
except:
self.log.error(str("Request error in '{}' = '{}'").format(self.__class__.__name__, element))
if len(data) == 0:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "r+") as fp:
data = fp.read().splitlines()
else:
with open(str("assets/cache/{}.txt").format(self.__class__.__name__), "w+") as fp:
if len(data) != 0:
with open(self.cache, "w+") as fp:
fp.write(str("\n").join(data))
if len(data) == 0 and os.path.isfile(self.cache):
with open(self.cache, "r+") as fp:
data = fp.read().splitlines()
for element in data:
try:
content, revlookup = self.parse(element)
Expand Down

0 comments on commit c022d4c

Please sign in to comment.