diff --git a/deluge/common.py b/deluge/common.py index 7b76d245c2..35994e7ddf 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -1039,7 +1039,7 @@ def is_interface_name(name): """Returns True if an interface name exists. Args: - name (str): The Interface to test. eg. eth0 linux. GUID on Windows. + name (str): The Interface to test. eg. eth0 linux. GUID or "Nice Name" eg.Local Area Connection" on Windows. Returns: bool: Whether name is valid or not. @@ -1049,6 +1049,8 @@ def is_interface_name(name): True >>> is_interface_name("{7A30AE62-23ZA-3744-Z844-A5B042524871}") True + >>> is_interface_name("Local Area Connection") + True """ @@ -1066,7 +1068,9 @@ def is_interface_name(name): except OSError: return True else: - return any([name == a.name for a in adapters]) + return any([name == a.name for a in adapters]) or any( + [name == a.nice_name for a in adapters] + ) if windows_check(): regex = '^{[0-9A-Z]{8}-([0-9A-Z]{4}-){3}[0-9A-Z]{12}}$' @@ -1074,6 +1078,37 @@ def is_interface_name(name): return True +def convert_win_ifaddr_nice_name_to_name(interface): + """Returns name or guid for an interface from ifaddr. + + Args: + name (str): The Interface to convert. eg. "Local Area Connection" + + Returns: + str: A GUID eg. {EB51199A-G725-5138-3H29-3529J3D419F7}. + + Examples: + >>> convert_win_ifaddr_nice_name_to_name("Local Area Connection") + "{EB51199A-G725-5138-3H29-3529J3D419F7}" + + """ + if ifaddr: + if windows_check: + if is_interface(interface): + regex = '^{[0-9A-Z]{8}-([0-9A-Z]{4}-){3}[0-9A-Z]{12}}$' + # if is_interface is true and doesnt match what a GUID would look like + # It is a nice name find what GUID belongs to the nice name for use in LT + if not bool(re.search(regex, str(interface))): + try: + adapters = ifaddr.get_adapters() + except OSError: + return interface + else: + for a in adapters: + if a.nice_name == interface: + interface = a.name + return interface + def decode_bytes(byte_str, encoding='utf8'): """Decodes a byte string and return unicode. diff --git a/deluge/core/core.py b/deluge/core/core.py index e2130f595a..054f024231 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -10,6 +10,7 @@ import glob import logging import os +import re import shutil import tempfile from base64 import b64decode, b64encode @@ -166,6 +167,19 @@ def __init__( if listen_interface: if deluge.common.is_interface(listen_interface): self._old_listen_interface = self.config['listen_interface'] + if deluge.common.windows_check: + if deluge.common.is_interface(listen_interface): + regex = '^{[0-9A-Z]{8}-([0-9A-Z]{4}-){3}[0-9A-Z]{12}}$' + # if is_interface is true and doesnt match what a GUID would look like + # It is a nice name find what GUID belongs to the nice name for use in LT + if ( + not bool(re.search(regex, str(listen_interface))) + ): + listen_interface = ( + deluge.common.convert_win_ifaddr_nice_name_to_name( + listen_interface + ) + ) self.config['listen_interface'] = listen_interface else: log.error( @@ -177,6 +191,19 @@ def __init__( if outgoing_interface: if deluge.common.is_interface(outgoing_interface): self._old_outgoing_interface = self.config['outgoing_interface'] + if deluge.common.windows_check: + if deluge.common.is_interface(outgoing_interface): + regex = '^{[0-9A-Z]{8}-([0-9A-Z]{4}-){3}[0-9A-Z]{12}}$' + # if is_interface is true and doesnt match what a GUID would look like + # It is a nice name find what GUID belongs to the nice name for use in LT + if ( + not bool(re.search(regex, str(outgoing_interface))) + ): + outgoing_interface = ( + deluge.common.convert_win_ifaddr_nice_name_to_name( + outgoing_interface + ) + ) self.config['outgoing_interface'] = outgoing_interface else: log.error( diff --git a/deluge/ui/console/modes/preferences/preference_panes.py b/deluge/ui/console/modes/preferences/preference_panes.py index 8ae0deaca8..f8ad3cf476 100644 --- a/deluge/ui/console/modes/preferences/preference_panes.py +++ b/deluge/ui/console/modes/preferences/preference_panes.py @@ -7,8 +7,9 @@ # import logging +import re -from deluge.common import is_interface +from deluge.common import convert_win_ifaddr_nice_name_to_name, is_interface, windows_check from deluge.decorators import overrides from deluge.i18n import get_languages from deluge.ui.client import client @@ -92,10 +93,36 @@ def add_config_values(self, conf_dict): elif ipt.name == 'listen_interface': listen_interface = ipt.get_value().strip() if is_interface(listen_interface) or not listen_interface: + if windows_check: + if is_interface(listen_interface): + regex = '^{[0-9A-Z]{8}-([0-9A-Z]{4}-){3}[0-9A-Z]{12}}$' + # if is_interface is true and doesnt match what a GUID would look like + # It is a nice name find what GUID belongs to the nice name for use in LT + if ( + not bool(re.search(regex, str(listen_interface))) + ): + listen_interface = ( + convert_win_ifaddr_nice_name_to_name( + listen_interface + ) + ) conf_dict['listen_interface'] = listen_interface elif ipt.name == 'outgoing_interface': outgoing_interface = ipt.get_value().strip() if is_interface(outgoing_interface) or not outgoing_interface: + if windows_check: + if is_interface(outgoing_interface): + regex = '^{[0-9A-Z]{8}-([0-9A-Z]{4}-){3}[0-9A-Z]{12}}$' + # if is_interface is true and doesnt match what a GUID would look like + # It is a nice name find what GUID belongs to the nice name for use in LT + if ( + not bool(re.search(regex, str(outgoing_interface))) + ): + outgoing_interface = ( + convert_win_ifaddr_nice_name_to_name( + outgoing_interface + ) + ) conf_dict['outgoing_interface'] = outgoing_interface elif ipt.name.startswith('proxy_'): if ipt.name == 'proxy_type': diff --git a/deluge/ui/gtk3/preferences.py b/deluge/ui/gtk3/preferences.py index 59b22264b2..db10efaa06 100644 --- a/deluge/ui/gtk3/preferences.py +++ b/deluge/ui/gtk3/preferences.py @@ -9,6 +9,7 @@ import logging import os +import re from hashlib import sha1 as sha from urllib.parse import urlparse @@ -687,11 +688,37 @@ def set_config(self, hide=False): ).get_active() incoming_address = self.builder.get_object('entry_interface').get_text().strip() if deluge.common.is_interface(incoming_address) or not incoming_address: + if deluge.common.windows_check: + if deluge.common.is_interface(incoming_address): + regex = '^{[0-9A-Z]{8}-([0-9A-Z]{4}-){3}[0-9A-Z]{12}}$' + # if is_interface is true and doesnt match what a GUID would look like + # It is a nice name find what GUID belongs to the nice name for use in LT + if ( + not bool(re.search(regex, str(incoming_address))) + ): + incoming_address = ( + deluge.common.convert_win_ifaddr_nice_name_to_name( + incoming_address + ) + ) new_core_config['listen_interface'] = incoming_address outgoing_address = ( self.builder.get_object('entry_outgoing_interface').get_text().strip() ) if deluge.common.is_interface(outgoing_address) or not outgoing_address: + if deluge.common.windows_check: + if deluge.common.is_interface(outgoing_address): + regex = '^{[0-9A-Z]{8}-([0-9A-Z]{4}-){3}[0-9A-Z]{12}}$' + # if is_interface is true and doesnt match what a GUID would look like + # It is a nice name find what GUID belongs to the nice name for use in LT + if ( + not bool(re.search(regex, str(outgoing_address))) + ): + outgoing_address = ( + deluge.common.convert_win_ifaddr_nice_name_to_name( + outgoing_address + ) + ) new_core_config['outgoing_interface'] = ( self.builder.get_object('entry_outgoing_interface').get_text().strip() )