mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #1154 from YunoHost/fix-upnp-closing-port
fix upnp closing port
This commit is contained in:
commit
4476c968c0
2 changed files with 20 additions and 4 deletions
|
@ -2,6 +2,8 @@ uPnP:
|
||||||
enabled: false
|
enabled: false
|
||||||
TCP: [22, 25, 80, 443, 587, 993, 5222, 5269]
|
TCP: [22, 25, 80, 443, 587, 993, 5222, 5269]
|
||||||
UDP: []
|
UDP: []
|
||||||
|
TCP_TO_CLOSE: []
|
||||||
|
UDP_TO_CLOSE: []
|
||||||
ipv4:
|
ipv4:
|
||||||
TCP: [22, 25, 53, 80, 443, 587, 993, 5222, 5269]
|
TCP: [22, 25, 53, 80, 443, 587, 993, 5222, 5269]
|
||||||
UDP: [53, 5353]
|
UDP: [53, 5353]
|
||||||
|
|
|
@ -82,6 +82,8 @@ def firewall_allow(protocol, port, ipv4_only=False, ipv6_only=False,
|
||||||
# Add port forwarding with UPnP
|
# Add port forwarding with UPnP
|
||||||
if not no_upnp and port not in firewall['uPnP'][p]:
|
if not no_upnp and port not in firewall['uPnP'][p]:
|
||||||
firewall['uPnP'][p].append(port)
|
firewall['uPnP'][p].append(port)
|
||||||
|
if firewall['uPnP'][p + "_TO_CLOSE"] and port in firewall['uPnP'][p + "_TO_CLOSE"]:
|
||||||
|
firewall['uPnP'][p + "_TO_CLOSE"].remove(port)
|
||||||
|
|
||||||
# Update and reload firewall
|
# Update and reload firewall
|
||||||
_update_firewall_file(firewall)
|
_update_firewall_file(firewall)
|
||||||
|
@ -139,6 +141,9 @@ def firewall_disallow(protocol, port, ipv4_only=False, ipv6_only=False,
|
||||||
# Remove port forwarding with UPnP
|
# Remove port forwarding with UPnP
|
||||||
if upnp and port in firewall['uPnP'][p]:
|
if upnp and port in firewall['uPnP'][p]:
|
||||||
firewall['uPnP'][p].remove(port)
|
firewall['uPnP'][p].remove(port)
|
||||||
|
if not firewall['uPnP'][p + "_TO_CLOSE"]:
|
||||||
|
firewall['uPnP'][p + "_TO_CLOSE"] = []
|
||||||
|
firewall['uPnP'][p + "_TO_CLOSE"].append(port)
|
||||||
|
|
||||||
# Update and reload firewall
|
# Update and reload firewall
|
||||||
_update_firewall_file(firewall)
|
_update_firewall_file(firewall)
|
||||||
|
@ -356,6 +361,16 @@ def firewall_upnp(action='status', no_refresh=False):
|
||||||
else:
|
else:
|
||||||
# Iterate over ports
|
# Iterate over ports
|
||||||
for protocol in ['TCP', 'UDP']:
|
for protocol in ['TCP', 'UDP']:
|
||||||
|
if firewall['uPnP'][protocol + "_TO_CLOSE"]:
|
||||||
|
for port in firewall['uPnP'][protocol + "_TO_CLOSE"]:
|
||||||
|
# Clean the mapping of this port
|
||||||
|
if upnpc.getspecificportmapping(port, protocol):
|
||||||
|
try:
|
||||||
|
upnpc.deleteportmapping(port, protocol)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
firewall['uPnP'][protocol + "_TO_CLOSE"] = []
|
||||||
|
|
||||||
for port in firewall['uPnP'][protocol]:
|
for port in firewall['uPnP'][protocol]:
|
||||||
# Clean the mapping of this port
|
# Clean the mapping of this port
|
||||||
if upnpc.getspecificportmapping(port, protocol):
|
if upnpc.getspecificportmapping(port, protocol):
|
||||||
|
@ -374,14 +389,13 @@ def firewall_upnp(action='status', no_refresh=False):
|
||||||
port, exc_info=1)
|
port, exc_info=1)
|
||||||
enabled = False
|
enabled = False
|
||||||
|
|
||||||
|
_update_firewall_file(firewall)
|
||||||
|
|
||||||
if enabled != firewall['uPnP']['enabled']:
|
if enabled != firewall['uPnP']['enabled']:
|
||||||
firewall = firewall_list(raw=True)
|
firewall = firewall_list(raw=True)
|
||||||
firewall['uPnP']['enabled'] = enabled
|
firewall['uPnP']['enabled'] = enabled
|
||||||
|
|
||||||
# Make a backup and update firewall file
|
_update_firewall_file(firewall)
|
||||||
os.system("cp {0} {0}.old".format(FIREWALL_FILE))
|
|
||||||
with open(FIREWALL_FILE, 'w') as f:
|
|
||||||
yaml.safe_dump(firewall, f, default_flow_style=False)
|
|
||||||
|
|
||||||
if not no_refresh:
|
if not no_refresh:
|
||||||
# Display success message if needed
|
# Display success message if needed
|
||||||
|
|
Loading…
Add table
Reference in a new issue