Fix up LpLogin, errrr, FreenodeAuth

This commit is contained in:
Dennis Kaarsemaker 2007-09-17 21:39:44 +02:00
parent 23b50f539a
commit 6ec9cd85da
9 changed files with 65 additions and 102 deletions

3
FreenodeAuth/README.txt Normal file
View File

@ -0,0 +1,3 @@
Allows any nickserv-identified user to login without password. Written
specifically for Freenode. Can also auto-create accounts from a list with
nicknames.

View File

@ -1,6 +1,5 @@
###
# Copyright (c) 2007, Dennis Kaarsemaker
# All rights reserved.
#
# 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
@ -14,17 +13,16 @@
###
"""
Add a description of the plugin (to be presented to the user inside the wizard)
here. This should describe *what* the plugin does.
Let nickserv-identified users log in without password
"""
import supybot
import supybot.world as world
__version__ = "0.1"
__version__ = "0.2"
__author__ = supybot.Author("Dennis Kaarsemaker","Seveas","dennis@kaarsemaker.net")
__contributors__ = {}
__url__ = 'http://bots.ubuntulinux.nl/'
__url__ = 'http://ubotu.ubuntu-nl.org/'
import config
reload(config)

24
FreenodeAuth/config.py Normal file
View File

@ -0,0 +1,24 @@
###
# Copyright (c) 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 supybot.conf as conf
import supybot.registry as registry
def configure(advanced):
from supybot.questions import expect, anything, something, yn
conf.registerPlugin('FreenodeAuth', True)
FreenodeAuth = conf.registerPlugin('FreenodeAuth')
conf.registerGlobalValue(FreenodeAuth, 'UserList',
registry.String('', """Filename of file with list of users""",private=True))

View File

@ -1,7 +1,14 @@
###
# Copyright (c) 2007, Dennis Kaarsemaker
# All rights reserved.
#
# 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.
#
###
@ -16,20 +23,10 @@ import supybot.conf as conf
import supybot.schedule as schedule
import random, os
class LpLogin(callbacks.Plugin):
"""Add the help for "@plugin help LpLogin" here
This should describe *how* to use this plugin."""
class FreenodeAuth(callbacks.Plugin):
"""Use @login to login"""
threaded = True
def __init__(self, irc):
callbacks.Plugin.__init__(self, irc)
try:
schedule.removeEvent(self.name() + '.nickreload')
except:
pass
# Reload every 6 hours
#schedule.addPeriodicEvent(lambda: self.reportnewbugs(irc), 60*60*6, name=self.name() + '.nickreload')
def loadnicks(self):
uf = self.registryValue('UserList')
if not uf or not os.path.exists(uf):
@ -41,13 +38,7 @@ class LpLogin(callbacks.Plugin):
knownusers = [x.lower() for x in users.split() if x]
self.knownusers = knownusers
allusers = [u.name.lower() for u in ircdb.users.itervalues()]
#print knownusers, allusers
if self.registryValue('DeleteUnknowns'):
to_delete = [x for x in allusers if x not in knownusers and not
ircdb.users.getUser(x)._checkCapability('owner')]
for u in to_delete:
self.log.info("Would delete %s" % u)
to_add = [x for x in knownusers if x not in allusers]
for a in to_add:
self.log.info("Adding %s" % a)
@ -83,12 +74,13 @@ class LpLogin(callbacks.Plugin):
try:
user = ircdb.users.getUser(msg.prefix[:msg.prefix.find('!')])
except:
irc.error(conf.supybot.replies.incorrectAuthentication())
return
self.loadnicks()
try:
user = ircdb.users.getUser(msg.prefix[:msg.prefix.find('!')])
except:
irc.error(conf.supybot.replies.incorrectAuthentication())
return
user.addAuth(msg.prefix)
ircdb.users.setUser(user, flush=False)
login = wrap(login)
Class = LpLogin
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
Class = FreenodeAuth

18
FreenodeAuth/test.py Normal file
View File

@ -0,0 +1,18 @@
###
# Copyright (c) 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.
#
###
from supybot.test import *
class FreenodeAuthTestCase(PluginTestCase):
plugins = ('FreenodeAuth',)

View File

@ -1 +0,0 @@
Insert a description of your plugin here, with any notes, etc. about using it.

View File

@ -1,20 +0,0 @@
###
# Copyright (c) 2007, Dennis Kaarsemaker
# All rights reserved.
#
#
###
import supybot.conf as conf
import supybot.registry as registry
def configure(advanced):
from supybot.questions import expect, anything, something, yn
conf.registerPlugin('LpLogin', True)
LpLogin = conf.registerPlugin('LpLogin')
conf.registerGlobalValue(LpLogin, 'UserList',
registry.String('', """Filename of file with list of users"""))
conf.registerGlobalValue(LpLogin, 'DeleteUnknowns',
registry.Boolean(True, """Unregister people not in the list"""))

View File

@ -1,37 +0,0 @@
#!/usr/bin/python
import urllib, urllib2
import xml.dom.minidom as dom
import re, sys, optparse
usage = "Usage: %prog [options] launchpad_group"
parser = optparse.OptionParser(usage=usage)
parser.add_option("-o", "--output", dest='outfile', help="Output to FILE",
metavar="FILE")
(options, args) = parser.parse_args()
if len(args) < 1:
parser.error('No group specified')
lp_group = args[0]
if options.outfile:
outfd = open(options.outfile,'w')
else:
outfd = sys.stdout
people_re = re.compile(r'href="/~([^/"]*)"')
nickname_re = re.compile(r'<code.*?120.*?>(.*?)</code>.*\n.*freenode',re.I)
def get_group_members(group):
nicks = []
u = urllib2.urlopen('http://launchpad.net/~%s/+members' % urllib.quote(group))
html = u.read().lower()
# Split into people and groups
p1 = html.find('active members')
p2 = html.find('pending members')
people = people_re.findall(html[p1:p2])
for p in people:
u = urllib2.urlopen('http://launchpad.net/~%s' % urllib.quote(p))
html = u.read()
n = nickname_re.findall(html)
nicks += n
return [x.lower() for x in nicks]
outfd.write("\n".join(get_group_members(lp_group)))

View File

@ -1,14 +0,0 @@
###
# Copyright (c) 2007, Dennis Kaarsemaker
# All rights reserved.
#
#
###
from supybot.test import *
class LpLoginTestCase(PluginTestCase):
plugins = ('LpLogin',)
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: