Small fixes regarding errorhandling

This commit is contained in:
panki27 2017-12-08 17:44:17 +01:00
parent 5edc52bec8
commit 6b3c04d759

View File

@ -8,15 +8,12 @@ ERRSTR = '!!!!!!!!!!!!! '
# REMEMBER TO CHANGE THESE!!! # REMEMBER TO CHANGE THESE!!!
TARGET_URL = 'https://www.cert-bund.de/overview/AdvisoryShort' TARGET_URL = 'https://www.cert-bund.de/overview/AdvisoryShort'
MEMORY_PATH = 'C:\Users\Panki\Desktop\Privat\Dev\certAlert\out.txt'
MEMORY_PATH = 'C:\Users\Panki\Desktop\Privat\Dev\certAlert\out.txt'
KEY_FILE_PATH = 'C:\Users\Panki\Desktop\Privat\Dev\keyfile' KEY_FILE_PATH = 'C:\Users\Panki\Desktop\Privat\Dev\keyfile'
# To monitor more programs, simply add a string here # To monitor more programs, simply add a string here
PROGRAMS = [u'Git', u'Chrome', u'OpenSSH', u'Java', u'Linux', u'Apache', u'Windows'] PROGRAMS = [u'Android', u'Git', u'Chrome', u'OpenSSH', u'Java', u'Linux', u'Apache', u'Windows']
# object to store a single cert alert # object to store a single cert alert
class Advisory: class Advisory:
@ -35,6 +32,7 @@ class Advisory:
print('link: ' + self.link) print('link: ' + self.link)
def startLogger(): def startLogger():
# todo: figure out how this works?
# thanks to whoever i stole this from # thanks to whoever i stole this from
logger = logging.getLogger('certAlert') logger = logging.getLogger('certAlert')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
@ -52,7 +50,7 @@ def getHTML(url):
print(ERRSTR + 'Check your internet connection or TARGET_URL.') print(ERRSTR + 'Check your internet connection or TARGET_URL.')
sys.exit(ERRSTR + 'Stopping execution!') sys.exit(ERRSTR + 'Stopping execution!')
except: except:
e = sys.exc_info()[0] e = sys.exc_info()[1]
print(ERRSTR + 'Error getting Webpage!') print(ERRSTR + 'Error getting Webpage!')
print(e) print(e)
sys.exit(ERRSTR + 'Stopping execution!') sys.exit(ERRSTR + 'Stopping execution!')
@ -64,16 +62,18 @@ def readFile(path, lines = False):
with open(path, 'r') as file: with open(path, 'r') as file:
if(lines): if(lines):
contents = file.readlines() contents = file.readlines()
else:contents = file.read() else:
contents = file.read()
file.close() file.close()
except IOError: except IOError:
# this most likely means file not found. this can happen during the first run # this most likely means file not found. this can happen during the first run
print(ERRSTR + 'Error reading file ' + path + '!') print(ERRSTR + 'Error reading file ' + path + '!')
contents = '' contents = ''
except: except:
e = sys.exc_info()[0] e = sys.exc_info()[1]
print('An unknown error occured!') print('An unknown error occured!')
print(e) print(e)
contents = ''
finally: finally:
return contents return contents
@ -81,7 +81,7 @@ def main():
# this loads our API keys into memory from an external file which is specified above # this loads our API keys into memory from an external file which is specified above
try: try:
contents = readFile(KEY_FILE_PATH, True) contents = readFile(KEY_FILE_PATH, True)
# extract just the text behind the equals sign # extract just the text behind the equals sign
API_KEY = contents[0].split("=",1)[1] API_KEY = contents[0].split("=",1)[1]
USER_KEYS = contents[1].split("=",1)[1] USER_KEYS = contents[1].split("=",1)[1]
# get rid of that pesky newline # get rid of that pesky newline
@ -89,7 +89,7 @@ def main():
# now we split along semicolons to get single keys in a list # now we split along semicolons to get single keys in a list
USER_KEYS = USER_KEYS.split(";") USER_KEYS = USER_KEYS.split(";")
except: except:
e = sys.exc_info()[0] e = sys.exc_info()[1]
print(e) print(e)
print(ERRSTR + "I couldn't load your credentials. Did you specify your keyfile?") print(ERRSTR + "I couldn't load your credentials. Did you specify your keyfile?")
sys.exit(ERRSTR + 'Stopping execution!') sys.exit(ERRSTR + 'Stopping execution!')
@ -120,7 +120,7 @@ def main():
key = key.rstrip() key = key.rstrip()
response = client.notify_single_device(registration_id=key, message_body=result.description, message_title=result.identifier) response = client.notify_single_device(registration_id=key, message_body=result.description, message_title=result.identifier)
except: except:
e = sys.exc_info()[0] e = sys.exc_info()[1]
print(e) print(e)
print("we fucked up!") print("we fucked up!")
result.debug() result.debug()
@ -133,6 +133,5 @@ def main():
memFile.write(result.identifier + '\r') memFile.write(result.identifier + '\r')
memFile.close() memFile.close()
if __name__ == '__main__': if __name__ == '__main__':
main() main()