Beispiel #1
0
 def _kban(self, irc, msg, args, bannedNick, reason):
 # Check that they're not trying to make us kickban ourself.
     channel = msg.args[0]
     if not irc.isNick(bannedNick[0]):
         self.log.warning('%q tried to kban a non nick: %q',
                          msg.prefix, bannedNick)
         raise callbacks.ArgumentError
     elif bannedNick == irc.nick:
         self.log.warning('%q tried to make me kban myself.', msg.prefix)
         irc.error('I cowardly refuse to kickban myself.')
         return
     if not reason:
         reason = msg.nick
     try:
         bannedHostmask = irc.state.nickToHostmask(bannedNick)
     except KeyError:
         irc.error(format('I haven\'t seen %s.', bannedNick), Raise=True)
     capability = ircdb.makeChannelCapability(channel, 'op')
     banmaskstyle = conf.supybot.protocols.irc.banmask
     banmask = banmaskstyle.makeBanmask(bannedHostmask, ["host", "user"])
     # Check (again) that they're not trying to make us kickban ourself.
     if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
         if ircutils.hostmaskPatternEqual(bannedHostmask, irc.prefix):
             self.log.warning('%q tried to make me kban myself.',msg.prefix)
             irc.error('I cowardly refuse to ban myself.')
             return
         else:
             self.log.warning('Using exact hostmask since banmask would '
                              'ban myself.')
             banmask = bannedHostmask
     # Now, let's actually get to it.  Check to make sure they have
     # #channel,op and the bannee doesn't have #channel,op; or that the
     # bannee and the banner are both the same person.
     def doBan():
         if irc.state.channels[channel].isOp(bannedNick):
             irc.queueMsg(ircmsgs.deop(channel, bannedNick))
         irc.queueMsg(ircmsgs.ban(channel, banmask))
         irc.queueMsg(ircmsgs.kick(channel, bannedNick, reason))
         def f():
             if channel in irc.state.channels and \
                banmask in irc.state.channels[channel].bans:
                 irc.queueMsg(ircmsgs.unban(channel, banmask))
         schedule.addEvent(f, 3600)
     if bannedNick == msg.nick:
         doBan()
     elif ircdb.checkCapability(msg.prefix, capability):
         if ircdb.checkCapability(bannedHostmask, capability):
             self.log.warning('%s tried to ban %q, but both have %s',
                              msg.prefix, bannedHostmask, capability)
             irc.error(format('%s has %s too, you can\'t ban him/her/it.',
                              bannedNick, capability))
         else:
             doBan()
     else:
         self.log.warning('%q attempted kban without %s',
                          msg.prefix, capability)
         irc.errorNoCapability(capability)
         exact,nick,user,host
Beispiel #2
0
 def checkIgnored(self, prefix):
     now = time.time()
     mask = getmask(prefix)
     for (hostmask, expiration) in self.hostmasks.items():
         if expiration and now > expiration:
             del self.hostmasks[hostmask]
         else:
             if ircutils.hostmaskPatternEqual(hostmask, prefix) or ircutils.hostmaskPatternEqual(hostmask, mask):
                 return True
     return False
Beispiel #3
0
 def testHostmaskPatternEqual(self):
     for msg in msgs:
         if msg.prefix and ircutils.isUserHostmask(msg.prefix):
             s = msg.prefix
             self.failUnless(ircutils.hostmaskPatternEqual(s, s), "%r did not match itself." % s)
             banmask = ircutils.banmask(s)
             self.failUnless(ircutils.hostmaskPatternEqual(banmask, s), "%r did not match %r" % (s, banmask))
     s = "[email protected]"
     self.failUnless(ircutils.hostmaskPatternEqual(s, s))
     s = "jamessan|[email protected]." "abr-ubr1.sbo-abr.ma.cable.rcn.com"
     self.failUnless(ircutils.hostmaskPatternEqual(s, s))
Beispiel #4
0
 def checkBan(self, hostmask):
     """Checks whether a given hostmask is banned by the channel banlist."""
     assert ircutils.isUserHostmask(hostmask), "got %s" % hostmask
     now = time.time()
     mask = getmask(hostmask)
     for (pattern, expiration) in self.bans.items():
         if now < expiration or not expiration:
             if ircutils.hostmaskPatternEqual(pattern, hostmask) or ircutils.hostmaskPatternEqual(pattern, mask):
                 return True
         else:
             self.expiredBans.append((pattern, expiration))
             del self.bans[pattern]
     return False
Beispiel #5
0
 def testHostmaskPatternEqual(self):
     for msg in msgs:
         if msg.prefix and ircutils.isUserHostmask(msg.prefix):
             s = msg.prefix
             self.failUnless(ircutils.hostmaskPatternEqual(s, s),
                             '%r did not match itself.' % s)
             banmask = ircutils.banmask(s)
             self.failUnless(ircutils.hostmaskPatternEqual(banmask, s),
                             '%r did not match %r' % (s, banmask))
     s = '[email protected]'
     self.failUnless(ircutils.hostmaskPatternEqual(s, s))
     s = 'jamessan|[email protected].' \
         'abr-ubr1.sbo-abr.ma.cable.rcn.com'
     self.failUnless(ircutils.hostmaskPatternEqual(s, s))
Beispiel #6
0
 def setUser(self, user, flush=True):
     """Sets a user (given its id) to the IrcUser given it."""
     self.nextId = max(self.nextId, user.id)
     try:
         if self.getUserId(user.name) != user.id:
             raise DuplicateHostmask, hostmask
     except KeyError:
         pass
     for hostmask in user.hostmasks:
         for (i, u) in self.iteritems():
             if i == user.id:
                 continue
             elif u.checkHostmask(hostmask):
                 # We used to remove the hostmask here, but it's not
                 # appropriate for us both to remove the hostmask and to
                 # raise an exception.  So instead, we'll raise an
                 # exception, but be nice and give the offending hostmask
                 # back at the same time.
                 raise DuplicateHostmask, hostmask
             for otherHostmask in u.hostmasks:
                 if ircutils.hostmaskPatternEqual(hostmask, otherHostmask):
                     raise DuplicateHostmask, hostmask
     self.invalidateCache(user.id)
     self.users[user.id] = user
     if flush:
         self.flush()
 def doPrivmsg(self, irc, msg):
     channel, text = msg.args
     text = text.lower()
     if '#' in channel:
         #print self.regex
         #irc.reply('testing %s against %s' % (text, self._regexString))
         if self.regex.match(text):
             try:
                 hostmask = irc.state.nickToHostmask(msg.nick)
             except KeyError:
                 return
             (nick, user, host) = ircutils.splitHostmask(hostmask)
             user = self._fnUser.sub('*', user)
             banmask = ircutils.joinHostmask('*', user, msg.host)
             if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
                 return
             irc.queueMsg(ban(channel, banmask, 'For swearing. 5 minute timeout'))
             irc.queueMsg(kick(channel, msg.nick, 'For swearing'))
             def unBan():
                 if channel in irc.state.channels and \
                    banmask in irc.state.channels[channel].bans:
                     irc.queueMsg(unban(channel, banmask))
             schedule.addEvent(unBan, time.time()+300)
         elif 'f*g' in text.split():
             try:
                 hostmask = irc.state.nickToHostmask(msg.nick)
             except KeyError:
                 return
             (nick, user, host) = ircutils.splitHostmask(hostmask)
             irc.reply('No thanks %s I don\'t smoke' % user)
     return msg
