diff --git a/action_map.yml b/action_map.yml index 3e24cdb7..7808df04 100644 --- a/action_map.yml +++ b/action_map.yml @@ -504,6 +504,11 @@ firewall: ### firewall_stop() stop: action_help: Stop iptables and ip6tables + + + ### firewall_checkupnp() + checkupnp: + action_help: check if UPNP is install or not (0 yes 1 no) ############################# # Tools # ############################# diff --git a/firewall.yml b/firewall.yml index c6601498..ea27f005 100644 --- a/firewall.yml +++ b/firewall.yml @@ -1,3 +1,4 @@ +UPNP: false ipv4: TCP: [22, 25, 53, 80, 443, 5222, 5269, 5280, 6767] UDP: [53] diff --git a/yunohost_firewall.py b/yunohost_firewall.py index 071d801d..2988c82b 100644 --- a/yunohost_firewall.py +++ b/yunohost_firewall.py @@ -227,10 +227,21 @@ def firewall_installupnp(): Return None """ + + with open('firewall.yml', 'r') as f: + firewall = yaml.load(f) + + firewall['UPNP']=True; + os.system("touch /etc/cron.d/yunohost-firewall") os.system("echo '*/50 * * * * root yunohost firewall reload -u>>/dev/null'>/etc/cron.d/yunohost-firewall") win_msg(_("UPNP cron installed")) + os.system("mv firewall.yml firewall.yml.old") + + with open('firewall.yml', 'w') as f: + yaml.dump(firewall, f) + def firewall_removeupnp(): """ @@ -240,14 +251,39 @@ def firewall_removeupnp(): Return None """ + with open('firewall.yml', 'r') as f: + firewall = yaml.load(f) + + firewall['UPNP']=False; try: os.remove("/etc/cron.d/yunohost-firewall") except: raise YunoHostError(167,_("UPNP cron was not installed!")) - + win_msg(_("UPNP cron removed")) + os.system("mv firewall.yml firewall.yml.old") + + with open('firewall.yml', 'w') as f: + yaml.dump(firewall, f) + +def firewall_checkupnp(): + """ + Check if UPNP is installed + Keyword arguments: + None + Return + 0 if installed + 1 if not + """ + with open('firewall.yml', 'r') as f: + firewall = yaml.load(f) + + if firewall['UPNP']: + win_msg(_("UPNP is activated")) + else: + raise YunoHostError(167,_("UPNP not activated!")) def firewall_stop(): """ @@ -265,5 +301,6 @@ def firewall_stop(): os.system ("ip6tables -P INPUT ACCEPT") os.system ("ip6tables -F") os.system ("ip6tables -X") + if(os.path.exists("/etc/cron.d/yunohost-firewall")): + firewall_removeupnp() - firewall_removeupnp()