#!/usr/local/bin/python -u """Provide a password-interface wrapper around a hierarchy of web pages. Currently this is organized to obtain passwords for mailman maillist subscribers. - Set the ROOT variable to point to the root of your archives private hierarchy. The script will look there for the private archive files. - Put the ../misc/Cookie.py script in ../../cgi-bin (where the wrapper executables are). """ __version__ = "$Revision: 429 $" import sys, os, string, re sys.path.append( os.path.expanduser('~mailman/mailman/modules/') ) import maillist, mm_err, mm_utils sys.path.append('.') import Cookie sys.stderr = sys.stdout ROOT = "/local/pipermail/private/" SECRET = "secret" # XXX used for hashing PAGE = """
A list named,', repr(list_name), "was not found." return 0 try: listobj.ConfirmUserPassword( username, password) except (mm_err.MMBadUserError, mm_err.MMBadPasswordError): return 1 import base64, md5 token = md5.new(SECRET + list_name + SECRET).digest() token = base64.encodestring(token) token = string.strip(token) c = Cookie.Cookie() c[list_name] = token print c # Output the cookie return 1 def true_path(path): "Ensure that the path is safe by removing .." path = string.split(path, '/') for i in range(len(path)): if path[i] == ".": path[i] = "" # ./ is just redundant elif path[i] == "..": # Remove any .. components path[i] = "" j=i-1 while j>0 and path[j] == "": j=j-1 path[j] = "" path = filter(None, path) return string.join(path, '/') def processPage(page): """Change any URLs that start with ../ to work properly when output from /cgi-bin/private""" # Escape any % signs not followed by ( page = re.sub('%([^(])', r'%%\1', page) # Convert references like HREF="../doc" to just /doc. page = re.sub('([\'="])../', r'\1/', page) return page def main(): path = os.environ.get('PATH_INFO', "/index.html") true_filename = os.path.join(ROOT, true_path(path) ) list_name = getListName(path) if os.path.isdir(true_filename): true_filename = true_filename + '/index.html' if not isAuthenticated(list_name): # Output the password form page = processPage( PAGE ) listobj = GetListobj(list_name) if login_attempted: message = ("Your email address or password were incorrect." " Please try again.") else: message = ("Please enter your %s subscription email address." " and password " % listobj.real_name) while path and path[0] == '/': path=path[1:] # Remove leading /'s basepath = os.path.split(listobj.GetBaseArchiveURL())[0] listname = listobj.real_name print '\n\n', page % vars() sys.exit(0) print '\n\n' # Authorization confirmed... output the desired file try: f = open(true_filename, 'r') except IOError: print "