Esempio n. 1
0
def check_auth(server, user):
    if 'username' not in user:
        return

    if user['nick'] == '*':
        return

    data = {
        'nick': user['nick'],
        'username': user['username'],
        'realname': decolon(user['realname']),
        'expires': time.time() + 60
    }

    hex_data = json.dumps(data).encode('hex')
    h = hmac.new(server.config.hmac_key, hex_data, hashlib.sha256)
    dispatch(server, user, 'AUTH %s %s' % (hex_data, h.hexdigest()))
Esempio n. 2
0
File: kernel.py Progetto: hcit/ircd
    def user_message(self, tag, message):
        logging.debug('message %s %s', tag, message)

        self.timeout.update(tag)

        user = self.load_user(tag)
        if not user:
            logging.error('user %s not found' % tag)
            return

        try:
            message.decode('utf-8')
        except:
            self.send_reply(user, 'ERR_NONUTF8')
            return

        command.dispatch(self, user, message)
Esempio n. 3
0
def check_auth(server, user):
    if 'username' not in user:
        return

    if user['nick'] == '*':
        return

    data = {
        'nick': user['nick'],
        'username': user['username'],
        'realname': decolon(user['realname']),
        'expires': time.time() + 60
    }

    hex_data = msgpack.dumps(data).encode('hex')
    h = hmac.new(server.config.hmac_key, hex_data, hashlib.sha256)
    dispatch(server, user, 'AUTH %s %s' % (hex_data, h.hexdigest()))
Esempio n. 4
0
    def user_disconnect(self, tag, reason):
        logging.debug('disconnect %s %s', tag, reason)

        self.timeout.remove(tag)

        user = self.load_user(tag)
        if not user:
            logging.error('user %s not found' % tag)
            return

        chans = self.user_chans(user)
        for chan_name in chans:
            command.dispatch(self, user, 'PART %s' % chan_name)

        if 'auth' in user:
            self.unregister_nick(user)

        self.redis.delete('user:'******'server-users:' + prefix, tag)
Esempio n. 5
0
    def user_message(self, tag, message):
        logging.debug('message %s %s', tag, message)

        self.timeout.update(tag)

        message = message.strip()
        if not message:
            return

        user = self.load_user(tag)
        if not user:
            logging.error('user %s not found' % tag)
            return

        try:
            message.decode('utf-8')
        except:
            self.send_reply(user, 'ERR_NONUTF8')
            return

        command.dispatch(self, user, message)
Esempio n. 6
0
    def user_disconnect(self, tag, reason):
        logging.debug('disconnect %s %s', tag, reason)

        self.timeout.remove(tag)

        user = self.load_user(tag)
        if not user:
            logging.error('user %s not found' % tag)
            return

        chans = self.user_chans(user)
        for chan_name in chans:
            command.dispatch(self, user, 'PART %s' % chan_name)

        if 'auth' in user:
            self.unregister_nick(user)

        self.redis.delete('user:'******'server-users:' + prefix, tag)
Esempio n. 7
0
    def parse(self):
        '''Parse IRC protocol and call methods based on the results.'''

        global pattern

        # Go through every line in the recvq.
        while len(self.recvq):
            line = self.recvq.popleft()

            event.dispatch('OnParse', self.server, line)

            logger.debug('%s: %s -> %s' %
                         (self.server['id'], self.server['address'], line))
            parv = []

            # Split this crap up with the help of RE.
            try:
                origin, cmd, target, message = pattern.match(line).groups()
            except AttributeError:
                continue

            # Make an IRC parameter argument vector.
            if target:
                parv.append(target)

            parv.append(message)

            # Now see if the command is handled by the hash table.
            try:
                command.irc[cmd]
            except KeyError:
                pass

            if var.conf.get('options', 'irc_cmd_thread')[0]:
                command.dispatch(True, command.irc, cmd, self, origin, parv)
            else:
                command.dispatch(False, command.irc, cmd, self, origin, parv)

            if cmd == 'PING':
                event.dispatch('OnPING', self.server, parv[0])
                self.sendq.appendleft('PONG :%s' % parv[0])

            if cmd == '001':
                for i in self.server['chans']:
                    self.sendq.appendleft('JOIN %s' % i)
                    event.dispatch('OnJoinChannel', self.server, i)

            if cmd == 'PRIVMSG':
                try:
                    n, u, h = dissect_origin(origin)
                except:
                    return

                # Check to see if it's a channel.
                if parv[0].startswith('#') or parv[0].startswith('&'):
                    # Do the `chan_cmd` related stuff.
                    cmd = parv[1].split()

                    if not cmd:
                        return

                    # Chop the command off, as we don't want that.
                    message = cmd[1:]
                    message = ' '.join(message)
                    cmd = cmd[0].upper()

                    # Have we been addressed?
                    # If so, do the `chanme_cmd` related stuff.
                    if parv[1].startswith(self.server['nick']):
                        message = message.split()

                        if not message:
                            return

                        cmd = message[0].upper()
                        del message[0]
                        message = ' '.join(message)

                        # Call the handlers.
                        try:
                            command.chanme[cmd]
                        except KeyError:
                            return

                        if var.conf.get('options', 'chanme_cmd_thread')[0]:
                            command.dispatch(True, command.chanme, cmd, self,
                                             (n, u, h), parv[0], message)
                        else:
                            command.dispatch(False, command.chanme, cmd, self,
                                             (n, u, h), parv[0], message)
                    else:
                        # Call the handlers.
                        try:
                            command.chan[cmd]
                        except KeyError:
                            return

                        if var.conf.get('options', 'chan_cmd_thread')[0]:
                            command.dispatch(True, command.chan,
                                             self.server['trigger'] + cmd,
                                             self, (n, u, h), parv[0], message)
                        else:
                            command.dispatch(False, command.chan,
                                             self.server['trigger'] + cmd,
                                             self, (n, u, h), parv[0], message)
                else:
                    # CTCP?
                    if parv[1].startswith('\1'):
                        parv[1] = parv[1].strip('\1')
                        cmd = parv[1].split()

                        if not cmd:
                            return

                        message = cmd[1:]
                        message = ' '.join(message)
                        cmd = cmd[0].upper()

                        # Call the handlers.
                        try:
                            command.ctcp[cmd]
                        except KeyError:
                            return

                        if var.conf.get('options', 'ctcp_cmd_thread')[0]:
                            command.dispatch(True, command.ctcp, cmd, self,
                                             (n, u, h), message)
                        else:
                            command.dispatch(False, command.ctcp, cmd, self,
                                             (n, u, h), message)
                    else:
                        cmd = parv[1].split()

                        if not cmd:
                            return

                        message = cmd[1:]
                        message = ' '.join(message)
                        cmd = cmd[0].upper()

                        # Call the handlers.
                        try:
                            command.priv[cmd]
                        except KeyError:
                            try:
                                cmd = cmd[1:]
                                command.priv[cmd]
                            except KeyError:
                                return

                            if var.conf.get('options', 'priv_cmd_thread')[0]:
                                command.dispatch(True, command.priv, cmd, self,
                                                 (n, u, h), message)
                            else:
                                command.dispatch(False, command.priv, cmd,
                                                 self, (n, u, h), message)