Files
ubuntu-bots/commoncgi.py
Terence Simpson fd36bffcc0 (large commit, see bazaar log)
[Bantracker]
 * Less spaces in README.txt
 * Remove mention of table 'users' in README.txt
 * Add more detail on how to create the bans database in README.txt
 * Add note about supybot-wizard creating the initial database in README.txt
 * Don't hard-code default values in config.py:configure()
 * Tweak config.py
 * Clean up bans.cgi a bit

[Bugtracker]
 * Comment-out obsolete "bug reporting" variables in config.py
 * Update README.txt and remove "bug reporting" stuff, also remove extraneous license info
 * Comment-out obsolete "bug reporting" code
 * Don't import imaplib

[Encyclopedia]
 * Don't hard-code default values in config.py:configure()
 * Check for 'owner' capability before checking if the hostmask is ignored in plugin.py:checkIgnored()
 * Clean up README.txt

[PackageInfo]
 * Don't hard-code default values in config.py:configure()
 * Update default distributions in config.py:configure()
 * Update defaultRelease in config.py 
 * Update README.txt

* Add a few docstrings to commoncgi.py
* Update COPYING
* Update README.txt
2011-05-28 07:33:21 +01:00

72 lines
2.0 KiB
Python

# -*- Encoding: utf-8 -*-
###
# Copyright (c) 2006-2007 Dennis Kaarsemaker
# Copyright (c) 2008-2010 Terence Simpson
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
###
import cgi, cgitb, re, sys, math, os, hashlib, sqlite, random, time, datetime, pytz, Cookie, StringIO, urllib2
import cPickle as pickle
cgitb.enable()
form = cgi.FieldStorage()
cookie = Cookie.SimpleCookie()
if os.environ.has_key('HTTP_COOKIE'):
cookie.load(os.environ['HTTP_COOKIE'])
if cookie.has_key('sess'):
cookie['sess']['max-age'] = 2592000 * 3
cookie['sess']['version'] = 1
if cookie.has_key('tz'):
cookie['tz']['max-age'] = 2592000 * 3
cookie['tz']['version'] = 1
class IOWrapper:
'''Class to wrap default IO, used with templates'''
def __init__(self):
self.buf = []
def write(self, val):
self.buf.append(val)
def getvalue(self):
return self.buf
sys.stdout = IOWrapper()
sys.stderr = IOWrapper()
def send_page(template):
'''Sends a template page and exit'''
data = sys.stdout.getvalue()
errdata = sys.stderr.getvalue()
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
print "Content-Type: text/html"
print cookie
print ""
fd = open(template)
tmpl = fd.read()
fd.close()
print tmpl[:tmpl.find('%e')]
for e in errdata:
print e
print tmpl[tmpl.find('%e')+2:tmpl.find('%s')]
# print tmpl[:tmpl.find('%s')]
for d in data:
print d
print tmpl[tmpl.find('%s')+2:]
sys.exit(0)
def q(txt):
'''Simple HTML entity quoting'''
return txt.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;').replace('"','&quot;')