Beispiel #8
0
 def setUser(self, user, flush=True):
     """Sets a user (given its id) to the IrcUser given it."""
     self.nextId = max(self.nextId, user.id)
     try:
         if self.getUserId(user.name) != user.id:
             raise DuplicateHostmask, hostmask
     except KeyError:
         pass
     for hostmask in user.hostmasks:
         for (i, u) in self.iteritems():
             if i == user.id:
                 continue
             elif u.checkHostmask(hostmask):
                 # We used to remove the hostmask here, but it's not
                 # appropriate for us both to remove the hostmask and to
                 # raise an exception.  So instead, we'll raise an
                 # exception, but be nice and give the offending hostmask
                 # back at the same time.
                 raise DuplicateHostmask, hostmask
             for otherHostmask in u.hostmasks:
                 if ircutils.hostmaskPatternEqual(hostmask, otherHostmask):
                     raise DuplicateHostmask, hostmask
     self.invalidateCache(user.id)
     self.users[user.id] = user
     if flush:
         self.flush()
Beispiel #9
0
    def unban(self, irc, msg, args, channel, hostmask):
        """[<channel>] [<hostmask|--all>]

        Unbans <hostmask> on <channel>.  If <hostmask> is not given, unbans
        any hostmask currently banned on <channel> that matches your current
        hostmask.  Especially useful for unbanning yourself when you get
        unexpectedly (or accidentally) banned from the channel.  <channel> is
        only necessary if the message isn't sent in the channel itself.
        """
        if hostmask == '--all':
            bans = irc.state.channels[channel].bans
            self._sendMsg(irc, ircmsgs.unbans(channel, bans))
        elif hostmask:
            self._sendMsg(irc, ircmsgs.unban(channel, hostmask))
        else:
            bans = []
            for banmask in irc.state.channels[channel].bans:
                if ircutils.hostmaskPatternEqual(banmask, msg.prefix):
                    bans.append(banmask)
            if bans:
                irc.queueMsg(ircmsgs.unbans(channel, bans))
                irc.replySuccess(format(_('All bans on %s matching %s '
                                        'have been removed.'),
                                        channel, msg.prefix))
            else:
                irc.error(_('No bans matching %s were found on %s.') %
                          (msg.prefix, channel))
Beispiel #10
0
    def unban(self, irc, msg, args, channel, hostmask):
        """[<channel>] [<hostmask|--all>]

        Unbans <hostmask> on <channel>.  If <hostmask> is not given, unbans
        any hostmask currently banned on <channel> that matches your current
        hostmask.  Especially useful for unbanning yourself when you get
        unexpectedly (or accidentally) banned from the channel.  <channel> is
        only necessary if the message isn't sent in the channel itself.
        """
        if hostmask == '--all':
            bans = irc.state.channels[channel].bans
            self._sendMsg(irc, ircmsgs.unbans(channel, bans))
        elif hostmask:
            self._sendMsg(irc, ircmsgs.unban(channel, hostmask))
        else:
            bans = []
            for banmask in irc.state.channels[channel].bans:
                if ircutils.hostmaskPatternEqual(banmask, msg.prefix):
                    bans.append(banmask)
            if bans:
                irc.queueMsg(ircmsgs.unbans(channel, bans))
                irc.replySuccess(format(_('All bans on %s matching %s '
                                        'have been removed.'),
                                        channel, msg.prefix))
            else:
                irc.error(_('No bans matching %s were found on %s.') %
                          (msg.prefix, channel))
Beispiel #11
0
 def doPrivmsg(self, irc, msg):
     if ircmsgs.isCtcp(msg) and not ircmsgs.isAction(msg):
         return
     (channel, text) = msg.args
     if irc.isChannel(channel):
         irc = self._getRealIrc(irc)
         if channel not in self.registryValue('channels'):
             return
         ignores = self.registryValue('ignores', channel)
         for ignore in ignores:
             if ircutils.hostmaskPatternEqual(ignore, msg.prefix):
                 self.log.debug('Refusing to relay %s, ignored by %s.',
                                msg.prefix, ignore)
                 return
         # Let's try to detect other relay bots.
         if self._checkRelayMsg(msg):
             if self.registryValue('punishOtherRelayBots', channel):
                 self._punishRelayers(msg)
             # Either way, we don't relay the message.
             else:
                 self.log.warning('Refusing to relay message from %s, '
                                  'it appears to be a relay message.',
                                  msg.prefix)
         else:
             network = self._getIrcName(irc)
             s = self._formatPrivmsg(msg.nick, network, msg)
             m = self._msgmaker(channel, s)
             self._sendToOthers(irc, m)
Beispiel #12
0
def hostmaskPatternEqual(pattern, hostmask):
    if pattern.count('!') != 1 or pattern.count('@') != 1:
        return False
    if pattern.count('$') == 1:
        pattern = pattern.split('$',1)[0]
    if pattern.startswith('%'):
        pattern = pattern[1:]
    return ircutils.hostmaskPatternEqual(pattern, hostmask)
Beispiel #13
0
 def checkIgnored(self, prefix):
     now = time.time()
     for (hostmask, expiration) in self.hostmasks.items():
         if expiration and now > expiration:
             del self.hostmasks[hostmask]
         else:
             if ircutils.hostmaskPatternEqual(hostmask, prefix):
                 return True
     return False
Beispiel #14
0
    def rroulette(self, irc, msg, args, spin):
        """[spin]

        Fires the revolver.  If the bullet was in the chamber, you're dead.
        Tell me to spin the chambers and I will.
        """
        if spin:
            self._rouletteBullet = random.randrange(0, 6)
            irc.reply('*SPIN* Are you feeling lucky?', prefixNick=False)
            return
        channel = msg.args[0]
        if self._rouletteChamber == self._rouletteBullet:
            self._rouletteBullet = random.randrange(0, 6)
            self._rouletteChamber = random.randrange(0, 6)
            if irc.nick in irc.state.channels[channel].ops or irc.nick in irc.state.channels[channel].halfops:
                try:
                    bannedHostmask = irc.state.nickToHostmask(msg.nick)
                except KeyError:
                    irc.error(format('I haven\'t seen %s.', msg.nick), Raise=True)
                banmaskstyle = conf.supybot.protocols.irc.banmask
                banmask = banmaskstyle.makeBanmask(bannedHostmask, ["nick", "host"])
                if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
                    if ircutils.hostmaskPatternEqual(bannedHostmask, irc.prefix):
                        self.log.warning('%q played rroulette, but he\'s got the same hostmask as me, strangely enough.',msg.prefix)
                        irc.error('I\'m not playing this game.')
                        return
                    else:
                        self.log.warning('Using exact hostmask since banmask would '
                        'ban myself.')
                        banmask = bannedHostmask
                        def f():
                            if channel in irc.state.channels and banmask in irc.state.channels[channel].bans:
                                irc.queueMsg(ircmsgs.unban(channel, banmask))
                        schedule.addEvent(f, 60)
                irc.queueMsg(ircmsgs.ban(channel, banmask))
                irc.queueMsg(ircmsgs.kick(channel, msg.nick, 'BANG!'))
            else:
                irc.reply('*BANG* Hey, who put a blank in here?!',
                prefixNick=False)
                irc.reply('reloads and spins the chambers.', action=True)
        else:
            irc.reply('*click*')
            self._rouletteChamber += 1
            self._rouletteChamber %= 6
