mirror of
				https://gitlab.crans.org/mediatek/med.git
				synced 2025-11-04 05:02:19 +01:00 
			
		
		
		
	Commandes de management
This commit is contained in:
		@@ -11,11 +11,11 @@ User=root
 | 
				
			|||||||
Group=root
 | 
					Group=root
 | 
				
			||||||
PIDFile=/run/portail_captif.pid
 | 
					PIDFile=/run/portail_captif.pid
 | 
				
			||||||
WorkingDirectory=/var/www/portail_captif/
 | 
					WorkingDirectory=/var/www/portail_captif/
 | 
				
			||||||
ExecStartPre=/usr/bin/python3 /var/www/portail_captif/portail_captif/start_portail.py
 | 
					ExecStartPre=/usr/bin/python3 /var/www/portail_captif/manage.py start_portail
 | 
				
			||||||
ExecStart=/usr/bin/gunicorn3 portail_captif.wsgi:application --pid=/run/portail_captif.pid --name www-data --user www-data --group www-data --daemon --log-file /var/log/gunicorn/portail_captif.log --log-level=info --bind=unix:///tmp/gunicorn-portail_captif.sock --workers=1
 | 
					ExecStart=/usr/bin/gunicorn3 portail_captif.wsgi:application --pid=/run/portail_captif.pid --name www-data --user www-data --group www-data --daemon --log-file /var/log/gunicorn/portail_captif.log --log-level=info --bind=unix:///tmp/gunicorn-portail_captif.sock --workers=1
 | 
				
			||||||
ExecReload=/bin/kill -s HUP $MAINPID
 | 
					ExecReload=/bin/kill -s HUP $MAINPID
 | 
				
			||||||
ExecStop=/bin/kill -s TERM $MAINPID
 | 
					ExecStop=/bin/kill -s TERM $MAINPID
 | 
				
			||||||
ExecStopPost=/usr/bin/python3 /var/www/portail_captif/portail_captif/stop_portail.py
 | 
					ExecStopPost=/usr/bin/python3 /var/www/portail_captif/manage.py stop_portail
 | 
				
			||||||
Restart=on-failure
 | 
					Restart=on-failure
 | 
				
			||||||
RestartSec=65
 | 
					RestartSec=65
 | 
				
			||||||
StartLimitInterval=60
 | 
					StartLimitInterval=60
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,36 +19,26 @@
 | 
				
			|||||||
# Ce script est appellé avant le démarage du portail, il insère les bonnes règles
 | 
					# Ce script est appellé avant le démarage du portail, il insère les bonnes règles
 | 
				
			||||||
# dans l'iptables et active le routage
 | 
					# dans l'iptables et active le routage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os, sys
 | 
					from django.core.management.base import BaseCommand, CommandError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.core.wsgi import get_wsgi_application
 | 
					 | 
				
			||||||
from os.path import dirname
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
proj_path = "/var/www/portail_captif/"
 | 
					 | 
				
			||||||
# This is so Django knows where to find stuff.
 | 
					 | 
				
			||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "portail_captif.settings")
 | 
					 | 
				
			||||||
sys.path.append(proj_path)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# This is so my local_settings.py gets loaded.
 | 
					 | 
				
			||||||
os.chdir(proj_path)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
from users.models import restore_iptables, create_ip_set, fill_ipset, apply
 | 
					from users.models import restore_iptables, create_ip_set, fill_ipset, apply
 | 
				
			||||||
from portail_captif.settings import AUTORIZED_INTERFACES
 | 
					from portail_captif.settings import AUTORIZED_INTERFACES
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Command(BaseCommand):
 | 
				
			||||||
 | 
					    help = 'Mets en place iptables et le set ip au démarage'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
