Exemplo n.º 1
0
 def addRule(self, aSrcList, aDstList):
     """
     """
     result = ''
     for dst in aDstList:
         dst = str(dst)
         if len(dst.split('@')) > 1:
             dom = str(dst.split('@')[1])
             if not self._spyRules.has_key(dst):
                 self._spyRules[dst] = {}
                 self._spyRules[dst]['list'] = set()
                 self._spyRules[dst]['conId'] = None
     
             oMgr = CNBManager.getInstance()
             conId = oMgr.getConIdCNB(dom)
             if conId:
                 self._spyRules[dst]['list'].update(aSrcList)
                 self._spyRules[dst]['conId'] = conId
                 for src in aSrcList:
                     src = str(src)
                     result += '%s -> %s rule was added successfuly' % (src,dst)
             else:
                 result += "The destination address ""%s"" could not be found \n" % dst
         else:
             result += "The destination address ""%s"" is invalid \n" % dst
     return result
Exemplo n.º 2
0
 def processCmd(self, oMsg):
     result = ""
     if len(oMsg.args) > 0:
         oConMgr = CNBManager.getInstance()
         result = oConMgr.joinCNB(oMsg.conId, oMsg.args[0])
     else:
         result = "Specify a chan/room name. Check help for more."
     return result
Exemplo n.º 3
0
 def processCmd(self, oMsg):
     result = ''
     if len(oMsg.args) > 0:
         oConMgr = CNBManager.getInstance()
         result = oConMgr.joinCNB(oMsg.conId,oMsg.args[0])
     else:
         result = 'Specify a chan/room name. Check help for more.'
     return result
Exemplo n.º 4
0
 def processCmd(self, oMsg):
     result = ''
     if len(oMsg.args) > 1:
         sUser = str(oMsg.args[0])
         sMsg = str(' '.join(oMsg.args[1::]))
         oConMgr = CNBManager.getInstance()
         result = oConMgr.sayCNB(oMsg.conId,sUser,sMsg)
     else:
         result = 'Specify a user and a message. Check help for more.'
     return result
Exemplo n.º 5
0
 def processCmd(self, oMsg):
     result = ''
     if len(oMsg.args) == 0:
         t = 0
     else:
         t = int(oMsg.args[0])
     oMgr = CNBManager.getInstance()
     oMgr.killCNB()
     result = self.MSG_OUTPUT
     return result
Exemplo n.º 6
0
 def processCmd(self, oMsg):
     result = ''
     if len(oMsg.args) == 0:
         t = 0
     else:
         t = int(oMsg.args[0])
     oMgr = CNBManager.getInstance()
     oMgr.killCNB()
     result = self.MSG_OUTPUT
     return result
Exemplo n.º 7
0
    def checkPattern(self,oMsg):
        oMgr = CNBManager.getInstance()
        if oMgr.getConfigCNB(oMsg.conId).has_option('bot', 'muc-domain'):
            sMucDomain = oMgr.getConfigCNB(oMsg.conId).get('bot', 'muc-domain')
        else:
            sMucDomain = ''

        if not oMsg.getSource().endswith(sMucDomain) and oMsg.presType == self.OFFLINE:
            return True
        else:
            return False
Exemplo n.º 8
0
    def checkPattern(self, oMsg):
        oMgr = CNBManager.getInstance()
        if oMgr.getConfigCNB(oMsg.conId).has_option('bot', 'muc-domain'):
            sMucDomain = oMgr.getConfigCNB(oMsg.conId).get('bot', 'muc-domain')
        else:
            sMucDomain = ''

        if not oMsg.getSource().endswith(
                sMucDomain) and oMsg.presType == self.OFFLINE:
            return True
        else:
            return False
Exemplo n.º 9
0
 def processCmd(self, oMsg):
     """
     @todo: Invite only people that are not in the room
     """
     result = ''
     if oMsg.protocol == 'xmpp-gtalk':
         oMgr = CNBManager.getInstance()
         sRoom = oMgr.getConfigCNB(oMsg.conId).get('bot', 'monday-suck-room')
         oMgr.inviteCNB(oMsg.conId,self.GTALK_INVITE_LIST,sRoom)
     else:
         result = 'not'
     return result
