Exemplo n.º 1
0
 def _exitChuck(self, cmd, args):
     """ Exit the console
     Usage: exit
     Details: Exit this program"""
     result = ''
     result += 'Exiting...'
     oMgr = CNBManager.getInstance()
     oMgr.killCNB()
     return '\n' + result
Exemplo n.º 2
0
 def _stopChuck(self, cmd, args):
     """ Stop CNB
     Usage: stop
     Details: Stop this program (become idle)"""
     result = ''
     result += 'Stopping...'
     oMgr = CNBManager.getInstance()
     oMgr.stopCNB()
     return '\n' + result
Exemplo n.º 3
0
 def _startChuck(self, cmd, args):
     """ Start CNB
     Usage: start
     Details: Start this program"""
     result = ''
     result += 'Starting...'
     oMgr = CNBManager.getInstance()
     oMgr.startCNB()
     return '\n' + result
Exemplo n.º 4
0
    def _processMod(self, oMsg):
        """
        This method, called by connector specific methods (ex. processIrcMod, processXmppMod), determine if the user has access to call the module and then trigger an event or reply.
        @param oMsg: Message object containing a message, status change or a command.
        @type oMsg: CNBMessage
        """
        result = ''
        oMgr = CNBManager.getInstance()
        aAdminUsers = oMgr.getConfigCNB(oMsg.conId).get('bot', 'admins')
        oMod = self.getModuleFromCmd(oMsg.cmd)
        if oMod:
            # check for allowed users
            if self.isAllowed(oMod.users, oMsg.username, oMsg.domain):

                # check for admin modules
                if not oMod.isAdmin or (oMod.isAdmin
                                        and oMsg.username in aAdminUsers):

                    # Is this a cmd?
                    if oMod.enProcessCmd:
                        result = oMod.processCmd(oMsg)

                else:
                    result = 'unauthorized (admin)'
            else:
                result = 'unauthorized (users)'
        else:
            # Can spot a pattern?
            for (p, c) in self._patterns:
                if c(oMsg):
                    result = p(oMsg)
                    if result != '':
                        break

            # Otherwise, check something else?
            if result == '':
                for v in self._always:
                    result = v(oMsg)
                    if result != '':
                        break

        # Logs
        if oMsg.text != '' and oMsg.replyTo != None:
            self.log.info(
                str(oMsg.replyTo) + ' -> ' + str(self.LOG_NICK) + '>' +
                str(oMsg.text))
        if result != '' and oMsg.replyTo != None:
            self.log.info(
                str(self.LOG_NICK) + ' -> ' + str(oMsg.replyTo) + '>' +
                str(result))

        return result
Exemplo n.º 5
0
    def _processMod(self, oMsg):
        """
        This method, called by connector specific methods (ex. processIrcMod, processXmppMod), determine if the user has access to call the module and then trigger an event or reply.
        @param oMsg: Message object containing a message, status change or a command.
        @type oMsg: CNBMessage
        """
        result = ''
        oMgr = CNBManager.getInstance()
        aAdminUsers = oMgr.getConfigCNB(oMsg.conId).get('bot', 'admins')
        oMod = self.getModuleFromCmd(oMsg.cmd)
        if oMod:
            # check for allowed users
            if self.isAllowed(oMod.users, oMsg.username, oMsg.domain):

                # check for admin modules
                if not oMod.isAdmin or (oMod.isAdmin and oMsg.username in aAdminUsers):
                    
                    # Is this a cmd?
                    if oMod.enProcessCmd:
                        result = oMod.processCmd(oMsg)

                else:
                    result = 'unauthorized (admin)'
            else:
                result = 'unauthorized (users)'
        else:
            # Can spot a pattern?
            for (p,c) in self._patterns:
                if c(oMsg):
                    result = p(oMsg)
                    if result != '':
                        break

            # Otherwise, check something else?
            if result == '':
                for v in self._always:
                    result = v(oMsg)
                    if result != '':
                        break

        # Logs
        if oMsg.text != '' and oMsg.replyTo != None:
            self.log.info(str(oMsg.replyTo) + ' -> ' + str(self.LOG_NICK) + '>' + str(oMsg.text))
        if result != '' and oMsg.replyTo != None:
            self.log.info(str(self.LOG_NICK) + ' -> ' + str(oMsg.replyTo) + '>' + str(result))

        return result
Exemplo n.º 6
0
Arquivo: cnbCore.py Projeto: OSSSP/cnb
    def __init__(self):
        Thread.__init__(self)
        oConfig = CNBConfig.getInstance()
        if oConfig.get('global', 'daemon'):
            self._bEnableShellConsole = False
        self.log = logging.getLogger(self.__class__.__name__)
        self._configLogs(oConfig)

        oMgr = CNBManager.getInstance()
        oMgr.setCNB(self)

        self.oConMgr = CNBConnectorManager()
        self.oConMgr.loadDefault()

        if self._bEnableShellConsole:
            self.oConsole = CNBConsole()
            self.oConsole.start()

        oMatrix = CNBMatrix.getInstance()
Exemplo n.º 7
0
    def __init__(self):
        Thread.__init__(self)
        oConfig = CNBConfig.getInstance()
        if oConfig.get('global', 'daemon'):
            self._bEnableShellConsole = False
        self.log = logging.getLogger(self.__class__.__name__)
        self._configLogs(oConfig)

        oMgr = CNBManager.getInstance()
        oMgr.setCNB(self)

        self.oConMgr = CNBConnectorManager()
        self.oConMgr.loadDefault()

        if self._bEnableShellConsole:
            self.oConsole = CNBConsole()
            self.oConsole.start()

        oMatrix = CNBMatrix.getInstance()