Merge remote-tracking branch 'upstream/dev' into test

This commit is contained in:
Jerome Lebleu 2014-02-24 18:48:38 +01:00
commit e6dd0ab4e9
3 changed files with 39 additions and 30 deletions

View file

@ -1,12 +1,11 @@
UPNP: UPNP:
cron: false cron: false
ports: 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] UDP: [53, 137, 138]
ipv4: 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] UDP: [53, 137, 138]
ipv6: ipv6:
TCP: [22] TCP: [22]
UDP: [53] UDP: [53]

View file

@ -162,18 +162,17 @@ def monitor_network(units=None, human_readable=False):
for name, addrs in devices.items(): for name, addrs in devices.items():
if name == 'lo': if name == 'lo':
continue continue
if len(devices) == 2: if not isinstance(l_ip, dict):
l_ip = _extract_inet(addrs) l_ip = {}
else: l_ip[name] = _extract_inet(addrs)
if not isinstance(l_ip, dict):
l_ip = {}
l_ip[name] = _extract_inet(addrs)
gateway = 'unknown' gateway = 'unknown'
output = subprocess.check_output('ip route show'.split()) output = subprocess.check_output('ip route show'.split())
m = re.search('default via (.*) dev ([a-z]+[0-9]?)', output) m = re.search('default via (.*) dev ([a-z]+[0-9]?)', output)
if m: 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] = { result[u] = {
'public_ip': p_ip, 'public_ip': p_ip,
@ -413,36 +412,46 @@ def _get_glances_api():
raise YunoHostError(1, _("Connection to Glances server failed")) 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: Keyword argument:
string -- String to search in 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}' 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 = '(((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)' 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 += '/[0-9]{1,2})' if not skip_netmask else ')' ip4_pattern += '/[0-9]{1,2})' if not skip_netmask else ')'
ip6 += '/[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) for m in re.finditer(ip4_pattern, string):
ip6_prog = re.compile(ip6) addr = m.group(1)
result = [] if skip_loopback and addr.startswith('127.'):
continue
m = ip4_prog.search(string) # Limit to only one result
if m: result['ipv4'] = addr
result.append(m.group(1)) break
m = ip6_prog.search(string) for m in re.finditer(ip6_pattern, string):
if m: addr = m.group(1)
result.append(m.group(1)) if skip_loopback and addr == '::1':
continue
if len(result) > 1: # Limit to only one result
return result result['ipv6'] = addr
elif len(result) == 1: break
return result[0]
return None return result
def _binary_to_human(n, customary=False): def _binary_to_human(n, customary=False):

View file

@ -122,6 +122,7 @@ def tools_maindomain(old_domain, new_domain, dyndns=False):
'/etc/dovecot/dovecot.conf', '/etc/dovecot/dovecot.conf',
'/usr/share/yunohost/yunohost-config/others/startup', '/usr/share/yunohost/yunohost-config/others/startup',
'/home/yunohost.backup/tahoe/tahoe.cfg' '/home/yunohost.backup/tahoe/tahoe.cfg'
'/etc/amavis/conf.d/05-node_id'
] ]
config_dir = [] config_dir = []