diff --git a/tperimeter.py b/tperimeter.py new file mode 100644 index 0000000..261e5dd --- /dev/null +++ b/tperimeter.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python +# perimiter.py +# Copyright (c) 2006 TundraWare Inc. All Rights Reserved. +# For Updates See: http://www.tundraware.com/Software/tperimiter + +# Program Information + +PROGNAME = "perimiter.py" +RCSID = "$Id: tperimeter.py,v 1.100 2006/04/28 21:29:13 tundra Exp $" + +import os, re, sys + +##### +# Constants +##### + +Basedir = "/www/cgi-bin/perimeter/requests/" # Base directory to store requests +IPQuad = r"(\d{1,3}\.){3}\d{1,3}$" # Regex for IP Quads + + +##### +# Lookup Tables +##### + +Forbidden = ["0.0.0.0", "255.255.255.255"] # Forbidden IP addresses +Services = ["imapd", "leafnode", "sshd"] # Services we can open up + + +##### +# Print Routine +##### + +def Print(s): + + print "[User@%s] %s" % (requestor, s) + +##### +# Error/Abort Routine +##### + +def Error(s): + Print("ERROR: %s!
" % s) + Print( "Please Try Again ...

") + sys.exit(1) + +# End of 'Error()' + + +##### +# Print The HTML Header +#### + +print "Content-type: text/html\n\n" + +##### +# Process Passed Parameters +# Save locally in a variable of the same name +##### + +try: + requestor = os.environ["REMOTE_ADDR"] + service = address = "" + for argument in os.environ["QUERY_STRING"].split("&"): + exec('%s="%s"' % tuple(argument.split("="))) + +except: + Error("Internal Program Error") + +##### +# Validate Number And Content Of Passed Parameters +##### + +# Make sure both parameters were passed + +if not (service and address): + Error("You Must Specify Both A Service Name And Address") + + +# Make sure requested service is one of the ones allowed + +elif service not in Services: + Error("You Are Not Permitted To Change Access To %s" % service) + + +# Make sure address is in quad format + +if not re.match(IPQuad, address): + Error("You Must Specify Address In IP Quad Format") + + +# Make sure address is not on the forbidden list + +if address in Forbidden: + Error("You Are Not Permitted To Enable Access For Address: %s" % address) + +##### +# Output Content +##### + +Print("Requested...
Access To Service: %s
For Address: %s
" % (service, address)) + + +# Make sure there is a directory present to receive the request + +reqdir = Basedir + service + +try: + os.makedirs(reqdir) +except: + pass + +# Now write the request there + +reqfil = reqdir + os.sep + address +f=open(reqfil, "w") +f.close() +