-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathroundup.cgi
More file actions
executable file
·71 lines (65 loc) · 1.99 KB
/
roundup.cgi
File metadata and controls
executable file
·71 lines (65 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
import sys
if int(sys.version[0]) < 2:
print "Content-Type: text/plain\n"
print "Roundup requires Python 2.0 or newer."
import os, traceback, StringIO, cgi, binascii
try:
import cgitb
except:
print "Content-Type: text/html\n"
print "Failed to import cgitb"
print "<pre>"
s = StringIO.StringIO()
traceback.print_exc(None, s)
print cgi.escape(s.getvalue())
print "</pre>"
# Force import first from the same directory where this script lives.
dir, name = os.path.split(sys.argv[0])
sys.path[:0] = [dir or "."]
def main(out):
import config, roundupdb, roundup_cgi
db = roundupdb.openDB(config.DATABASE, 'admin')
auth = os.environ.get("HTTP_CGI_AUTHORIZATION", None)
message = 'Unauthorised'
if auth:
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 = roundup_cgi.Client(out, os.environ, user)
try:
client.main()
except roundup_cgi.Unauthorised:
out.write('Content-Type: text/html\n')
out.write('Status: 403\n\n')
out.write('Unauthorised')
out, err = sys.stdout, sys.stderr
try:
import config, roundup_cgi
sys.stdout = sys.stderr = open(config.LOG, 'a')
main(out)
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