plugin misc ip: fixed exception when a web error happen while retrieving IP from external website

This commit is contained in:
Goffi 2016-04-26 19:04:59 +02:00
commit faef205761

View file

@ -23,6 +23,7 @@ from sat.core.log import getLogger
log = getLogger(__name__)
from sat.tools import xml_tools
from twisted.web import client as webclient
from twisted.web import error as web_error
from twisted.internet import defer
from twisted.internet import reactor
from twisted.internet import protocol
@ -51,6 +52,7 @@ PLUGIN_INFO = {
"description": _("""This plugin help to discover our external IP address.""")
}
# TODO: GET_IP_PAGE should be configurable in sat.conf
GET_IP_PAGE = "http://www.goffi.org/sat_tools/get_ip.php" # This page must only return external IP of the requester
GET_IP_LABEL = D_(u"Allow external get IP")
GET_IP_CATEGORY = "General"
@ -289,6 +291,9 @@ class IPPlugin(object):
except (internet_error.DNSLookupError, internet_error.TimeoutError):
log.warning(u"Can't access Domain Name System")
ip = None
except web_error.Error as e:
log.warning(u"Error while retrieving IP on {url}: {message}".format(url=GET_IP_PAGE, message=e))
ip = None
else:
self._external_ip_cache = ip
defer.returnValue(ip)