Ejemplo n.º 1
0
    def mode(self, user, line):
        if utilities.validate(line, 2):
            self.trigger("not_enough_params", user, "MODE")
            return

        if not utilities.validate(line, 3):
            modes = " ".join(line[2:])
        else:
            modes = ""

        if line[1].startswith("#"):
            self.trigger("channels_mode", user, line[1][:30], modes)
        else:
            self.trigger("user_modes", user, line[1], "")
Ejemplo n.º 2
0
    def nick(self, user, line):
        connected = user.connected()

        if utilities.validate(line, 2):
            self.trigger('no_nickname', user)
            return

        nick = line[1][:15].lstrip(':')

        if not utilities.nick_re.match(nick):
            self.trigger('bad_nick', user, nick)
            return

        if self.trigger('find_user', nick):
            self.trigger('nick_in_use', user, nick)
            return

        if not user.connected():
            self.trigger('send_ping', user)

        if connected:
            self.trigger('user_nicked', user, nick)

        user.info['nick'] = nick

        if not connected and user.connected():
            self.trigger('user_registered', user)
Ejemplo n.º 3
0
    def privmsg(self, user, line):
        if utilities.validate(line, 2):
            self.trigger('no_recip', user)
            return

        if utilities.validate(line, 3):
            self.trigger('no_text', user)
            return

        message = utilities.join_msg(line[2:])
        if utilities.ctcp_re.match(message):
            self.trigger('attempted_ctcp', user)
            return

        if line[1].startswith('#'):
            self.trigger('channels_privmsg', user, line[1][:30], message)
        else:
            self.trigger('user_privmsg', user, line[1][:15], message)
Ejemplo n.º 4
0
    def topic(self, user, line):
        if utilities.validate(line, 2):
            self.trigger('not_enough_params', user, 'TOPIC')
            return

        if not utilities.validate(line, 3):
            new_topic = utilities.join_msg(line[2:])
        else:
            new_topic = None

        if not line[1].startswith('#'):
            channel = '#' + line[1]
        else:
            channel = line[1]

        channel = channel[:30]
        if utilities.chan_re.match(channel):
            self.trigger('channels_topic', user, channel, new_topic)
Ejemplo n.º 5
0
    def notice(self, user, line):
        if utilities.validate(line, 2):
            self.trigger("no_recip", user)
            return

        if utilities.validate(line, 3):
            self.trigger("no_text", user)
            return

        message = utilities.join_msg(line[2:])
        if utilities.ctcp_re.match(message):
            self.trigger("attempted_ctcp", user)
            return

        if line[1].startswith("#"):
            pass
        else:
            self.trigger("user_notice", user, line[1][:15], message)
Ejemplo n.º 6
0
    def names(self, user, line):
        if utilities.validate(line, 2):
            self.trigger('not_enough_params', user, 'NAMES')
            return

        if not line[1].startswith('#'):
            line[1] = '#' + line[1]

        chan = line[1][:30]
        self.trigger('channels_names', user, chan)
Ejemplo n.º 7
0
    def vhost(self, user, line):
        if utilities.validate(line, 2):
            self.trigger('not_enough_params', user, 'VHOST')
            return

        if not utilities.host_re.match(line[1]):
            self.trigger('bad_host', user, line[1])
            return

        user.info['hostname'] = line[1][:30]
Ejemplo n.º 8
0
    def setuser(self, user, line):
        if utilities.validate(line, 2):
            self.trigger('not_enough_params', user, 'SETUSER')
            return

        if not utilities.nick_re.match(line[1]):
            self.trigger('bad_nick', user, line[1])
            return

        user.info['user'] = line[1][:15]
Ejemplo n.º 9
0
    def kick(self, user, line):
        if utilities.validate(line, 3):
            self.trigger('not_enough_params', user, 'KICK')
            return

        if not utilities.validate(line, 4):
            message = utilities.join_msg(line[3:])
        else:
            message = 'kicked'

        if not line[1].startswith('#'):
            chan = '#' + line[1]
        else:
            chan = line[1]

        chan = chan[:30]
        if not utilities.chan_re.match(chan):
            return

        self.trigger('channels_kick', user, chan, line[2][:15], message)
Ejemplo n.º 10
0
    def who(self, user, line):
        if utilities.validate(line, 2):
            self.trigger('not_enough_params', user, 'WHO')
            return

        if not line[1].startswith('#'):
            self.trigger('user_who', user, line[1][:15], line[1][:15])
        else:
            chan = line[1][:30]
            if utilities.chan_re.match(chan):
                self.trigger('channels_who', user, chan)

        self.trigger('end_who', user, line[1])