Beispiel #15
0
 def testBanmask(self):
     for msg in msgs:
         if ircutils.isUserHostmask(msg.prefix):
             banmask = ircutils.banmask(msg.prefix)
             self.failUnless(
                 ircutils.hostmaskPatternEqual(banmask, msg.prefix), "%r didn't match %r" % (msg.prefix, banmask)
             )
     self.assertEqual(ircutils.banmask("foobar!user@host"), "*!*@host")
     self.assertEqual(ircutils.banmask("[email protected]"), "*!*@host.tld")
     self.assertEqual(ircutils.banmask("[email protected]"), "*!*@*.host.tld")
     self.assertEqual(ircutils.banmask("foo!bar@2001::"), "*!*@2001::*")
Beispiel #16
0
 def checkBan(self, hostmask):
     """Checks whether a given hostmask is banned by the channel banlist."""
     assert ircutils.isUserHostmask(hostmask), 'got %s' % hostmask
     now = time.time()
     for (pattern, expiration) in self.bans.items():
         if now < expiration or not expiration:
             if ircutils.hostmaskPatternEqual(pattern, hostmask):
                 return True
         else:
             self.expiredBans.append((pattern, expiration))
             del self.bans[pattern]
     return False
Beispiel #17
0
 def checkIgnored(self, hostmask):
     """Checks whether a given hostmask is to be ignored by the channel."""
     if self.lobotomized:
         return True
     if world.testing:
         return False
     try:
         assert ircutils.isUserHostmask(hostmask), "got %s" % hostmask
     except:
         return False
     if self.checkBan(hostmask):
         return True
     now = time.time()
     mask = getmask(hostmask)
     for (pattern, expiration) in self.ignores.items():
         if now < expiration or not expiration:
             if ircutils.hostmaskPatternEqual(pattern, hostmask) or ircutils.hostmaskPatternEqual(pattern, mask):
                 return True
         else:
             del self.ignores[pattern]
             # Later we may wish to keep expiredIgnores, but not now.
     return False
Beispiel #18
0
 def testBanmask(self):
     for msg in msgs:
         if ircutils.isUserHostmask(msg.prefix):
             banmask = ircutils.banmask(msg.prefix)
             self.failUnless(
                 ircutils.hostmaskPatternEqual(banmask, msg.prefix),
                 '%r didn\'t match %r' % (msg.prefix, banmask))
     self.assertEqual(ircutils.banmask('foobar!user@host'), '*!*@host')
     self.assertEqual(ircutils.banmask('[email protected]'),
                      '*!*@host.tld')
     self.assertEqual(ircutils.banmask('[email protected]'),
                      '*!*@*.host.tld')
     self.assertEqual(ircutils.banmask('foo!bar@2001::'), '*!*@2001::*')
Beispiel #19
0
 def testBanmask(self):
     for msg in msgs:
         if ircutils.isUserHostmask(msg.prefix):
             banmask = ircutils.banmask(msg.prefix)
             self.failUnless(ircutils.hostmaskPatternEqual(banmask,
                                                           msg.prefix),
                             '%r didn\'t match %r' % (msg.prefix, banmask))
     self.assertEqual(ircutils.banmask('foobar!user@host'), '*!*@host')
     self.assertEqual(ircutils.banmask('[email protected]'),
                      '*!*@host.tld')
     self.assertEqual(ircutils.banmask('[email protected]'),
                      '*!*@*.host.tld')
     self.assertEqual(ircutils.banmask('foo!bar@2001::'), '*!*@2001::*')
Beispiel #20
0
 def doPrivmsg(self, irc, msg):
     notes = self._notes.pop(msg.nick, [])
     # Let's try wildcards.
     removals = []
     for wildcard in self.wildcards:
         if ircutils.hostmaskPatternEqual(wildcard, msg.nick):
             removals.append(wildcard)
             notes.extend(self._notes.pop(wildcard))
         for removal in removals:
             self.wildcards.remove(removal)
     if notes:
         irc = callbacks.SimpleProxy(irc, msg)
         private = self.registryValue('private')
         for (when, whence, note) in notes:
             s = self._formatNote(when, whence, note)
             irc.reply(s, private=private)
         self._flushNotes()
Beispiel #21
0
 def checkIgnored(self, hostmask):
     """Checks whether a given hostmask is to be ignored by the channel."""
     if self.lobotomized:
         return True
     if world.testing:
         return False
     assert ircutils.isUserHostmask(hostmask), 'got %s' % hostmask
     if self.checkBan(hostmask):
         return True
     now = time.time()
     for (pattern, expiration) in self.ignores.items():
         if now < expiration or not expiration:
             if ircutils.hostmaskPatternEqual(pattern, hostmask):
                 return True
         else:
             del self.ignores[pattern]
             # Later we may wish to keep expiredIgnores, but not now.
     return False
Beispiel #22
0
 def doJoin(self, irc, msg):
     channel = ircutils.toLower(msg.args[0])
     mynick = irc.nick
     user = msg.nick
     hostname = irc.state.nickToHostmask(user)
     if not ircutils.strEqual(irc.nick, msg.nick):  # not me joining.
         if channel in self._channels.keys():  # do we have a matching channel?
             if irc.state.channels[channel].isOp(mynick):  # am I an op?
                 for (hostmask, username) in self._channels[channel]:
                     if ircutils.hostmaskPatternEqual(hostmask, hostname):  # do we have a matching user?
                         self.log.info("{0} matched {1} in {2} on username {3}. Sending ZNC challenge.".format(hostmask, user, channel, username))
                         challenge = self._zncchallenge()
                         self._challenges[user][channel] = (time.time() + 60, challenge, username)
                         challenge = "!ZNCAO CHALLENGE {0}".format(challenge)
                         def sendNotice():  # for the delayed send.
                             irc.queueMsg(ircmsgs.notice(user, challenge))
                         schedule.addEvent(sendNotice, (time.time() + choice(range(2, 6))))
                         break
