mirror of
https://github.com/ncoevoet/ChanTracker.git
synced 2025-04-26 13:01:06 -05:00
more efficient server.py
This commit is contained in:
parent
a3bd00f2b4
commit
8eb99e4b58
244
server.py
244
server.py
@ -7,13 +7,14 @@ import supybot.utils as utils
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
import collections
|
import collections
|
||||||
import urllib
|
import urllib
|
||||||
|
from StringIO import StringIO
|
||||||
|
|
||||||
host = 'http://domain.tld'
|
host = 'http://domain.tld'
|
||||||
port = 6666
|
port = 80
|
||||||
username = 'login'
|
username = 'username'
|
||||||
password = 'password'
|
password = 'password'
|
||||||
filename = '/home/user/bot/data/networkname/ChanTracker.db'
|
filename = '/home/botaccount/data/networkname/ChanTracker.db'
|
||||||
channels = ['#channelA','#channelb'] # empty to allows view of all channels recorded, otherwise restrict the views to channels
|
channels = [] # empty to allows view of all channels recorded, otherwise restrict the views to channels
|
||||||
|
|
||||||
# usage python server.py
|
# usage python server.py
|
||||||
|
|
||||||
@ -69,6 +70,7 @@ class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
|
|||||||
|
|
||||||
def page (self,query):
|
def page (self,query):
|
||||||
h = '%s:%s/' % (host,port)
|
h = '%s:%s/' % (host,port)
|
||||||
|
body = []
|
||||||
if not query:
|
if not query:
|
||||||
return
|
return
|
||||||
if query.startswith('/?username='):
|
if query.startswith('/?username='):
|
||||||
@ -88,20 +90,21 @@ class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
|
|||||||
else:
|
else:
|
||||||
query = '/?hash=%s' % base64string
|
query = '/?hash=%s' % base64string
|
||||||
if not query.startswith('/?hash='):
|
if not query.startswith('/?hash='):
|
||||||
body = '<html>\n<head>\n<title>ChanTracker</title>\n'
|
body.append('<html>\n<head>\n<title>ChanTracker</title>\n')
|
||||||
body += '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n'
|
body.append('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n')
|
||||||
body += "</head>\n<body>\n"
|
body.append("</head>\n<body>\n")
|
||||||
body += '<form action="%s">\n' % h
|
body.append('<form action="%s">\n' % h)
|
||||||
body += '<p>Username:<input name="username" /></p>\n'
|
body.append('<p>Username:<input name="username" /></p>\n')
|
||||||
body += '<p>Password:<input name="password" type="password"/></p>\n'
|
body.append('<p>Password:<input name="password" type="password"/></p>\n')
|
||||||
body += '<input type="submit" value="Login" />\n'
|
body.append('<input type="submit" value="Login" />\n')
|
||||||
body += "</form>\n"
|
body.append("</form>\n")
|
||||||
body += "</body>\n<html>\n"
|
body.append("</body>\n<html>\n")
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header("Content-type","text/html")
|
self.send_header("Content-type","text/html")
|
||||||
self.send_header("Content-length",str(len(body)))
|
full = ''.join(body)
|
||||||
|
self.send_header("Content-length",str(len(full)))
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(body)
|
self.wfile.write(full)
|
||||||
return
|
return
|
||||||
if query.startswith('/?hash='):
|
if query.startswith('/?hash='):
|
||||||
a = query.split('&')[0]
|
a = query.split('&')[0]
|
||||||
@ -111,19 +114,19 @@ class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
|
|||||||
q = '?hash=%s' % base64string
|
q = '?hash=%s' % base64string
|
||||||
query = urllib.unquote( query )
|
query = urllib.unquote( query )
|
||||||
print query
|
print query
|
||||||
body = '<html style="text-align:center;font-size:1.2em;">\n<head>\n<title>BanTracker - %s</title>\n' % query
|
body.append('<html style="text-align:center;font-size:1.2em;">\n<head>\n<title>BanTracker - %s</title>\n' % query)
|
||||||
body += '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n'
|
body.append('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n')
|
||||||
body += '<link rel="stylesheet" href="http://getbootstrap.com/dist/css/bootstrap.min.css"></link>\n'
|
body.append('<link rel="stylesheet" href="http://getbootstrap.com/dist/css/bootstrap.min.css"></link>\n')
|
||||||
body += '<script src="http://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>\n'
|
# body.append('<script src="http://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>\n')
|
||||||
body += '</head>\n<body style="margin:0.5em;width:98%;margin-left:auto;margin-right:auto;text-align:left;" class="container">\n'
|
body.append('</head>\n<body style="margin:0.5em;width:98%;margin-left:auto;margin-right:auto;text-align:left;" class="container">\n')
|
||||||
body += '<div class="row"><div class="col-xs-6">\n'
|
body.append('<div class="row"><div class="col-xs-6">\n')
|
||||||
body += '<form action="%s" class="form">\n' % q
|
body.append('<form action="%s" class="form">\n' % q)
|
||||||
body += '<div class="input-group">'
|
body.append('<div class="input-group">')
|
||||||
body += '<input type="hidden" name="hash" value="%s">' % base64string
|
body.append('<input type="hidden" name="hash" value="%s">' % base64string)
|
||||||
body += '<input name="search" class="form-control" />\n'
|
body.append('<input name="search" class="form-control" />\n')
|
||||||
body += '<span class="input-group-btn"><button type="submit" class="btn btn-default">Search</button></span>\n'
|
body.append('<span class="input-group-btn"><button type="submit" class="btn btn-default">Search</button></span>\n')
|
||||||
body += '</div></form></div>\n'
|
body.append('</div></form></div></div>\n')
|
||||||
body += '<div class="clearfix"></div>\n'
|
body.append('<div class="clearfix"></div>\n')
|
||||||
db = self._getbandb()
|
db = self._getbandb()
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
if query:
|
if query:
|
||||||
@ -131,80 +134,87 @@ class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
|
|||||||
if query.startswith('/&id='):
|
if query.startswith('/&id='):
|
||||||
search = query.split('/&id=')[1]
|
search = query.split('/&id=')[1]
|
||||||
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE id=? ORDER BY id DESC""",(search,))
|
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE id=? ORDER BY id DESC""",(search,))
|
||||||
if c.rowcount:
|
r = c.fetchall()
|
||||||
ban = c.fetchall()[0]
|
if len(r):
|
||||||
|
ban = r[0]
|
||||||
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
||||||
if not len(channels) or channel in channels:
|
if not len(channels) or channel in channels:
|
||||||
body += '<h3>#%s</h3>\n' % id
|
body.append('<h3>#%s</h3>\n' % id)
|
||||||
body += '<p>#%s by %s in %s : +%s : %s</p>\n' % (id,oper,channel,kind,mask)
|
body.append('<p>#%s by %s in %s : +%s : %s</p>\n' % (id,oper,channel,kind,mask))
|
||||||
body += '<p>Begin at %s</p>\n' % time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(begin_at)))
|
body.append('<p>Begin at %s</p>\n' % time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(begin_at))))
|
||||||
was = float(begin_at) == float(end_at)
|
was = float(begin_at) == float(end_at)
|
||||||
if was:
|
if was:
|
||||||
was = 'forever'
|
was = 'forever'
|
||||||
else:
|
else:
|
||||||
was = timeElapsed(float(end_at) - float(begin_at))
|
was = timeElapsed(float(end_at) - float(begin_at))
|
||||||
body += '<p>Original duration : %s</p>\n' % was
|
body.append('<p>Original duration : %s</p>\n' % was)
|
||||||
if not removed_at:
|
if not removed_at:
|
||||||
if was != 'forever':
|
if was != 'forever':
|
||||||
body += '<p>%s</p>\n' % 'It will expire in %s' % timeElapsed(float(end_at) - time.time())
|
body.append('<p>%s</p>\n' % 'It will expire in %s' % timeElapsed(float(end_at) - time.time()))
|
||||||
else:
|
else:
|
||||||
body += '<p>%s</p>\n' % 'Removed after %s on %s by %s' % (timeElapsed(float(removed_at)-float(begin_at)),time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(removed_at))),removed_by)
|
body.append('<p>%s</p>\n' % 'Removed after %s on %s by %s' % (timeElapsed(float(removed_at)-float(begin_at)),time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(removed_at))),removed_by))
|
||||||
c.execute("""SELECT full, log FROM nicks WHERE ban_id=?""",(id,))
|
c.execute("""SELECT full, log FROM nicks WHERE ban_id=?""",(id,))
|
||||||
if c.rowcount:
|
r = c.fetchall()
|
||||||
users = c.fetchall()
|
if len(r):
|
||||||
body += '<h3>Logs</h3>\n'
|
users = r
|
||||||
|
body.append('<h3>Logs</h3>\n')
|
||||||
for u in users:
|
for u in users:
|
||||||
(full,log) = u
|
(full,log) = u
|
||||||
body += '<p>for %s</p>\n' % full
|
body.append('<p>for %s</p>\n' % full)
|
||||||
if log != '':
|
if log != '':
|
||||||
body +='<ul>\n'
|
body.append('<ul>\n')
|
||||||
for line in log.split('\n'):
|
for line in log.split('\n'):
|
||||||
if line != '':
|
if line != '':
|
||||||
body += '<li>%s</li>\n' % line
|
body.append('<li>%s</li>\n' % line)
|
||||||
body += '</ul>\n'
|
body.append('</ul>\n')
|
||||||
c.execute("""SELECT oper, at, comment FROM comments WHERE ban_id=?""",(id,))
|
c.execute("""SELECT oper, at, comment FROM comments WHERE ban_id=?""",(id,))
|
||||||
if c.rowcount:
|
r = c.fetchall()
|
||||||
body += '<h3>Comments</h3>\n'
|
if len(r):
|
||||||
body += '<ul>\n'
|
body.append('<h3>Comments</h3>\n')
|
||||||
comments = c.fetchall()
|
body.append('<ul>\n')
|
||||||
|
comments = r
|
||||||
for com in comments:
|
for com in comments:
|
||||||
(oper,at,comment) = com
|
(oper,at,comment) = com
|
||||||
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(at)))
|
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(at)))
|
||||||
body += '<li>%s by %s : %s</li>\n' % (s,oper,comment)
|
body.append('<li>%s by %s : %s</li>\n' % (s,oper,comment))
|
||||||
body += '</ul>\n'
|
body.append('</ul>\n')
|
||||||
if query.startswith('/&channel='):
|
elif query.startswith('/&channel='):
|
||||||
search = '#'+query.split('/&channel=')[1]
|
search = '#'+query.split('/&channel=')[1]
|
||||||
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE channel=? ORDER BY id DESC""",(search,))
|
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE channel=? ORDER BY id DESC""",(search,))
|
||||||
if c.rowcount:
|
r = c.fetchall()
|
||||||
bans = c.fetchall()
|
if len(r):
|
||||||
|
bans = r
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
||||||
ar.append([int(id),channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by])
|
ar.append([int(id),channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by])
|
||||||
if query.startswith('/&removed_by='):
|
elif query.startswith('/&removed_by='):
|
||||||
search = query.split('/&removed_by=')[1]
|
search = query.split('/&removed_by=')[1]
|
||||||
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE removed_by=? ORDER BY id DESC""",(search,))
|
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE removed_by=? ORDER BY id DESC""",(search,))
|
||||||
if c.rowcount:
|
r = c.fetchall()
|
||||||
bans = c.fetchall()
|
if len(r):
|
||||||
|
bans = r
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
||||||
ar.append([int(id),channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by])
|
ar.append([int(id),channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by])
|
||||||
if query.startswith('/&oper='):
|
elif query.startswith('/&oper='):
|
||||||
search = query.split('/&oper=')[1]
|
search = query.split('/&oper=')[1]
|
||||||
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE oper=? ORDER BY id DESC""",(search,))
|
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE oper=? ORDER BY id DESC""",(search,))
|
||||||
if c.rowcount:
|
r = c.fetchall()
|
||||||
bans = c.fetchall()
|
if len(r):
|
||||||
|
bans = r
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
||||||
ar.append([int(id),channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by])
|
ar.append([int(id),channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by])
|
||||||
if query.startswith('/&mask='):
|
elif query.startswith('/&mask='):
|
||||||
search = query.split('/&mask=')[1]
|
search = query.split('/&mask=')[1]
|
||||||
glob = '*%s*' % search
|
glob = '*%s*' % search
|
||||||
like = '%'+search+'%'
|
like = '%'+search+'%'
|
||||||
c.execute("""SELECT ban_id, full FROM nicks WHERE full GLOB ? OR full LIKE ? OR log GLOB ? OR log LIKE ? ORDER BY ban_id DESC""",(glob,like,glob,like))
|
c.execute("""SELECT ban_id, full FROM nicks WHERE full GLOB ? OR full LIKE ? OR log GLOB ? OR log LIKE ? ORDER BY ban_id DESC""",(glob,like,glob,like))
|
||||||
L = []
|
L = []
|
||||||
a = {}
|
a = {}
|
||||||
if c.rowcount:
|
r = c.fetchall()
|
||||||
bans = c.fetchall()
|
if len(r):
|
||||||
|
bans = r
|
||||||
d = {}
|
d = {}
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
(id,full) = ban
|
(id,full) = ban
|
||||||
@ -212,14 +222,16 @@ class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
|
|||||||
d[id] = id
|
d[id] = id
|
||||||
for id in d:
|
for id in d:
|
||||||
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE id=? ORDER BY id DESC""",(int(id),))
|
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE id=? ORDER BY id DESC""",(int(id),))
|
||||||
if c.rowcount:
|
r = c.fetchall()
|
||||||
bans = c.fetchall()
|
if len(r):
|
||||||
|
bans = r
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
||||||
a[str(id)] = ban
|
a[str(id)] = ban
|
||||||
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE mask GLOB ? OR mask LIKE ? ORDER BY id DESC""",(glob,like))
|
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE mask GLOB ? OR mask LIKE ? ORDER BY id DESC""",(glob,like))
|
||||||
if c.rowcount:
|
r = c.fetchall()
|
||||||
bans = c.fetchall()
|
if len(r):
|
||||||
|
bans = r
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
||||||
a[str(id)] = ban
|
a[str(id)] = ban
|
||||||
@ -232,7 +244,7 @@ class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
|
|||||||
return item[0]
|
return item[0]
|
||||||
ar.sort(key=sort_function)
|
ar.sort(key=sort_function)
|
||||||
ar.sort(reverse=True)
|
ar.sort(reverse=True)
|
||||||
if query.startswith('/&search='):
|
elif query.startswith('/&search='):
|
||||||
search = query.split('/&search=')[1]
|
search = query.split('/&search=')[1]
|
||||||
search = search.replace('+','*')
|
search = search.replace('+','*')
|
||||||
print search
|
print search
|
||||||
@ -242,42 +254,43 @@ class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
|
|||||||
c.execute("""SELECT ban_id, full FROM nicks WHERE full GLOB ? OR full LIKE ? OR log GLOB ? OR log LIKE ? ORDER BY ban_id DESC""",(s,qu,s,qu))
|
c.execute("""SELECT ban_id, full FROM nicks WHERE full GLOB ? OR full LIKE ? OR log GLOB ? OR log LIKE ? ORDER BY ban_id DESC""",(s,qu,s,qu))
|
||||||
L = []
|
L = []
|
||||||
a = {}
|
a = {}
|
||||||
if c.rowcount:
|
r = c.fetchall()
|
||||||
bans = c.fetchall()
|
if len(r):
|
||||||
|
bans = r
|
||||||
d = {}
|
d = {}
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
(id,full) = ban
|
(id,full) = ban
|
||||||
if not id in d:
|
if not id in d:
|
||||||
d[id] = id
|
d[id] = id
|
||||||
for id in d:
|
for id in d:
|
||||||
c = db.cursor()
|
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE id=? ORDER BY id DESC""",(int(id),))
|
||||||
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE id=? ORDER BY id DESC""",(int(id),))
|
r = c.fetchall()
|
||||||
if c.rowcount:
|
if len(r):
|
||||||
bans = c.fetchall()
|
bans = r
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
||||||
a[id] = ban
|
a[id] = ban
|
||||||
c = db.cursor()
|
|
||||||
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE mask GLOB ? OR mask LIKE ? OR channel GLOB ? OR channel LIKE ? OR oper GLOB ? OR oper LIKE ? ORDER BY id DESC""",(s,qu,s,qu,s,qu))
|
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE mask GLOB ? OR mask LIKE ? OR channel GLOB ? OR channel LIKE ? OR oper GLOB ? OR oper LIKE ? ORDER BY id DESC""",(s,qu,s,qu,s,qu))
|
||||||
if c.rowcount:
|
r = c.fetchall()
|
||||||
bans = c.fetchall()
|
if len(r):
|
||||||
|
bans = r
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
||||||
a[id] = ban
|
a[id] = ban
|
||||||
c = db.cursor()
|
|
||||||
c.execute("""SELECT ban_id, comment FROM comments WHERE comment GLOB ? OR comment LIKE ? ORDER BY ban_id DESC""",(s,qu))
|
c.execute("""SELECT ban_id, comment FROM comments WHERE comment GLOB ? OR comment LIKE ? ORDER BY ban_id DESC""",(s,qu))
|
||||||
|
r = c.fetchall()
|
||||||
d = {}
|
d = {}
|
||||||
if c.rowcount:
|
if len(r):
|
||||||
bans = c.fetchall()
|
bans = r
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
(id,full) = ban
|
(id,full) = ban
|
||||||
d[id] = id
|
d[id] = id
|
||||||
for id in d:
|
for id in d:
|
||||||
if not id in a:
|
if not id in a:
|
||||||
c = db.cursor()
|
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE id=? ORDER BY id DESC LIMIT 1""",(int(id),))
|
||||||
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE id=? ORDER BY id DESC""",(int(id),))
|
r = c.fetchall()
|
||||||
if c.rowcount:
|
if len(r):
|
||||||
bans = c.fetchall()
|
bans = r
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
|
||||||
a[id] = ban
|
a[id] = ban
|
||||||
@ -291,56 +304,59 @@ class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
|
|||||||
ar.sort(key=sort_function)
|
ar.sort(key=sort_function)
|
||||||
ar.sort(reverse=True)
|
ar.sort(reverse=True)
|
||||||
else:
|
else:
|
||||||
body += '<p>nothing found</p>\n'
|
body.append('<p>nothing found</p>\n')
|
||||||
if len(ar):
|
if len(ar):
|
||||||
|
print 'found %s results' % len(ar)
|
||||||
i = 0
|
i = 0
|
||||||
body += '<h3>results <small>%s</small></h3>' % search
|
body.append('<h3>results <small>%s</small></h3>' % search)
|
||||||
body += '<table class="table table-bordered sortable">\n'
|
body.append('<div class="row"><div class="col-xs-12"><table class="table table-bordered sortable">\n')
|
||||||
body += '<thead><tr><th>ID</th><th>Channel</th><th>Operator</th><th>Kind</th><th>Target</th><th>Begin date</th><th>End date</th><th>Removed date</th><th>Removed by</th><th>affected</th></tr></thead>\n'
|
body.append('<thead><tr><th>ID</th><th>Channel</th><th>Operator</th><th>Kind</th><th>Target</th><th>Begin date</th><th>End date</th><th>Removed date</th><th>Removed by</th></tr></thead>\n')
|
||||||
body += '<tbody>\n'
|
body.append('<tbody>\n')
|
||||||
while i < len(ar):
|
while i < len(ar):
|
||||||
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ar[i]
|
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ar[i]
|
||||||
if not len(channels) or channel in channels:
|
if not len(channels) or channel in channels:
|
||||||
body += '<tr>\n'
|
body.append('<tr>\n')
|
||||||
body += '<td><a href="%s%s&id=%s">%s</a></td>\n' % (h,q,id,id)
|
body.append('<td><a href="%s%s&id=%s">%s</a></td>\n' % (h,q,id,id))
|
||||||
body += '<td><a href="%s%s&channel=%s">%s</a></td>\n' % (h,q,channel.split('#')[1],channel)
|
body.append('<td><a href="%s%s&channel=%s">%s</a></td>\n' % (h,q,channel.split('#')[1],channel))
|
||||||
body += '<td><a href="%s%s&%s">%s</a></td>\n' % (h,q,urllib.urlencode({'oper':oper}),oper)
|
body.append('<td><a href="%s%s&%s">%s</a></td>\n' % (h,q,urllib.urlencode({'oper':oper}),oper))
|
||||||
body += '<td>+%s</td>\n' % kind
|
body.append('<td>+%s</td>\n' % kind)
|
||||||
body += '<td><a href="%s%s&%s">%s</a></td>\n' % (h,q,urllib.urlencode({'mask':mask}),mask)
|
body.append('<td><a href="%s%s&%s">%s</a></td>\n' % (h,q,urllib.urlencode({'mask':mask}),mask))
|
||||||
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(begin_at)))
|
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(begin_at)))
|
||||||
body += '<td>%s</td>\n' % s
|
body.append('<td>%s</td>\n' % s)
|
||||||
if end_at and end_at != begin_at:
|
if end_at and end_at != begin_at:
|
||||||
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(end_at)))
|
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(end_at)))
|
||||||
body += '<td>%s</td>\n' % s
|
body.append( '<td>%s</td>\n' % s)
|
||||||
else:
|
else:
|
||||||
body += '<td></td>'
|
body.append( '<td></td>')
|
||||||
if removed_at:
|
if removed_at:
|
||||||
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(removed_at)))
|
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(removed_at)))
|
||||||
body += '<td>%s</td>' % s
|
body.append( '<td>%s</td>' % s)
|
||||||
else:
|
else:
|
||||||
body += '<td></td>\n'
|
body.append( '<td></td>\n' )
|
||||||
if removed_by:
|
if removed_by:
|
||||||
body += '<td><a href="%s%s&%s">%s</a></td>\n' % (h,q,urllib.urlencode({'removed_by':removed_by}),removed_by)
|
body.append( '<td><a href="%s%s&%s">%s</a></td>\n' % (h,q,urllib.urlencode({'removed_by':removed_by}),removed_by))
|
||||||
else:
|
else:
|
||||||
body += '<td></td>\n'
|
body.append( '<td></td>\n')
|
||||||
affected = ''
|
# affected = ''
|
||||||
try:
|
# try:
|
||||||
c.execute("""SELECT full, log FROM nicks WHERE ban_id=?""",(id,))
|
# c.execute("""SELECT full, log FROM nicks WHERE ban_id=?""",(id,))
|
||||||
affected = len(c.fetchall())
|
# affected = len(c.fetchall())
|
||||||
except:
|
# except:
|
||||||
affected = ''
|
# affected = ''
|
||||||
body += '<td>%s</td>\n' % affected
|
# body.append( '<td>%s</td>\n' % affected)
|
||||||
body += '</tr>\n'
|
body.append( '</tr>\n')
|
||||||
i = i+1
|
i = i+1
|
||||||
body += '</tbody>\n'
|
body.append('</tbody>\n')
|
||||||
body += '</table>\n'
|
body.append('</table></div>\n')
|
||||||
c.close()
|
body.append("</body></html>")
|
||||||
body += "</body></html>"
|
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header("Content-type","text/html")
|
self.send_header("Content-type","text/html")
|
||||||
self.send_header("Content-length",str(len(body)))
|
full = ''.join(body)
|
||||||
|
print 'html lines %s' % len(full)
|
||||||
|
self.send_header("Content-length",len(full))
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(body)
|
self.wfile.write(full)
|
||||||
|
c.close()
|
||||||
|
|
||||||
def _getbandb (self):
|
def _getbandb (self):
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user