Exemplo n.º 10
0
    def processCmd(self, oMsg):
        result = ''
        if len(oMsg.args) > 1:
            hashType = oMsg.args[0].upper()
            stringList = oMsg.args[1::]

            # Create temporary file
            oConfig = CNBConfig.getInstance()
            sLogDir = oConfig.get('global', 'log-dir')
            tmpFileName = sLogDir + self.FIND_MY_HASH_FILE + strftime(
                "%Y-%m-%d_%H%M%S") + '.txt'
            if len(stringList) > 1:
                fh = open(tmpFileName, "w")
                for h in stringList:
                    fh.write(h + "\n")
                fh.close()
            else:
                fh = open(tmpFileName, "w")
                fh.write(stringList[0] + "\n")
                fh.close()

            sTpDir = oConfig.get('global', 'tp-dir')
            cmd = copy(self.FIND_MY_HASH_CMD)
            cmd[0] = sTpDir + cmd[0]
            cmd.insert(1, hashType)
            cmd.append(tmpFileName)
            self.log.info(str(cmd))

            # Telling the user that the hash will be cracked
            oConMgr = CNBManager.getInstance()
            oConMgr.sayCNB(oMsg.conId, oMsg.getSource(), self.MSG_CRACKING)

            # Process and reply
            result = subprocess.Popen(cmd,
                                      stdout=subprocess.PIPE).communicate()[0]

            # If the pass was cracked, remove some crap before sending results
            if self.MSG_CRACKED in result:
                result = result[result.find(self.MSG_CRACKED)::]
                fh = open(tmpFileName, "a")
                fh.write(result + "\n")
                fh.close()
        else:
            result = "This cmd takes at least 2 arguments, check help"
        return result
Exemplo n.º 11
0
    def processCmd(self, oMsg):
        result = ''
        if len(oMsg.args) > 1:
            hashType = oMsg.args[0].upper()
            stringList = oMsg.args[1::]
            
            # Create temporary file
            oConfig = CNBConfig.getInstance()
            sLogDir = oConfig.get('global', 'log-dir')
            tmpFileName = sLogDir + self.FIND_MY_HASH_FILE + strftime("%Y-%m-%d_%H%M%S") + '.txt'
            if len(stringList) > 1:
                fh = open(tmpFileName,"w")
                for h in stringList:
                    fh.write(h + "\n")
                fh.close()
            else:
                fh = open(tmpFileName,"w")
                fh.write(stringList[0] + "\n")
                fh.close()
                
            sTpDir = oConfig.get('global', 'tp-dir')
            cmd = copy(self.FIND_MY_HASH_CMD)
            cmd[0] = sTpDir + cmd[0]
            cmd.insert(1, hashType)
            cmd.append(tmpFileName)
            self.log.info(str(cmd))

            # Telling the user that the hash will be cracked
            oConMgr = CNBManager.getInstance()
            oConMgr.sayCNB(oMsg.conId,oMsg.getSource(),self.MSG_CRACKING)

            # Process and reply
            result = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]

            # If the pass was cracked, remove some crap before sending results
            if self.MSG_CRACKED in result:
                result = result[result.find(self.MSG_CRACKED)::]
                fh = open(tmpFileName,"a")
                fh.write(result + "\n")
                fh.close()
        else:
            result = "This cmd takes at least 2 arguments, check help"
        return result
Exemplo n.º 12
0
 def checkPattern(self,oMsg):
     """
     """
     oMgr = CNBManager.getInstance()
     bAutoJoin = oMgr.getConfigCNB(oMsg.conId).get('bot', 'auto-join')
     if oMgr.getConfigCNB(oMsg.conId).has_option('bot', 'muc-domain'):
         sMucDomain = oMgr.getConfigCNB(oMsg.conId).get('bot', 'muc-domain')
     else:
         sMucDomain = ''
     if bAutoJoin \
         and oMsg.room != None \
         and oMsg.text != None \
         and oMsg.room.endswith(sMucDomain) \
         and ((oMsg.protocol == 'xmpp-gtalk' and self.GMAIL_ROOM_INVITE_TEXT in oMsg.text) \
             or (oMsg.protocol == 'xmpp' and self.JAB_ROOM_INVITE_TEXT+' '+oMsg.room in oMsg.text) \
             or (oMsg.protocol.startswith('irc'))):
         return True
     else:
         return False
