Ejemplo n.º 1
0
def init():
    """ called after reload """
    saymonitor.start()
    jabbermonitor.start()
    saymonitor.add('relay', saycb, prerelaysay, True)
    jabbermonitor.add('relay', jabbersaycb, jabberprerelaysay, True)
    return 1
Ejemplo n.º 2
0
    def _connect(self, reconnect=True):
        """ connect to server .. start read loop. """

        try:
            self.username = self.user.split('@')[0]
        except ValueError:
            raise Exception("i need config user with a @ in it")

        self.me = self.user
        self.jid = xmpp.JID(self.user)
        self.server = self.jid.getDomain()
        self.nick = self.username
        rlog(10, self.name, 'connecting to %s' % self.server)

        if config['debug']:
            self.connection = xmpp.Client(self.server,
                                          debug=['always', 'nodebuilder'])
        else:
            self.connection = xmpp.Client(self.server, debug=[])

        time.sleep(2)

        try:
            try:
                import DNS
                self.connection.connect()
            except (ImportError, ValueError):
                if config['debug']:
                    self.connection = xmpp.Client(
                        self.server, debug=['always', 'nodebuilder'])
                else:
                    self.connection = xmpp.Client(self.server, debug=[])
                self.connection.connect((self.host, self.port))
        except AttributeError:
            handle_exception()
            rlog(10, self.name, "can't connect to %s" % self.host)
            return

        if not self.connection:
            rlog(10, self.name, "can't connect to %s" % self.host)
            return

        try:
            rlog(10, self.name, 'doing auth')
            auth = self.connection.auth(self.username, self.password, \
'gozerbot')
        except AttributeError:
            #handle_exception()
            rlog(10, self.name, "can't auth to %s" % self.host)
            return

        if not auth:
            rlog(10, self.name, 'auth for %s failed .. trying register' \
% self.username)
            info = {'username': self.username, 'password': self.password}
            xmpp.features.getRegInfo(self.connection, self.host, info)
            if not xmpp.features.register(self.connection, self.host, info):
                rlog(100, self.name, "can't register")
                return
            else:
                self.connection = xmpp.Client(self.server, debug=[])
                self.connection.connect((self.host, self.port))
                auth = self.connection.auth(self.username, self.password,
                                            'gozerbot')
                rlog(100, self.name, "register succeded")
        self.connecttime = time.time()
        rlog(100, self.name, 'connected! type: %s' % \
self.connection.connected)
        self.connection.RegisterHandler('message', self.messageHandler)
        self.connection.RegisterHandler('presence', self.presenceHandler)
        self.connection.RegisterHandler('iq', self.iqHandler)
        self.connection.UnregisterDisconnectHandler(\
self.connection.DisconnectHandler)
        self.connection.RegisterDisconnectHandler(self.disconnectHandler)
        self.connection.UnregisterHandlerOnce = self.UnregisterHandlerOnce
        self.stopped = 0
        jabbermonitor.start()
        start_new_thread(self._doprocess, ())
        start_new_thread(self._keepalive, ())
        start_new_thread(self._outputloop, ())
        start_new_thread(self._keepchannelsalive, ())
        self.connection.sendInitPresence()
        #self.connection.getRoster()
        self.connectok.set()
        return 1
Ejemplo n.º 3
0
    def _connect(self, reconnect=True):

        """ connect to server .. start read loop. """

        try:
            self.username = self.user.split('@')[0]
        except ValueError:
            raise Exception("i need config user with a @ in it")

        self.me = self.user
        self.jid = xmpp.JID(self.user)
        self.server = self.jid.getDomain()
        self.nick = self.username
        rlog(10, self.name, 'connecting to %s' % self.server)

        if config['debug']:
            self.connection = xmpp.Client(self.server, debug=['always', 'nodebuilder'])
        else:
            self.connection = xmpp.Client(self.server, debug=[])

        time.sleep(2)

        try:
            try:
                import DNS
                self.connection.connect()
            except (ImportError, ValueError):
                if config['debug']:
                    self.connection = xmpp.Client(self.server, debug=['always', 'nodebuilder'])
                else:
                    self.connection = xmpp.Client(self.server, debug=[])
                self.connection.connect((self.host, self.port))
        except AttributeError:
            handle_exception()
            rlog(10, self.name, "can't connect to %s" % self.host)
            return

        if not self.connection:
            rlog(10, self.name, "can't connect to %s" % self.host)
            return

        try:
            rlog(10, self.name, 'doing auth')
            auth = self.connection.auth(self.username, self.password, \
'gozerbot')
        except AttributeError:
            #handle_exception()
            rlog(10, self.name, "can't auth to %s" % self.host)
            return

        if not auth:
            rlog(10, self.name, 'auth for %s failed .. trying register' \
% self.username)
            info = {'username': self.username, 'password': self.password}
            xmpp.features.getRegInfo(self.connection, self.host, info)
            if not xmpp.features.register(self.connection, self.host, info):
                rlog(100, self.name, "can't register")
                return
            else:
                self.connection = xmpp.Client(self.server, debug=[])
                self.connection.connect((self.host, self.port))
                auth = self.connection.auth(self.username, self.password, 'gozerbot')
                rlog(100, self.name, "register succeded")
        self.connecttime = time.time()
        rlog(100, self.name, 'connected! type: %s' % \
self.connection.connected)
        self.connection.RegisterHandler('message', self.messageHandler)
        self.connection.RegisterHandler('presence', self.presenceHandler)
        self.connection.RegisterHandler('iq', self.iqHandler)
        self.connection.UnregisterDisconnectHandler(\
self.connection.DisconnectHandler)
        self.connection.RegisterDisconnectHandler(self.disconnectHandler)
        self.connection.UnregisterHandlerOnce = self.UnregisterHandlerOnce
        self.stopped = 0
        jabbermonitor.start()
        start_new_thread(self._doprocess, ())
        start_new_thread(self._keepalive, ())
        start_new_thread(self._outputloop, ())
        start_new_thread(self._keepchannelsalive, ())
        self.connection.sendInitPresence()
        #self.connection.getRoster()
        self.connectok.set()
        return 1