Ejemplo n.º 11
0
    def part(self, user, line):
        if utilities.validate(line, 2):
            self.trigger("not_enough_params", user, "PART")
            return

        if len(line) > 2 and line[2]:
            message = utilities.join_msg(line[2:])
        else:
            message = ""

        chans = line[1].split(",")
        for chan in chans:
            if not chan.startswith("#"):
                chan = "#" + chan
            chan = chan[:30]
            if utilities.chan_re.match(chan):
                self.trigger("channels_part", user, chan, message)
Ejemplo n.º 12
0
    def list_chans(self, user, line):
        if not config.get(user, 'oper') or utilities.validate(line, 2):
            return

        allow_chans = config.get(line[1], 'chan_allow', True) or []
        deny_chans = config.get(line[1], 'chan_deny', True) or []

        for chan in allow_chans:
            if chan in deny_chans:
                deny_chans.remove(chan)

        user.srv_notice('%s : [*] Allowed channels:' % (user.info['nick']))
        for chan in allow_chans:
            user.srv_notice('%s : - %s' % (user.info['nick'], chan))

        user.srv_notice('%s : [*] Denied channels:' % (user.info['nick']))
        for chan in deny_chans:
            user.srv_notice('%s : - %s' % (user.info['nick'], chan))
Ejemplo n.º 13
0
    def manage_chan(self, user, line, deny=True):
        if not config.get(user, 'oper') or utilities.validate(line, 2):
            return

        allow_chans = Set([])
        deny_chans  = Set([])
        blocks      = []

        for listen in config.get(None, 'listen'):
            if 'user' in listen and listen['user'] == line[1]:
                blocks.append(listen)

        if not blocks:
            user.srv_notice('%s: [!] User not found: %s' % (user.info['nick'], line[1]))
            return

        action = 'Allow'
        if deny:
            action = 'Deny'

        user.srv_notice('%s : [*] %sing channel: %s' % (user.info['nick'], action, line[2]))

        for block in blocks:
            def merge(elem, chans):
                if elem not in block:
                    return
                chans.update(block[elem])

            merge('chan_allow', allow_chans)
            merge('chan_deny', deny_chans)

        if deny:
            allow_chans.discard(line[2])
            deny_chans.add(line[2])
        else:
            allow_chans.add(line[2])
            deny_chans.discard(line[2])

        for block in blocks:
            block['chan_allow'] = list(allow_chans)
            block['chan_deny'] = list(deny_chans)

        config.write_config()
Ejemplo n.º 14
0
    def spawn(self, user, line):
        if not config.get(user, "oper") or utilities.validate(line, 2):
            return

        def _spawn():
            user.srv_notice("%s : [*] Spawning onion for %s" % (user.info["nick"], line[1]))

            u = GetUser(line[1])
            if not u.exists:
                u.create()
                user.srv_notice("%s : - Added user %s onion: %s" % (user.info["nick"], line[1], u.onion()))
            else:
                user.srv_notice("%s : - User %s already exists!" % (user.info["nick"], line[1]))
            self.thread = None

        if hasattr(self, "thread") and self.thread:
            user.srv_notice("%s : [!] Spawn or banish already in progress." % user.info["nick"])
        else:
            self.thread = threading.Thread(target=_spawn)
            self.thread.start()
Ejemplo n.º 15
0
    def banish(self, user, line):
        if not config.get(user, "oper") or utilities.validate(line, 2):
            return

        def _banish():
            user.srv_notice("%s : [*] Banishing %s!" % (user.info["nick"], line[1]))
            u = GetUser(line[1])
            if u.exists:
                for port in u.banish():
                    self.trigger("close_server_sock", port[0], port[1])
                user.srv_notice("%s : - Banished %s!" % (user.info["nick"], line[1]))
            else:
                user.srv_notice("%s : - User %s does not exist!" % (user.info["nick"], line[1]))
            self.thread = None

        if hasattr(self, "thread") and self.thread:
            user.srv_notice("%s : [!] Spawn or banish already in progress." % user.info["nick"])
        else:
            user.thread = threading.Thread(target=_banish)
            user.thread.start()
Ejemplo n.º 16
0
    def whois(self, user, line):
        if utilities.validate(line, 2):
            self.trigger('no_nickname', user)
            return

        self.trigger('user_whois', user, line[1][:15])