Fix up the Bantracker plugin
This commit is contained in:
parent
378cacceeb
commit
3b2158fd11
|
@ -37,3 +37,5 @@ CREATE TABLE users (
|
|||
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
|
||||
|
||||
The btlogin function needs the FreenodeAuth plugin
|
||||
|
|
|
@ -18,10 +18,10 @@ This plugin can store all kick/ban/remove/mute actions
|
|||
import supybot
|
||||
import supybot.world as world
|
||||
|
||||
__version__ = "0.3"
|
||||
__version__ = "0.3.1"
|
||||
__author__ = supybot.Author("Dennis Kaarsemaker","Seveas","dennis@kaarsemaker.net")
|
||||
__contributors__ = {}
|
||||
__url__ = 'https://bots.ubuntulinux.nl'
|
||||
__url__ = 'https://ubotu.ubuntu-nl.org'
|
||||
|
||||
import config
|
||||
reload(config)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
###
|
||||
|
||||
import sys
|
||||
sys.path.append('/var/www/bots.ubuntulinux.nl')
|
||||
sys.path.append('/var/www/ubotu.ubuntu-nl.org')
|
||||
from commoncgi import *
|
||||
|
||||
### Variables
|
||||
|
|
|
@ -53,11 +53,11 @@
|
|||
</head>
|
||||
<body>
|
||||
<div class="main">
|
||||
<h1>Ubugtu Bantracker</h1>
|
||||
<h1>Ubotu Bantracker</h1>
|
||||
<p>
|
||||
%s
|
||||
</p>
|
||||
<p>©2006 Dennis Kaarsemaker</p>
|
||||
<p>©2006-2007 Dennis Kaarsemaker</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -21,7 +21,5 @@ def configure(advanced):
|
|||
Bantracker = conf.registerPlugin('Bantracker')
|
||||
conf.registerChannelValue(conf.supybot.plugins.Bantracker, 'enabled',
|
||||
registry.Boolean(False, """Enable the bantracker"""))
|
||||
conf.registerChannelValue(conf.supybot.plugins.Bantracker, 'stats',
|
||||
registry.Boolean(False, """Enable join/part stats"""))
|
||||
conf.registerGlobalValue(conf.supybot.plugins.Bantracker, 'database',
|
||||
registry.String('', "Filename of the bans database"))
|
||||
registry.String('', "Filename of the bans database",private=True))
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
#!/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 urllib,urllib2
|
||||
import xml.dom.minidom as dom
|
||||
import sha, re
|
||||
|
||||
_login_url = 'https://launchpad.net/+login'
|
||||
_login_data = 'loginpage_email=%s&loginpage_password=%s&loginpage_submit_login=Log%%20In'
|
||||
_login_re = re.compile('logged in as.*?a href=".*?/people/(.*?)"', re.DOTALL)
|
||||
_urlopener = urllib2.build_opener(urllib2.HTTPCookieProcessor(), urllib2.HTTPRedirectHandler())
|
||||
|
||||
class LaunchpadException(Exception):
|
||||
pass
|
||||
|
||||
class LaunchpadPerson:
|
||||
def __init__(self, email = None, password = None, nick = None):
|
||||
self.authenticated = False
|
||||
if email and password:
|
||||
self.email = email
|
||||
_nick = self._login(password)
|
||||
if _nick:
|
||||
self.authenticated = True
|
||||
nick = _nick
|
||||
if nick:
|
||||
self.get_data(nick)
|
||||
|
||||
def get_data(self, nick):
|
||||
self.nick = nick
|
||||
try:
|
||||
u = urllib2.urlopen('http://launchpad.net/people/%s/+rdf' % urllib.quote(nick))
|
||||
rdf = u.read()
|
||||
rdf = dom.parseString(rdf)
|
||||
except:
|
||||
raise
|
||||
raise LaunchpadException('Could not parse launchpad data')
|
||||
self.mail_shasums = map(lambda x: x.childNodes[0].data.lower(), rdf.getElementsByTagName('foaf:mbox_sha1sum'))
|
||||
self.name = rdf.getElementsByTagName('foaf:name')[0].childNodes[0].data
|
||||
try:
|
||||
self.img = rdf.getElementsByTagName('foaf:img')[0].getAttribute('rdf:resource')
|
||||
except: # No image
|
||||
self.img = None
|
||||
try:
|
||||
self.key = rdf.getElementsByTagName('wot:fingerprint')[0].childNodes[0].data
|
||||
except: # No image
|
||||
self.key = None
|
||||
|
||||
def check_group_membership(self, group):
|
||||
try:
|
||||
self.mail_shasums
|
||||
except AttributeError:
|
||||
raise LaunchpadException("Person not logged in and launchpad username not known")
|
||||
try:
|
||||
fd = urllib2.urlopen('http://launchpad.net/people/%s/+rdf' % urllib.quote(group))
|
||||
rdf = fd.read()
|
||||
rdf = dom.parseString(rdf)
|
||||
except:
|
||||
raise LaunchpadException('Could not parse launchpad data')
|
||||
group_mail_shasums = map(lambda x: x.childNodes[0].data.lower(), rdf.getElementsByTagName('foaf:mbox_sha1sum'))
|
||||
# If the intersection of shasums and shasums2 is not empty, the persons
|
||||
# prefered mail address is in the group.
|
||||
return len([x for x in self.mail_shasums if x in group_mail_shasums]) > 0
|
||||
|
||||
def _login(self, pw):
|
||||
req = urllib2.Request(_login_url, _login_data % (urllib.quote(self.email),urllib.quote(pw)))
|
||||
try:
|
||||
fd = _urlopener.open(req)
|
||||
data = fd.read().lower()
|
||||
except: # Launchpad offline perhaps...
|
||||
raise LaunchpadException('Could not parse launchpad data')
|
||||
try:
|
||||
return _login_re.search(data).group(1)
|
||||
except:
|
||||
return False
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
person = LaunchpadPerson(sys.argv[1], sys.argv[2])
|
||||
print person.authenticated
|
||||
try:
|
||||
print person.nick
|
||||
print person.name
|
||||
print person.mail_shasums
|
||||
print person.img
|
||||
except:
|
||||
raise
|
||||
pass
|
||||
print person.check_group_membership(sys.argv[3])
|
|
@ -65,8 +65,6 @@ class Bantracker(callbacks.Plugin):
|
|||
self.lastMsgs = {}
|
||||
self.lastStates = {}
|
||||
self.logs = {}
|
||||
# for channel in irc.state.channels:
|
||||
# self.doStatsLog(irc, channel, "START")
|
||||
|
||||
db = self.registryValue('database')
|
||||
if db:
|
||||
|
@ -115,15 +113,6 @@ class Bantracker(callbacks.Plugin):
|
|||
s = time.strftime(format) + " " + ircutils.stripFormatting(s)
|
||||
self.logs[channel] = self.logs[channel][-199:] + [s.strip()]
|
||||
|
||||
# def doStatsLog(self, irc, chan, type):
|
||||
# if not self.registryValue('stats', chan):
|
||||
# return
|
||||
# num = len(irc.state.channels[chan].users)
|
||||
# format = conf.supybot.log.timestampFormat()
|
||||
# statslog = open('/home/dennis/ubugtu/data/statslog','a')
|
||||
# statslog.write("%-20s %f %s %-6s %d\n" % (chan, time.time(), time.strftime(format), type, num))
|
||||
# statslog.close()
|
||||
|
||||
def doKickban(self, irc, channel, nick, target, kickmsg = None):
|
||||
if not self.registryValue('enabled', channel):
|
||||
return
|
||||
|
@ -168,8 +157,6 @@ class Bantracker(callbacks.Plugin):
|
|||
for channel in msg.args[0].split(','):
|
||||
self.doLog(irc, channel,
|
||||
'*** %s has joined %s\n' % (msg.nick or msg.prefix, channel))
|
||||
#if irc.prefix != msg.prefix:
|
||||
# self.doStatsLog(irc, msg.args[0], "JOIN")
|
||||
|
||||
def doKick(self, irc, msg):
|
||||
if len(msg.args) == 3:
|
||||
|
@ -184,7 +171,6 @@ class Bantracker(callbacks.Plugin):
|
|||
self.doLog(irc, channel,
|
||||
'*** %s was kicked by %s\n' % (target, msg.nick))
|
||||
self.doKickban(irc, channel, msg.nick, target, kickmsg)
|
||||
#self.doStatsLog(irc, msg.args[0], "KICK")
|
||||
|
||||
def doPart(self, irc, msg):
|
||||
for channel in msg.args[0].split(','):
|
||||
|
@ -192,8 +178,6 @@ class Bantracker(callbacks.Plugin):
|
|||
if msg.args[1].startswith('requested by'):
|
||||
args = msg.args[1].split()
|
||||
self.doKickban(irc, channel, args[2].replace(':',''), msg.nick, ' '.join(args[3:])[1:-1].strip())
|
||||
#if irc.prefix != msg.prefix:
|
||||
# self.doStatsLog(irc, msg.args[0], "PART")
|
||||
|
||||
def doMode(self, irc, msg):
|
||||
channel = msg.args[0]
|
||||
|
@ -229,7 +213,6 @@ class Bantracker(callbacks.Plugin):
|
|||
for (channel, chan) in self.lastStates[irc].channels.iteritems():
|
||||
if msg.nick in chan.users:
|
||||
self.doLog(irc, channel, '*** %s has quit IRC (%s)\n' % (msg.nick, msg.args[0]))
|
||||
#self.doStatsLog(irc, channel, "QUIT")
|
||||
|
||||
def outFilter(self, irc, msg):
|
||||
# Gotta catch my own messages *somehow* :)
|
||||
|
@ -240,11 +223,7 @@ class Bantracker(callbacks.Plugin):
|
|||
self(irc, m)
|
||||
return msg
|
||||
|
||||
#def do366(self, irc, msg):
|
||||
# self.doStatsLog(irc, msg.args[1], "START")
|
||||
|
||||
def btlogin(self, irc, msg, args):
|
||||
print "hi!"
|
||||
if msg.tagged('identified'):
|
||||
try:
|
||||
user = ircdb.users.getUser(msg.prefix[:msg.prefix.find('!')])
|
||||
|
@ -257,7 +236,7 @@ class Bantracker(callbacks.Plugin):
|
|||
sessid = md5.new('%s%s%d' % (msg.prefix, time.time(), random.randint(1,100000))).hexdigest()
|
||||
self.db_run("""INSERT INTO sessions (session_id, user, time) VALUES (%s, %s, %d);""",
|
||||
(sessid, msg.prefix[:msg.prefix.find('!')], int(time.time())))
|
||||
irc.reply('Log in at https://bots.ubuntulinux.nl/bans.cgi?sess=%s' % sessid, private=True)
|
||||
irc.reply('Log in at https://ubotu.ubuntu-nl.org/bans.cgi?sess=%s' % sessid, private=True)
|
||||
|
||||
btlogin = wrap(btlogin)
|
||||
|
||||
|
|
Loading…
Reference in New Issue