Beispiel #23
0
 def callCommand(self, command, irc, msg, *args, **kwargs):
     if conf.supybot.abuse.flood.ctcp():
         now = time.time()
         for (ignore, expiration) in self.ignores.items():
             if expiration < now:
                 del self.ignores[ignore]
             elif ircutils.hostmaskPatternEqual(ignore, msg.prefix):
                     return
         self.floods.enqueue(msg)
         max = conf.supybot.abuse.flood.ctcp.maximum()
         if self.floods.len(msg) > max:
             expires = conf.supybot.abuse.flood.ctcp.punishment()
             self.log.warning('Apparent CTCP flood from %s, '
                              'ignoring CTCP messages for %s seconds.',
                              msg.prefix, expires)
             ignoreMask = '*!%s@%s' % (msg.user, msg.host)
             self.ignores[ignoreMask] = now + expires
             return
     self.__parent.callCommand(command, irc, msg, *args, **kwargs)
Beispiel #24
0
 def getHostFromBan(self, irc, msg, mask):
     if irc not in self.lastStates:
         self.lastStates[irc] = irc.state.copy()
     if mask[0] == '%':
         mask = mask[1:]
     try:
         (nick, ident, host) = ircutils.splitHostmask(mask)
     except AssertionError:
         # not a hostmask
         return None
     channel = None
     chan = None
     if mask[0] not in ('*', '?'): # Nick ban
         if nick in self.nicks:
             return self.nicks[nick]
     else: # Host/ident ban
         for (inick, ihost) in self.nicks.iteritems():
             if ircutils.hostmaskPatternEqual(mask, ihost):
                 return ihost
     return None
Beispiel #25
0
 def _ban(self, irc, nick, channel):
     try:
         hostmask = irc.state.nickToHostmask(nick)
     except KeyError:
         return
     (nick, user, host) = ircutils.splitHostmask(hostmask)
     user = self._fnUser.sub('*', user)
     banmask = ircutils.joinHostmask('*', user, host)
     if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
         return
     irc.queueMsg(ircmsgs.ban(channel, banmask))
     irc.queueMsg(ircmsgs.kick(channel, nick))
     expiry = self.registryValue('autokban.timeout', channel)
     if expiry > 0:
         expiry += time.time()
         def f():
             if channel in irc.state.channels and \
                banmask in irc.state.channels[channel].bans:
                 irc.queueMsg(ircmsgs.unban(channel, banmask))
         schedule.addEvent(f, expiry)
Beispiel #26
0
 def checkHostmask(self, hostmask, useAuth=True):
     """Checks a given hostmask against the user's hostmasks or current
     authentication.  If useAuth is False, only checks against the user's
     hostmasks.
     """
     if useAuth:
         timeout = conf.supybot.databases.users.timeoutIdentification()
         removals = []
         try:
             for (when, authmask) in self.auth:
                 if timeout and when + timeout < time.time():
                     removals.append((when, authmask))
                 elif hostmask == authmask:
                     return True
         finally:
             while removals:
                 self.auth.remove(removals.pop())
     for pat in self.hostmasks:
         if ircutils.hostmaskPatternEqual(pat, hostmask):
             return pat
     return False
    def doPrivmsg(self, irc, msg):
        channel = msg.args[0]
        targets = list(map(lambda x:x.split(':'),
            self.registryValue('queries', channel)))
        whitelist = self.registryValue('authorWhitelist', channel)
        if whitelist:
            if all(not ircutils.hostmaskPatternEqual(pattern, msg.prefix)
                   for pattern in whitelist):
                return

        cb = irc.getCallback('Google')
        if targets and cb is None:
            self.log.error('WikiTrans used but Google plugin not loaded.')
            return

        for lang in set(map(operator.itemgetter(1), targets)):
            (text, language) = cb._translate('auto', lang, msg.args[1])
            text = '<%s@%s> %s' % (msg.nick, channel, text)
            for (nick, user_lang) in targets:
                if user_lang != language and user_lang == lang:
                    irc.reply(text, to=nick, private=True, notice=False)
Beispiel #28
0
    def lastlojban(self, irc, msg, args, channel, nick, percent):
        """[channel] [nick] [percent]

        Get the last Lojban message as determined by potential-percentage.
        """
        if not percent:
            percent = 40
        for ircmsg in reversed(irc.state.history):
            if ircmsg.command == 'PRIVMSG':
                msgs = [ircmsg.args[1]]
                if '{' in msgs[0]:
                    msgs = reversed(list(re.findall(r'\{(.+?)\}', msgs[0])))
                for imsg in msgs:
                    if self._cenlai(imsg) >= percent:
                        if not channel or \
                           ircutils.strEqual(channel, ircmsg.args[0]):
                            if not nick or \
                               ircutils.hostmaskPatternEqual(nick,
                                                             ircmsg.nick):
                                irc.reply(imsg)
                                return
Beispiel #29
0
 def checkHostmask(self, hostmask, useAuth=True):
     """Checks a given hostmask against the user's hostmasks or current
     authentication.  If useAuth is False, only checks against the user's
     hostmasks.
     """
     if useAuth:
         timeout = conf.supybot.databases.users.timeoutIdentification()
         removals = []
         try:
             for (when, authmask) in self.auth:
                 if timeout and when+timeout < time.time():
                     removals.append((when, authmask))
                 elif hostmask == authmask:
                     return True
         finally:
             while removals:
                 self.auth.remove(removals.pop())
     for pat in self.hostmasks:
         if ircutils.hostmaskPatternEqual(pat, hostmask):
             return pat
     return False
Beispiel #30
0
 def doPrivmsg(self, irc, msg):
     if ircmsgs.isCtcp(msg) and not ircmsgs.isAction(msg):
         return
     notes = self._notes.pop(msg.nick, [])
     # Let's try wildcards.
     removals = []
     for wildcard in self.wildcards:
         if ircutils.hostmaskPatternEqual(wildcard, msg.nick):
             removals.append(wildcard)
             notes.extend(self._notes.pop(wildcard))
         for removal in removals:
             self.wildcards.remove(removal)
     if notes:
         old_repliedto = msg.repliedTo
         irc = callbacks.SimpleProxy(irc, msg)
         private = self.registryValue('private')
         for (when, whence, note) in notes:
             s = self._formatNote(when, whence, note)
             irc.reply(s, private=private, prefixNick=not private)
         self._flushNotes()
         msg.repliedTo = old_repliedto
Beispiel #31
0
 def doPrivmsg(self, irc, msg):
     if ircmsgs.isCtcp(msg) and not ircmsgs.isAction(msg):
         return
     notes = self._notes.pop(msg.nick, [])
     # Let's try wildcards.
     removals = []
     for wildcard in self.wildcards:
         if ircutils.hostmaskPatternEqual(wildcard, msg.prefix):
             removals.append(wildcard)
             notes.extend(self._notes.pop(wildcard))
         for removal in removals:
             self.wildcards.remove(removal)
     if notes:
         old_repliedto = msg.repliedTo
         irc = callbacks.SimpleProxy(irc, msg)
         private = self.registryValue('private')
         for (when, whence, note) in notes:
             s = self._formatNote(when, whence, note)
             irc.reply(s, private=private, prefixNick=not private)
         self._flushNotes()
         msg.tag('repliedTo', old_repliedto)
