mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make bonjour for the content server advertize an IP address set in tweaks.
This commit is contained in:
parent
f967610679
commit
1f7965b96d
@ -11,6 +11,7 @@ from PyQt4.Qt import QToolButton, QMenu, pyqtSignal, QIcon, QTimer
|
|||||||
|
|
||||||
from calibre.gui2.actions import InterfaceAction
|
from calibre.gui2.actions import InterfaceAction
|
||||||
from calibre.utils.smtp import config as email_config
|
from calibre.utils.smtp import config as email_config
|
||||||
|
from calibre.utils.config import tweaks
|
||||||
from calibre.constants import iswindows, isosx
|
from calibre.constants import iswindows, isosx
|
||||||
from calibre.customize.ui import is_disabled
|
from calibre.customize.ui import is_disabled
|
||||||
from calibre.devices.bambook.driver import BAMBOOK
|
from calibre.devices.bambook.driver import BAMBOOK
|
||||||
@ -84,10 +85,14 @@ class ShareConnMenu(QMenu): # {{{
|
|||||||
action=self.toggle_server_action, group=gr)
|
action=self.toggle_server_action, group=gr)
|
||||||
|
|
||||||
def server_state_changed(self, running):
|
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')
|
text = _('Start Content Server')
|
||||||
if running:
|
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)
|
self.toggle_server_action.setText(text)
|
||||||
|
|
||||||
def hide_smartdevice_menus(self):
|
def hide_smartdevice_menus(self):
|
||||||
|
@ -5,7 +5,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os
|
import os, socket
|
||||||
import logging
|
import logging
|
||||||
from logging.handlers import RotatingFileHandler
|
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 import listen_on, log_access_file, log_error_file
|
||||||
from calibre.library.server.utils import expose, AuthController
|
from calibre.library.server.utils import expose, AuthController
|
||||||
from calibre.utils.mdns import publish as publish_zeroconf, \
|
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.content import ContentServer
|
||||||
from calibre.library.server.mobile import MobileServer
|
from calibre.library.server.mobile import MobileServer
|
||||||
from calibre.library.server.xml import XMLServer
|
from calibre.library.server.xml import XMLServer
|
||||||
@ -78,6 +78,7 @@ class BonJour(SimplePlugin): # {{{
|
|||||||
SimplePlugin.__init__(self, engine)
|
SimplePlugin.__init__(self, engine)
|
||||||
self.port = port
|
self.port = port
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
|
self.ip_address = '0.0.0.0'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mdns_services(self):
|
def mdns_services(self):
|
||||||
@ -90,9 +91,10 @@ class BonJour(SimplePlugin): # {{{
|
|||||||
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
zeroconf_ip_address = verify_ipV4_address(self.ip_address)
|
||||||
try:
|
try:
|
||||||
for s in self.mdns_services:
|
for s in self.mdns_services:
|
||||||
publish_zeroconf(*s)
|
publish_zeroconf(*s, use_ip_address=zeroconf_ip_address)
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
cherrypy.log.error('Failed to start BonJour:')
|
cherrypy.log.error('Failed to start BonJour:')
|
||||||
@ -140,6 +142,7 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache,
|
|||||||
if not opts.url_prefix:
|
if not opts.url_prefix:
|
||||||
opts.url_prefix = ''
|
opts.url_prefix = ''
|
||||||
|
|
||||||
|
cherrypy.engine.bonjour.ip_address = listen_on
|
||||||
cherrypy.engine.bonjour.port = opts.port
|
cherrypy.engine.bonjour.port = opts.port
|
||||||
cherrypy.engine.bonjour.prefix = opts.url_prefix
|
cherrypy.engine.bonjour.prefix = opts.url_prefix
|
||||||
|
|
||||||
|
@ -39,6 +39,19 @@ def _get_external_ip():
|
|||||||
#print 'ipaddr: %s' % ipaddr
|
#print 'ipaddr: %s' % ipaddr
|
||||||
return 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
|
_ext_ip = None
|
||||||
def get_external_ip():
|
def get_external_ip():
|
||||||
global _ext_ip
|
global _ext_ip
|
||||||
|
Loading…
x
Reference in New Issue
Block a user