Revert "patch From: Krytarik Raido <krytarik@gmail.com>"

This reverts commit 2060b4f8c6d611bebc0b64089daa82094a495e35.
This commit is contained in:
Nicolas Coevoet 2021-02-09 15:06:07 +00:00
parent 2060b4f8c6
commit 26646c7d7f

547
server.py
View File

@ -1,6 +1,13 @@
import os, re, time, base64 import http.server
import os
import time
import base64
import re
import supybot.utils as utils import supybot.utils as utils
import http.server, sqlite3 import sqlite3
import collections
import urllib.parse
from io import StringIO
host = 'http://domain.tld' host = 'http://domain.tld'
port = 80 port = 80
@ -9,11 +16,11 @@ webpath = '/bantracker'
username = 'username' username = 'username'
password = 'password' password = 'password'
filename = '/home/botaccount/data/networkname/ChanTracker.db' filename = '/home/botaccount/data/networkname/ChanTracker.db'
channels = [] # empty to allow 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
auth = '%s:%s' % (username,password) auth = '%s:%s' % (username,password)
base64string = base64.b64encode(auth.encode('utf-8')).decode('utf-8') base64string = base64.b64encode(auth.encode('UTF-8'))
def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True, def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True,
weeks=True, days=True, hours=True, minutes=True, seconds=True): weeks=True, days=True, hours=True, minutes=True, seconds=True):
@ -58,35 +65,21 @@ def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True,
else: else:
return format('%L', ret) return format('%L', ret)
class MyHandler(http.server.BaseHTTPRequestHandler): class MyHandler( http.server.BaseHTTPRequestHandler ):
server_version= "Ircd-Seven/1.1"
if not standalone: if not standalone:
def log_request(self, *args): def log_request(self, *args):
pass # disable logging pass # disable logging
def do_GET(self): def do_GET( self ):
self.page(self.path) self.page( self.path )
def page(self, query):
def write(subtitle, body):
page = [
'<html style="text-align:center;font-size:1.2em;">',
'<head>\n<title>BanTracker%s</title>' % (' &raquo; %s' % subtitle if subtitle else ''),
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',
'<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"></link>',
'</head>\n<body style="margin:0.5em;width:98%;margin-left:auto;margin-right:auto;text-align:left;" class="container">'
] + body + ['</body>\n</html>']
self.send_response(200)
self.send_header("Content-type","text/html")
full = '\n'.join(page)
print('HTML lines %s' % len(full))
self.send_header("Content-length",len(full))
self.end_headers()
self.wfile.write(full.encode('utf-8'))
def page (self,query):
if standalone: if standalone:
h = '%s:%s/' % (host,port) h = '%s:%s/' % (host,port)
else: else:
h = '%s/' % webpath h = '%s/' % webpath
body = []
if not query: if not query:
return return
if query.startswith('/?username='): if query.startswith('/?username='):
@ -100,260 +93,287 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
if aa[0] == 'password': if aa[0] == 'password':
p = aa[1] p = aa[1]
if u and p: if u and p:
raw = base64.b64encode('%s:%s'.encode('utf-8') % (u,p)).decode('utf-8') raw = base64.encodebytes(bytes('%s:%s' % (u,p), 'UTF-8'))[:-1]
if raw != base64string: if not raw == base64string:
query = '' query = ''
else: else:
query = '/?hash=%s' % base64string query = '/?hash=%s' % base64string.decode('UTF-8')
if not query.startswith('/?hash='): if not query.startswith('/?hash='):
subtitle = '' body.append('<html>\n<head>\n<title>ChanTracker</title>\n')
body = [ body.append('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n')
'<form action="%s">' % h, body.append("</head>\n<body>\n")
'<p>Username: <input name="username" /></p>', body.append('<form action="%s">\n' % h)
'<p>Password: <input name="password" type="password"/></p>', body.append('<p>Username:<input name="username" /></p>\n')
'<button type="submit" class="btn btn-default">Login</button>', body.append('<p>Password:<input name="password" type="password"/></p>\n')
'</form>' body.append('<input type="submit" value="Login" />\n')
] body.append("</form>\n")
write(subtitle, body) body.append("</body>\n<html>\n")
self.send_response(200)
self.send_header("Content-type","text/html")
full = ''.join(body)
self.send_header("Content-length",str(len(full)))
self.end_headers()
self.wfile.write(full.encode('UTF-8'))
return return
query = query.replace('%3D','=') if query.startswith('/?hash='):
query = query.replace('/?hash=%s' % base64string,'') a = query.split('&')[0]
query = query.lstrip('&') a = a.replace('/?hash=','')
q = '?hash=%s' % base64string query = query.replace('%3D','=')
query = utils.web.urlunquote(query) query = query.replace('/?hash=%s' % base64string.decode('UTF-8'),'/')
subtitle = '' q = '?hash=%s' % base64string.decode('UTF-8')
body = [ query = urllib.parse.unquote( query )
'<div class="row"><div class="col-xs-6">', print(query)
'<form action="%s" class="form">' % q, body.append('<html style="text-align:center;font-size:1.2em;">\n<head>\n<title>BanTracker - %s</title>\n' % query)
'<div class="input-group">', body.append('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n')
'<input type="hidden" name="hash" value="%s">' % base64string, body.append('<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"></link>\n')
'<input name="search" class="form-control" />', # body.append('<script src="http://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>\n')
'<span class="input-group-btn"><button type="submit" class="btn btn-default">Search</button></span>', body.append('</head>\n<body style="margin:0.5em;width:98%;margin-left:auto;margin-right:auto;text-align:left;" class="container">\n')
'</div></form></div></div>', body.append('<div class="row"><div class="col-xs-6">\n')
'<div class="clearfix"></div>' body.append('<form action="%s" class="form">\n' % q)
] body.append('<div class="input-group">')
if not query: body.append('<input type="hidden" name="hash" value="%s">' % base64string.decode('UTF-8'))
write(subtitle, body) body.append('<input name="search" class="form-control" />\n')
return body.append('<span class="input-group-btn"><button type="submit" class="btn btn-default">Search</button></span>\n')
print(query) body.append('</div></form></div></div>\n')
subtitle = query body.append('<div class="clearfix"></div>\n')
db = self._getbandb() db = self._getbandb()
c = db.cursor() c = db.cursor()
ar = [] if query:
if query.startswith('id='): ar = []
search = query.split('=')[1] if query.startswith('/&id='):
si = int(search) 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=?""",(si,)) 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,))
r = c.fetchall()
if len(r):
ban = r[0]
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
if not channels or channel in channels:
body.extend([
'<h3>#%d</h3>' % id,
'<p>#%d by <a href="%s%s&%s">%s</a>' % (id,h,q,utils.web.urlencode({'oper':oper}),oper),
'in <a href="%s%s&channel=%s">%s</a>:' % (h,q,channel.split('#')[1],channel),
'+%s <a href="%s%s&%s">%s</a></p>' % (kind,h,q,utils.web.urlencode({'mask':mask}),mask),
'<p>Begin at %s</p>' % time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(begin_at)))
])
was = float(begin_at) == float(end_at)
if was:
was = 'forever'
else:
was = timeElapsed(float(end_at) - float(begin_at))
body.append('<p>Original duration: %s</p>' % was)
if not removed_at:
if was != 'forever':
body.append('<p>It will expire in %s</p>' % timeElapsed(float(end_at) - time.time()))
else:
body.extend(['<p>Removed after %s' % timeElapsed(float(removed_at)-float(begin_at)),
'on %s' % time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(removed_at))),
'by <a href="%s%s&%s">%s</a></p>' % (h,q,utils.web.urlencode({'removed_by':removed_by}),removed_by)])
c.execute("""SELECT full,log FROM nicks WHERE ban_id=?""",(id,))
r = c.fetchall()
if len(r):
body.append('<h3>Logs</h3>')
for nick in r:
(full,log) = nick
body.append('<p>for %s</p>' % full)
if log != '':
body.append('<ul>')
for line in log.split('\n'):
if line != '':
body.append('<li>%s</li>' % line)
body.append('</ul>')
c.execute("""SELECT oper,at,comment FROM comments WHERE ban_id=?""",(id,))
r = c.fetchall()
if len(r):
body.extend(['<h3>Comments</h3>', '<ul>'])
for comment in r:
(oper,at,com) = comment
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(at)))
body.append('<li>%s by %s: %s</li>' % (s,oper,com))
body.append('</ul>')
c.close()
write(subtitle, body)
return
elif query.startswith('channel='):
search = '#'+query.split('=')[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,))
r = c.fetchall()
if len(r):
ar.extend(r)
elif query.startswith('removed_by='):
search = query.split('=')[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,))
r = c.fetchall()
if len(r):
ar.extend(r)
elif query.startswith('oper='):
search = query.split('=')[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,))
r = c.fetchall()
if len(r):
ar.extend(r)
elif query.startswith('mask='):
search = query.split('=')[1]
sg = '*%s*' % search
sl = '%%%s%%' % 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""",(sg,sl,sg,sl))
r = c.fetchall()
L = []
a = {}
if len(r):
d = {}
for ban in r:
(id,full) = ban
if id not in d:
d[id] = id
for id in d:
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE id=?""",(id,))
r = c.fetchall()
if len(r):
for ban in r:
a[ban[0]] = 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""",(sg,sl))
r = c.fetchall()
if len(r):
for ban in r:
a[ban[0]] = ban
if len(a):
ar = []
for ban in list(a.keys()):
ar.append(a[ban])
ar.sort(key=lambda x: x[0], reverse=True)
elif query.startswith('search='):
search = query.split('=')[1]
search = search.replace('+','*')
print(search)
if search:
if not re.match(r'^[0-9]+$', search):
sg = '*%s*' % search
sl = '%%%s%%' % search
si = None
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""",(sg,sl,sg,sl))
r = c.fetchall()
else:
si = int(search)
r = []
L = []
a = {}
if len(r):
d = {}
for ban in r:
(id,full) = ban
if id not in d:
d[id] = id
for id in d:
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE id=?""",(id,))
r = c.fetchall()
if len(r):
for ban in r:
a[ban[0]] = ban
if not si:
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""",(sg,sl,sg,sl,sg,sl))
else:
c.execute("""SELECT id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by FROM bans WHERE id=?""",(si,))
r = c.fetchall() r = c.fetchall()
if len(r): if len(r):
for ban in r: ban = r[0]
a[ban[0]] = ban (id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
if not si: if not len(channels) or channel in channels:
c.execute("""SELECT ban_id, comment FROM comments WHERE comment GLOB ? OR comment LIKE ? ORDER BY ban_id DESC""",(sg,sl)) body.append('<h3>#%s</h3>\n' % id)
r = c.fetchall() body.append('<p>#%s by %s in %s : +%s : %s</p>\n' % (id,oper,channel,kind,mask))
else: body.append('<p>Begin at %s</p>\n' % time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(begin_at))))
r = [] was = float(begin_at) == float(end_at)
d = {} if was:
was = 'forever'
else:
was = timeElapsed(float(end_at) - float(begin_at))
body.append('<p>Original duration : %s</p>\n' % was)
if not removed_at:
if was != 'forever':
body.append('<p>%s</p>\n' % 'It will expire in %s' % timeElapsed(float(end_at) - time.time()))
else:
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,))
r = c.fetchall()
if len(r):
users = r
body.append('<h3>Logs</h3>\n')
for u in users:
(full,log) = u
body.append('<p>for %s</p>\n' % full)
if log != '':
body.append('<ul>\n')
for line in log.split('\n'):
if line != '':
body.append('<li>%s</li>\n' % line)
body.append('</ul>\n')
c.execute("""SELECT oper, at, comment FROM comments WHERE ban_id=?""",(id,))
r = c.fetchall()
if len(r):
body.append('<h3>Comments</h3>\n')
body.append('<ul>\n')
comments = r
for com in comments:
(oper,at,comment) = com
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(at)))
body.append('<li>%s by %s : %s</li>\n' % (s,oper,comment))
body.append('</ul>\n')
elif query.startswith('/&channel='):
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,))
r = c.fetchall()
if len(r): if len(r):
for ban in r: bans = r
for ban in bans:
(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])
elif query.startswith('/&removed_by='):
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,))
r = c.fetchall()
if len(r):
bans = r
for ban in bans:
(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])
elif query.startswith('/&oper='):
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,))
r = c.fetchall()
if len(r):
bans = r
for ban in bans:
(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])
elif query.startswith('/&mask='):
search = query.split('/&mask=')[1]
glob = '*%s*' % 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))
L = []
a = {}
r = c.fetchall()
if len(r):
bans = r
d = {}
for ban in bans:
(id,full) = ban (id,full) = ban
d[id] = id if not id in d:
d[id] = id
for id in d: for id in d:
if id not in a: 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=?""",(id,)) r = c.fetchall()
r = c.fetchall() if len(r):
if len(r): bans = r
for ban in r: for ban in bans:
a[ban[0]] = ban (id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = 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))
r = c.fetchall()
if len(r):
bans = r
for ban in bans:
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
a[str(id)] = ban
if len(a): if len(a):
ar = [] ar = []
for ban in list(a.keys()): for ban in a:
ar.append(a[ban]) (id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = a[ban]
ar.sort(key=lambda x: x[0], reverse=True) ar.append([int(id),channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by])
if len(ar): def sort_function (item):
print('Found %s results' % len(ar)) return item[0]
body.extend([ ar.sort(key=sort_function)
'<h3>Results <small>%s</small></h3>' % search, ar.sort(reverse=True)
'<div class="row"><div class="col-xs-12"><table class="table table-bordered sortable">', elif query.startswith('/&search='):
'<thead><tr><th>ID</th><th>Channel</th><th>Operator</th><th>Type</th><th>Mask</th><th>Begin date</th><th>End date</th><th>Removed</th><th>Removed by</th></tr></thead>', search = query.split('/&search=')[1]
'<tbody>' search = search.replace('+','*')
]) print(search)
for ban in ar: if search:
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban s = '*%s*' % search
if not channels or channel in channels: qu = '%'+search+'%'
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(begin_at))) 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))
body.extend([ L = []
'<tr>', a = {}
'<td><a href="%s%s&id=%d">%d</a></td>' % (h,q,id,id), r = c.fetchall()
'<td><a href="%s%s&channel=%s">%s</a></td>' % (h,q,channel.split('#')[1],channel), if len(r):
'<td><a href="%s%s&%s">%s</a></td>' % (h,q,utils.web.urlencode({'oper':oper}),oper), bans = r
'<td>+%s</td>' % kind, d = {}
'<td><a href="%s%s&%s">%s</a></td>' % (h,q,utils.web.urlencode({'mask':mask}),mask), for ban in bans:
'<td>%s</td>' % s (id,full) = ban
]) if not id in d:
if end_at and end_at != begin_at: d[id] = id
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(end_at))) for id in d:
body.append('<td>%s</td>' % s) 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),))
else: r = c.fetchall()
body.append('<td></td>') if len(r):
if removed_at: bans = r
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(removed_at))) for ban in bans:
body.append('<td>%s</td>' % s) (id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
else: a[id] = ban
body.append('<td></td>') 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 removed_by: r = c.fetchall()
body.append('<td><a href="%s%s&%s">%s</a></td>' % (h,q,utils.web.urlencode({'removed_by':removed_by}),removed_by)) if len(r):
else: bans = r
body.append('<td></td>') for ban in bans:
# affected = '' (id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
# try: a[id] = ban
# c.execute("""SELECT full, log FROM nicks WHERE ban_id=?""",(id,)) c.execute("""SELECT ban_id, comment FROM comments WHERE comment GLOB ? OR comment LIKE ? ORDER BY ban_id DESC""",(s,qu))
# affected = len(c.fetchall()) r = c.fetchall()
# except: d = {}
if len(r):
bans = r
for ban in bans:
(id,full) = ban
d[id] = id
for id in d:
if not id in a:
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),))
r = c.fetchall()
if len(r):
bans = r
for ban in bans:
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ban
a[id] = ban
if len(a):
ar = []
for ban in a:
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = a[ban]
ar.append([int(id),channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by])
def sort_function (item):
return item[0]
ar.sort(key=sort_function)
ar.sort(reverse=True)
else:
body.append('<p>nothing found</p>\n')
if len(ar):
print('found %s results' % len(ar))
i = 0
body.append('<h3>results <small>%s</small></h3>' % search)
body.append('<div class="row"><div class="col-xs-12"><table class="table table-bordered sortable">\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.append('<tbody>\n')
while i < len(ar):
(id,channel,oper,kind,mask,begin_at,end_at,removed_at,removed_by) = ar[i]
if not len(channels) or channel in channels:
body.append('<tr>\n')
body.append('<td><a href="%s%s&id=%s">%s</a></td>\n' % (h,q,id,id))
body.append('<td><a href="%s%s&channel=%s">%s</a></td>\n' % (h,q,channel.split('#')[1],channel))
body.append('<td><a href="%s%s&%s">%s</a></td>\n' % (h,q,urllib.parse.urlencode({'oper':oper}),oper))
body.append('<td>+%s</td>\n' % kind)
body.append('<td><a href="%s%s&%s">%s</a></td>\n' % (h,q,urllib.parse.urlencode({'mask':mask}),mask))
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(begin_at)))
body.append('<td>%s</td>\n' % s)
if end_at and end_at != begin_at:
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(end_at)))
body.append( '<td>%s</td>\n' % s)
else:
body.append( '<td></td>')
if removed_at:
s = time.strftime('%Y-%m-%d %H:%M:%S GMT',time.gmtime(float(removed_at)))
body.append( '<td>%s</td>' % s)
else:
body.append( '<td></td>\n' )
if removed_by:
body.append( '<td><a href="%s%s&%s">%s</a></td>\n' % (h,q,urllib.parse.urlencode({'removed_by':removed_by}),removed_by))
else:
body.append( '<td></td>\n')
# affected = '' # affected = ''
# body.append('<td>%s</td>' % affected) # try:
body.append('</tr>') # c.execute("""SELECT full, log FROM nicks WHERE ban_id=?""",(id,))
body.extend(['</tbody>', '</table></div>']) # affected = len(c.fetchall())
else: # except:
body.append('<p>Nothing found</p>') # affected = ''
# body.append( '<td>%s</td>\n' % affected)
body.append( '</tr>\n')
i = i+1
body.append('</tbody>\n')
body.append('</table></div>\n')
body.append("</body></html>")
self.send_response(200)
self.send_header("Content-type","text/html")
full = ''.join(body)
print('html lines %s' % len(full))
self.send_header("Content-length",len(full))
self.end_headers()
self.wfile.write(full.encode('UTF-8'))
c.close() c.close()
write(subtitle, body)
def _getbandb(self): def _getbandb (self):
if os.path.exists(filename): if os.path.exists(filename):
db = sqlite3.connect(filename,timeout=10) db = sqlite3.connect(filename,timeout=10)
db.text_factory = str
return db return db
db = sqlite3.connect(filename) db = sqlite3.connect(filename)
db.text_factory = str
c = db.cursor() c = db.cursor()
c.execute("""CREATE TABLE bans ( c.execute("""CREATE TABLE bans (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
@ -367,23 +387,24 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
removed_by VARCHAR(1000) removed_by VARCHAR(1000)
)""") )""")
c.execute("""CREATE TABLE nicks ( c.execute("""CREATE TABLE nicks (
ban_id INTEGER, ban_id INTEGER,
ban VARCHAR(1000) NOT NULL, ban VARCHAR(1000) NOT NULL,
full VARCHAR(1000) NOT NULL, full VARCHAR(1000) NOT NULL,
log TEXT NOT NULL log TEXT NOT NULL
)""") )""")
c.execute("""CREATE TABLE comments ( c.execute("""CREATE TABLE comments (
ban_id INTEGER, ban_id INTEGER,
oper VARCHAR(1000) NOT NULL, oper VARCHAR(1000) NOT NULL,
at TIMESTAMP NOT NULL, at TIMESTAMP NOT NULL,
comment TEXT NOT NULL comment TEXT NOT NULL
)""") )""")
db.commit() db.commit()
return db return db
def httpd(handler_class=MyHandler, server_address=('', port)): def httpd(handler_class=MyHandler, server_address = ('', port), ):
srvr = http.server.HTTPServer(server_address, handler_class) srvr = http.server.HTTPServer(server_address, handler_class)
srvr.serve_forever() srvr.serve_forever()
if __name__ == "__main__": if __name__ == "__main__":
httpd() httpd( )