Skip to content

Commit 023cfd3

Browse files
author
gtencate
committed
and testing...
1 parent c7eba90 commit 023cfd3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

skf/skf.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,23 @@ def log(message, value, threat):
7373
dateTime = now.strftime("%Y-%m-%d %H:%M")
7474
headers_list = request.headers.getlist("X-Forwarded-For")
7575
ip = headers_list[0] if headers_list else request.remote_addr
76-
file = open('logs/'+dateLog+'.txt', 'rw')
76+
try:
77+
file = open('logs/'+dateLog+'.txt', 'a+')
78+
except IOError:
79+
# If not exists, create the file
80+
file = open('logs/'+dateLog+'.txt', 'w+')
7781
file.write(dateTime +' '+ message +' ' + ' ' + value + ' ' + threat + ' ' +ip + "\r\n")
7882
file.close
7983

8084
def blockUsers():
8185
"""Check the log file and based on the FAIL items block a user"""
8286
dateLog = datetime.datetime.now().strftime("%Y-%m")
8387
count = 0
84-
read = open('logs/'+dateLog+'.txt', 'r+')
88+
try:
89+
read = open('logs/'+dateLog+'.txt', 'a+')
90+
except IOError:
91+
# If not exists, create the file
92+
read = open('logs/'+dateLog+'.txt', 'w+')
8593
for line in read:
8694
match = re.search('FAIL', line)
8795
# If-statement after search() tests if it succeeded

0 commit comments

Comments
 (0)