\n')
+ body.append('\n')
db = self._getbandb()
c = db.cursor()
if query:
@@ -131,80 +134,87 @@ class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
if query.startswith('/&id='):
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,))
- if c.rowcount:
- ban = c.fetchall()[0]
+ 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 len(channels) or channel in channels:
- body += '
\n' % 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 += '
Original duration : %s
\n' % was
+ body.append('
Original duration : %s
\n' % was)
if not removed_at:
if was != 'forever':
- body += '
%s
\n' % 'It will expire in %s' % timeElapsed(float(end_at) - time.time())
+ body.append('
%s
\n' % 'It will expire in %s' % timeElapsed(float(end_at) - time.time()))
else:
- body += '
%s
\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('
%s
\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,))
- if c.rowcount:
- users = c.fetchall()
- body += '
Logs
\n'
+ r = c.fetchall()
+ if len(r):
+ users = r
+ body.append('
Logs
\n')
for u in users:
(full,log) = u
- body += '
for %s
\n' % full
+ body.append('
for %s
\n' % full)
if log != '':
- body +='
\n'
+ body.append('
\n')
for line in log.split('\n'):
if line != '':
- body += '
%s
\n' % line
- body += '
\n'
+ body.append('
%s
\n' % line)
+ body.append('
\n')
c.execute("""SELECT oper, at, comment FROM comments WHERE ban_id=?""",(id,))
- if c.rowcount:
- body += '
Comments
\n'
- body += '
\n'
- comments = c.fetchall()
+ r = c.fetchall()
+ if len(r):
+ body.append('
Comments
\n')
+ body.append('
\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 += '
%s by %s : %s
\n' % (s,oper,comment)
- body += '
\n'
- if query.startswith('/&channel='):
+ body.append('
%s by %s : %s
\n' % (s,oper,comment))
+ body.append('
\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,))
- if c.rowcount:
- bans = c.fetchall()
+ 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])
- if query.startswith('/&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,))
- if c.rowcount:
- bans = c.fetchall()
+ 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])
- if query.startswith('/&oper='):
+ 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,))
- if c.rowcount:
- bans = c.fetchall()
+ 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])
- if query.startswith('/&mask='):
+ 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 = {}
- if c.rowcount:
- bans = c.fetchall()
+ r = c.fetchall()
+ if len(r):
+ bans = r
d = {}
for ban in bans:
(id,full) = ban
@@ -212,14 +222,16 @@ class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
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=? ORDER BY id DESC""",(int(id),))
- if c.rowcount:
- bans = c.fetchall()
+ 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
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:
- bans = c.fetchall()
+ 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
@@ -232,7 +244,7 @@ class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
return item[0]
ar.sort(key=sort_function)
ar.sort(reverse=True)
- if query.startswith('/&search='):
+ elif query.startswith('/&search='):
search = query.split('/&search=')[1]
search = search.replace('+','*')
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))
L = []
a = {}
- if c.rowcount:
- bans = c.fetchall()
+ r = c.fetchall()
+ if len(r):
+ bans = r
d = {}
for ban in bans:
(id,full) = ban
if not id in d:
d[id] = id
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),))
- if c.rowcount:
- bans = c.fetchall()
+ 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 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
- 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))
- if c.rowcount:
- bans = c.fetchall()
+ 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
- c = db.cursor()
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 = {}
- if c.rowcount:
- bans = c.fetchall()
+ 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 = 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),))
- if c.rowcount:
- bans = c.fetchall()
+ 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
@@ -291,56 +304,59 @@ class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
ar.sort(key=sort_function)
ar.sort(reverse=True)
else:
- body += '
nothing found
\n'
+ body.append('
nothing found
\n')
if len(ar):
+ print 'found %s results' % len(ar)
i = 0
- body += '
results %s
' % search
- body += '
\n'
- body += '
ID
Channel
Operator
Kind
Target
Begin date
End date
Removed date
Removed by
affected
\n'
- body += '\n'
+ body.append('
results %s
' % search)
+ body.append('
\n')
+ body.append('
ID
Channel
Operator
Kind
Target
Begin date
End date
Removed date
Removed by
\n')
+ body.append('\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 += '