From d218ddad74506f3c80131fab9d0680902e1d0ede Mon Sep 17 00:00:00 2001 From: Dennis Kaarsemaker Date: Fri, 8 Jun 2007 20:16:37 +0200 Subject: [PATCH] Misc fixes Add CVE snarfer Malone -> Launchpad rename --- Bugtracker/plugin.py | 44 ++++++++++++++++++++++++++++++--------- Encyclopedia/factoids.cgi | 4 +++- Encyclopedia/plugin.py | 4 ++-- Encyclopedia/update_apt | 1 + Lart/plugin.py | 5 +++-- LpLogin/plugin.py | 4 +++- Mess/plugin.py | 32 +++++++++++++++++++++------- commoncgi.py | 2 +- 8 files changed, 71 insertions(+), 25 deletions(-) diff --git a/Bugtracker/plugin.py b/Bugtracker/plugin.py index 7411596..8aa9fd1 100644 --- a/Bugtracker/plugin.py +++ b/Bugtracker/plugin.py @@ -72,11 +72,12 @@ class BugNotFoundError(Exception): """Pity, bug isn't there""" pass +cvere = re.compile(r']*>description\s*]*>(.*?)\s*', re.I | re.DOTALL) class Bugtracker(callbacks.PluginRegexp): """Show a link to a bug report with a brief description""" threaded = True callBefore = ['URL'] - regexps = ['turlSnarfer', 'bugSnarfer', 'oopsSnarfer'] + regexps = ['turlSnarfer', 'bugSnarfer', 'oopsSnarfer', 'cveSnarfer'] def __init__(self, irc): callbacks.PluginRegexp.__init__(self, irc) @@ -155,9 +156,9 @@ class Bugtracker(callbacks.PluginRegexp): if tag not in bugs: bugs[tag] = {} - # Determine bugtracker type (currently only Malone is supported anyway) + # Determine bugtracker type (currently only Launchpad is supported anyway) if bug['X-Launchpad-Bug']: - tracker = self.db['malone'] + tracker = self.db['launchpad'] id = int(bug['Reply-To'].split()[1]) if self.is_new(tracker, tag, id): component = bug['X-Launchpad-Bug'] @@ -171,6 +172,8 @@ class Bugtracker(callbacks.PluginRegexp): bugs[tag][id] = self.get_bug('',tracker, id, False)[0].replace('"','(%s) "' % component, 1) else: bugs[tag][id] = self.get_bug('',tracker, id, False)[0] + if '[apport]' in bugs[tag][id]: + bugs[tag].pop(id) except: self.log.info("Unable to get new bug %d" % id) pass @@ -185,12 +188,13 @@ class Bugtracker(callbacks.PluginRegexp): continue for b in sorted(bugs[tag].keys()): irc.queueMsg(ircmsgs.privmsg(c,'New bug: #%s' % bugs[tag][b][bugs[tag][b].find('bug ')+4:])) + print "Reported!" def add(self, irc, msg, args, name, trackertype, url, description): """ [] Add a bugtracker to the list of defined bugtrackers. is the - type of the tracker (currently only Malone, Debbugs, Bugzilla, + type of the tracker (currently only Launchpad, Debbugs, Bugzilla, Issuezilla and Trac are known). is the name that will be used to reference the bugzilla in all commands. Unambiguous abbreviations of will be accepted also. is the common name for the @@ -373,9 +377,26 @@ class Bugtracker(callbacks.PluginRegexp): # Only useful for launchpad developers def oopsSnarfer(self, irc, msg, match): r"OOPS-(?P\d*[A-Z]\d+)" + if msg.args[0][0] == '#' and not self.registryValue('bugSnarfer', msg.args[0]): + return oopsid = match.group(1) irc.reply("https://devpad.canonical.com/~jamesh/oops.cgi/%s" % oopsid, prefixNick=False) + def cveSnarfer(self, irc, msg, match): + r"(cve[- ]\d{4}[- ]\d{4})" + if msg.args[0][0] == '#' and not self.registryValue('bugSnarfer', msg.args[0]): + return + cve = match.group(1).replace(' ','-').upper() + url = 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=%s' % cve + cvedata = utils.web.getUrl(url) + m = cvere.search(cvedata) + if m: + cve = m.group(1).replace('\n', ' ') + irc.reply("%s (%s)" % (cve,url)) + + def cveUrlSnarfer(self, irc, msg, match): + pass + def get_tracker(self,snarfurl,sfdata): snarfurl = snarfurl.replace('sf.net','sourceforge.net') snarfhost = snarfurl.replace('http://','').replace('https://','') @@ -517,7 +538,7 @@ class Issuezilla(IBugtracker): raise BugtrackerError, s return [(id, component, title, severity, status, assignee, "%s/show_bug.cgi?id=%d" % (self.url, id))] -class Malone(IBugtracker): +class Launchpad(IBugtracker): def _parse(self, task): parser = email.FeedParser.FeedParser() parser.feed(task) @@ -525,7 +546,7 @@ class Malone(IBugtracker): def _sort(self, task1, task2): # Status sort: try: - statuses = ['Rejected', 'Fix Released', 'Fix Committed', 'Unconfirmed', 'Needs Info', 'In Progress', 'Confirmed'] + statuses = ['Rejected', 'Fix Released', 'Fix Committed', 'Unconfirmed','Needs Info','Confirmed','In Progress'] severities = ['Undecided', 'Wishlist', 'Minor', 'Low', 'Normal', 'Medium', 'Major', 'High', 'Critical'] if task1['status'] not in statuses and task2['status'] in statuses: return -1 if task1['status'] in statuses and task2['status'] not in statuses: return 1 @@ -544,7 +565,8 @@ class Malone(IBugtracker): return 0 def get_bug(self, id): try: - bugdata = utils.web.getUrl("%s/%d/+text" % (self.url.replace('malone','bugs'),id)) + print("%s/bugs/%d/+text" % (self.url,id)) + bugdata = utils.web.getUrl("%s/bugs/%d/+text" % (self.url,id)) except Exception, e: if '404' in str(e): raise BugNotFoundError @@ -576,9 +598,9 @@ class Malone(IBugtracker): if bugdata['duplicate-of']: dupbug = self.get_bug(int(bugdata['duplicate-of'])) return [(id, t, bugdata['title'] + (' (dup-of: %d)' % dupbug[0][0]), taskdata['importance'], - taskdata['status'], taskdata['assignee'], "%s/bugs/%s" % (self.url.replace('/malone',''), id))] + dupbug + taskdata['status'], taskdata['assignee'], "%s/bugs/%s" % (self.url, id))] + dupbug return [(id, t, bugdata['title'], taskdata['importance'], - taskdata['status'], taskdata['assignee'], "%s/bugs/%s" % (self.url.replace('/malone',''), id))] + taskdata['status'], taskdata['assignee'], "%s/bugs/%s" % (self.url, id))] # # Debbugs sucks donkeyballs @@ -784,7 +806,9 @@ registerBugtracker('ximian', 'http://bugzilla.ximian.com', 'Ximian', 'bugzilla') registerBugtracker('freedesktop', 'http://bugzilla.freedesktop.org', 'Freedesktop', 'bugzilla') registerBugtracker('freedesktop2', 'http://bugs.freedesktop.org', 'Freedesktop', 'bugzilla') registerBugtracker('openoffice', 'http://openoffice.org/issues', 'OpenOffice.org', 'issuezilla') -registerBugtracker('malone', 'https://launchpad.net/malone', 'Malone', 'malone') +registerBugtracker('launchpad', 'https://launchpad.net', 'Launchpad', 'launchpad') +registerBugtracker('lp', 'https://launchpad.net', 'Launchpad', 'launchpad') +registerBugtracker('malone', 'https://launchpad.net', 'Launchpad', 'launchpad') registerBugtracker('debian', 'http://bugs.debian.org', 'Debian', 'debbugs') registerBugtracker('trac', 'http://trac.edgewall.org/ticket', 'Trac', 'trac') registerBugtracker('django', 'http://code.djangoproject.com/ticket', 'Django', 'trac') diff --git a/Encyclopedia/factoids.cgi b/Encyclopedia/factoids.cgi index 027d665..ae718d0 100755 --- a/Encyclopedia/factoids.cgi +++ b/Encyclopedia/factoids.cgi @@ -51,7 +51,9 @@ if 'search' in form: # Select factoids if search: - keys = [x.strip() for x in search.split() if len(x.strip()) >2][:5] + keys = [urllib2.unquote(x.strip()) for x in search.split() if len(x.strip()) >2][:5] + if not keys: + keys = [''] query1 = "SELECT name, value, author, added, popularity FROM facts WHERE name NOT LIKE '%-also' AND (" query2 = "SELECT COUNT(name) FROM facts WHERE " bogus = False diff --git a/Encyclopedia/plugin.py b/Encyclopedia/plugin.py index bbe89bb..008fd7e 100644 --- a/Encyclopedia/plugin.py +++ b/Encyclopedia/plugin.py @@ -318,7 +318,7 @@ class Encyclopedia(callbacks.Plugin): text, target, retmsg = self.get_target(msg.nick, orig_text, target) if text.startswith('bug ') and text != ('bug 1'): return - if text == self.registryValue('alert') and msg.args[0][0] == '#': + if text == self.registryValue('alert') and msg.args[0][0] == '#' and not display_info: msg.tag('alert') ret = self.factoid_lookup(text, channel, display_info) @@ -348,7 +348,7 @@ class Encyclopedia(callbacks.Plugin): queue(irc, target, retmsg + ret[0]) if msg.tagged('alert'): queue(irc, self.registryValue('relayChannel'), '%s called the ops in %s' % (msg.nick, msg.args[0])) - queue(irc, self.registryValue('relayChannel'), retmsg + ret[0]) + #queue(irc, self.registryValue('relayChannel'), retmsg + ret[0]) for r in ret[1:]: queue(irc, target, r) diff --git a/Encyclopedia/update_apt b/Encyclopedia/update_apt index 900d1e9..c4832fe 100755 --- a/Encyclopedia/update_apt +++ b/Encyclopedia/update_apt @@ -3,6 +3,7 @@ DIR=/home/dennis/ubotu/data/apt for DIST in "$DIR"/*.list; do + test -h $DIST && continue DIST=${DIST:${#DIR}} DIST=${DIST/.list} touch "$DIR/$DIST.status" diff --git a/Lart/plugin.py b/Lart/plugin.py index 475b854..59685fc 100644 --- a/Lart/plugin.py +++ b/Lart/plugin.py @@ -60,6 +60,7 @@ class Lart(plugins.ChannelIdDatabasePlugin): (target, reason) = map(str.strip, text.split(' for ', 1)) else: (target, reason) = (text, '') + print target if id is not None: try: lart = self.db.get(channel, id) @@ -74,8 +75,8 @@ class Lart(plugins.ChannelIdDatabasePlugin): return text = self._replaceFirstPerson(lart.text, msg.nick) if ircutils.strEqual(target, irc.nick) or \ - 'ubotu' in target.lower() or 'ubugtu' in target.lower() or \ - 'seveas' in target.lower() or \ + 'ubotu' in ircutils.stripFormatting(target).lower() or \ + 'seveas' in ircutils.stripFormatting(target).lower() or \ ((not msg.prefix.endswith('seveas')) and random.uniform(0,100) < 25): target = msg.nick reason = '' diff --git a/LpLogin/plugin.py b/LpLogin/plugin.py index d92178b..7caf83d 100644 --- a/LpLogin/plugin.py +++ b/LpLogin/plugin.py @@ -28,7 +28,7 @@ class LpLogin(callbacks.Plugin): except: pass # Reload every 6 hours - schedule.addPeriodicEvent(lambda: self.reportnewbugs(irc), 60*60*6, name=self.name() + '.nickreload') + #schedule.addPeriodicEvent(lambda: self.reportnewbugs(irc), 60*60*6, name=self.name() + '.nickreload') def loadnicks(self): uf = self.registryValue('UserList') @@ -66,6 +66,8 @@ class LpLogin(callbacks.Plugin): def do376(self, irc, msg): irc.queueMsg(ircmsgs.IrcMsg('CAPAB IDENTIFY-MSG')) + def do422(self, irc, msg): # MOTD missing + irc.queueMsg(ircmsgs.IrcMsg('CAPAB IDENTIFY-MSG')) def inFilter(self, irc, msg): if getattr(irc,'_Freenode_capabed',None) and msg.command == 'PRIVMSG': diff --git a/Mess/plugin.py b/Mess/plugin.py index 7f10171..76db515 100644 --- a/Mess/plugin.py +++ b/Mess/plugin.py @@ -19,6 +19,7 @@ import supybot.ircutils as ircutils import supybot.callbacks as callbacks import random, re, time, commands, urllib2 import supybot.ircmsgs as ircmsgs +import supybot.conf as conf mess = { 't': ('http://4q.cc/?pid=fact&person=mrt', r'.*?

