From abf0b6c0d9a37c3b790bc03f299da67eea7f5b90 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 12 Jun 2018 23:22:31 +0200 Subject: [PATCH 1/5] Typo --- locales/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locales/en.json b/locales/en.json index 37160d403..4ca65826c 100644 --- a/locales/en.json +++ b/locales/en.json @@ -235,7 +235,7 @@ "migration_0003_not_jessie": "The current debian distribution is not Jessie !", "migration_0003_system_not_fully_up_to_date": "Your system is not fully up to date. Please perform a regular upgrade before running the migration to stretch.", "migration_0003_still_on_jessie_after_main_upgrade": "Something wrong happened during the main upgrade : system is still on Jessie !? To investigate the issue, please look at {log} :s ...", - "migration_0003_general_warning": "Please note that this migration is a delicate operation. While the YunoHost team did its best to review and test it, the migration might still break parts of the system or apps.\n\nTherefore, we recommend you to :\n - Perform a backup of any critical data or app. More infos on https://yunohost.org/backup ;\n - Be patient after launching the migration : depending on your internet connection and hardware, it might take up to a few hours for everything to upgrade.\n\nAdditionally, the port for SMTP, used by external email clients like (Thunderbird or K9-Mail) was changed from 465 (SSL/TLS) to 587 (STARTTLS). The old port 465 will automatically be closed and the new port 587 will be opened in the firewall. You and your users *will* have to adapt the configuration of your email clients accordingly!", + "migration_0003_general_warning": "Please note that this migration is a delicate operation. While the YunoHost team did its best to review and test it, the migration might still break parts of the system or apps.\n\nTherefore, we recommend you to :\n - Perform a backup of any critical data or app. More infos on https://yunohost.org/backup ;\n - Be patient after launching the migration : depending on your internet connection and hardware, it might take up to a few hours for everything to upgrade.\n\nAdditionally, the port for SMTP, used by external email clients (like Thunderbird or K9-Mail) was changed from 465 (SSL/TLS) to 587 (STARTTLS). The old port 465 will automatically be closed and the new port 587 will be opened in the firewall. You and your users *will* have to adapt the configuration of your email clients accordingly!", "migration_0003_problematic_apps_warning": "Please note that the following possibly problematic installed apps were detected. It looks like those were not installed from an applist or are not flagged as 'working'. Consequently, we cannot guarantee that they will still work after the upgrade : {problematic_apps}", "migration_0003_modified_files": "Please note that the following files were found to be manually modified and might be overwritten at the end of the upgrade : {manually_modified_files}", "migrations_backward": "Migrating backward.", From 9df14c6506993ba81af186764731296af009d261 Mon Sep 17 00:00:00 2001 From: Bram Date: Tue, 12 Jun 2018 23:43:40 +0200 Subject: [PATCH 2/5] [fix] remove slice by mistake in 14c270cebdc67a1123331237cee6dba347ee7623 --- src/yunohost/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yunohost/service.py b/src/yunohost/service.py index 0ce8073fa..ef711a4a9 100644 --- a/src/yunohost/service.py +++ b/src/yunohost/service.py @@ -709,7 +709,7 @@ def _tail(file, n): lines = f.read().splitlines() if len(lines) >= to_read or pos == 0: - return lines[-to_read] + return lines[-to_read:] avg_line_length *= 1.3 From 8b08de665a17881052d57a676546d443564d9c25 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 13 Jun 2018 19:39:56 +0200 Subject: [PATCH 3/5] Add util functions to extract network interfaces and gateway --- src/yunohost/monitor.py | 2 + src/yunohost/utils/network.py | 76 +++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/src/yunohost/monitor.py b/src/yunohost/monitor.py index ed13d532d..fc10a4fbc 100644 --- a/src/yunohost/monitor.py +++ b/src/yunohost/monitor.py @@ -164,6 +164,7 @@ def monitor_network(units=None, human_readable=False): units = ['check', 'usage', 'infos'] # Get network devices and their addresses + # TODO / FIXME : use functions in utils/network.py to manage this devices = {} output = subprocess.check_output('ip addr show'.split()) for d in re.split('^(?:[0-9]+: )', output, flags=re.MULTILINE): @@ -213,6 +214,7 @@ def monitor_network(units=None, human_readable=False): elif u == 'infos': p_ipv4 = get_public_ip() or 'unknown' + # TODO / FIXME : use functions in utils/network.py to manage this l_ip = 'unknown' for name, addrs in devices.items(): if name == 'lo': diff --git a/src/yunohost/utils/network.py b/src/yunohost/utils/network.py index e22d1644d..470354f63 100644 --- a/src/yunohost/utils/network.py +++ b/src/yunohost/utils/network.py @@ -19,10 +19,13 @@ """ import logging +import re +import subprocess from urllib import urlopen logger = logging.getLogger('yunohost.utils.network') + def get_public_ip(protocol=4): """Retrieve the public IP address from ip.yunohost.org""" @@ -37,3 +40,76 @@ def get_public_ip(protocol=4): return urlopen(url).read().strip() except IOError: return None + + +def get_network_interfaces(): + + # Get network devices and their addresses (raw infos from 'ip addr') + devices_raw = {} + output = subprocess.check_output('ip addr show'.split()) + for d in re.split('^(?:[0-9]+: )', output, flags=re.MULTILINE): + # Extract device name (1) and its addresses (2) + m = re.match('([^\s@]+)(?:@[\S]+)?: (.*)', d, flags=re.DOTALL) + if m: + devices_raw[m.group(1)] = m.group(2) + + # Parse relevant informations for each of them + devices = {name: _extract_inet(addrs) for name, addrs in devices_raw.items() if name != "lo"} + + return devices or "unknown" + + +def get_gateway(): + + output = subprocess.check_output('ip route show'.split()) + m = re.search('default via (.*) dev ([a-z]+[0-9]?)', output) + if not m: + return "unknown" + + addr = _extract_inet(m.group(1), True) + return addr.popitem()[1] if len(addr) == 1 else "unknown" + + +############################################################################### + + +def _extract_inet(string, skip_netmask=False, skip_loopback=True): + """ + Extract IP addresses (v4 and/or v6) from a string limited to one + address by protocol + + Keyword argument: + string -- String to search in + skip_netmask -- True to skip subnet mask extraction + skip_loopback -- False to include addresses reserved for the + loopback interface + + Returns: + A dict of {protocol: address} with protocol one of 'ipv4' or 'ipv6' + + """ + ip4_pattern = '((25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}' + ip6_pattern = '(((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)' + ip4_pattern += '/[0-9]{1,2})' if not skip_netmask else ')' + ip6_pattern += '/[0-9]{1,3})' if not skip_netmask else ')' + result = {} + + for m in re.finditer(ip4_pattern, string): + addr = m.group(1) + if skip_loopback and addr.startswith('127.'): + continue + + # Limit to only one result + result['ipv4'] = addr + break + + for m in re.finditer(ip6_pattern, string): + addr = m.group(1) + if skip_loopback and addr == '::1': + continue + + # Limit to only one result + result['ipv6'] = addr + break + + return result From 2aeed38ea5574ae8d12df6bb0c32aea3942f53e5 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 13 Jun 2018 20:01:41 +0200 Subject: [PATCH 4/5] Disable predictable network interface names to avoid cases where devices don't reboot properly because interface name changed... --- .../0003_migrate_to_stretch.py | 20 +++++++++++++++++++ src/yunohost/utils/network.py | 6 +++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/yunohost/data_migrations/0003_migrate_to_stretch.py b/src/yunohost/data_migrations/0003_migrate_to_stretch.py index 8b8d37447..105480241 100644 --- a/src/yunohost/data_migrations/0003_migrate_to_stretch.py +++ b/src/yunohost/data_migrations/0003_migrate_to_stretch.py @@ -15,6 +15,7 @@ from yunohost.service import (_run_service_command, manually_modified_files_compared_to_debian_default) from yunohost.utils.filesystem import free_space_in_directory from yunohost.utils.packages import get_installed_version +from yunohost.utils.network import get_network_interfaces logger = getActionLogger('yunohost.migration') @@ -68,6 +69,8 @@ class MyMigration(Migration): self.apt_dist_upgrade(conf_flags=["new", "miss", "def"]) _run_service_command("restart", "fail2ban") + self.disable_predicable_interface_names() + # Clean the mess os.system("apt autoremove --assume-yes") os.system("apt clean --assume-yes") @@ -352,3 +355,20 @@ class MyMigration(Migration): # command showing in the terminal, since 'info' channel is only # enabled if the user explicitly add --verbose ... os.system(command) + + def disable_predicable_interface_names(self): + + # Try to see if currently used interface names are predictable ones or not... + # If we ain't using "eth0" or "wlan0", assume we are using predictable interface + # names and therefore they shouldnt be disabled + network_interfaces = get_network_interfaces().keys() + if "eth0" not in network_interfaces and "wlan0" not in network_interfaces: + return + + interfaces_config = read_file("/etc/network/interfaces") + if "eth0" not in interfaces_config and "wlan0" not in interfaces_config: + return + + # Disable predictive interface names + # c.f. https://unix.stackexchange.com/a/338730 + os.system("ln -s /dev/null /etc/systemd/network/99-default.link") diff --git a/src/yunohost/utils/network.py b/src/yunohost/utils/network.py index 470354f63..dec0384bf 100644 --- a/src/yunohost/utils/network.py +++ b/src/yunohost/utils/network.py @@ -56,7 +56,7 @@ def get_network_interfaces(): # Parse relevant informations for each of them devices = {name: _extract_inet(addrs) for name, addrs in devices_raw.items() if name != "lo"} - return devices or "unknown" + return devices def get_gateway(): @@ -64,10 +64,10 @@ def get_gateway(): output = subprocess.check_output('ip route show'.split()) m = re.search('default via (.*) dev ([a-z]+[0-9]?)', output) if not m: - return "unknown" + return None addr = _extract_inet(m.group(1), True) - return addr.popitem()[1] if len(addr) == 1 else "unknown" + return addr.popitem()[1] if len(addr) == 1 else None ############################################################################### From 022524473e532ec5f6ebe9d0bd889a6e3e384206 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 15 Jun 2018 16:21:54 +0200 Subject: [PATCH 5/5] Update changelog --- debian/changelog | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/debian/changelog b/debian/changelog index 2c855eae1..2e480e1bb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ + +yunohost (2.7.13.6) testing; urgency=low + + * Misc fixes + * [stretch-migration] Disable predictable network interface names + + Fixes by Bram and Aleks + + -- Alexandre Aubin Fri, 15 Jun 2018 16:20:00 +0000 + yunohost (2.7.13.5) testing; urgency=low * [fix] a bug when log to be fetched is empty