X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=cgi-bin%2Froundup.cgi;h=1518c400b98111965ddeb1bc662dddc9103afc2b;hb=7520e02f86cafa83c87f69a0c671a583aae14368;hp=383754be7cae810b6a6e74e20b1329190c771ea4;hpb=c853df7b1fb5c3deee55fd7c8396f56259b060f6;p=roundup.git diff --git a/cgi-bin/roundup.cgi b/cgi-bin/roundup.cgi index 383754b..1518c40 100755 --- a/cgi-bin/roundup.cgi +++ b/cgi-bin/roundup.cgi @@ -5,7 +5,7 @@ # under the same terms as Python, so long as this copyright message and # disclaimer are retained in their original form. # -# IN NO EVENT SHALL THE BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR +# IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. @@ -16,22 +16,38 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: roundup.cgi,v 1.9 2001-08-07 00:15:51 richard Exp $ +# $Id: roundup.cgi,v 1.33 2002-09-23 00:50:32 richard Exp $ # python version check +from roundup import version_check +from roundup.i18n import _ import sys -if int(sys.version[0]) < 2: - print "Content-Type: text/plain\n" - print "Roundup requires Python 2.0 or newer." - sys.exit(0) # ## Configuration # +# Configuration can also be provided through the OS environment (or via +# the Apache "SetEnv" configuration directive). If the variables +# documented below are set, they _override_ any configuation defaults +# given in this file. + +# TRACKER_HOMES is a list of instances, in the form +# "NAME=DIRNAME2=DIR2...", where is the directory path +# separator (";" on Windows, ":" on Unix). + +# Make sure the NAME part doesn't include any url-unsafe characters like +# spaces, as these confuse the cookie handling in browsers like IE. + +# ROUNDUP_LOG is the name of the logfile; if it's empty or does not exist, +# logging is turned off (unless you changed the default below). + +# ROUNDUP_DEBUG is a debug level, currently only 0 (OFF) and 1 (ON) are +# used in the code. Higher numbers means more debugging output. + # This indicates where the Roundup instance lives -ROUNDUP_INSTANCE_HOMES = { - 'test': '/tmp/roundup_test', +TRACKER_HOMES = { + 'demo': '/var/roundup/instances/demo', } # Where to log debugging information to. Use an instance of DevNull if you @@ -39,8 +55,10 @@ ROUNDUP_INSTANCE_HOMES = { class DevNull: def write(self, info): pass -LOG = open('/var/log/roundup.cgi.log', 'a') -#LOG = DevNull() + def close(self): + pass +#LOG = open('/var/log/roundup.cgi.log', 'a') +LOG = DevNull() # ## end configuration @@ -52,104 +70,144 @@ LOG = open('/var/log/roundup.cgi.log', 'a') # try: import traceback, StringIO, cgi - from roundup import cgitb + from roundup.cgi import cgitb except: - print "Content-Type: text/html\n" - print "Failed to import cgitb.
"
+    print "Content-Type: text/plain\n"
+    print _("Failed to import cgitb!\n\n")
     s = StringIO.StringIO()
     traceback.print_exc(None, s)
