diff --git a/src/calibre/gui2/actions/device.py b/src/calibre/gui2/actions/device.py index 6e215661c8..3ec7738362 100644 --- a/src/calibre/gui2/actions/device.py +++ b/src/calibre/gui2/actions/device.py @@ -11,6 +11,7 @@ from PyQt4.Qt import QToolButton, QMenu, pyqtSignal, QIcon, QTimer from calibre.gui2.actions import InterfaceAction from calibre.utils.smtp import config as email_config +from calibre.utils.config import tweaks from calibre.constants import iswindows, isosx from calibre.customize.ui import is_disabled from calibre.devices.bambook.driver import BAMBOOK @@ -84,10 +85,14 @@ class ShareConnMenu(QMenu): # {{{ action=self.toggle_server_action, group=gr) def server_state_changed(self, running): - from calibre.utils.mdns import get_external_ip + from calibre.utils.mdns import get_external_ip, verify_ipV4_address text = _('Start Content Server') if running: - text = _('Stop Content Server') + ' [%s]'%get_external_ip() + listen_on = verify_ipV4_address(tweaks['server_listen_on']) + if listen_on: + text = _('Stop Content Server') + ' [%s]'%listen_on + else: + text = _('Stop Content Server') + ' [%s]'%get_external_ip() self.toggle_server_action.setText(text) def hide_smartdevice_menus(self): diff --git a/src/calibre/library/server/base.py b/src/calibre/library/server/base.py index 3554268c3b..884d273ea9 100644 --- a/src/calibre/library/server/base.py +++ b/src/calibre/library/server/base.py @@ -5,7 +5,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os +import os, socket import logging from logging.handlers import RotatingFileHandler @@ -17,7 +17,7 @@ from calibre.utils.date import fromtimestamp from calibre.library.server import listen_on, log_access_file, log_error_file from calibre.library.server.utils import expose, AuthController from calibre.utils.mdns import publish as publish_zeroconf, \ - unpublish as unpublish_zeroconf, get_external_ip + unpublish as unpublish_zeroconf, get_external_ip, verify_ipV4_address from calibre.library.server.content import ContentServer from calibre.library.server.mobile import MobileServer from calibre.library.server.xml import XMLServer @@ -78,6 +78,7 @@ class BonJour(SimplePlugin): # {{{ SimplePlugin.__init__(self, engine) self.port = port self.prefix = prefix + self.ip_address = '0.0.0.0' @property def mdns_services(self): @@ -90,9 +91,10 @@ class BonJour(SimplePlugin): # {{{ def start(self): + zeroconf_ip_address = verify_ipV4_address(self.ip_address) try: for s in self.mdns_services: - publish_zeroconf(*s) + publish_zeroconf(*s, use_ip_address=zeroconf_ip_address) except: import traceback cherrypy.log.error('Failed to start BonJour:') @@ -140,6 +142,7 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache, if not opts.url_prefix: opts.url_prefix = '' + cherrypy.engine.bonjour.ip_address = listen_on cherrypy.engine.bonjour.port = opts.port cherrypy.engine.bonjour.prefix = opts.url_prefix diff --git a/src/calibre/utils/mdns.py b/src/calibre/utils/mdns.py index abbd6c2247..706516e32c 100644 --- a/src/calibre/utils/mdns.py +++ b/src/calibre/utils/mdns.py @@ -39,6 +39,19 @@ def _get_external_ip(): #print 'ipaddr: %s' % ipaddr return ipaddr +def verify_ipV4_address(ip_address): + result = None + if ip_address != '0.0.0.0' and ip_address != '::': + # do some more sanity checks on the address + try: + socket.inet_aton(ip_address) + if len(ip_address.split('.')) == 4: + result = ip_address + except socket.error: + # Not legal ip address + pass + return result + _ext_ip = None def get_external_ip(): global _ext_ip