Beispiel #32
0
 def doNotice(self, irc, msg):
     mynick = irc.nick
     user = msg.nick
     hostname = irc.state.nickToHostmask(user)
     (recipients, text) = msg.args
     if ircmsgs.isCtcp(msg) or ircmsgs.isAction(msg) or irc.isChannel(msg.args[0]):  # ignore obvious non.
         return
     elif text.startswith('!ZNCAO'):  # we only process notices with !ZNCAO.
         textparts = text.split()  # split. should be 3.
         if len(textparts) != 3:  # make sure we have 3 parts to a valid ZNC message.
             self.log.error("ERROR: ZNC notice from {0} is malformed. I got: {1}".format(user, text))
             return
         if textparts[0] == "!ZNCAO" and textparts[1] == "CHALLENGE":  # if user is opped and we are not. we get challenge.
             self.log.info("We got a ZNC challenge from {0}".format(user))
             challenge = textparts[2]
             for (key, value) in self._users.items():  # iterate now through our users for key.
                 hostmask, key, channel = value[0]
                 if ircutils.hostmaskPatternEqual(hostmask, hostname):  # if we have a match.
                     if not irc.state.channels[channel].isOp(mynick) and irc.state.channels[channel].isOp(user):  # and they're opped, we're not.
                         response = "!ZNCAO RESPONSE {0}".format(self._zncresponse(key, challenge))  # this key and the challenge.
                         self.log.info("Sending {0} {1}".format(user, response))
                         irc.queueMsg(ircmsgs.notice(user, response))
         elif textparts[0] == "!ZNCAO" and textparts[1] == "RESPONSE":  # means we sent a challenge. we're opped, user is not.
             self.log.info("We got a ZNC response from {0}".format(user))
             if user in self._challenges:  # user is in challenges because their hostname matched.
                 for chan in self._challenges[user]:
                     if irc.state.channels[chan].isOp(mynick) and not irc.state.channels[chan].isOp(user):  # im op. they're not.
                         (chaltime, challenge, chaluser) = self._challenges[user][chan]
                         if chaltime - time.time() < 60:  # challenge less than 60s ago.
                             hostmask, key, channel = self._users[chaluser][0]  # find the user in the db.
                             mychallenge = self._zncresponse(key, challenge)  # create my own based on challenge/key to auth.
                             if mychallenge == textparts[2]:  # compare my md5 hash and theirs.
                                 self.log.info("Giving ZNC OP to {0} on {1} after valid key matching.".format(user, chan))
                                 irc.queueMsg(ircmsgs.op(chan, user))  # op if they're valid.
                             else:  # invalid key.
                                 self.log.info("ERROR: Invalid key from: {0} on {1}".format(user, chan))
                         else:  # key is too old.
                             self.log.info("ERROR: {0} in {1} challenge was more than 60s ago.".format(user, chan))
             else:
                 self.log.info("ERROR: {0} not found in ZNC challenges.".format(user))
Beispiel #33
0
    def _ban(self, irc, nick, channel):
        try:
            hostmask = irc.state.nickToHostmask(nick)
        except KeyError:
            return
        (nick, user, host) = ircutils.splitHostmask(hostmask)
        user = self._fnUser.sub('*', user)
        banmask = ircutils.joinHostmask('*', user, host)
        if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
            return
        irc.queueMsg(ircmsgs.ban(channel, banmask))
        irc.queueMsg(ircmsgs.kick(channel, nick))
        expiry = self.registryValue('autokban.timeout', channel)
        if expiry > 0:
            expiry += time.time()

            def f():
                if channel in irc.state.channels and \
                   banmask in irc.state.channels[channel].bans:
                    irc.queueMsg(ircmsgs.unban(channel, banmask))

            schedule.addEvent(f, expiry)
Beispiel #34
0
    def doPrivmsg(self, irc, msg):
        channel = msg.args[0]
        targets = list(
            map(lambda x: x.split(':'), self.registryValue('queries',
                                                           channel)))
        whitelist = self.registryValue('authorWhitelist', channel)
        if whitelist:
            if all(not ircutils.hostmaskPatternEqual(pattern, msg.prefix)
                   for pattern in whitelist):
                return

        cb = irc.getCallback('Google')
        if targets and cb is None:
            self.log.error('WikiTrans used but Google plugin not loaded.')
            return

        for lang in set(map(operator.itemgetter(1), targets)):
            (text, language) = cb._translate('auto', lang, msg.args[1])
            text = '<%s@%s> %s' % (msg.nick, channel, text)
            for (nick, user_lang) in targets:
                if user_lang != language and user_lang == lang:
                    irc.reply(text, to=nick, private=True, notice=False)
Beispiel #35
0
 def doKick(self, irc, msg):
     channel = msg.args[0]
     kicked = msg.args[1].split(',')
     protected = []
     for nick in kicked:
         if ircutils.strEqual(nick, irc.nick):
             return # Channel will handle the rejoin.
     for nick in kicked:
         hostmask = irc.state.nickToHostmask(nick)
         if self.isProtected(irc, channel, hostmask):
             self.log.info('%s was kicked from %s and is protected; '
                           'inviting back.', hostmask, channel)
             hostmask = '%s!%s' % (nick, irc.state.nickToHostmask(nick))
             protected.append(nick)
             bans = []
             for banmask in irc.state.channels[channel].bans:
                 if ircutils.hostmaskPatternEqual(banmask, hostmask):
                     bans.append(banmask)
             irc.queueMsg(ircmsgs.unbans(channel, bans))
             irc.queueMsg(ircmsgs.invite(nick, channel))
     if not self.isOp(irc, channel, msg.prefix):
         self.demote(irc, channel, msg.nick)
Beispiel #36
0
    def zncadduser(self, irc, msg, args, username, hostmask, key, channel):
        """<username> <hostmask> <key> <channel>
        
        Add a user to the ZNC auto-op database. Ex: user1 *!*[email protected] passkey #channel
        NOTICE: I must be run via private message by an admin.
        """

        # declare failcheck.
        failcheck = False

        if irc.isChannel(ircutils.toLower(msg.args[0])):
            irc.reply("ERROR: I must be run via private message by an admin.")
            return
        if username in self._users:  # do our checks now to see if we can add.
            irc.reply("ERROR: I already have a user: {0}".format(username))
            return
        if not ircutils.isChannel(channel):  # make sure the channel is valid.
            irc.reply("ERROR: {0} is not a valid channel".format(channel))
            return
        if not ircutils.isUserHostmask(hostmask):  # make sure hostmask is valid.
            irc.reply("ERROR: {0} is not a valid hostmask.".format(hostmask))
            return
        if len(self._users) > 0:  # make sure we have users to check against.
            for (k, v) in self._users.items():  # check the hostnames.
                userhostname, userkey, userchannel = v[0]
                if ircutils.hostmaskPatternEqual(hostmask, userhostname) and channel == userchannel:
                    irc.reply("ERROR: I cannot add {0}. Hostmask {1} matches the hostmask {2} in existing user: {3} for {4}".format(username, hostmask, userhostname, k, channel))
                    failcheck = True
                    break
        # check if hostname passed.
        if failcheck:
            return
        # username and hostmask are clean. lets add.
        try:
            self._addUser(username, hostmask, key, channel)
            irc.replySuccess()
        except ValueError, e:
            irc.reply("Error adding {0} :: {1}".format(username, e))
