mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
firewall_list: Don't miserably crash when trying to sort port range ("12300:12400", ain't an int)
This commit is contained in:
parent
0af05ea312
commit
278a95ab0e
1 changed files with 4 additions and 3 deletions
|
@ -188,18 +188,19 @@ def firewall_list(raw=False, by_ip_version=False, list_forwarded=False):
|
||||||
for i in ["ipv4", "ipv6"]:
|
for i in ["ipv4", "ipv6"]:
|
||||||
f = firewall[i]
|
f = firewall[i]
|
||||||
# Combine TCP and UDP ports
|
# Combine TCP and UDP ports
|
||||||
ports[i] = sorted(set(f["TCP"]) | set(f["UDP"]))
|
ports[i] = sorted(set(f["TCP"]) | set(f["UDP"]), key=lambda p: int(p.split(':')[0]) if isinstance(p, str) else p)
|
||||||
|
|
||||||
if not by_ip_version:
|
if not by_ip_version:
|
||||||
# Combine IPv4 and IPv6 ports
|
# Combine IPv4 and IPv6 ports
|
||||||
ports = sorted(set(ports["ipv4"]) | set(ports["ipv6"]))
|
ports = sorted(set(ports["ipv4"]) | set(ports["ipv6"]), key=lambda p: int(p.split(':')[0]) if isinstance(p, str) else p)
|
||||||
|
|
||||||
# Format returned dict
|
# Format returned dict
|
||||||
ret = {"opened_ports": ports}
|
ret = {"opened_ports": ports}
|
||||||
if list_forwarded:
|
if list_forwarded:
|
||||||
# Combine TCP and UDP forwarded ports
|
# Combine TCP and UDP forwarded ports
|
||||||
ret["forwarded_ports"] = sorted(
|
ret["forwarded_ports"] = sorted(
|
||||||
set(firewall["uPnP"]["TCP"]) | set(firewall["uPnP"]["UDP"])
|
set(firewall["uPnP"]["TCP"]) | set(firewall["uPnP"]["UDP"]),
|
||||||
|
key=lambda p: int(p.split(':')[0]) if isinstance(p, str) else p
|
||||||
)
|
)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue