mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Change port from str to int and update yunohost.py
This commit is contained in:
parent
ef70c05290
commit
36dab1cd02
3 changed files with 18 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
||||||
ipv4:
|
ipv4:
|
||||||
TCP: ['22', '25', '53', '80', '443', '5222', '5269', '5280']
|
TCP: [22, 25, 53, 80, 443, 5222, 5269, 5280]
|
||||||
UDP: []
|
UDP: []
|
||||||
ipv6:
|
ipv6:
|
||||||
TCP: ['22']
|
TCP: [22]
|
||||||
UDP: []
|
UDP: []
|
||||||
|
|
11
yunohost.py
11
yunohost.py
|
@ -45,10 +45,15 @@ def pretty_print_dict(d, depth=0):
|
||||||
elif isinstance(v, list):
|
elif isinstance(v, list):
|
||||||
print((" ") * depth + ("%s: " % k))
|
print((" ") * depth + ("%s: " % k))
|
||||||
for value in v:
|
for value in v:
|
||||||
print((" ") * (depth+1) + "- " + value)
|
if isinstance(value,str):
|
||||||
|
print((" ") * (depth+1) + "- " + value)
|
||||||
|
else:
|
||||||
|
print((" ") * (depth+1) + "- " +str(value))
|
||||||
else:
|
else:
|
||||||
print((" ") * depth + "%s: %s" % (k, v))
|
if isinstance(v,str):
|
||||||
|
print((" ") * depth + "%s: %s" % (k, v))
|
||||||
|
else:
|
||||||
|
print((" ") * depth + "%s: %s" % (k, str(v)))
|
||||||
def win_msg(astr):
|
def win_msg(astr):
|
||||||
"""
|
"""
|
||||||
Display a success message if isatty
|
Display a success message if isatty
|
||||||
|
|
|
@ -25,8 +25,8 @@ def firewall_allow(protocol=None,port=None,ipv6=None):
|
||||||
Dict
|
Dict
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
port=int(port)
|
||||||
if int(port)<65536 and int(port)>0:
|
if port<65536 and port>0:
|
||||||
if protocol == "Both":
|
if protocol == "Both":
|
||||||
update_yml(port,'tcp','a',ipv6)
|
update_yml(port,'tcp','a',ipv6)
|
||||||
update_yml(port,'udp','a',ipv6)
|
update_yml(port,'udp','a',ipv6)
|
||||||
|
@ -57,6 +57,7 @@ def firewall_disallow(protocol=None,port=None,ipv6=None):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
port=int(port)
|
||||||
if protocol == "Both":
|
if protocol == "Both":
|
||||||
update_yml(port,'tcp','r',ipv6)
|
update_yml(port,'tcp','r',ipv6)
|
||||||
update_yml(port,'udp','r',ipv6)
|
update_yml(port,'udp','r',ipv6)
|
||||||
|
@ -101,15 +102,15 @@ def firewall_reload():
|
||||||
os.system ("iptables -P INPUT ACCEPT")
|
os.system ("iptables -P INPUT ACCEPT")
|
||||||
os.system ("iptables -F")
|
os.system ("iptables -F")
|
||||||
os.system ("iptables -X")
|
os.system ("iptables -X")
|
||||||
if '22' not in firewall['ipv4']['TCP']:
|
if 22 not in firewall['ipv4']['TCP']:
|
||||||
update_yml('22','TCP','a',False)
|
update_yml(22,'TCP','a',False)
|
||||||
|
|
||||||
|
|
||||||
os.system ("ip6tables -P INPUT ACCEPT")
|
os.system ("ip6tables -P INPUT ACCEPT")
|
||||||
os.system ("ip6tables -F")
|
os.system ("ip6tables -F")
|
||||||
os.system ("ip6tables -X")
|
os.system ("ip6tables -X")
|
||||||
if '22' not in firewall['ipv6']['TCP']:
|
if 22 not in firewall['ipv6']['TCP']:
|
||||||
update_yml('22','TCP','a',True)
|
update_yml(22,'TCP','a',True)
|
||||||
|
|
||||||
for i,port in enumerate (firewall['ipv4']['TCP']):
|
for i,port in enumerate (firewall['ipv4']['TCP']):
|
||||||
os.system ("iptables -A INPUT -p tcp -i eth0 --dport "+ str(port) +" -j ACCEPT")
|
os.system ("iptables -A INPUT -p tcp -i eth0 --dport "+ str(port) +" -j ACCEPT")
|
||||||
|
@ -170,7 +171,7 @@ def update_yml(port=None,protocol=None,mode=None,ipv6=None):
|
||||||
else:
|
else:
|
||||||
raise YunoHostError(22,_("Port already closed :")+port)
|
raise YunoHostError(22,_("Port already closed :")+port)
|
||||||
|
|
||||||
firewall[ip][protocol].sort(key=int)
|
firewall[ip][protocol].sort()
|
||||||
|
|
||||||
os.system("mv firewall.yml firewall.yml.old")
|
os.system("mv firewall.yml firewall.yml.old")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue