mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Bug Fix
This commit is contained in:
parent
a94a1a143f
commit
5cf6e5bf16
3 changed files with 34 additions and 20 deletions
|
@ -408,6 +408,10 @@ firewall:
|
||||||
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:
|
||||||
action_help: Allow connection port/protocol
|
action_help: Allow connection port/protocol
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
|
|
10
firewall.yml
10
firewall.yml
|
@ -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: [22]
|
||||||
TCP: []
|
|
||||||
UDP: []
|
UDP: []
|
||||||
|
|
|
@ -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:
|
else:
|
||||||
if port not in firewall[ip][protocol]:
|
print("Port already open")
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue