mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Use automatic server address if listen_on value is ''
This commit is contained in:
parent
dc4ba2e18b
commit
091404eb0d
@ -17,10 +17,10 @@ from calibre.utils.smtp import config as email_config
|
|||||||
|
|
||||||
def local_url_for_content_server():
|
def local_url_for_content_server():
|
||||||
from calibre.srv.opts import server_config
|
from calibre.srv.opts import server_config
|
||||||
from calibre.utils.network import is_ipv6_addr
|
from calibre.utils.network import is_ipv6_addr, get_fallback_server_addr
|
||||||
|
|
||||||
opts = server_config()
|
opts = server_config()
|
||||||
interface = opts.listen_on or '0.0.0.0'
|
interface = opts.listen_on or get_fallback_server_addr()
|
||||||
|
|
||||||
addr_map = {'0.0.0.0': '127.0.0.1',
|
addr_map = {'0.0.0.0': '127.0.0.1',
|
||||||
'::': '::1'}
|
'::': '::1'}
|
||||||
|
@ -1299,11 +1299,11 @@ class ConfigWidget(ConfigWidgetBase):
|
|||||||
self.stopping_msg.accept()
|
self.stopping_msg.accept()
|
||||||
|
|
||||||
def test_server(self):
|
def test_server(self):
|
||||||
from calibre.utils.network import is_ipv6_addr
|
from calibre.utils.network import is_ipv6_addr, get_fallback_server_addr
|
||||||
|
|
||||||
prefix = self.advanced_tab.get('url_prefix') or ''
|
prefix = self.advanced_tab.get('url_prefix') or ''
|
||||||
protocol = 'https' if self.advanced_tab.has_ssl else 'http'
|
protocol = 'https' if self.advanced_tab.has_ssl else 'http'
|
||||||
lo = self.advanced_tab.get('listen_on') or '0.0.0.0'
|
lo = self.advanced_tab.get('listen_on') or get_fallback_server_addr()
|
||||||
|
|
||||||
addr_map = {'0.0.0.0': '127.0.0.1',
|
addr_map = {'0.0.0.0': '127.0.0.1',
|
||||||
'::': '::1'}
|
'::': '::1'}
|
||||||
|
@ -11,7 +11,6 @@ from collections import OrderedDict, namedtuple
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from socket import has_dualstack_ipv6
|
|
||||||
|
|
||||||
from calibre.constants import config_dir
|
from calibre.constants import config_dir
|
||||||
from calibre.utils.localization import _
|
from calibre.utils.localization import _
|
||||||
@ -111,7 +110,7 @@ raw_options = (
|
|||||||
' there are more than this number of items. Set to zero to disable.'),
|
' there are more than this number of items. Set to zero to disable.'),
|
||||||
|
|
||||||
_('The interface on which to listen for connections'),
|
_('The interface on which to listen for connections'),
|
||||||
'listen_on', '::' if has_dualstack_ipv6() else '0.0.0.0',
|
'listen_on', '',
|
||||||
_('The default is to listen on all available IPv6 and IPv4 interfaces. You can change this to, for'
|
_('The default is to listen on all available IPv6 and IPv4 interfaces. You can change this to, for'
|
||||||
' example, "127.0.0.1" to only listen for connections from the local machine, or'
|
' example, "127.0.0.1" to only listen for connections from the local machine, or'
|
||||||
' to "::" to listen to all incoming IPv6 and IPv4 connections.'),
|
' to "::" to listen to all incoming IPv6 and IPv4 connections.'),
|
||||||
|
@ -116,3 +116,10 @@ def is_ipv6_addr(addr):
|
|||||||
return True
|
return True
|
||||||
except OSError:
|
except OSError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_fallback_server_addr():
|
||||||
|
from socket import has_dualstack_ipv6
|
||||||
|
if has_dualstack_ipv6():
|
||||||
|
return '::'
|
||||||
|
else:
|
||||||
|
return '0.0.0.0'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user