Small fixes regarding errorhandling

master
panki27 7 years ago
parent 5edc52bec8
commit 6b3c04d759

@ -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
@ -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()
Loading…
Cancel
Save