Beispiel #37
0
 def doKick(self, irc, msg):
     channel = msg.channel
     kicked = msg.args[1].split(',')
     protected = []
     for nick in kicked:
         if ircutils.strEqual(nick, irc.nick):
             return  # Channel will handle the rejoin.
     for nick in kicked:
         hostmask = irc.state.nickToHostmask(nick)
         if self.isProtected(irc, channel, hostmask):
             self.log.info(
                 '%s was kicked from %s and is protected; '
                 'inviting back.', hostmask, channel)
             hostmask = '%s!%s' % (nick, irc.state.nickToHostmask(nick))
             protected.append(nick)
             bans = []
             for banmask in irc.state.channels[channel].bans:
                 if ircutils.hostmaskPatternEqual(banmask, hostmask):
                     bans.append(banmask)
             irc.queueMsg(ircmsgs.unbans(channel, bans))
             irc.queueMsg(ircmsgs.invite(nick, channel))
     if not self.isOp(irc, channel, msg.prefix):
         self.demote(irc, channel, msg.nick)
Beispiel #38
0
    def chanban(self, irc, msg, args, channel, optlist, bannedHostmask, expiry,
                reason):
        """[<channel>] [--{exact,nick,user,host}] <hostmask> [<seconds>] [<reason>]
 
         If you have the #channel,op capability, this will ban <hostmask> for
         as many seconds as you specify, or else (if you specify 0 seconds or
         don't specify a number of seconds) it will ban the person indefinitely.
         --exact bans only the exact hostmask; --nick bans just the nick;
         --user bans just the user, and --host bans just the host.  You can
         combine these options as you choose.  <reason> is a reason to give for
         the kick.
         <channel> is only necessary if the message isn't sent in the channel
         itself.
         """
        # Check that they're not trying to make us kickban ourself.
        self.log.debug('In chanban')
        if not reason:
            reason = msg.nick
        capability = ircdb.makeChannelCapability(channel, 'op')

        def makeBanmask(bannedHostmask, options):
            (nick, user, host) = ircutils.splitHostmask(bannedHostmask)
            self.log.debug('*** nick: %s', nick)
            self.log.debug('*** user: %s', user)
            self.log.debug('*** host: %s', host)
            bnick = '*'
            buser = '******'
            bhost = '*'
            for option in options:
                if option == 'nick':
                    bnick = nick
                elif option == 'user':
                    buser = user
                elif option == 'host':
                    bhost = host
                elif option == 'exact':
                    (bnick, buser, bhost) = \
                                   ircutils.splitHostmask(bannedHostmask)
            return ircutils.joinHostmask(bnick, buser, bhost)

        if optlist:
            banmask = makeBanmask(bannedHostmask, [o[0] for o in optlist])
        else:
            banmask = makeBanmask(bannedHostmask,
                                  self.registryValue('banmask', channel))
        # Check (again) that they're not trying to make us kickban ourself.
        if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
            if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
                self.log.warning('%q tried to make me chanban myself.',
                                 msg.prefix)
                irc.error('I cowardly refuse to chanban myself.')
                return
            else:
                banmask = bannedHostmask
        # Now, let's actually get to it.  Check to make sure they have
        # #channel,op and the bannee doesn't have #channel,op; or that the
        # bannee and the banner are both the same person.
        def doBan():
            irc.queueMsg(ircmsgs.ban(channel, banmask))
            if expiry > 0:

                def f():
                    if channel in irc.state.channels and \
                       banmask in irc.state.channels[channel].bans:
                        irc.queueMsg(ircmsgs.unban(channel, banmask))

                schedule.addEvent(f, expiry)

        if ircdb.checkCapability(msg.prefix, capability):
            if ircdb.checkCapability(bannedHostmask, capability):
                self.log.warning('%s tried to ban %q, but both have %s',
                                 msg.prefix, bannedHostmask, capability)
                irc.error(
                    format('%s has %s too, you can\'t ban him/her/it.',
                           bannedHostmask, capability))
            else:
                doBan()
        else:
            self.log.warning('%q attempted chanban without %s', msg.prefix,
                             capability)
            irc.errorNoCapability(capability)
            exact, nick, user, host
Beispiel #39
0
    def kban(self, irc, msg, args,
             channel, optlist, bannedNick, expiry, reason):
        """[<channel>] [--{exact,nick,user,host}] <nick> [<seconds>] [<reason>]

        If you have the #channel,op capability, this will kickban <nick> for
        as many seconds as you specify, or else (if you specify 0 seconds or
        don't specify a number of seconds) it will ban the person indefinitely.
        --exact bans only the exact hostmask; --nick bans just the nick;
        --user bans just the user, and --host bans just the host.  You can
        combine these options as you choose.  <reason> is a reason to give for
        the kick.
        <channel> is only necessary if the message isn't sent in the channel
        itself.
        """
        # Check that they're not trying to make us kickban ourself.
        if not irc.isNick(bannedNick):
            self.log.warning('%q tried to kban a non nick: %q',
                             msg.prefix, bannedNick)
            raise callbacks.ArgumentError
        elif bannedNick == irc.nick:
            self.log.warning('%q tried to make me kban myself.', msg.prefix)
            irc.error(_('I cowardly refuse to kickban myself.'))
            return
        if not reason:
            reason = msg.nick
        try:
            bannedHostmask = irc.state.nickToHostmask(bannedNick)
        except KeyError:
            irc.error(format(_('I haven\'t seen %s.'), bannedNick), Raise=True)
        capability = ircdb.makeChannelCapability(channel, 'op')
        banmaskstyle = conf.supybot.protocols.irc.banmask
        banmask = banmaskstyle.makeBanmask(bannedHostmask, [o[0] for o in optlist])
        # Check (again) that they're not trying to make us kickban ourself.
        if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
            if ircutils.hostmaskPatternEqual(bannedHostmask, irc.prefix):
                self.log.warning('%q tried to make me kban myself.',msg.prefix)
                irc.error(_('I cowardly refuse to ban myself.'))
                return
            else:
                self.log.warning('Using exact hostmask since banmask would '
                                 'ban myself.')
                banmask = bannedHostmask
        # Now, let's actually get to it.  Check to make sure they have
        # #channel,op and the bannee doesn't have #channel,op; or that the
        # bannee and the banner are both the same person.
        def doBan():
            if irc.state.channels[channel].isOp(bannedNick):
                irc.queueMsg(ircmsgs.deop(channel, bannedNick))
            irc.queueMsg(ircmsgs.ban(channel, banmask))
            irc.queueMsg(ircmsgs.kick(channel, bannedNick, reason))
            if expiry > 0:
                def f():
                    if channel in irc.state.channels and \
                       banmask in irc.state.channels[channel].bans:
                        irc.queueMsg(ircmsgs.unban(channel, banmask))
                schedule.addEvent(f, expiry)
        if bannedNick == msg.nick:
            doBan()
        elif ircdb.checkCapability(msg.prefix, capability):
            if ircdb.checkCapability(bannedHostmask, capability) and \
                    not ircdb.checkCapability(msg.prefix, 'owner'):
                self.log.warning('%s tried to ban %q, but both have %s',
                                 msg.prefix, bannedHostmask, capability)
                irc.error(format(_('%s has %s too, you can\'t ban '
                                 'him/her/it.'), bannedNick, capability))
            else:
                doBan()
        else:
            self.log.warning('%q attempted kban without %s',
                             msg.prefix, capability)
            irc.errorNoCapability(capability)
            exact,nick,user,host
