Mercurial > libervia-backend
comparison src/plugins/plugin_misc_ip.py @ 1953:f6d560cabeee
plugin misc ip: fixed exception when a web error happen while retrieving IP from external website
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 26 Apr 2016 19:04:59 +0200 |
parents | 2daf7b4c6756 |
children | a74047906dfd |
comparison
equal
deleted
inserted
replaced
1952:2c1a1b56dd22 | 1953:f6d560cabeee |
---|---|
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core.log import getLogger | 22 from sat.core.log import getLogger |
23 log = getLogger(__name__) | 23 log = getLogger(__name__) |
24 from sat.tools import xml_tools | 24 from sat.tools import xml_tools |
25 from twisted.web import client as webclient | 25 from twisted.web import client as webclient |
26 from twisted.web import error as web_error | |
26 from twisted.internet import defer | 27 from twisted.internet import defer |
27 from twisted.internet import reactor | 28 from twisted.internet import reactor |
28 from twisted.internet import protocol | 29 from twisted.internet import protocol |
29 from twisted.internet import endpoints | 30 from twisted.internet import endpoints |
30 from twisted.internet import error as internet_error | 31 from twisted.internet import error as internet_error |
49 "main": "IPPlugin", | 50 "main": "IPPlugin", |
50 "handler": "yes", | 51 "handler": "yes", |
51 "description": _("""This plugin help to discover our external IP address.""") | 52 "description": _("""This plugin help to discover our external IP address.""") |
52 } | 53 } |
53 | 54 |
55 # TODO: GET_IP_PAGE should be configurable in sat.conf | |
54 GET_IP_PAGE = "http://www.goffi.org/sat_tools/get_ip.php" # This page must only return external IP of the requester | 56 GET_IP_PAGE = "http://www.goffi.org/sat_tools/get_ip.php" # This page must only return external IP of the requester |
55 GET_IP_LABEL = D_(u"Allow external get IP") | 57 GET_IP_LABEL = D_(u"Allow external get IP") |
56 GET_IP_CATEGORY = "General" | 58 GET_IP_CATEGORY = "General" |
57 GET_IP_NAME = "allow_get_ip" | 59 GET_IP_NAME = "allow_get_ip" |
58 GET_IP_CONFIRM_TITLE = D_(u"Confirm external site request") | 60 GET_IP_CONFIRM_TITLE = D_(u"Confirm external site request") |
287 try: | 289 try: |
288 ip = (yield webclient.getPage(GET_IP_PAGE)) if allow_get_ip else None | 290 ip = (yield webclient.getPage(GET_IP_PAGE)) if allow_get_ip else None |
289 except (internet_error.DNSLookupError, internet_error.TimeoutError): | 291 except (internet_error.DNSLookupError, internet_error.TimeoutError): |
290 log.warning(u"Can't access Domain Name System") | 292 log.warning(u"Can't access Domain Name System") |
291 ip = None | 293 ip = None |
294 except web_error.Error as e: | |
295 log.warning(u"Error while retrieving IP on {url}: {message}".format(url=GET_IP_PAGE, message=e)) | |
296 ip = None | |
292 else: | 297 else: |
293 self._external_ip_cache = ip | 298 self._external_ip_cache = ip |
294 defer.returnValue(ip) | 299 defer.returnValue(ip) |
295 | 300 |
296 | 301 |