Exemplo n.º 13
0
    def processCmd(self, oMsg):
        oMatrix = CNBMatrix.getInstance()
        oMgr = CNBManager.getInstance()

        sUser = oMsg.jid
        prot = oMsg.protocol
        sInitCmd = oMsg.cmd
        sInitArgs = oMsg.args

        # For all protocols
        for sCmd in self._allCmds:
            oMsg.text = sCmd
            oMsg.initCmd()
            if prot.startswith('xmpp'):
                result = 'cmd: ' + sCmd + "\nresult: " + oMatrix.processXmppMod(oMsg)
            elif prot.startswith('irc'):
                result = 'cmd: ' + sCmd + "\nresult: " + oMatrix.processIrcMod(oMsg)
            oMgr.sayCNB(oMsg.conId,sUser,result)
            sleep(1)

        # For xmpp only
        for sCmd in self._xmppCmds:
            oMsg.text = sCmd
            oMsg.initCmd()
            if prot.startswith('xmpp'):
                result = 'cmd: ' + sCmd + "\nresult: " + oMatrix.processXmppMod(oMsg)
            oMgr.sayCNB(oMsg.conId,sUser,result)
            sleep(1)

        # For irc only
        for sCmd in self._ircCmds:
            oMsg.text = sCmd
            oMsg.initCmd()
            if prot.startswith('irc'):
                result = 'cmd: ' + sCmd + "\nresult: " + oMatrix.processIrcMod(oMsg)
            oMgr.sayCNB(oMsg.conId,sUser,result)
            sleep(1)

        return ''
Exemplo n.º 14
0
 def sayTrivia(self, msg):
     oMgr = CNBManager.getInstance()
     return oMgr.sayCNB(self._conId, self._room, msg)
Exemplo n.º 15
0
    def processCmd(self, oMsg):
        result = 'Missing arguments, check help'
        (args, err) = self.getParsedArgs(oMsg.args)

        globalConfig = CNBConfig.getInstance()
        oMgr = CNBManager.getInstance()
        instConfig = oMgr.getConfigCNB(oMsg.conId)
        if self._aGameInst.has_key(oMsg.conId):
            oGame = self._aGameInst[oMsg.conId]
        else:
            oGame = None
        
        if self._isAllowed(self._aLocalUsers, oMsg.username, oMsg.domain, args):    
            if err != '':
                result = err
            elif args.adm_start:
                if not oGame:
                    if not oMsg.isPrivate:
                        oGame = CNBMMTriviaGame(oMsg.conId,oMsg.room)
                        self._aGameInst[oMsg.conId] = oGame
                        result = 'Starting the trivia game'
                    else:
                        result = 'You must start trivia in a public room/chan'
                else:
                    result = 'Game already started'
            elif args.adm_starttime:
                if not oGame:
                    if not oMsg.isPrivate:
                        try:
                            f = '%Y-%m-%d_%H:%M'
                            v = ' '.join(args.adm_starttime)
                            d = datetime.strptime(v, f)
                            isValid = (v == d.strftime(f)) # this makes sure the parsed date matches the original string
                        except ValueError:
                            isValid = False
                        if isValid:
                            oGame = CNBMMTriviaGame(oMsg.conId,oMsg.room,d)
                            self._aGameInst[oMsg.conId] = oGame
                            result = 'Game will start on ' + str(args.adm_starttime)
                        else:
                            result = 'Bad date/time format'
                    else:
                        result = 'You must start trivia in a public room/chan'
                else:
                    result = 'Game already started'
            elif args.adm_stop: 
                if oGame:
                    if not oMsg.isPrivate:
                        oGame.stopTrivia()
                        del oGame
                        oGame = None
                        self._aGameInst.pop(oMsg.conId)
                        result = 'Stopping...'
                    else:
                        result = 'You must stop trivia in a public room/chan'
                else:
                    result = 'Game not started yet'
            elif args.adm_next:
                if oGame:
                    oGame.chgQt()
                    result = ''
                else:
                    result = 'Game not started yet'
            elif args.adm_save:
                if oGame:
                    result = oGame.save()
                else:
                    result = 'Game not started yet'
            elif args.adm_load:
                if oGame:
                    result = oGame.load()
                else:
                    result = 'Game not started yet'
            elif args.adm_status:
                if oGame:
                    result = oGame.getStatus()
                else:
                    result = 'Game not started yet'
            elif args.adm_qinfo:
                if oGame:
                    if oMsg.isPrivate:
                        v = args.adm_qinfo[0]
                        result = oGame.getQuestionInfo(v)
                    else:
                        result = 'You must submit in private'
                else:
                    result = 'Game not started yet'
            elif args.answer:
                if oGame: 
                    if oMsg.isPrivate:
                        v = ' '.join(args.answer)
                        result = oGame.submitAnswer(oMsg.username, v)
                        #result = oGame.submitAnswer(oMsg.username, args.answer)
                    else:
                        result = 'You must submit in private'
                else:
                    result = 'Game not started yet'
            elif args.question: 
                if oGame:
                    result = oGame.getCurQtMsg()
                else:
                    result = 'Game not started yet'
            elif args.score: 
                if oGame:
                    result = "Score: \n" + oGame.getResult()
                else:
                    result = 'Game not started yet'
            elif args.help:
                result = self.getUsage()
            else:
                result = self.getUsage()
        else:
            result = 'Unauthorized :)'

        return result
