Commit 0db6c091 authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

Commandes de management

parent 353cea2f
...@@ -11,11 +11,11 @@ User=root ...@@ -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 @@ ...@@ -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'
def handle(self, *args, **options):
# Creation de l'ipset
create_ip_set()
# Remplissage avec les macs autorisées
fill_ipset()
# Restauration de l'iptables
restore_iptables()
# Activation du routage sur les bonnes if
for interface in AUTORIZED_INTERFACES:
apply(["sudo", "-n", "sysctl", "net.ipv6.conf.%s.forwarding=1" % interface])
apply(["sudo", "-n", "sysctl", "net.ipv4.conf.%s.forwarding=1" % interface])
application = get_wsgi_application()
# Creation de l'ipset
create_ip_set()
# Remplissage avec les macs autorisées
fill_ipset()
# Restauration de l'iptables
restore_iptables()
# Activation du routage sur les bonnes if
for interface in AUTORIZED_INTERFACES:
apply("echo 1 > /proc/sys/net/ipv6/conf/%s/forwarding" % interface)
apply("echo 1 > /proc/sys/net/ipv4/conf/%s/forwarding" % interface)
...@@ -15,30 +15,27 @@ ...@@ -15,30 +15,27 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# #
# 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.
os.chdir(proj_path)
from users.models import restore_iptables, apply from users.models import restore_iptables, create_ip_set, fill_ipset, disable_iptables, apply
from portail_captif.settings import AUTORIZED_INTERFACES from portail_captif.settings import AUTORIZED_INTERFACES
# Destruction de l'iptables class Command(BaseCommand):
apply("iptables -t nat -F") help = 'Mets en place iptables et le set ip au démarage'
apply("iptables -t filter -F")
apply("iptables -t mangle -F") def handle(self, *args, **options):
# Desactivation du routage sur les bonnes if # Destruction de l'iptables
for interface in AUTORIZED_INTERFACES: disable_iptables()
apply("echo 0 > /proc/sys/net/ipv6/conf/%s/forwarding" % interface) # Desactivation du routage sur les bonnes if
apply("echo 0 > /proc/sys/net/ipv4/conf/%s/forwarding" % interface) for interface in AUTORIZED_INTERFACES:
apply(["sudo", "-n", "sysctl", "net.ipv6.conf.%s.forwarding=0" % interface])
apply(["sudo", "-n", "sysctl", "net.ipv4.conf.%s.forwarding=0" % interface])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment