Mercurial > libervia-backend
comparison src/plugins/plugin_misc_ip.py @ 1668:a9e86f660653
plugin ip: fixed ip check (XEP-0279) use
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 25 Nov 2015 00:22:23 +0100 |
parents | d5f59ba166fe |
children | d17772b0fe22 |
comparison
equal
deleted
inserted
replaced
1667:bf67dc424784 | 1668:a9e86f660653 |
---|---|
29 from twisted.internet import endpoints | 29 from twisted.internet import endpoints |
30 from twisted.internet import error as internet_error | 30 from twisted.internet import error as internet_error |
31 from zope.interface import implements | 31 from zope.interface import implements |
32 from wokkel import disco, iwokkel | 32 from wokkel import disco, iwokkel |
33 from twisted.words.protocols.jabber.xmlstream import XMPPHandler | 33 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
34 from twisted.words.protocols.jabber.error import StanzaError | |
34 import urlparse | 35 import urlparse |
35 try: | 36 try: |
36 import netifaces | 37 import netifaces |
37 except ImportError: | 38 except ImportError: |
38 log.warning(u"netifaces is not available, it help discovering IPs, you can install it on https://pypi.python.org/pypi/netifaces") | 39 log.warning(u"netifaces is not available, it help discovering IPs, you can install it on https://pypi.python.org/pypi/netifaces") |
250 """ | 251 """ |
251 if self._external_ip_cache is not None: | 252 if self._external_ip_cache is not None: |
252 defer.returnValue(self._external_ip_cache) | 253 defer.returnValue(self._external_ip_cache) |
253 | 254 |
254 # we first try with XEP-0279 | 255 # we first try with XEP-0279 |
255 if self.host.hasFeature(NS_IP_CHECK, profile=profile): | 256 ip_check = yield self.host.hasFeature(NS_IP_CHECK, profile=profile) |
257 if ip_check: | |
256 log.debug(u"Server IP Check available, we use it to retrieve our IP") | 258 log.debug(u"Server IP Check available, we use it to retrieve our IP") |
257 client = self.host.getClient(profile) | 259 client = self.host.getClient(profile) |
258 iq_elt = client.IQ("get") | 260 iq_elt = client.IQ("get") |
259 iq_elt.addElement((NS_IP_CHECK, 'address')) | 261 iq_elt.addElement((NS_IP_CHECK, 'address')) |
260 result_elt = yield iq_elt.send() | |
261 try: | 262 try: |
263 result_elt = yield iq_elt.send() | |
262 address_elt = result_elt.elements(NS_IP_CHECK, 'address').next() | 264 address_elt = result_elt.elements(NS_IP_CHECK, 'address').next() |
263 ip_elt = address_elt.elements(NS_IP_CHECK,'ip').next() | 265 ip_elt = address_elt.elements(NS_IP_CHECK,'ip').next() |
264 except StopIteration: | 266 except StopIteration: |
265 log.warning(u"Server returned invalid result on XEP-0279 request, we ignore it") | 267 log.warning(u"Server returned invalid result on XEP-0279 request, we ignore it") |
268 except StanzaError as e: | |
269 log.warning(u"error while requesting ip to server: {}".format(e)) | |
266 else: | 270 else: |
267 # FIXME: server IP may not be the same as external IP (server can be on local machine or network) | 271 # FIXME: server IP may not be the same as external IP (server can be on local machine or network) |
268 # IP should be checked to see if we have a local one, and rejected in this case | 272 # IP should be checked to see if we have a local one, and rejected in this case |
269 external_ip = str(ip_elt) | 273 external_ip = str(ip_elt) |
270 log.debug(u"External IP found: {}".format(external_ip)) | 274 log.debug(u"External IP found: {}".format(external_ip)) |