Beispiel #40
0
 def f(m, arg=arg):
     return ircutils.hostmaskPatternEqual(arg, m.nick)
Beispiel #41
0
 def do352(self, irc, msg):
     for mask in self.whos:
         if ircutils.hostmaskPatternEqual(mask, str(msg)):
             self.whos[mask][1].append(msg)
Beispiel #42
0
 def _ban(self, irc, msg, args,
         channel, optlist, target, expiry, reason, kick):
     # Check that they're not trying to make us kickban ourself.
     if irc.isNick(target):
         bannedNick = target
         try:
             bannedHostmask = irc.state.nickToHostmask(target)
             banmaskstyle = conf.supybot.protocols.irc.banmask
             banmask = banmaskstyle.makeBanmask(bannedHostmask, [o[0] for o in optlist])
         except KeyError:
             if not conf.supybot.protocols.irc.strictRfc() and \
                     target.startswith('$'):
                 # Select the last part, or the whole target:
                 bannedNick = target.split(':')[-1]
                 banmask = bannedHostmask = target
             else:
                 irc.error(format(_('I haven\'t seen %s.'), bannedNick), Raise=True)
     else:
         bannedNick = ircutils.nickFromHostmask(target)
         banmask = bannedHostmask = target
     if not irc.isNick(bannedNick):
         self.log.warning('%q tried to kban a non nick: %q',
                          msg.prefix, bannedNick)
         raise callbacks.ArgumentError
     elif bannedNick == irc.nick:
         self.log.warning('%q tried to make me kban myself.', msg.prefix)
         irc.error(_('I cowardly refuse to kickban myself.'))
         return
     if not reason:
         reason = msg.nick
     capability = ircdb.makeChannelCapability(channel, 'op')
     # Check (again) that they're not trying to make us kickban ourself.
     if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
         if ircutils.hostmaskPatternEqual(bannedHostmask, irc.prefix):
             self.log.warning('%q tried to make me kban myself.',msg.prefix)
             irc.error(_('I cowardly refuse to ban myself.'))
             return
         else:
             self.log.warning('Using exact hostmask since banmask would '
                              'ban myself.')
             banmask = bannedHostmask
     # Now, let's actually get to it.  Check to make sure they have
     # #channel,op and the bannee doesn't have #channel,op; or that the
     # bannee and the banner are both the same person.
     def doBan():
         if irc.state.channels[channel].isOp(bannedNick):
             irc.queueMsg(ircmsgs.deop(channel, bannedNick))
         irc.queueMsg(ircmsgs.ban(channel, banmask))
         if kick:
             irc.queueMsg(ircmsgs.kick(channel, bannedNick, reason))
         if expiry > 0:
             def f():
                 if channel in irc.state.channels and \
                    banmask in irc.state.channels[channel].bans:
                     irc.queueMsg(ircmsgs.unban(channel, banmask))
             schedule.addEvent(f, expiry)
     if bannedNick == msg.nick:
         doBan()
     elif ircdb.checkCapability(msg.prefix, capability):
         if ircdb.checkCapability(bannedHostmask, capability) and \
                 not ircdb.checkCapability(msg.prefix, 'owner'):
             self.log.warning('%s tried to ban %q, but both have %s',
                              msg.prefix, bannedHostmask, capability)
             irc.error(format(_('%s has %s too, you can\'t ban '
                              'them.'), bannedNick, capability))
         else:
             doBan()
     else:
         self.log.warning('%q attempted kban without %s',
                          msg.prefix, capability)
         irc.errorNoCapability(capability)
Beispiel #43
0
 def predicate(entry):
     return entry.channel == channel and \
             ircutils.hostmaskPatternEqual(hostmask, entry.hostmask)
Beispiel #44
0
    def kban(self, irc, msg, args, channel, optlist, bannedNick, expiry,
             reason):
        """[<channel>] [--{exact,nick,user,host}] <nick> [<seconds>] [<reason>]

        If you have the #channel,op capability, this will kickban <nick> for
        as many seconds as you specify, or else (if you specify 0 seconds or
        don't specify a number of seconds) it will ban the person indefinitely.
        --exact bans only the exact hostmask; --nick bans just the nick;
        --user bans just the user, and --host bans just the host.  You can
        combine these options as you choose.  <reason> is a reason to give for
        the kick.
        <channel> is only necessary if the message isn't sent in the channel
        itself.
        """
        # Check that they're not trying to make us kickban ourself.
        if not irc.isNick(bannedNick):
            self.log.warning('%q tried to kban a non nick: %q', msg.prefix,
                             bannedNick)
            raise callbacks.ArgumentError
        elif bannedNick == irc.nick:
            self.log.warning('%q tried to make me kban myself.', msg.prefix)
            irc.error(_('I cowardly refuse to kickban myself.'))
            return
        if not reason:
            reason = msg.nick
        try:
            bannedHostmask = irc.state.nickToHostmask(bannedNick)
        except KeyError:
            irc.error(format(_('I haven\'t seen %s.'), bannedNick), Raise=True)
        capability = ircdb.makeChannelCapability(channel, 'op')
        banmaskstyle = conf.supybot.protocols.irc.banmask
        banmask = banmaskstyle.makeBanmask(bannedHostmask,
                                           [o[0] for o in optlist])
        # Check (again) that they're not trying to make us kickban ourself.
        if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
            if ircutils.hostmaskPatternEqual(bannedHostmask, irc.prefix):
                self.log.warning('%q tried to make me kban myself.',
                                 msg.prefix)
                irc.error(_('I cowardly refuse to ban myself.'))
                return
            else:
                self.log.warning('Using exact hostmask since banmask would '
                                 'ban myself.')
                banmask = bannedHostmask
        # Now, let's actually get to it.  Check to make sure they have
        # #channel,op and the bannee doesn't have #channel,op; or that the
        # bannee and the banner are both the same person.
        def doBan():
            if irc.state.channels[channel].isOp(bannedNick):
                irc.queueMsg(ircmsgs.deop(channel, bannedNick))
            irc.queueMsg(ircmsgs.ban(channel, banmask))
            irc.queueMsg(ircmsgs.kick(channel, bannedNick, reason))
            if expiry > 0:

                def f():
                    if channel in irc.state.channels and \
                       banmask in irc.state.channels[channel].bans:
                        irc.queueMsg(ircmsgs.unban(channel, banmask))

                schedule.addEvent(f, expiry)

        if bannedNick == msg.nick:
            doBan()
        elif ircdb.checkCapability(msg.prefix, capability):
            if ircdb.checkCapability(bannedHostmask, capability) and \
                    not ircdb.checkCapability(msg.prefix, 'owner'):
                self.log.warning('%s tried to ban %q, but both have %s',
                                 msg.prefix, bannedHostmask, capability)
                irc.error(
                    format(_('%s has %s too, you can\'t ban '
                             'him/her/it.'), bannedNick, capability))
            else:
                doBan()
        else:
            self.log.warning('%q attempted kban without %s', msg.prefix,
                             capability)
            irc.errorNoCapability(capability)
            exact, nick, user, host
