diff --git a/Bantracker/cgi/bans.cgi b/Bantracker/cgi/bans.cgi index 3d376c5..52eb992 100755 --- a/Bantracker/cgi/bans.cgi +++ b/Bantracker/cgi/bans.cgi @@ -17,20 +17,59 @@ import os import sys import time import urllib -# This needs to be set to the location of the commoncgi.py file -sys.path.append('/var/www/bot') -from commoncgi import * +import ConfigParser + +CONFIG_FILENAME = "bantracker.conf" +config = ConfigParser.RawConfigParser() +config.add_section('webpage') + +# set default values +config.set('webpage', 'database', 'bans.db') +config.set('webpage', 'results_per_page', '100') +config.set('webpage', 'anonymous_access', 'True') +config.set('webpage', 'PLUGIN_PATH', '') + +try: + config.readfp(open(CONFIG_FILENAME)) +except IOError: + config.write(open(CONFIG_FILENAME, 'w')) + +# This needs to be set to the location of the commoncgi.py file +PLUGIN_PATH = config.get('webpage', 'PLUGIN_PATH') +if PLUGIN_PATH: + sys.path.append(PLUGIN_PATH) + +try: + from commoncgi import * +except: + print "Content-Type: text/html" + print + print "
Failed to load the module commoncgi
" + print "Check that the config option PLUGIN_PATH in '%s' is correct.
" % CONFIG_FILENAME + sys.exit(-1) + +db = config.get('webpage', 'database') +num_per_page = config.getint('webpage', 'results_per_page') +anonymous_access = config.getboolean('webpage', 'anonymous_access') -### Variables -db = '/home/bot/data/bans.db' -num_per_page = 100 pagename = os.path.basename(sys.argv[0]) -disable_anonymous = False # Set this to True to disable anonymous access t1 = time.time() -con = sqlite.connect(db) -cur = con.cursor() +try: + con = sqlite.connect(db) + cur = con.cursor() +except sqlite.DatabaseError: + print "Unable to connect to to database '%s'" % db + send_page('bans.tmpl') + +def db_execute(query, args): + try: + cur.execute(query, args) + return cur + except sqlite.OperationalError: + print "The database is locked, wait a bit and try again." + send_page('bans.tmpl') # Login check error = '' @@ -55,11 +94,10 @@ if cookie.has_key('sess'): con.commit() pass -if not user and disable_anonymous: +if not user and not anonymous_access: print "Sorry, bantracker is not available for anonymous users