#!/usr/bin/env python
###
# Copyright (c) 2005-2007 Dennis Kaarsemaker
#
# 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 sys
# This needs to be set to the location of the commoncgi.py file
sys.path.append('/var/www/bot')
from commoncgi import *
### Variables
db = '/home/bot/data/bans.db'
num_per_page = 100
con = sqlite.connect(db)
cur = con.cursor()
# Login check
error = ''
user = None
# Delete old sessions
try:
cur.execute("""DELETE FROM sessions WHERE time < %d""", int(time.time()) - 2592000 * 3)
except:
pass
# Session handling
if form.has_key('sess'):
cookie['sess'] = form['sess'].value
if cookie.has_key('sess'):
try:
sess = cookie['sess'].value
cur.execute("""SELECT user FROM sessions WHERE session_id=%s""",sess)
user = cur.fetchall()[0][0]
except:
con.commit()
pass
if not user:
print "Sorry, bantracker has been shut down for anonymous users due to server load
"
print "Join #ubuntu-ops on irc.freenode.net to discuss bans"
send_page('bans.tmpl')
# Log
if form.has_key('log'):
cur.execute("""SELECT log FROM bans WHERE id=%s""", form['log'].value)
log = cur.fetchall()
con.commit()
if form.has_key('mark'):
marked = form['mark'].value
lines = log[0][0].splitlines()
for line in lines:
if marked.lower() in line.lower():
print '%s
' % q(line)
else:
print "%s
" % q(line)
else:
print q(log[0][0]).replace('\n', '
')
send_page('empty.tmpl')
# Main page
# Process comments
if form.has_key('comment') and form.has_key('comment_id') and user:
cur.execute("""SELECT ban_id FROM comments WHERE ban_id=%s and comment=%s""", (form['comment_id'].value, form['comment'].value))
comm = cur.fetchall()
if not len(comm):
cur.execute("""INSERT INTO comments (ban_id, who, comment, time) VALUES (%s, %s, %s, %s)""",
(form['comment_id'].value,user,form['comment'].value,pickle.dumps(datetime.datetime.now(pytz.UTC))))
con.commit()
# Write the page
print '