Exemplo n.º 16
0
 def processPattern(self, oMsg):
     result = ''
     oMgr = CNBManager.getInstance()
     result = oMgr.joinCNB(oMsg.conId,oMsg.room)
     return result
Exemplo n.º 17
0
 def _send(self, oMsg, conId, dst):
     sMsg = '[' + oMsg.getFullSource() + '] ' + str(oMsg.text)
     oConMgr = CNBManager.getInstance()
     result = oConMgr.sayCNB(conId,dst,sMsg)
Exemplo n.º 18
0
    def processCmd(self, oMsg):
        result = 'Missing arguments, check help'
        (args, err) = self.getParsedArgs(oMsg.args)

        globalConfig = CNBConfig.getInstance()
        oMgr = CNBManager.getInstance()
        instConfig = oMgr.getConfigCNB(oMsg.conId)
        if self._aGameInst.has_key(oMsg.conId):
            oGame = self._aGameInst[oMsg.conId]
        else:
            oGame = None

        if self._isAllowed(self._aLocalUsers, oMsg.username, oMsg.domain,
                           args):
            if err != '':
                result = err
            elif args.adm_start:
                if not oGame:
                    if not oMsg.isPrivate:
                        oGame = CNBMMTriviaGame(oMsg.conId, oMsg.room)
                        self._aGameInst[oMsg.conId] = oGame
                        result = 'Starting the trivia game'
                    else:
                        result = 'You must start trivia in a public room/chan'
                else:
                    result = 'Game already started'
            elif args.adm_starttime:
                if not oGame:
                    if not oMsg.isPrivate:
                        try:
                            f = '%Y-%m-%d_%H:%M'
                            v = ' '.join(args.adm_starttime)
                            d = datetime.strptime(v, f)
                            isValid = (
                                v == d.strftime(f)
                            )  # this makes sure the parsed date matches the original string
                        except ValueError:
                            isValid = False
                        if isValid:
                            oGame = CNBMMTriviaGame(oMsg.conId, oMsg.room, d)
                            self._aGameInst[oMsg.conId] = oGame
                            result = 'Game will start on ' + str(
                                args.adm_starttime)
                        else:
                            result = 'Bad date/time format'
                    else:
                        result = 'You must start trivia in a public room/chan'
                else:
                    result = 'Game already started'
            elif args.adm_stop:
                if oGame:
                    if not oMsg.isPrivate:
                        oGame.stopTrivia()
                        del oGame
                        oGame = None
                        self._aGameInst.pop(oMsg.conId)
                        result = 'Stopping...'
                    else:
                        result = 'You must stop trivia in a public room/chan'
                else:
                    result = 'Game not started yet'
            elif args.adm_next:
                if oGame:
                    oGame.chgQt()
                    result = ''
                else:
                    result = 'Game not started yet'
            elif args.adm_save:
                if oGame:
                    result = oGame.save()
                else:
                    result = 'Game not started yet'
            elif args.adm_load:
                if oGame:
                    result = oGame.load()
                else:
                    result = 'Game not started yet'
            elif args.adm_status:
                if oGame:
                    result = oGame.getStatus()
                else:
                    result = 'Game not started yet'
            elif args.adm_qinfo:
                if oGame:
                    if oMsg.isPrivate:
                        v = args.adm_qinfo[0]
                        result = oGame.getQuestionInfo(v)
                    else:
                        result = 'You must submit in private'
                else:
                    result = 'Game not started yet'
            elif args.answer:
                if oGame:
                    if oMsg.isPrivate:
                        v = ' '.join(args.answer)
                        result = oGame.submitAnswer(oMsg.username, v)
                        #result = oGame.submitAnswer(oMsg.username, args.answer)
                    else:
                        result = 'You must submit in private'
                else:
                    result = 'Game not started yet'
            elif args.question:
                if oGame:
                    result = oGame.getCurQtMsg()
                else:
                    result = 'Game not started yet'
            elif args.score:
                if oGame:
                    result = "Score: \n" + oGame.getResult()
                else:
                    result = 'Game not started yet'
            elif args.help:
                result = self.getUsage()
            else:
                result = self.getUsage()
        else:
            result = 'Unauthorized :)'

        return result
Exemplo n.º 19
0
 def sayTrivia(self,msg):
     oMgr = CNBManager.getInstance()
     return oMgr.sayCNB(self._conId,self._room,msg)