diff --git a/waccess b/waccess index bb9bb7f..43c3a7f 100755 --- a/waccess +++ b/waccess @@ -1,6 +1,6 @@ #!/usr/bin/env python # waccess - Copyright (c) 2001,2002, TundraWare Inc., All Rights Reserved -# $Id: waccess,v 1.64 2002/09/02 19:04:17 tundra Exp $ +# $Id: waccess,v 1.65 2002/09/02 19:25:19 tundra Exp $ # # Look for selected strings passed on the command line in the http access log. @@ -10,6 +10,7 @@ import commands import getopt +import os import socket import sys @@ -26,10 +27,14 @@ # List of IP addesses to ignore. Records with IP addresses found # in this list will be ignored entirely. The addresses here may -# be partial IP quads. +# be partial IP quads. If IGNOREDFILE exists, its contents will +# be appended to the IGNORED data structure at program startup. IGNORED = ["127.0", "192.168.0."] +IGNOREDFILE = os.path.join(os.getenv("HOME"), ".waccessignored") + + # This table is built dynamically at run time to keep track of # all DNS reverse lookups. Index into the table by IP address. @@ -68,7 +73,7 @@ # Print program usage information and error exit. def usage(): - print "usage: waccess [-irs -f logfile]" + print "usage: waccess [-ilrs -f logfile]" sys.exit(2) @@ -77,13 +82,14 @@ # Command Line Processing ########## -LOG = "/var/log/httpd-access.log" -NOIGNORE = FALSE -REVERSE = FALSE -SHOW = TRUE +LOG = "/var/log/httpd-access.log" +LISTIGNORE = FALSE +NOIGNORE = FALSE +REVERSE = FALSE +SHOW = TRUE try: - opts, args = getopt.getopt(sys.argv[1:], '-f:irs') + opts, args = getopt.getopt(sys.argv[1:], '-f:ilrs') except getopt.GetoptError: usage() @@ -92,6 +98,8 @@ LOG = val if opt == "-i": NOIGNORE = TRUE + if opt == "-l": + LISTIGNORE = TRUE if opt == "-r": REVERSE = TRUE SHOW = TRUE @@ -100,6 +108,25 @@ REVERSE = FALSE ########## +# Process the ignored rc file, if any +########## + +if os.path.exists(IGNOREDFILE): + i = open(IGNOREDFILE) + for ip in i.read().splitlines(): + 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 ##########