plugin ip: fixed ip check (XEP-0279) use

This commit is contained in:
Goffi 2015-11-25 00:22:23 +01:00
commit 99e012e4cb

View file

@ -31,6 +31,7 @@ from twisted.internet import error as internet_error
from zope.interface import implements
from wokkel import disco, iwokkel
from twisted.words.protocols.jabber.xmlstream import XMPPHandler
from twisted.words.protocols.jabber.error import StanzaError
import urlparse
try:
import netifaces
@ -252,17 +253,20 @@ class IPPlugin(object):
defer.returnValue(self._external_ip_cache)
# we first try with XEP-0279
if self.host.hasFeature(NS_IP_CHECK, profile=profile):
ip_check = yield self.host.hasFeature(NS_IP_CHECK, profile=profile)
if ip_check:
log.debug(u"Server IP Check available, we use it to retrieve our IP")
client = self.host.getClient(profile)
iq_elt = client.IQ("get")
iq_elt.addElement((NS_IP_CHECK, 'address'))
result_elt = yield iq_elt.send()
try:
result_elt = yield iq_elt.send()
address_elt = result_elt.elements(NS_IP_CHECK, 'address').next()
ip_elt = address_elt.elements(NS_IP_CHECK,'ip').next()
except StopIteration:
log.warning(u"Server returned invalid result on XEP-0279 request, we ignore it")
except StanzaError as e:
log.warning(u"error while requesting ip to server: {}".format(e))
else:
# FIXME: server IP may not be the same as external IP (server can be on local machine or network)
# IP should be checked to see if we have a local one, and rejected in this case