application = get_wsgi_application()
 | 
					    def handle(self, *args, **options):
 | 
				
			||||||
 | 
					 | 
				
			||||||
        # Creation de l'ipset
 | 
					        # Creation de l'ipset
 | 
				
			||||||
        create_ip_set()
 | 
					        create_ip_set()
 | 
				
			||||||
 | 
					 | 
				
			||||||
        # Remplissage avec les macs autorisées
 | 
					        # Remplissage avec les macs autorisées
 | 
				
			||||||
        fill_ipset()
 | 
					        fill_ipset()
 | 
				
			||||||
 | 
					 | 
				
			||||||
        # Restauration de l'iptables
 | 
					        # Restauration de l'iptables
 | 
				
			||||||
        restore_iptables()
 | 
					        restore_iptables()
 | 
				
			||||||
        # Activation du routage sur les bonnes if
 | 
					        # Activation du routage sur les bonnes if
 | 
				
			||||||
        for interface in AUTORIZED_INTERFACES:
 | 
					        for interface in AUTORIZED_INTERFACES:
 | 
				
			||||||
    apply("echo 1 > /proc/sys/net/ipv6/conf/%s/forwarding" % interface)
 | 
					            apply(["sudo", "-n", "sysctl",  "net.ipv6.conf.%s.forwarding=1" % interface])
 | 
				
			||||||
    apply("echo 1 > /proc/sys/net/ipv4/conf/%s/forwarding" % interface)
 | 
					            apply(["sudo", "-n", "sysctl",  "net.ipv4.conf.%s.forwarding=1" % interface])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,26 +19,23 @@
 | 
				
			|||||||
# Ce script est appellé avant le démarage du portail, il insère les bonnes règles
 | 
					# Ce script est appellé avant le démarage du portail, il insère les bonnes règles
 | 
				
			||||||
# dans l'iptables et active le routage
 | 
					# dans l'iptables et active le routage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os, sys
 | 
					from django.core.management.base import BaseCommand, CommandError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
proj_path = "/var/www/portail_captif/"
 | 
					 | 
				
			||||||
# This is so Django knows where to find stuff.
 | 
					 | 
				
			||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "portail_captif.settings")
 | 
					 | 
				
			||||||
sys.path.append(proj_path)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# This is so my local_settings.py gets loaded.
 | 
					from users.models import restore_iptables, create_ip_set, fill_ipset, disable_iptables, apply
 | 
				
			||||||
os.chdir(proj_path)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
from users.models import restore_iptables, apply
 | 
					 | 
				
			||||||
from portail_captif.settings import AUTORIZED_INTERFACES
 | 
					from portail_captif.settings import AUTORIZED_INTERFACES
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Command(BaseCommand):
 | 
				
			||||||
 | 
					    help = 'Mets en place iptables et le set ip au démarage'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def handle(self, *args, **options):
 | 
				
			||||||
        # Destruction de l'iptables
 | 
					        # Destruction de l'iptables
 | 
				
			||||||
apply("iptables -t nat -F")
 | 
					        disable_iptables()
 | 
				
			||||||
apply("iptables -t filter -F")
 | 
					 | 
				
			||||||
apply("iptables -t mangle  -F")
 | 
					 | 
				
			||||||
        # Desactivation du routage sur les bonnes if
 | 
					        # Desactivation du routage sur les bonnes if
 | 
				
			||||||
        for interface in AUTORIZED_INTERFACES:
 | 
					        for interface in AUTORIZED_INTERFACES:
 | 
				
			||||||
    apply("echo 0 > /proc/sys/net/ipv6/conf/%s/forwarding" % interface)
 | 
					            apply(["sudo", "-n", "sysctl",  "net.ipv6.conf.%s.forwarding=0" % interface])
 | 
				
			||||||
    apply("echo 0 > /proc/sys/net/ipv4/conf/%s/forwarding" % interface)
 | 
					            apply(["sudo", "-n", "sysctl",  "net.ipv4.conf.%s.forwarding=0" % interface])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Reference in New Issue
	
	Block a user