This commit is contained in:
Titoko 2012-12-12 19:20:09 +01:00
parent 3126a20079
commit ace2253eae
3 changed files with 34 additions and 20 deletions

View file

@ -407,6 +407,10 @@ firewall:
### firewall_list() ### firewall_list()
list: list:
action_help: List all firewall rules action_help: List all firewall rules
### firewall_reload()
reload:
action_help: Reload all firewall rules
### firewall_allow() ### firewall_allow()
allow: allow:
@ -420,10 +424,10 @@ firewall:
- UDP - UDP
- TCP - TCP
- Both - Both
-i: #-i:
full: --ipv6 # full: --ipv6
help: ipv6 # help: ipv6
action: store_true # action: store_true
### firewall_disallow() ### firewall_disallow()
@ -438,10 +442,10 @@ firewall:
- UDP - UDP
- TCP - TCP
- Both - Both
-i: #-i:
full: --ipv6 # full: --ipv6
help: ipv6 # help: ipv6
action: store_true # action: store_true
############################# #############################

View file

@ -1,10 +1,6 @@
# Ports to open
#
ipv4: ipv4:
TCP: [22, 25, 53, 80, 443, 5222, 5269, 5280] TCP: [22, 25, 53, 80, 443, 5222, 5269, 5280]
UDP: [53] UDP: []
ipv6: ipv6:
TCP: [] TCP: [22]
UDP: [] UDP: []

View file

@ -21,6 +21,7 @@ def firewall_allow(protocol=None,port=None,ip=None):
if protocol == "Both": if protocol == "Both":
TCP_rule = iptables+" -A INPUT -p tcp -i eth0 --dport "+ port +" -j ACCEPT" TCP_rule = iptables+" -A INPUT -p tcp -i eth0 --dport "+ port +" -j ACCEPT"
UDP_rule = iptables+" -A INPUT -p udp -i eth0 --dport "+ port +" -j ACCEPT" UDP_rule = iptables+" -A INPUT -p udp -i eth0 --dport "+ port +" -j ACCEPT"
append_remove_port(port,'tcp','a',ip) append_remove_port(port,'tcp','a',ip)
append_remove_port(port,'udp','a',ip) append_remove_port(port,'udp','a',ip)
@ -120,15 +121,19 @@ def firewall_reload():
for i,port in enumerate (TCP_port_list_ipv4): for i,port in enumerate (TCP_port_list_ipv4):
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")
print("Port "+str(port)+" on protocol TCP with ipv4 Open")
for i,port in enumerate (UDP_port_list_ipv4): for i,port in enumerate (UDP_port_list_ipv4):
os.system ("iptables -A INPUT -p udp -i eth0 --dport "+ str(port) +" -j ACCEPT") os.system ("iptables -A INPUT -p udp -i eth0 --dport "+ str(port) +" -j ACCEPT")
print("Port "+str(port)+" on protocol UDP with ipv4 Open")
for i,port in enumerate (TCP_port_list_ipv6): for i,port in enumerate (TCP_port_list_ipv6):
os.system ("ip6tables -A INPUT -p tcp -i eth0 --dport "+ str(port) +" -j ACCEPT") os.system ("ip6tables -A INPUT -p tcp -i eth0 --dport "+ str(port) +" -j ACCEPT")
print("Port "+str(port)+" on protocol TCP with ipv6 Open")
for i,port in enumerate (UDP_port_list_ipv6): for i,port in enumerate (UDP_port_list_ipv6):
os.system ("ip6tables -A INPUT -p udp -i eth0 --dport "+ str(port) +" -j ACCEPT") os.system ("ip6tables -A INPUT -p udp -i eth0 --dport "+ str(port) +" -j ACCEPT")
print("Port "+str(port)+" on protocol UDP with ipv6 Open")
os.system ("iptables -P INPUT DROP") os.system ("iptables -P INPUT DROP")
os.system ("ip6tables -P INPUT DROP") os.system ("ip6tables -P INPUT DROP")
@ -139,16 +144,25 @@ def append_remove_port(port=None,protocol=None,mode=None,ip=None):
''' '''
Append port in firewall.yml Append port in firewall.yml
''' '''
if ip == True:
ip = 'ipv6'
else:
ip = 'ipv4'
with open('firewall.yml','r') as f: with open('firewall.yml','r') as f:
firewall = yaml.load(f) firewall = yaml.load(f)
if mode == 'a': if mode == 'a':
if port not in firewall[ip][protocol]: if int(port) not in firewall[ip][protocol]:
firewall[ip][protocol].append(int(port)) firewall[ip][protocol].append(int(port))
print("Port "+port+" on protocol "+protocol+" with "+ip+" Open")
else:
print("Port already open")
else: else:
if port not in firewall[ip][protocol]: if int(port) in firewall[ip][protocol]:
firewall[ip][protocol].remove(int(port)) firewall[ip][protocol].remove(int(port))
print("Port "+port+" on protocol "+protocol+" with "+ip+" Close")
else:
print("Port already close")
firewall[ip][protocol].sort() firewall[ip][protocol].sort()
f.close f.close