diff --git a/waccess b/waccess index 9874504..cd7c25e 100755 --- a/waccess +++ b/waccess @@ -2,7 +2,7 @@ # waccess - Copyright (c) 2001,2002, TundraWare Inc., All Rights Reserved -VERSION = "$Id: waccess,v 1.67 2002/09/03 17:50:42 tundra Exp $" +VERSION = "$Id: waccess,v 1.68 2002/09/03 19:34:03 tundra Exp $" # # Look for selected strings passed on the command line in the http access log. @@ -87,7 +87,7 @@ ########## def usage(): - print "usage: waccess [-ailqrsv -f logfile]" + print "usage: waccess [-acilqrsv -f logfile]" sys.exit(2) @@ -96,28 +96,31 @@ # Command Line Processing ########## -LOG = "/var/log/httpd-access.log" -LISTIGNORE = FALSE -NOIGNORE = FALSE -SUMMARY = TRUE -REVERSE = FALSE -SHOW = TRUE -SORTED = FALSE +IGNORECASE = FALSE +LOG = "/var/log/httpd-access.log" +SHOWIGNORED = FALSE +NOIGNORE = FALSE +SUMMARY = TRUE +REVERSE = FALSE +SHOW = TRUE +SORTED = FALSE try: - opts, args = getopt.getopt(sys.argv[1:], '-af:ilqrsv') + opts, args = getopt.getopt(sys.argv[1:], '-acf:ilqrsv') except getopt.GetoptError: usage() for opt, val in opts: if opt == "-a": SORTED = TRUE + if opt == "-c": + IGNORECASE = TRUE if opt == "-f": LOG = val if opt == "-i": NOIGNORE = TRUE if opt == "-l": - LISTIGNORE = TRUE + SHOWIGNORED = TRUE if opt == "-q": SUMMARY = FALSE if opt == "-r": @@ -140,14 +143,6 @@ IGNORED.append(ip) i.close() -# Show contents of final ignore table if user asked for it. -# This is done only if the ignore feature is enabled. - -if LISTIGNORE and not NOIGNORE: - print "Ignoring Addresses:" - for a in IGNORED: - print 20*" " + a - print "\n\n" ########## # Process the log @@ -166,6 +161,7 @@ for record in f.read().splitlines(): total += 1 + fields = record.split() # These field definitions are appropriate for Apache access logs. @@ -190,7 +186,7 @@ MATCHED = FALSE for a in args: - if record.count(a): + if (not IGNORECASE and record.count(a)) or (IGNORECASE and record.lower().count(a.lower())): matched[a] += 1 MATCHED = TRUE # Save if new IP address encountered @@ -222,11 +218,26 @@ if SUMMARY: + # Show total number of records processed. + print "\nProcessed %d Total Records.\n" % (total,) + # Show contents of final ignore table if user asked for it. + # This is done only if the ignore feature is enabled. + + if SHOWIGNORED and not NOIGNORE: + print "The Following Addresses Were Ignored:\n" + for a in IGNORED: + print a + print "\n\n" + + # Sort output if user requested it + if SORTED: args.sort() + # Summarize number of hits and unique IPs by seach key + for a in args: num_matched = str(matched[a]) num_unique = str(len(UNIQUE_IP[a]))