-    print cgi.escape(s.getvalue()), "
" - -def main(instance, out): - from roundup import cgi_client - db = instance.open('admin') - auth = os.environ.get("HTTP_CGI_AUTHORIZATION", None) - message = 'Unauthorised' - if auth: - import binascii - l = binascii.a2b_base64(auth.split(' ')[1]).split(':') - user = l[0] - password = None - if len(l) > 1: - password = l[1] - try: - uid = db.user.lookup(user) - except KeyError: - auth = None - message = 'Username not recognised' - else: - if password != db.user.get(uid, 'password'): - message = 'Incorrect password' - auth = None - if not auth: - out.write('Content-Type: text/html\n') - out.write('Status: 401\n') - out.write('WWW-Authenticate: basic realm="Roundup"\n\n') - keys = os.environ.keys() - keys.sort() - out.write(message) - return - client = instance.Client(out, db, os.environ, user) - try: - client.main() - except cgi_client.Unauthorised: - out.write('Content-Type: text/html\n') - out.write('Status: 403\n\n') - out.write('Unauthorised') + print s.getvalue() + # -# Now do the actual CGI handling -# -out, err = sys.stdout, sys.stderr -try: - sys.stdout = sys.stderr = LOG +# Check environment for config items +# +def checkconfig(): + import os, string + global TRACKER_HOMES, LOG + + # see if there's an environment var. ROUNDUP_INSTANCE_HOMES is the + # old name for it. + if os.environ.has_key('ROUNDUP_INSTANCE_HOMES'): + homes = os.environ.get('ROUNDUP_INSTANCE_HOMES') + else: + homes = os.environ.get('TRACKER_HOMES', '') + if homes: + TRACKER_HOMES = {} + for home in string.split(homes, os.pathsep): + try: + name, dir = string.split(home, '=', 1) + except ValueError: + # ignore invalid definitions + continue + if name and dir: + TRACKER_HOMES[name] = dir + + logname = os.environ.get('ROUNDUP_LOG', '') + if logname: + LOG = open(logname, 'a') + + # ROUNDUP_DEBUG is checked directly in "roundup.cgi.client" + + +# +# Provide interface to CGI HTTP response handling +# +class RequestWrapper: + '''Used to make the CGI server look like a BaseHTTPRequestHandler + ''' + def __init__(self, wfile): + self.wfile = wfile + def write(self, data): + self.wfile.write(data) + def send_response(self, code): + self.write('Status: %s\r\n'%code) + def send_header(self, keyword, value): + self.write("%s: %s\r\n" % (keyword, value)) + def end_headers(self): + self.write("\r\n") + +# +# Main CGI handler +# +def main(out, err): import os, string import roundup.instance - path = string.split(os.environ['PATH_INFO'], '/') + path = string.split(os.environ.get('PATH_INFO', '/'), '/') + request = RequestWrapper(out) + request.path = os.environ.get('PATH_INFO', '/') instance = path[1] + os.environ['TRACKER_NAME'] = instance os.environ['PATH_INFO'] = string.join(path[2:], '/') - if ROUNDUP_INSTANCE_HOMES.has_key(instance): - instance_home = ROUNDUP_INSTANCE_HOMES[instance] - instance = roundup.instance.open(instance_home) + if TRACKER_HOMES.has_key(instance): + # redirect if we need a trailing '/' + if len(path) == 2: + request.send_response(301) + # redirect + if os.environ.get('HTTPS', '') == 'on': + protocol = 'https' + else: + protocol = 'http' + absolute_url = '%s://%s%s/'%(protocol, os.environ['HTTP_HOST'], + os.environ['REQUEST_URI']) + request.send_header('Location', absolute_url) + request.end_headers() + out.write('Moved Permanently') + else: + instance_home = TRACKER_HOMES[instance] + instance = roundup.instance.open(instance_home) + from roundup.cgi.client import Unauthorised, NotFound + client = instance.Client(instance, request, os.environ) + try: + client.main() + except Unauthorised: + request.send_response(403) + request.send_header('Content-Type', 'text/html') + request.end_headers() + out.write('Unauthorised') + except NotFound: + request.send_response(404) + request.send_header('Content-Type', 'text/html') + request.end_headers() + out.write('Not found: %s'%client.path) + else: - raise ValueError, 'No such instance "%s"'%instance - main(instance, out) + import urllib + request.send_response(200) + request.send_header('Content-Type', 'text/html') + request.end_headers() + w = request.write + w(_('Roundup instances index\n')) + w(_('

Roundup instances index

    \n')) + homes = TRACKER_HOMES.keys() + homes.sort() + for instance in homes: + w(_('
  1. %(instance_name)s\n')%{ + 'instance_url': os.environ['SCRIPT_NAME']+'/'+urllib.quote(instance), + 'instance_name': cgi.escape(instance)}) + w(_('
')) + +# +# Now do the actual CGI handling +# +out, err = sys.stdout, sys.stderr +try: + # force input/output to binary (important for file up/downloads) + if sys.platform == "win32": + import os, msvcrt + msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) + msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) + checkconfig() + sys.stdout = sys.stderr = LOG + main(out, err) +except SystemExit: + pass except: sys.stdout, sys.stderr = out, err out.write('Content-Type: text/html\n\n') cgitb.handler() sys.stdout.flush() sys.stdout, sys.stderr = out, err +LOG.close() -# -# $Log: not supported by cvs2svn $ -# Revision 1.8 2001/08/05 07:43:52 richard -# Instances are now opened by a special function that generates a unique -# module name for the instances on import time. -# -# Revision 1.7 2001/08/03 01:28:33 richard -# Used the much nicer load_package, pointed out by Steve Majewski. -# -# Revision 1.6 2001/08/03 00:59:34 richard -# Instance import now imports the instance using imp.load_module so that -# we can have instance homes of "roundup" or other existing python package -# names. -# -# Revision 1.5 2001/07/29 07:01:39 richard -# Added vim command to all source so that we don't get no steenkin' tabs :) -# -# Revision 1.4 2001/07/23 04:47:27 anthonybaxter -# renamed ROUNDUPS to ROUNDUP_INSTANCE_HOMES -# sys.exit(0) if python version wrong. -# -# Revision 1.3 2001/07/23 04:33:30 richard -# brought the CGI instance config dict in line with roundup-server -# -# Revision 1.2 2001/07/23 04:31:40 richard -# Fixed the roundup CGI script for updates to cgi_client.py -# -# Revision 1.1 2001/07/22 11:47:07 richard -# More Grande Splite -# -# # vim: set filetype=python ts=4 sw=4 et si