From 80ff31022f22a9d823cc480c40945cc1e932a0ad Mon Sep 17 00:00:00 2001 From: Titoko Date: Mon, 11 Mar 2013 23:07:16 +0100 Subject: [PATCH 1/7] upnp cron --- action_map.yml | 8 ++++++++ firewall.yml | 8 ++++---- yunohost_firewall.py | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/action_map.yml b/action_map.yml index 30a53018..4cae9976 100644 --- a/action_map.yml +++ b/action_map.yml @@ -491,6 +491,14 @@ firewall: action: store_true + ### firewall_upnpinstall() + upnpinstall: + action_help: Add upnp cron + + + ### firewall_upnpremove() + upnpremove: + action_help: Remove upnp cron ############################# # Tools # ############################# diff --git a/firewall.yml b/firewall.yml index 688c1da7..ff6ebc99 100644 --- a/firewall.yml +++ b/firewall.yml @@ -1,6 +1,6 @@ ipv4: - TCP: [22, 25, 53, 80, 443, 5222, 5269, 5280] - UDP: [] + TCP: [22, 25, 53, 80, 443, 5222, 5269, 5280] + UDP: [] ipv6: - TCP: [22] - UDP: [] + TCP: [22] + UDP: [] diff --git a/yunohost_firewall.py b/yunohost_firewall.py index 6674d588..d810939d 100644 --- a/yunohost_firewall.py +++ b/yunohost_firewall.py @@ -217,3 +217,17 @@ def add_portmapping(protocol=None, upnp=False, ipv6=None): upnp.addportmapping(port, protocol, upnp.lanaddr, port, 'yunohost firewall : port %u' % port, '') os.system ("iptables -P INPUT DROP") + +def firewall_installupnp(): + """ + Add upnp cron + Keyword arguments: + None + Return + None + """ + os.system("touch /etc/cron.d/yunohost-firewall") + os.system("echo '*/50 * * * * root yunohost firewall reload -u>>/dev/null'>/etc/cron.d/yunohost-firewall") + +def firewall_removeupnp(): + os.system("rm /etc/cron.d/yunohost-firewall") From eb39a80db08aa481ae810c977e8038769414e9aa Mon Sep 17 00:00:00 2001 From: titoko Date: Wed, 13 Mar 2013 09:34:29 +0100 Subject: [PATCH 2/7] Cron install/uninstall --- action_map.yml | 8 ++++---- yunohost_firewall.py | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/action_map.yml b/action_map.yml index 4cae9976..dcda6abf 100644 --- a/action_map.yml +++ b/action_map.yml @@ -491,13 +491,13 @@ firewall: action: store_true - ### firewall_upnpinstall() - upnpinstall: + ### firewall_installupnp() + installupnp: action_help: Add upnp cron - ### firewall_upnpremove() - upnpremove: + ### firewall_removeupnp() + removeupnp: action_help: Remove upnp cron ############################# # Tools # diff --git a/yunohost_firewall.py b/yunohost_firewall.py index d810939d..62f8f59e 100644 --- a/yunohost_firewall.py +++ b/yunohost_firewall.py @@ -228,6 +228,9 @@ def firewall_installupnp(): """ 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 install")) + def firewall_removeupnp(): os.system("rm /etc/cron.d/yunohost-firewall") + win_msg(_("Upnp remove")) From b384a41b0e4f787752b8353833f026393c45056b Mon Sep 17 00:00:00 2001 From: Titoko Date: Wed, 13 Mar 2013 11:31:22 +0100 Subject: [PATCH 3/7] Restart fail2ban! --- yunohost_firewall.py | 1 + 1 file changed, 1 insertion(+) diff --git a/yunohost_firewall.py b/yunohost_firewall.py index 62f8f59e..a15f3d95 100644 --- a/yunohost_firewall.py +++ b/yunohost_firewall.py @@ -128,6 +128,7 @@ def firewall_reload(upnp=False): os.system ("iptables -P INPUT DROP") os.system ("ip6tables -P INPUT DROP") + os.system("service fail2ban restart") win_msg(_("Firewall successfully reloaded")) From a48c0006f53f1866ad9e95f64fdb7175ba1e3699 Mon Sep 17 00:00:00 2001 From: Titoko Date: Wed, 13 Mar 2013 13:32:40 +0100 Subject: [PATCH 4/7] Bug fix and add port 53 UDP --- firewall.yml | 4 ++-- yunohost_firewall.py | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/firewall.yml b/firewall.yml index ff6ebc99..976ac43d 100644 --- a/firewall.yml +++ b/firewall.yml @@ -1,6 +1,6 @@ ipv4: TCP: [22, 25, 53, 80, 443, 5222, 5269, 5280] - UDP: [] + UDP: [53] ipv6: TCP: [22] - UDP: [] + UDP: [53] diff --git a/yunohost_firewall.py b/yunohost_firewall.py index a15f3d95..9738afee 100644 --- a/yunohost_firewall.py +++ b/yunohost_firewall.py @@ -229,9 +229,13 @@ def firewall_installupnp(): """ 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 install")) + win_msg(_("UPNP cron installed")) def firewall_removeupnp(): - os.system("rm /etc/cron.d/yunohost-firewall") - win_msg(_("Upnp remove")) + try: + os.remove("/etc/cron.d/yunohost-firewall") + except: + raise YunoHostError(167,_("UPNP cron was not installed!")) + + win_msg(_("UPNP cron removed")) From ae8c3275835c31b301f9aabdcee8bdf5d247922b Mon Sep 17 00:00:00 2001 From: Titoko Date: Fri, 15 Mar 2013 14:18:30 +0100 Subject: [PATCH 5/7] Add stop firewall action --- action_map.yml | 5 +++++ yunohost_firewall.py | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/action_map.yml b/action_map.yml index dcda6abf..3e24cdb7 100644 --- a/action_map.yml +++ b/action_map.yml @@ -499,6 +499,11 @@ firewall: ### firewall_removeupnp() removeupnp: action_help: Remove upnp cron + + + ### firewall_stop() + stop: + action_help: Stop iptables and ip6tables ############################# # Tools # ############################# diff --git a/yunohost_firewall.py b/yunohost_firewall.py index 9738afee..57bdd789 100644 --- a/yunohost_firewall.py +++ b/yunohost_firewall.py @@ -239,3 +239,14 @@ def firewall_removeupnp(): raise YunoHostError(167,_("UPNP cron was not installed!")) win_msg(_("UPNP cron removed")) + + +def firewall_stop(): + + os.system ("iptables -P INPUT ACCEPT") + os.system ("iptables -F") + os.system ("iptables -X") + + os.system ("ip6tables -P INPUT ACCEPT") + os.system ("ip6tables -F") + os.system ("ip6tables -X") From cac8d54a37b7a5fc1597db7192a2084763423d47 Mon Sep 17 00:00:00 2001 From: Titoko Date: Fri, 15 Mar 2013 14:20:12 +0100 Subject: [PATCH 6/7] Uninstall cron when stop firewall --- yunohost_firewall.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/yunohost_firewall.py b/yunohost_firewall.py index 57bdd789..ceeaa1cc 100644 --- a/yunohost_firewall.py +++ b/yunohost_firewall.py @@ -250,3 +250,5 @@ def firewall_stop(): os.system ("ip6tables -P INPUT ACCEPT") os.system ("ip6tables -F") os.system ("ip6tables -X") + + firewall_removeupnp() From 85ac83b7e1ff6830e135b9f2c8643e00aaf93e99 Mon Sep 17 00:00:00 2001 From: Titoko Date: Fri, 15 Mar 2013 14:28:52 +0100 Subject: [PATCH 7/7] Add comment --- yunohost_firewall.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/yunohost_firewall.py b/yunohost_firewall.py index ceeaa1cc..071d801d 100644 --- a/yunohost_firewall.py +++ b/yunohost_firewall.py @@ -233,6 +233,14 @@ def firewall_installupnp(): def firewall_removeupnp(): + """ + Remove upnp cron + Keyword arguments: + None + Return + None + """ + try: os.remove("/etc/cron.d/yunohost-firewall") except: @@ -242,6 +250,13 @@ def firewall_removeupnp(): def firewall_stop(): + """ + Stop firewall + Keyword arguments: + None + Return + None + """ os.system ("iptables -P INPUT ACCEPT") os.system ("iptables -F")