From 36dab1cd02df1ae5625837fb1c209468bf495713 Mon Sep 17 00:00:00 2001 From: titoko Date: Wed, 19 Dec 2012 17:49:04 +0100 Subject: [PATCH] Change port from str to int and update yunohost.py --- firewall.yml | 4 ++-- yunohost.py | 11 ++++++++--- yunohost_firewall.py | 15 ++++++++------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/firewall.yml b/firewall.yml index b0220024..688c1da7 100644 --- a/firewall.yml +++ b/firewall.yml @@ -1,6 +1,6 @@ ipv4: - TCP: ['22', '25', '53', '80', '443', '5222', '5269', '5280'] + TCP: [22, 25, 53, 80, 443, 5222, 5269, 5280] UDP: [] ipv6: - TCP: ['22'] + TCP: [22] UDP: [] diff --git a/yunohost.py b/yunohost.py index faa6a634..4ebc6ade 100644 --- a/yunohost.py +++ b/yunohost.py @@ -45,10 +45,15 @@ def pretty_print_dict(d, depth=0): elif isinstance(v, list): print((" ") * depth + ("%s: " % k)) for value in v: - print((" ") * (depth+1) + "- " + value) + if isinstance(value,str): + print((" ") * (depth+1) + "- " + value) + else: + print((" ") * (depth+1) + "- " +str(value)) 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): """ Display a success message if isatty diff --git a/yunohost_firewall.py b/yunohost_firewall.py index 407746aa..7ecb33c9 100644 --- a/yunohost_firewall.py +++ b/yunohost_firewall.py @@ -25,8 +25,8 @@ def firewall_allow(protocol=None,port=None,ipv6=None): Dict """ - - if int(port)<65536 and int(port)>0: + port=int(port) + if port<65536 and port>0: if protocol == "Both": update_yml(port,'tcp','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": update_yml(port,'tcp','r',ipv6) update_yml(port,'udp','r',ipv6) @@ -101,15 +102,15 @@ def firewall_reload(): os.system ("iptables -P INPUT ACCEPT") os.system ("iptables -F") os.system ("iptables -X") - if '22' not in firewall['ipv4']['TCP']: - update_yml('22','TCP','a',False) + if 22 not in firewall['ipv4']['TCP']: + update_yml(22,'TCP','a',False) os.system ("ip6tables -P INPUT ACCEPT") os.system ("ip6tables -F") os.system ("ip6tables -X") - if '22' not in firewall['ipv6']['TCP']: - update_yml('22','TCP','a',True) + if 22 not in firewall['ipv6']['TCP']: + update_yml(22,'TCP','a',True) for i,port in enumerate (firewall['ipv4']['TCP']): 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: 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")