mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[mod] autopep8
This commit is contained in:
parent
fc5e37edc8
commit
088fc01b06
1 changed files with 14 additions and 11 deletions
|
@ -125,7 +125,7 @@ def firewall_disallow(protocol, port, ipv4_only=False, ipv6_only=False,
|
||||||
ipvs = ['ipv4', 'ipv6']
|
ipvs = ['ipv4', 'ipv6']
|
||||||
upnp = True
|
upnp = True
|
||||||
if ipv4_only and ipv6_only:
|
if ipv4_only and ipv6_only:
|
||||||
upnp = True # automatically disallow UPnP
|
upnp = True # automatically disallow UPnP
|
||||||
elif ipv4_only:
|
elif ipv4_only:
|
||||||
ipvs = ['ipv4',]
|
ipvs = ['ipv4',]
|
||||||
upnp = upnp_only
|
upnp = upnp_only
|
||||||
|
@ -180,7 +180,7 @@ def firewall_list(raw=False, by_ip_version=False, list_forwarded=False):
|
||||||
ports = sorted(set(ports['ipv4']) | set(ports['ipv6']))
|
ports = sorted(set(ports['ipv4']) | set(ports['ipv6']))
|
||||||
|
|
||||||
# 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(
|
||||||
|
@ -224,8 +224,8 @@ def firewall_reload(skip_upnp=False):
|
||||||
# Iterate over ports and add rule
|
# Iterate over ports and add rule
|
||||||
for protocol in ['TCP', 'UDP']:
|
for protocol in ['TCP', 'UDP']:
|
||||||
for port in firewall['ipv4'][protocol]:
|
for port in firewall['ipv4'][protocol]:
|
||||||
rules.append("iptables -A INPUT -p %s --dport %s -j ACCEPT" \
|
rules.append("iptables -A INPUT -p %s --dport %s -j ACCEPT"
|
||||||
% (protocol, process.quote(str(port))))
|
% (protocol, process.quote(str(port))))
|
||||||
rules += [
|
rules += [
|
||||||
"iptables -A INPUT -i lo -j ACCEPT",
|
"iptables -A INPUT -i lo -j ACCEPT",
|
||||||
"iptables -A INPUT -p icmp -j ACCEPT",
|
"iptables -A INPUT -p icmp -j ACCEPT",
|
||||||
|
@ -253,8 +253,8 @@ def firewall_reload(skip_upnp=False):
|
||||||
# Iterate over ports and add rule
|
# Iterate over ports and add rule
|
||||||
for protocol in ['TCP', 'UDP']:
|
for protocol in ['TCP', 'UDP']:
|
||||||
for port in firewall['ipv6'][protocol]:
|
for port in firewall['ipv6'][protocol]:
|
||||||
rules.append("ip6tables -A INPUT -p %s --dport %s -j ACCEPT" \
|
rules.append("ip6tables -A INPUT -p %s --dport %s -j ACCEPT"
|
||||||
% (protocol, process.quote(str(port))))
|
% (protocol, process.quote(str(port))))
|
||||||
rules += [
|
rules += [
|
||||||
"ip6tables -A INPUT -i lo -j ACCEPT",
|
"ip6tables -A INPUT -i lo -j ACCEPT",
|
||||||
"ip6tables -A INPUT -p icmpv6 -j ACCEPT",
|
"ip6tables -A INPUT -p icmpv6 -j ACCEPT",
|
||||||
|
@ -308,13 +308,14 @@ def firewall_upnp(action='status', no_refresh=False):
|
||||||
try:
|
try:
|
||||||
# Remove old cron job
|
# Remove old cron job
|
||||||
os.remove('/etc/cron.d/yunohost-firewall')
|
os.remove('/etc/cron.d/yunohost-firewall')
|
||||||
except: pass
|
except:
|
||||||
|
pass
|
||||||
action = 'status'
|
action = 'status'
|
||||||
no_refresh = False
|
no_refresh = False
|
||||||
|
|
||||||
if action == 'status' and no_refresh:
|
if action == 'status' and no_refresh:
|
||||||
# Only return current state
|
# Only return current state
|
||||||
return { 'enabled': enabled }
|
return {'enabled': enabled}
|
||||||
elif action == 'enable' or (enabled and action == 'status'):
|
elif action == 'enable' or (enabled and action == 'status'):
|
||||||
# Add cron job
|
# Add cron job
|
||||||
with open(upnp_cron_job, 'w+') as f:
|
with open(upnp_cron_job, 'w+') as f:
|
||||||
|
@ -330,7 +331,8 @@ def firewall_upnp(action='status', no_refresh=False):
|
||||||
try:
|
try:
|
||||||
# Remove cron job
|
# Remove cron job
|
||||||
os.remove(upnp_cron_job)
|
os.remove(upnp_cron_job)
|
||||||
except: pass
|
except:
|
||||||
|
pass
|
||||||
enabled = False
|
enabled = False
|
||||||
if action == 'status':
|
if action == 'status':
|
||||||
no_refresh = True
|
no_refresh = True
|
||||||
|
@ -364,7 +366,8 @@ def firewall_upnp(action='status', no_refresh=False):
|
||||||
if upnpc.getspecificportmapping(port, protocol):
|
if upnpc.getspecificportmapping(port, protocol):
|
||||||
try:
|
try:
|
||||||
upnpc.deleteportmapping(port, protocol)
|
upnpc.deleteportmapping(port, protocol)
|
||||||
except: pass
|
except:
|
||||||
|
pass
|
||||||
if not enabled:
|
if not enabled:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
|
@ -403,7 +406,7 @@ def firewall_upnp(action='status', no_refresh=False):
|
||||||
|
|
||||||
if action == 'enable' and not enabled:
|
if action == 'enable' and not enabled:
|
||||||
raise MoulinetteError(errno.ENXIO, m18n.n('upnp_port_open_failed'))
|
raise MoulinetteError(errno.ENXIO, m18n.n('upnp_port_open_failed'))
|
||||||
return { 'enabled': enabled }
|
return {'enabled': enabled}
|
||||||
|
|
||||||
|
|
||||||
def firewall_stop():
|
def firewall_stop():
|
||||||
|
|
Loading…
Add table
Reference in a new issue