"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "frontends/roundup.cgi" between
roundup-1.6.1.tar.gz and roundup-2.0.0.tar.gz

About: Roundup is an highly customisable issue-tracking system with command-line, web and e-mail interfaces (written in Python).

roundup.cgi  (roundup-1.6.1):roundup.cgi  (roundup-2.0.0)
skipping to change at line 20 skipping to change at line 20
# OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
# #
# BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
# python version check # python version check
from __future__ import print_function
from roundup import version_check from roundup import version_check
from roundup.i18n import _ from roundup.i18n import _
from roundup.anypy.strings import s2b, StringIO
import sys, time import sys, time
# #
## Configuration ## Configuration
# #
# Configuration can also be provided through the OS environment (or via # Configuration can also be provided through the OS environment (or via
# the Apache "SetEnv" configuration directive). If the variables # the Apache "SetEnv" configuration directive). If the variables
# documented below are set, they _override_ any configuation defaults # documented below are set, they _override_ any configuation defaults
# given in this file. # given in this file.
skipping to change at line 72 skipping to change at line 74
LOG = DevNull() LOG = DevNull()
# #
## end configuration ## end configuration
# #
# #
# Set up the error handler # Set up the error handler
# #
try: try:
import traceback, StringIO, cgi import traceback, cgi
from roundup.cgi import cgitb from roundup.cgi import cgitb
except: except:
print "Content-Type: text/plain\n" print("Content-Type: text/plain\n")
print _("Failed to import cgitb!\n\n") print(_("Failed to import cgitb!\n\n"))
s = StringIO.StringIO() s = StringIO()
traceback.print_exc(None, s) traceback.print_exc(None, s)
print s.getvalue() print(s.getvalue())
# #
# Check environment for config items # Check environment for config items
# #
def checkconfig(): def checkconfig():
import os, string import os
global TRACKER_HOMES, LOG global TRACKER_HOMES, LOG
# see if there's an environment var. ROUNDUP_INSTANCE_HOMES is the # see if there's an environment var. ROUNDUP_INSTANCE_HOMES is the
# old name for it. # old name for it.
if os.environ.has_key('ROUNDUP_INSTANCE_HOMES'): if 'ROUNDUP_INSTANCE_HOMES' in os.environ:
homes = os.environ.get('ROUNDUP_INSTANCE_HOMES') homes = os.environ.get('ROUNDUP_INSTANCE_HOMES')
else: else:
homes = os.environ.get('TRACKER_HOMES', '') homes = os.environ.get('TRACKER_HOMES', '')
if homes: if homes:
TRACKER_HOMES = {} TRACKER_HOMES = {}
for home in string.split(homes, os.pathsep): for home in homes.split(os.pathsep):
try: try:
name, dir = string.split(home, '=', 1) name, dir = home.split('=', 1)
except ValueError: except ValueError:
# ignore invalid definitions # ignore invalid definitions
continue continue
if name and dir: if name and dir:
TRACKER_HOMES[name] = dir TRACKER_HOMES[name] = dir
logname = os.environ.get('ROUNDUP_LOG', '') logname = os.environ.get('ROUNDUP_LOG', '')
if logname: if logname:
LOG = open(logname, 'a') LOG = open(logname, 'a')
skipping to change at line 123 skipping to change at line 125
# #
class RequestWrapper: class RequestWrapper:
'''Used to make the CGI server look like a BaseHTTPRequestHandler '''Used to make the CGI server look like a BaseHTTPRequestHandler
''' '''
def __init__(self, wfile): def __init__(self, wfile):
self.rfile = sys.stdin self.rfile = sys.stdin
self.wfile = wfile self.wfile = wfile
def write(self, data): def write(self, data):
self.wfile.write(data) self.wfile.write(data)
def send_response(self, code): def send_response(self, code):
self.write('Status: %s\r\n'%code) self.write(s2b('Status: %s\r\n'%code))
def send_header(self, keyword, value): def send_header(self, keyword, value):
self.write("%s: %s\r\n" % (keyword, value)) self.write(s2b("%s: %s\r\n" % (keyword, value)))
def end_headers(self): def end_headers(self):
self.write("\r\n") self.write(b"\r\n")
def start_response(self, headers, response): def start_response(self, headers, response):
self.send_response(response) self.send_response(response)
for key, value in headers: for key, value in headers:
self.send_header(key, value) self.send_header(key, value)
self.end_headers() self.end_headers()
# #
# Main CGI handler # Main CGI handler
# #
def main(out, err): def main(out, err):
import os, string import os
import roundup.instance import roundup.instance
path = string.split(os.environ.get('PATH_INFO', '/'), '/') path = os.environ.get('PATH_INFO', '/').split('/')
request = RequestWrapper(out) request = RequestWrapper(out)
request.path = os.environ.get('PATH_INFO', '/') request.path = os.environ.get('PATH_INFO', '/')
tracker = path[1] tracker = path[1]
os.environ['TRACKER_NAME'] = tracker os.environ['TRACKER_NAME'] = tracker
os.environ['PATH_INFO'] = string.join(path[2:], '/') os.environ['PATH_INFO'] = '/'.join(path[2:])
if TRACKER_HOMES.has_key(tracker): if tracker in TRACKER_HOMES:
# redirect if we need a trailing '/' # redirect if we need a trailing '/'
if len(path) == 2: if len(path) == 2:
request.send_response(301) request.send_response(301)
# redirect # redirect
if os.environ.get('HTTPS', '') == 'on': if os.environ.get('HTTPS', '') == 'on':
protocol = 'https' protocol = 'https'
else: else:
protocol = 'http' protocol = 'http'
absolute_url = '%s://%s%s/'%(protocol, os.environ['HTTP_HOST'], absolute_url = '%s://%s%s/'%(protocol, os.environ['HTTP_HOST'],
os.environ.get('REQUEST_URI', '')) os.environ.get('REQUEST_URI', ''))
request.send_header('Location', absolute_url) request.send_header('Location', absolute_url)
request.end_headers() request.end_headers()
out.write('Moved Permanently') out.write(b'Moved Permanently')
else: else:
tracker_home = TRACKER_HOMES[tracker] tracker_home = TRACKER_HOMES[tracker]
tracker = roundup.instance.open(tracker_home) tracker = roundup.instance.open(tracker_home)
import roundup.cgi.client import roundup.cgi.client
if hasattr(tracker, 'Client'): if hasattr(tracker, 'Client'):
client = tracker.Client(tracker, request, os.environ) client = tracker.Client(tracker, request, os.environ)
else: else:
client = roundup.cgi.client.Client(tracker, request, os.environ) client = roundup.cgi.client.Client(tracker, request, os.environ)
try: try:
client.main() client.main()
except roundup.cgi.client.Unauthorised: except roundup.cgi.client.Unauthorised:
request.send_response(403) request.send_response(403)
request.send_header('Content-Type', 'text/html') request.send_header('Content-Type', 'text/html')
request.end_headers() request.end_headers()
out.write('Unauthorised') out.write(b'Unauthorised')
except roundup.cgi.client.NotFound: except roundup.cgi.client.NotFound:
request.send_response(404) request.send_response(404)
request.send_header('Content-Type', 'text/html') request.send_header('Content-Type', 'text/html')
request.end_headers() request.end_headers()
out.write('Not found: %s'%cgi.escape(client.path)) out.write(s2b('Not found: %s'%cgi.escape(client.path)))
else: else:
import urllib from roundup.anypy import urllib_
request.send_response(200) request.send_response(200)
request.send_header('Content-Type', 'text/html') request.send_header('Content-Type', 'text/html')
request.end_headers() request.end_headers()
w = request.write w = request.write
w(_('<html><head><title>Roundup trackers index</title></head>\n')) w(s2b(_('<html><head><title>Roundup trackers index</title></head>\n')))
w(_('<body><h1>Roundup trackers index</h1><ol>\n')) w(s2b(_('<body><h1>Roundup trackers index</h1><ol>\n')))
homes = TRACKER_HOMES.keys() homes = sorted(TRACKER_HOMES.keys())
homes.sort()
for tracker in homes: for tracker in homes:
w(_('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n')%{ w(s2b(_('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n' )%{
'tracker_url': os.environ['SCRIPT_NAME']+'/'+ 'tracker_url': os.environ['SCRIPT_NAME']+'/'+
urllib.quote(tracker), urllib_.quote(tracker),
'tracker_name': cgi.escape(tracker)}) 'tracker_name': cgi.escape(tracker)}))
w(_('</ol></body></html>')) w(s2b(_('</ol></body></html>')))
# #
# Now do the actual CGI handling # Now do the actual CGI handling
# #
out, err = sys.stdout, sys.stderr out, err = sys.stdout, sys.stderr
try: try:
# force input/output to binary (important for file up/downloads) # force input/output to binary (important for file up/downloads)
if sys.platform == "win32": if sys.platform == "win32":
import os, msvcrt import os, msvcrt
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
checkconfig() checkconfig()
sys.stdout = sys.stderr = LOG sys.stdout = sys.stderr = LOG
main(out, err) if sys.version_info[0] > 2:
out_buf = out.buffer
else:
out_buf = out
main(out_buf, err)
except SystemExit: except SystemExit:
pass pass
except: except:
sys.stdout, sys.stderr = out, err sys.stdout, sys.stderr = out, err
out.write('Content-Type: text/html\n\n') out.write('Content-Type: text/html\n\n')
if DEBUG_TO_CLIENT: if DEBUG_TO_CLIENT:
cgitb.handler() cgitb.handler()
else: else:
out.write(cgitb.breaker()) out.write(cgitb.breaker())
ts = time.ctime() ts = time.ctime()
out.write('''<p>%s: An error occurred. Please check out.write('''<p>%s: An error occurred. Please check
the server log for more information.</p>'''%ts) the server log for more information.</p>'''%ts)
print >> sys.stderr, 'EXCEPTION AT', ts print('EXCEPTION AT', ts, file=sys.stderr)
traceback.print_exc(0, sys.stderr) traceback.print_exc(0, sys.stderr)
sys.stdout.flush() sys.stdout.flush()
sys.stdout, sys.stderr = out, err sys.stdout, sys.stderr = out, err
LOG.close() LOG.close()
# vim: set filetype=python ts=4 sw=4 et si # vim: set filetype=python ts=4 sw=4 et si
 End of changes. 24 change blocks. 
30 lines changed or deleted 35 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)