From 1d85e6e7bc27ad11084c6e06b02a4ec9fd7099e6 Mon Sep 17 00:00:00 2001 From: abeudin Date: Tue, 11 Feb 2014 10:30:27 +0100 Subject: [PATCH 1/4] Update yunohost_tools.py --- yunohost_tools.py | 1 + 1 file changed, 1 insertion(+) diff --git a/yunohost_tools.py b/yunohost_tools.py index 5b3fc05b..aecd9ce9 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -121,6 +121,7 @@ def tools_maindomain(old_domain, new_domain, dyndns=False): '/etc/dovecot/dovecot.conf', '/usr/share/yunohost/yunohost-config/others/startup', '/home/yunohost.backup/tahoe/tahoe.cfg' + '/etc/amavis/conf.d/05-node_id' ] config_dir = [] From ed23a131dfc3e83526d6ab36b5d241f8198fe169 Mon Sep 17 00:00:00 2001 From: Jerome Lebleu Date: Fri, 14 Feb 2014 21:30:21 +0100 Subject: [PATCH 2/4] Always associate network interface's name to local_ip --- yunohost_monitor.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/yunohost_monitor.py b/yunohost_monitor.py index ed4f7db1..32fef40b 100644 --- a/yunohost_monitor.py +++ b/yunohost_monitor.py @@ -161,12 +161,9 @@ def monitor_network(units=None, human_readable=False): for name, addrs in devices.items(): if name == 'lo': continue - if len(devices) == 2: - l_ip = _extract_inet(addrs) - else: - if not isinstance(l_ip, dict): - l_ip = {} - l_ip[name] = _extract_inet(addrs) + if not isinstance(l_ip, dict): + l_ip = {} + l_ip[name] = _extract_inet(addrs) gateway = 'unknown' output = subprocess.check_output('ip route show'.split()) From 8880dc8a3d9134a64b8224b91e369647a9765844 Mon Sep 17 00:00:00 2001 From: Alexis Gavoty Date: Mon, 17 Feb 2014 11:59:12 +0100 Subject: [PATCH 3/4] Update firewall.yml --- firewall.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firewall.yml b/firewall.yml index 075116cf..6767886a 100644 --- a/firewall.yml +++ b/firewall.yml @@ -1,10 +1,10 @@ UPNP: cron: false ports: - TCP: [22, 25, 53, 80, 443, 465, 993, 5222, 5269, 5280, 6767, 7676] + TCP: [22, 25, 53, 80, 443, 465, 993, 5222, 5269, 5290] UDP: [53, 137, 138] ipv4: - TCP: [22, 25, 53, 80, 443, 465, 993, 5222, 5269, 5280, 6767, 7676] + TCP: [22, 25, 53, 80, 443, 465, 993, 5222, 5269, 5290] UDP: [53, 137, 138] ipv6: TCP: [22] From 4396baa584d93d51942990da21b753cb29aafd3a Mon Sep 17 00:00:00 2001 From: Jerome Lebleu Date: Wed, 19 Feb 2014 18:28:44 +0100 Subject: [PATCH 4/4] Better ipv4/ipv6 addresses extracting and returning --- yunohost_monitor.py | 54 +++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/yunohost_monitor.py b/yunohost_monitor.py index 32fef40b..9875ae77 100644 --- a/yunohost_monitor.py +++ b/yunohost_monitor.py @@ -169,7 +169,9 @@ def monitor_network(units=None, human_readable=False): output = subprocess.check_output('ip route show'.split()) m = re.search('default via (.*) dev ([a-z]+[0-9]?)', output) if m: - gateway = _extract_inet(m.group(1), True) + addr = _extract_inet(m.group(1), True) + if len(addr) == 1: + proto, gateway = addr.popitem() result[u] = { 'public_ip': p_ip, @@ -409,36 +411,46 @@ def _get_glances_api(): raise YunoHostError(1, _("Connection to Glances server failed")) -def _extract_inet(string, skip_netmask=False): +def _extract_inet(string, skip_netmask=False, skip_loopback=True): """ - Extract IP address (v4 or v6) from a string + 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 = '((25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}' - ip6 = '(((?:[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 += '/[0-9]{1,2})' if not skip_netmask else ')' - ip6 += '/[0-9]{1,2})' if not skip_netmask else ')' + 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,2})' if not skip_netmask else ')' + result = {} - ip4_prog = re.compile(ip4) - ip6_prog = re.compile(ip6) - result = [] + for m in re.finditer(ip4_pattern, string): + addr = m.group(1) + if skip_loopback and addr.startswith('127.'): + continue - m = ip4_prog.search(string) - if m: - result.append(m.group(1)) + # Limit to only one result + result['ipv4'] = addr + break - m = ip6_prog.search(string) - if m: - result.append(m.group(1)) + for m in re.finditer(ip6_pattern, string): + addr = m.group(1) + if skip_loopback and addr == '::1': + continue - if len(result) > 1: - return result - elif len(result) == 1: - return result[0] - return None + # Limit to only one result + result['ipv6'] = addr + break + + return result def _binary_to_human(n, customary=False):