diff --git a/waccess b/waccess index 0e549a7..9874504 100755 --- a/waccess +++ b/waccess @@ -1,6 +1,8 @@ #!/usr/bin/env python # waccess - Copyright (c) 2001,2002, TundraWare Inc., All Rights Reserved -# $Id: waccess,v 1.66 2002/09/03 03:07:46 tundra Exp $ + + +VERSION = "$Id: waccess,v 1.67 2002/09/03 17:50:42 tundra Exp $" # # Look for selected strings passed on the command line in the http access log. @@ -51,9 +53,11 @@ # Function Defintions ########## +########## # Do a reverse lookup on an IP address, caching the results # so that subsequent reverse lookups can use the cache instead of # doing another lookup. +########## def IPReverse(ipadr): if REVERSE_CACHE.has_key(ipadr): @@ -69,11 +73,21 @@ return revname +########## +# Print program version number and exit normally +########## +def version(): + print VERSION + sys.exit(0) + + +########## # Print program usage information and error exit. +########## def usage(): - print "usage: waccess [-ilrs -f logfile]" + print "usage: waccess [-ailqrsv -f logfile]" sys.exit(2) @@ -85,27 +99,36 @@ LOG = "/var/log/httpd-access.log" LISTIGNORE = FALSE NOIGNORE = FALSE +SUMMARY = TRUE REVERSE = FALSE SHOW = TRUE +SORTED = FALSE try: - opts, args = getopt.getopt(sys.argv[1:], '-f:ilrs') + opts, args = getopt.getopt(sys.argv[1:], '-af:ilqrsv') except getopt.GetoptError: usage() for opt, val in opts: + if opt == "-a": + SORTED = TRUE if opt == "-f": LOG = val if opt == "-i": NOIGNORE = TRUE if opt == "-l": LISTIGNORE = TRUE + if opt == "-q": + SUMMARY = FALSE if opt == "-r": REVERSE = TRUE SHOW = TRUE if opt == "-s": SHOW = FALSE REVERSE = FALSE + if opt == "-v": + version() + ########## # Process the ignored rc file, if any @@ -190,6 +213,25 @@ f.close() -print "\nProcessed %d Total Records.\n" % (total,) -for a in args: - print "%s%s=> %d Accesses from %s Unique IPs" % (a, (20-len(a))*" ", matched[a], len(UNIQUE_IP[a])) + + +########## +# Output Summary Of Results Unless Told Not To +########## + + +if SUMMARY: + + print "\nProcessed %d Total Records.\n" % (total,) + + if SORTED: + args.sort() + + for a in args: + num_matched = str(matched[a]) + num_unique = str(len(UNIQUE_IP[a])) + + print "%s : %s Accesses From %s Unique IPs" % (\ + a + (20 - len(a)) * " ", \ + (" " * (8 - len(num_matched))) + num_matched, \ + (" " * (8 - len(num_unique))) + num_unique)