Permalink
Browse files

Fix bug in relation with feeds caching files

  • Loading branch information...
root
root committed Jul 17, 2018
1 parent 704c04d commit c022d4c60713f48df67a1ce9aad488512e53e906
Showing with 56 additions and 48 deletions.
  1. +7 −6 feeds/alienvault.py
  2. +7 −6 feeds/blocklist.py
  3. +7 −6 feeds/ciarmy.py
  4. +7 −6 feeds/greensnow.py
  5. +7 −6 feeds/openphish.py
  6. +7 −6 feeds/phishtank.py
  7. +7 −6 feeds/ransomware.py
  8. +7 −6 feeds/spamhaus.py
@@ -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):
@@ -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 = []
@@ -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)
@@ -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):
@@ -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 = []
@@ -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)
@@ -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):
@@ -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 = []
@@ -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)
@@ -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):
@@ -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 = []
@@ -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)
@@ -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):
@@ -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 = []
@@ -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)
@@ -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):
@@ -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 = []
@@ -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)
@@ -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):
@@ -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 = []
@@ -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)
@@ -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):
@@ -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 = []
@@ -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)

0 comments on commit c022d4c

Please sign in to comment.