(?P.*?)

', False), @@ -37,10 +38,12 @@ mess = { 'mjg59': ('http://www.angryfacts.com', r'

(?P.*?)

', False), 'vmjg': ('http://www.rjek.com/vmjg59.cgi', r'(?P.*?)

', True), 'vmjg59': ('http://www.rjek.com/vmjg59.cgi', r'(?P.*?)

', True), - 'bofh': ('/home/dennis/ubotu/plugins/Mess/bofh.txt', 'BOFH Excuse #%d: ', False), - '42': ('/home/dennis/ubotu/plugins/Mess/42.txt', '', False), - 'magic8ball': ('/home/dennis/ubotu/plugins/Mess/ball.txt', '', False), - 'ferengi': ('/home/dennis/ubotu/plugins/Mess/ferengi.txt', 'Ferengi rule of acquisition ', False) + 'shakespeare': ('http://www.pangloss.com/seidel/Shaker/', r'(?P.*?)', False), + 'lugradio': ('http://planet.lugradio.org/facts/', r'

\s*(?P.*?)

', False), + 'bofh': ('/home/dennis/ubotu/plugins/Mess/bofh.txt', 'BOFH Excuse #%d: ', False), + '42': ('/home/dennis/ubotu/plugins/Mess/42.txt', '', False), + 'magic8ball': ('/home/dennis/ubotu/plugins/Mess/ball.txt', '', False), + 'ferengi': ('/home/dennis/ubotu/plugins/Mess/ferengi.txt', 'Ferengi rule of acquisition ', False) } data = {} for m in mess.keys(): @@ -53,7 +56,7 @@ for m in mess.keys(): badwords = ['sex','masturbate','fuck','rape','dick','pussy','prostitute','hooker', 'orgasm','sperm','cunt','penis','shit','piss','urin','bitch','semen','cock', - 'retarded'] + 'retard'] tagre = re.compile(r'<.*?>') def filter(txt,off): _txt = txt.lower() @@ -119,12 +122,25 @@ class Mess(callbacks.PluginRegexp): return callbacks.PluginRegexp.getCommandMethod(self, command) except AttributeError: return self.messcb + + def _callCommand(self, command, irc, msg, *args, **kwargs): + method = self.getCommandMethod(command) + if command[0] in mess: + msg.tag('messcmd', command[0]) + try: + method(irc, msg, *args, **kwargs) + except Exception, e: + self.log.exception('Uncaught exception in %s.', command) + if conf.supybot.reply.error.detailed(): + irc.error(utils.exnToString(e)) + else: + irc.replyError() @ok - def messcb(self, irc, msg, args): + def messcb(self, irc, msg, args, text): """General mess""" global data - cmd = msg.args[1].split()[-1] + cmd = msg.tagged('messcmd') try: (loc, tx, off) = mess[cmd] except: @@ -147,7 +163,7 @@ class Mess(callbacks.PluginRegexp): if '%d' in tx: tx = tx % i irc.reply(tx + data[loc][i]) - messcb = wrap(messcb) + messcb = wrap(messcb, [additional('text')]) # WARNING: depends on an alteration in supybot/callbacks.py - don't do # str(s) if s is unicode! diff --git a/commoncgi.py b/commoncgi.py index 63ce0dc..f2b1ce8 100644 --- a/commoncgi.py +++ b/commoncgi.py @@ -12,7 +12,7 @@ # ### -import cgi, cgitb, re, sys, math, os, md5, sqlite, random, time, datetime, pytz, Cookie, StringIO +import cgi, cgitb, re, sys, math, os, md5, sqlite, random, time, datetime, pytz, Cookie, StringIO, urllib2 import cPickle as pickle cgitb.enable()