#!/usr/local/bin/python -OO """ scgi/web2ldap.py - stub script for running as SCGI server web2ldap - web-based LDAP Client, see http://www.web2ldap.de (c) by Michael Stroeder This software is distributed under the terms of the GPL (GNU GENERAL PUBLIC LICENSE) Version 2 (see http://www.gnu.org/copyleft/gpl.html) $Id: web2ldap.py,v 1.8 2004/07/07 08:06:08 michael Exp $ """ try: import psyco except ImportError: pass else: psyco.full() import sys,os,signal,time,scgi.scgi_server exec_startdir = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) sys.path.insert(0,os.sep.join([exec_startdir,'etc','web2ldap'])) sys.path.insert(0,os.sep.join([exec_startdir,'pylib'])) if os.name == 'posix': # For finding web2ldapcnf.py in /etc/web2ldap on Unix systems sys.path.append('/etc/web2ldap') import web2ldapcnf.misc,web2ldapcnf.scgi open(web2ldapcnf.scgi.pid_file,'w').write(str(os.getpid())) for i in web2ldapcnf.misc.pylibdirs: sys.path.insert(0,i) import mssignals,w2lapp.handler,w2lapp.core class W2LHandler(scgi.scgi_server.SCGIHandler): prefix = web2ldapcnf.scgi.prefix def __init__(self,*args,**kwargs): scgi.scgi_server.SCGIHandler.__init__(self,*args,**kwargs) def handle_connection(self,conn): inputf = conn.makefile("r") outputf = conn.makefile("w") env = self.read_env(inputf) if not env.has_key('PATH_INFO'): path = env['SCRIPT_NAME'] env['SCRIPT_NAME'] = self.prefix env['PATH_INFO'] = path[len(self.prefix):] try: w2lapp.handler.HandleHTTPRequest( inputf,outputf,sys.stderr,env ) finally: outputf.close() inputf.close() conn.close() class SCGIServer(scgi.scgi_server.SCGIServer): def delegate_request(self,conn): pass # Start the clean-up thread import w2lapp.session w2lapp.session.cleanUpThread.start() try: if len(sys.argv)==2: host,port = '127.0.0.1',int(sys.argv[1]) elif len(sys.argv)==3: host,port = sys.argv[1],int(sys.argv[2]) else: host,port = '127.0.0.1',scgi.scgi_server.SCGIServer.DEFAULT_PORT sys.stderr.write('***Started SCGIServer on %s:%s\n' % (host,port)) scgiserver = scgi.scgi_server.SCGIServer( handler_class=W2LHandler,host=host,port=port,max_children=1 ) scgiserver.serve() except KeyboardInterrupt: # Stop clean-up thread w2lapp.session.cleanUpThread.enabled=0 os.remove(web2ldapcnf.scgi.pid_file)