diff --git a/Bantracker/README.txt b/Bantracker/README.txt index f0b21aa..689bc28 100644 --- a/Bantracker/README.txt +++ b/Bantracker/README.txt @@ -9,35 +9,35 @@ kick/ban someone. It also uses commoncgi.py which should be on your sys.path (or as you can see in the script, sys.path is modified to include the dir of commoncgi.py) -The schema of the sqlite database: +The schema of the SQLite2 database: CREATE TABLE bans ( - id INTEGER PRIMARY KEY, - channel VARCHAR(30) NOT NULL, - mask VARCHAR(100) NOT NULL, - operator VARCHAR(30) NOT NULL, - time VARCHAR(300) NOT NULL, - removal DATETIME, - removal_op VARCHAR(30), - log TEXT - ); -CREATE TABLE comments ( - ban_id INTEGER, - who VARCHAR(100) NOT NULL, - comment MEDIUMTEXT NOT NULL, - time VARCHAR(300) NOT NULL - ); -CREATE TABLE sessions ( - session_id VARCHAR(50) PRIMARY KEY, - user MEDIUMTEXT NOT NULL, - time INT NOT NULL + id INTEGER PRIMARY KEY, + channel VARCHAR(30) NOT NULL, + mask VARCHAR(100) NOT NULL, + operator VARCHAR(30) NOT NULL, + time VARCHAR(300) NOT NULL, + removal DATETIME, + removal_op VARCHAR(30), + log TEXT ); -CREATE TABLE users ( - username VARCHAR(50) PRIMARY KEY, - salt VARCHAR(8), - password VARCHAR(50) +CREATE TABLE comments ( + ban_id INTEGER, + who VARCHAR(100) NOT NULL, + comment MEDIUMTEXT NOT NULL, + time VARCHAR(300) NOT NULL +); +CREATE TABLE sessions ( + session_id VARCHAR(50) PRIMARY KEY, + user MEDIUMTEXT NOT NULL, + time INT NOT NULL ); -To configure the plugin, create the sqlite database with above structure and set -supybot.plugins.bantracker.database to its filename. Then enable it per channel -by setting the channel variable supybot.plugins.bantracker.enabled +To configure the plugin, create the SQLite2 database with above structure and +set supybot.plugins.bantracker.database to its filename. Then enable it, either +per-channel or globally, by setting the channel variable: +supybot.plugins.bantracker.enabled +You can create the database by using the "sqlite" command-line tool by passing +the file name and then copy/paste the above table schema. +If you choose to enable this plugin during the initial setup (with the command +supybot-wizard), then the database will be created automatically for you. diff --git a/Bantracker/bans.cgi b/Bantracker/bans.cgi index 5f433a3..445ef6a 100755 --- a/Bantracker/bans.cgi +++ b/Bantracker/bans.cgi @@ -31,7 +31,8 @@ user = None # Delete old sessions try: - cur.execute("""DELETE FROM sessions WHERE time < %d""", int(time.time()) - 2592000 * 3) + session_timeout = int(time.time()) - (2592000 * 3) + cur.execute('DELETE FROM sessions WHERE time < %d', (session_timeout,)) except: pass @@ -41,7 +42,7 @@ if form.has_key('sess'): if cookie.has_key('sess'): try: sess = cookie['sess'].value - cur.execute("""SELECT user FROM sessions WHERE session_id=%s""",sess) + cur.execute('SELECT user FROM sessions WHERE session_id=%s',(sess,)) user = cur.fetchall()[0][0] except: con.commit() @@ -54,7 +55,7 @@ if not user: # Log if form.has_key('log'): - cur.execute("""SELECT log FROM bans WHERE id=%s""", form['log'].value) + cur.execute('SELECT log FROM bans WHERE id=%s', (form['log'].value,)) log = cur.fetchall() con.commit() if form.has_key('mark'): @@ -72,10 +73,10 @@ if form.has_key('log'): # 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)) + 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)""", + 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() @@ -178,10 +179,10 @@ print '