#!/usr/bin/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('/home/ubottu/bot/plugins/')
from commoncgi import *
### Variables
# Location of the bans database
db = '/home/ubottu/data/bans.db'
# Number of bans to show per page
num_per_page = 100
### You shouldn't have to change anything under this line ###
con = sqlite.connect(db)
cur = con.cursor()
# Login check
error = ''
user = None
# Delete old sessions
# FAIL!
try:
cur.execute("DELETE FROM sessions WHERE time < %d", int(time.mktime(time.gmtime())) - 2592000 * 3)
con.commit()
con.close()
except:
try:
con.commit()
except:
pass
finally:
con.close()
# Session handling
if form.has_key('sess'):
cookie['sess'] = form['sess'].value
if cookie.has_key('sess'):
try:
sess = cookie['sess'].value
con = sqlite.connect(db)
cur = con.cursor()
cur.execute("SELECT user FROM sessions WHERE session_id=%s",sess)
user = cur.fetchall()[0][0]
con.commit()
con.close()
except:
con.commit()
con.close()
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 descuss bans"
send_page('bans.tmpl')
# Log
if form.has_key('log'):
con = sqlite.connect(db)
cur = con.cursor()
cur.execute("SELECT log FROM bans WHERE id=%s", form['log'].value)
log = cur.fetchall()
con.commit()
con.close()
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:
con = sqlite.connect(db)
cur = con.cursor()
cur.execute("SELECT ban_id FROM comments WHERE ban_id=%s and comment=%s", (form['comment_id'].value, form['comment'].value))
comm = cur.fetchall()
con.commit()
con.close()
if not len(comm):
con = sqlite.connect(db)
cur = con.cursor()
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()
con.close()
# Write the page
print '