#!/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.11 2001-09-29 13:27:00 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 = { 'test': '/tmp/roundup_test', } # 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()), ""
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')
def index(out):
''' Print up an index of the available instances
'''
w = out.write
w("Content-Type: text/html\n\n")
w('