diff --git a/abck b/abck index 04b760c..52a7cce 100755 --- a/abck +++ b/abck @@ -9,7 +9,7 @@ ########## -VERSION = "$Id: abck,v 1.97 2001/07/27 02:11:59 tundra Exp $" +VERSION = "$Id: abck,v 1.98 2001/07/27 05:46:32 tundra Exp $" @@ -18,6 +18,7 @@ #################### import commands +import exceptions import getopt import os import re @@ -120,6 +121,26 @@ IPQuad = r"(\d{1,3}\.){3}\d{1,3}$" #################### +# Classes +#################### + +# Signify that the record under consideration is to be +# permanently forgotten + +class ForgetRecord(exceptions.Exception): + def __init__(self, args=None): + self.args = args + + +# Signify that the user want to quit the program + +class QuitAbck(exceptions.Exception): + def __init__(self, args=None): + self.args = args + + + +#################### # Function Definitions #################### @@ -256,21 +277,29 @@ default)) # Parse the response - if st == "s": # Skip this record - sendto = "" - DONE = TRUE + + if st.lower() == "f": # Forget this record forever + raise ForgetRecord # Raise error as the way back elif st.lower() == "l": # More depth in recipient name if depth < len(hostname.split('.')): depth += 1 + elif st.lower() == "q": # Quit the program + raise QuitAbck + elif st.lower() == "r": # Less depth in recipient name if depth > 2: depth -= 1 - elif st.lower() == "w": # Run a whois on 'em + elif st.lower() == "s": # Skip this record + sendto = "" + DONE = TRUE + + elif st.lower() == "w": # Run a 'whois' on 'em print commands.getoutput(WHO + hostquad) + else: if st: # User keyed in their own recipient hostname = st @@ -338,16 +367,18 @@ f.close() # Remove any previously handled log events from further consideration +# unless all we're doing is showing records. In that case, show +# all records that match, even if we've already processed them. -if os.path.exists(HISTFILE): - f = open(HISTFILE, "r") - for histrec in f.read().splitlines(): - if logfile.count(histrec): - logfile.remove(histrec) +if not SHOWONLY: + if os.path.exists(HISTFILE): + f = open(HISTFILE, "r") + for histrec in f.read().splitlines(): + if logfile.count(histrec): + logfile.remove(histrec) f.close() - # Examine, and possibly process, each record in the log for logrecord in logfile: @@ -387,13 +418,18 @@ # If we passed all those tests, it's time to process this record. if DOIT: - sendto = ProcessLogRecord(logrecord, NOMATCH, SHOWONLY) - - # If we get a non-null string back, we need to let someone know - # about the attempted intrusion - if sendto: - Notify(logrecord, sendto) + try: + sendto = ProcessLogRecord(logrecord, NOMATCH, SHOWONLY) + except (ForgetRecord): Processed.append(logrecord) + except (QuitAbck): + sys.exit() + else: + # If we get a non-null string back, we need to let someone know + # about the attempted intrusion + if sendto: + Notify(logrecord, sendto) + Processed.append(logrecord) if os.path.exists(HISTFILE): f = open(HISTFILE, "a")