#!/usr/bin/env python # # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/) # This module is free software, and you may redistribute it and/or modify # under the same terms as Python, so long as this copyright message and # disclaimer are retained in their original form. # # 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. # # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # # $Id: roundup.cgi,v 1.16 2001-11-01 22:04:37 richard Exp $ # python version check 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 # # This indicates where the Roundup instance lives ROUNDUP_INSTANCE_HOMES = { 'demo': '/var/roundup/instances/demo', } # Where to log debugging information to. Use an instance of DevNull if you # don't want to log anywhere. class DevNull: def write(self, info): pass #LOG = open('/var/log/roundup.cgi.log', 'a') LOG = DevNull() # ## end configuration # # # Set up the error handler # try: import traceback, StringIO, cgi from roundup import cgitb except: print "Content-Type: text/html\n" print "Failed to import cgitb.
"
s = StringIO.StringIO()
traceback.print_exc(None, s)
print cgi.escape(s.getvalue()), ""
class RequestWrapper:
'''Used to make the CGI server look like a BaseHTTPRequestHandler
'''
def __init__(self, wfile):
self.wfile = wfile
def send_response(self, code):
self.wfile.write('Status: %s\r\n'%code)
def send_header(self, keyword, value):
self.wfile.write("%s: %s\r\n" % (keyword, value))
def end_headers(self, keyword, value):
self.wfile.write("\r\n")
def main(out, err):
import os, string
import roundup.instance
path = string.split(os.environ.get('PATH_INFO', '/'), '/')
instance = path[1]
os.environ['INSTANCE_NAME'] = instance
os.environ['PATH_INFO'] = string.join(path[2:], '/')
request = RequestWrapper(out)
if ROUNDUP_INSTANCE_HOMES.has_key(instance):
instance_home = ROUNDUP_INSTANCE_HOMES[instance]
instance = roundup.instance.open(instance_home)
from roundup import cgi_client
client = instance.Client(instance, request, os.environ)
try:
client.main()
except cgi_client.Unauthorised:
request.send_response(403)
request.send_header('Content-Type', 'text/html')
request.end_headers()
out.write('Unauthorised')
except cgi_client.NotFound:
request.send_response(404)
request.send_header('Content-Type', 'text/html')
request.end_headers()
out.write('Not found: %s'%client.path)
else:
import urllib
request.send_response(200)
request.send_header('Content-Type', 'text/html')
w = request.wfile.write
w('