[#2082] Validate ip address for listen_interface entry
This ensures that only ip addresses are accepted for listen_interface as libtorrent cannot accept interface names (eth0) and will cause unexpected results for user.
This commit is contained in:
parent
bddfb2a5c6
commit
2be5474f3a
|
@ -52,7 +52,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
from deluge.error import *
|
from deluge.error import InvalidPathError
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -593,10 +593,10 @@ def is_ip(ip):
|
||||||
#first we test ipv4
|
#first we test ipv4
|
||||||
try:
|
try:
|
||||||
if windows_check():
|
if windows_check():
|
||||||
if socket.inet_aton("%s" % (ip)):
|
if socket.inet_aton(ip):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
if socket.inet_pton(socket.AF_INET, "%s" % (ip)):
|
if socket.inet_pton(socket.AF_INET, ip):
|
||||||
return True
|
return True
|
||||||
except socket.error:
|
except socket.error:
|
||||||
if not socket.has_ipv6:
|
if not socket.has_ipv6:
|
||||||
|
@ -607,7 +607,7 @@ def is_ip(ip):
|
||||||
log.warning("ipv6 check unavailable on windows")
|
log.warning("ipv6 check unavailable on windows")
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
if socket.inet_pton(socket.AF_INET6, "%s" % (ip)):
|
if socket.inet_pton(socket.AF_INET6, ip):
|
||||||
return True
|
return True
|
||||||
except socket.error:
|
except socket.error:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -137,7 +137,7 @@ class Core(component.Component):
|
||||||
# If there was an interface value from the command line, use it, but
|
# If there was an interface value from the command line, use it, but
|
||||||
# store the one in the config so we can restore it on shutdown
|
# store the one in the config so we can restore it on shutdown
|
||||||
self.__old_interface = None
|
self.__old_interface = None
|
||||||
if listen_interface:
|
if listen_interface and deluge.common.is_ip(listen_interface):
|
||||||
self.__old_interface = self.config["listen_interface"]
|
self.__old_interface = self.config["listen_interface"]
|
||||||
self.config["listen_interface"] = listen_interface
|
self.config["listen_interface"] = listen_interface
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ from twisted.internet import reactor
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.configmanager import get_config_dir
|
from deluge.configmanager import get_config_dir
|
||||||
from deluge.common import get_version, windows_check
|
from deluge.common import get_version, windows_check, is_ip
|
||||||
from deluge.core.rpcserver import RPCServer, export
|
from deluge.core.rpcserver import RPCServer, export
|
||||||
from deluge.error import DaemonRunningError
|
from deluge.error import DaemonRunningError
|
||||||
from deluge.core.core import Core
|
from deluge.core.core import Core
|
||||||
|
@ -110,7 +110,7 @@ class Daemon(object):
|
||||||
SetConsoleCtrlHandler(win_handler)
|
SetConsoleCtrlHandler(win_handler)
|
||||||
|
|
||||||
listen_interface = None
|
listen_interface = None
|
||||||
if options and options.listen_interface:
|
if options and options.listen_interface and is_ip(options.listen_interface):
|
||||||
listen_interface = options.listen_interface
|
listen_interface = options.listen_interface
|
||||||
|
|
||||||
# Start the core as a thread and join it until it's done
|
# Start the core as a thread and join it until it's done
|
||||||
|
|
|
@ -611,7 +611,10 @@ class Preferences(component.Component):
|
||||||
new_core_config["outgoing_ports"] = outgoing_ports
|
new_core_config["outgoing_ports"] = outgoing_ports
|
||||||
new_core_config["random_outgoing_ports"] = \
|
new_core_config["random_outgoing_ports"] = \
|
||||||
self.builder.get_object("chk_random_outgoing_ports").get_active()
|
self.builder.get_object("chk_random_outgoing_ports").get_active()
|
||||||
new_core_config["listen_interface"] = self.builder.get_object("entry_interface").get_text()
|
|
||||||
|
incoming_address = self.builder.get_object("entry_interface").get_text()
|
||||||
|
if deluge.common.is_ip(incoming_address) or not incoming_address:
|
||||||
|
new_core_config["listen_interface"] = incoming_address
|
||||||
new_core_config["peer_tos"] = self.builder.get_object("entry_peer_tos").get_text()
|
new_core_config["peer_tos"] = self.builder.get_object("entry_peer_tos").get_text()
|
||||||
new_core_config["dht"] = self.builder.get_object("chk_dht").get_active()
|
new_core_config["dht"] = self.builder.get_object("chk_dht").get_active()
|
||||||
new_core_config["upnp"] = self.builder.get_object("chk_upnp").get_active()
|
new_core_config["upnp"] = self.builder.get_object("chk_upnp").get_active()
|
||||||
|
|
Loading…
Reference in New Issue