Exemplo n.º 1
0
def test_client_db():
    bumper.db = "tests/tmp.db"  # Set db location for testing
    bumper.client_add("user_123", "realm_123", "resource_123")
    assert bumper.client_get("resource_123")  # Test client was added

    bumper.client_set_mqtt("resource_123", True)
    assert bumper.client_get("resource_123")[
        "mqtt_connection"]  # Test that mqtt was set True for client

    bumper.client_set_xmpp("resource_123", False)
    assert (bumper.client_get("resource_123")["xmpp_connection"] == False
            )  # Test that xmpp was set False for client
    assert (len(bumper.get_disconnected_xmpp_clients()) == 1
            )  # Test len of connected xmpp clients is 1
Exemplo n.º 2
0
    async def handle_RemoveClient(self, request):
        try:
            resource = request.match_info.get("resource", "")
            bumper.client_remove(resource)
            if bumper.client_get(resource):
                return web.json_response({"status": "failed to remove client"})
            else:
                return web.json_response(
                    {"status": "successfully removed client"})

        except Exception as e:
            confserverlog.exception("{}".format(e))
            pass
Exemplo n.º 3
0
    async def on_broker_client_disconnected(self, client_id):

        didsplit = str(client_id).split("@")

        bot = bumper.bot_get(didsplit[0])
        if bot:
            bumper.bot_set_mqtt(bot["did"], False)
            return

        clientresource = didsplit[1].split("/")[1]
        client = bumper.client_get(clientresource)
        if client:
            bumper.client_set_mqtt(client["resource"], False)
            return
Exemplo n.º 4
0
    def _handle_bind(self, xml):
        try:

            bot = bumper.bot_get(self.uid)
            if bot:
                bumper.bot_set_xmpp(bot["did"], True)

            client = bumper.client_get(self.clientresource)
            if client:
                bumper.client_set_xmpp(client["resource"], True)

            clientbindxml = xml.getchildren()
            clientresourcexml = clientbindxml[0].getchildren()
            if self.devclass:  # its a bot
                self.name = "XMPP_Client_{}_{}".format(self.uid, self.devclass)
                self.bumper_jid = "{}@{}.ecorobot.net/atom".format(
                    self.uid, self.devclass
                )
                xmppserverlog.debug("new bot {}".format(self.uid))
                res = '<iq type="result" id="{}"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>{}</jid></bind></iq>'.format(
                    xml.get("id"), self.bumper_jid
                )
            elif len(clientresourcexml) > 0:
                self.clientresource = clientresourcexml[0].text
                self.name = "XMPP_Client_{}".format(self.clientresource)
                self.bumper_jid = "{}@{}/{}".format(
                    self.uid, XMPPServer.server_id, self.clientresource
                )
                xmppserverlog.debug(
                    "new client {} using resource {}".format(
                        self.uid, self.clientresource
                    )
                )
                res = '<iq type="result" id="{}"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>{}</jid></bind></iq>'.format(
                    xml.get("id"), self.bumper_jid
                )
            else:
                self.name = "XMPP_Client_{}_{}".format(self.uid, self.address)
                self.bumper_jid = "{}@{}".format(self.uid, XMPPServer.server_id)
                xmppserverlog.debug("new client {}".format(self.uid))
                res = '<iq type="result" id="{}"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>{}</jid></bind></iq>'.format(
                    xml.get("id"), self.bumper_jid
                )

            self._set_state("BIND")
            self.send(res)

        except Exception as e:
            xmppserverlog.exception("{}".format(e))
Exemplo n.º 5
0
    def _disconnect(self):
        try:

            bot = bumper.bot_get(self.uid)
            if bot:
                bumper.bot_set_xmpp(bot["did"], False)

            client = bumper.client_get(self.clientresource)
            if client:
                bumper.client_set_xmpp(client["resource"], False)

            self.transport.close()

        except Exception as e:
            xmppserverlog.error("{}".format(e))
Exemplo n.º 6
0
    async def on_broker_client_disconnected(self, client_id):
        try:
            didsplit = str(client_id).split("@")

            bot = bumper.bot_get(didsplit[0])
            if bot:
                bumper.bot_set_mqtt(bot["did"], False)

            #clientuserid = didsplit[0]
            clientresource = didsplit[1].split("/")[1]
            client = bumper.client_get(clientresource)
            if client:
                bumper.client_set_mqtt(client["resource"], False)

        except Exception as e:
            mqttserverlog.exception("{}".format(e))