Beispiel #45
0
 def _ban(self, irc, msg, args,
         channel, optlist, target, expiry, reason, kick):
     # Check that they're not trying to make us kickban ourself.
     if irc.isNick(target):
         bannedNick = target
         try:
             bannedHostmask = irc.state.nickToHostmask(target)
             banmaskstyle = conf.supybot.protocols.irc.banmask
             banmask = banmaskstyle.makeBanmask(bannedHostmask, [o[0] for o in optlist])
         except KeyError:
             if not conf.supybot.protocols.irc.strictRfc() and \
                     target.startswith('$'):
                 # Select the last part, or the whole target:
                 bannedNick = target.split(':')[-1]
                 banmask = bannedHostmask = target
             else:
                 irc.error(format(_('I haven\'t seen %s.'), bannedNick), Raise=True)
     else:
         bannedNick = ircutils.nickFromHostmask(target)
         banmask = bannedHostmask = target
     if not irc.isNick(bannedNick):
         self.log.warning('%q tried to kban a non nick: %q',
                          msg.prefix, bannedNick)
         raise callbacks.ArgumentError
     elif bannedNick == irc.nick:
         self.log.warning('%q tried to make me kban myself.', msg.prefix)
         irc.error(_('I cowardly refuse to kickban myself.'))
         return
     if not reason:
         reason = msg.nick
     capability = ircdb.makeChannelCapability(channel, 'op')
     # Check (again) that they're not trying to make us kickban ourself.
     if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
         if ircutils.hostmaskPatternEqual(bannedHostmask, irc.prefix):
             self.log.warning('%q tried to make me kban myself.',msg.prefix)
             irc.error(_('I cowardly refuse to ban myself.'))
             return
         else:
             self.log.warning('Using exact hostmask since banmask would '
                              'ban myself.')
             banmask = bannedHostmask
     # Now, let's actually get to it.  Check to make sure they have
     # #channel,op and the bannee doesn't have #channel,op; or that the
     # bannee and the banner are both the same person.
     def doBan():
         if irc.state.channels[channel].isOp(bannedNick):
             irc.queueMsg(ircmsgs.deop(channel, bannedNick))
         irc.queueMsg(ircmsgs.ban(channel, banmask))
         if kick:
             irc.queueMsg(ircmsgs.kick(channel, bannedNick, reason))
         if expiry > 0:
             def f():
                 if channel in irc.state.channels and \
                    banmask in irc.state.channels[channel].bans:
                     irc.queueMsg(ircmsgs.unban(channel, banmask))
             schedule.addEvent(f, expiry)
     if bannedNick == msg.nick:
         doBan()
     elif ircdb.checkCapability(msg.prefix, capability):
         if ircdb.checkCapability(bannedHostmask, capability) and \
                 not ircdb.checkCapability(msg.prefix, 'owner'):
             self.log.warning('%s tried to ban %q, but both have %s',
                              msg.prefix, bannedHostmask, capability)
             irc.error(format(_('%s has %s too, you can\'t ban '
                              'them.'), bannedNick, capability))
         else:
             doBan()
     else:
         self.log.warning('%q attempted kban without %s',
                          msg.prefix, capability)
         irc.errorNoCapability(capability)
Beispiel #46
0
 def f(m, arg=arg):
     return ircutils.hostmaskPatternEqual(arg, m.nick)
Beispiel #47
0
    def chanban(self, irc, msg, args,
              channel, optlist, bannedHostmask, expiry, reason):
         """[<channel>] [--{exact,nick,user,host}] <hostmask> [<seconds>] [<reason>]
 
         If you have the #channel,op capability, this will ban <hostmask> for
         as many seconds as you specify, or else (if you specify 0 seconds or
         don't specify a number of seconds) it will ban the person indefinitely.
         --exact bans only the exact hostmask; --nick bans just the nick;
         --user bans just the user, and --host bans just the host.  You can
         combine these options as you choose.  <reason> is a reason to give for
         the kick.
         <channel> is only necessary if the message isn't sent in the channel
         itself.
         """
         # Check that they're not trying to make us kickban ourself.
         self.log.debug('In chanban')
         if not reason:
             reason = msg.nick
         capability = ircdb.makeChannelCapability(channel, 'op')
         def makeBanmask(bannedHostmask, options):
             (nick, user, host) = ircutils.splitHostmask(bannedHostmask)
             self.log.debug('*** nick: %s', nick)
             self.log.debug('*** user: %s', user)
             self.log.debug('*** host: %s', host)
             bnick = '*'
             buser = '******'
             bhost = '*'
             for option in options:
                 if option == 'nick':
                     bnick = nick
                 elif option == 'user':
                     buser = user
                 elif option == 'host':
                     bhost = host
                 elif option == 'exact':
                     (bnick, buser, bhost) = \
                                    ircutils.splitHostmask(bannedHostmask)
             return ircutils.joinHostmask(bnick, buser, bhost)
         if optlist:
             banmask = makeBanmask(bannedHostmask, [o[0] for o in optlist])
         else:
             banmask = makeBanmask(bannedHostmask,
                                   self.registryValue('banmask', channel))
         # Check (again) that they're not trying to make us kickban ourself.
         if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
             if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
                 self.log.warning('%q tried to make me chanban myself.',msg.prefix)
                 irc.error('I cowardly refuse to chanban myself.')
                 return
             else:
                 banmask = bannedHostmask
         # Now, let's actually get to it.  Check to make sure they have
         # #channel,op and the bannee doesn't have #channel,op; or that the
         # bannee and the banner are both the same person.
         def doBan():
             irc.queueMsg(ircmsgs.ban(channel, banmask))
             if expiry > 0:
                 def f():
                     if channel in irc.state.channels and \
                        banmask in irc.state.channels[channel].bans:
                         irc.queueMsg(ircmsgs.unban(channel, banmask))
                 schedule.addEvent(f, expiry)
         if ircdb.checkCapability(msg.prefix, capability):
             if ircdb.checkCapability(bannedHostmask, capability):
                 self.log.warning('%s tried to ban %q, but both have %s',
                                  msg.prefix, bannedHostmask, capability)
                 irc.error(format('%s has %s too, you can\'t ban him/her/it.',
                                  bannedHostmask, capability))
             else:
                 doBan()
         else:
             self.log.warning('%q attempted chanban without %s',
                              msg.prefix, capability)
             irc.errorNoCapability(capability)
             exact,nick,user,host
Beispiel #48
0
 def do352(self, irc, msg):
     for mask in self.whos:
         if ircutils.hostmaskPatternEqual(mask, str(msg)):
             self.whos[mask][1].append(msg)