Commit 77a596bd authored by Gabriel Detraz's avatar Gabriel Detraz

Interface de gestion du parc wifi sur l'intranet, transmet les bonnes commandes au backend

parent dc172720
# -*- coding: utf-8 -*-
from django import forms
from django.forms import widgets
class Wifi_Action(forms.Form):
actions_possibles = forms.ChoiceField(widget=forms.RadioSelect(), label=u'Actions possible sur les bornes ', required=False)
class Wifi_Info(forms.Form):
vlan_select = forms.CharField(label=u'Vlan séléctionné', max_length=40, required=False)
ssid_name = forms.CharField(label=u'Nom du ssid', max_length=40, required=False)
encryption_mode = forms.CharField(label=u'Protocole de sécurité (choisir wpa2, psk ou open)', max_length=40, required=False)
encryption_server = forms.CharField(label=u'Serveur Radius (ipv6)', max_length=60, required=False)
encryption_key = forms.CharField(label=u'Clef de Sécurité Radius', max_length=40, required=False)
class Bornes_Cibles(forms.Form):
batiment = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, label=u'Action à effectuer sur les batiments ', required=False)
borne = forms.CharField(label=u'Action sur une borne en particulier ', max_length=40, required=False)
......@@ -24,6 +24,7 @@ urlpatterns = patterns('',
url('^$', views.index),
url('^get_xml$', views.get_xml),
url('^update\((\w+),(\d+\.?\d+),(\d+\.?\d+)\)$', views.update),
url('^change_conf$', views.change_conf),
)
......@@ -27,11 +27,18 @@ from django.shortcuts import get_object_or_404
from django.contrib.auth.decorators import login_required, permission_required
from django.views.decorators.csrf import csrf_exempt
from django.contrib import messages
from models import VirtAP
from forms import Wifi_Action
from forms import Bornes_Cibles
from forms import Wifi_Info
from django.utils.importlib import import_module
conn_pool = import_module('conn_pool', 'intranet')
from lc_ldap.crans_utils import escape as ldap_escape
from gestion.config.config import liste_bats
from wifi_new.manage_borne_conf import exec_conn
from wifi_new import template
import xml.dom.minidom
......@@ -52,7 +59,8 @@ def get_xml(request):
return HttpResponse(doc.toxml('utf-8'),content_type='text/xml; coding=utf-8')
def index(request):
return django.shortcuts.render_to_response('wifimap/index.html', context_instance=RequestContext(request))
public = not request.user.groups.filter(name='crans_nounou')
return django.shortcuts.render_to_response('wifimap/index.html', locals(), context_instance=RequestContext(request))
@csrf_exempt
@permission_required('wifimap.change_virtAP')
......@@ -83,3 +91,71 @@ def update(request,hostname, lon, lat):
doc.appendChild(borne)
ap.save()
return HttpResponse(doc.toxml('utf-8'),content_type='text/xml; coding=utf-8')
@permission_required('wifimap.change_virtAP')
def change_conf(request):
wifi_action = Wifi_Action()
bornes_cibles = Bornes_Cibles()
wifi_info = Wifi_Info()
BATS = [(bat,bat) for bat in liste_bats]
BATS.extend((('ens','ENS'),('all','Tous')))
OPTIONS = [('ssid','Ajouter un SSID'), ('vlan','Ajouter une interface réseau'), ('ssid_enable','Activer un SSID (Deja présent !)'), ('ssid_disable','Désactiver un SSID'), ('hostapd','Redémarer Hostapd'), ('network','Redémarer network interfaces')]
wifi_action.fields['actions_possibles'].choices = tuple(OPTIONS)
bornes_cibles.fields['batiment'].choices = tuple(BATS)
option=False
if request.method == "POST":
# On instancie
wifi_action = Wifi_Action(request.POST)
bornes_cibles = Bornes_Cibles(request.POST)
wifi_info = Wifi_Info(request.POST)
#On formatte
bornes_cibles.fields['batiment'].choices = tuple(BATS)
wifi_action.fields['actions_possibles'].choices = tuple(OPTIONS)
# Etape 1 : selection de l'action
if wifi_action.is_valid() and wifi_action.cleaned_data['actions_possibles']:
#print wifi_action.cleaned_data['actions_possibles']
option = str(wifi_action.cleaned_data['actions_possibles'])
# On renvoie tout pour les menus secondaires.
return django.shortcuts.render_to_response('wifimap/change_conf.html', locals(), context_instance=RequestContext(request))
# Etape 2 : info supplémentaires et zone cible
if bornes_cibles.is_valid() and 'option' in request.POST.keys():
option = str(request.POST['option'])
#print option
# On récupère la cmd et on formatte
cmd = getattr(template,option)
#print bornes_cibles.cleaned_data['batiment']
#print bornes_cibles.cleaned_data['borne']
# Si c'est pas valide, excepté les cas triviaux, on envoie bouler pour eviter une commande foireuse sur les bornes
if option!="hostapd" or option!="network":
if not wifi_info.is_valid():
return django.shortcuts.render_to_response('wifimap/change_conf.html', locals(), context_instance=RequestContext(request))
# On format pour les commandes complexes (vlan, add ssid)
if option=="vlan":
cmd = cmd.format(wifi_info.cleaned_data['vlan_select'])
if option=="ssid_enable" or option == "ssid_disable":
cmd = cmd.format(wifi_info.cleaned_data['ssid_name'])
if option=="ssid":
cmd = cmd.format(wifi_info.cleaned_data['vlan_select'],wifi_info.cleaned_data['encryption_mode'], wifi_info.cleaned_data['encryption_server'], wifi_info.cleaned_data['ssid_name'], wifi_info.cleaned_data['encryption_key'])
#print cmd
# On choisi la zone cible et on envoie la commande
if "borne" in bornes_cibles.changed_data:
exec_conn(bats=all, ens=False, cmd="pwd", borne=bornes_cibles.cleaned_data['borne']+".wifi.crans.org")
if "batiment" in bornes_cibles.changed_data:
if bornes_cibles.cleaned_data['batiment'] == u"ens":
exec_conn(bats=all, ens=True, cmd="pwd", borne=False)
else:
exec_conn(bats=bornes_cibles.cleaned_data['batiment'], ens=False, cmd="pwd", borne=False)
# On retourne à l'user
messages.success(request, u"""La configuration a été prise en compte""")
return django.shortcuts.redirect("/wifimap/")
return django.shortcuts.render_to_response('wifimap/change_conf.html', locals(), context_instance=RequestContext(request))
return django.shortcuts.render_to_response('wifimap/change_conf.html', locals(), context_instance=RequestContext(request))
{% extends "template.html" %}
{% block title %} Mise à jour de la configuration {% endblock %}
{% block h1 %} <h1>Mise à jour de la configuration du parc </h1> {% endblock %}
{% block content %}
<div style="text-align: center;">
<div class="wifi_manager">
<table class="wifi_manager">
{% if not option %}
<form action="/wifimap/change_conf" method="post">
{% csrf_token %}
<tr class="no-border"><td>{{ wifi_action.actions_possibles.label_tag }}</td><td> {{ wifi_action.actions_possibles }} {{ wifi_action.actions_possibles.errors }}</td></tr>
<tr><td colspan="2" style="text-align:center;"><input type="submit" value="Valider les changements"></td></tr>
</form>
{% else %}
<form action="/wifimap/change_conf" method="post">
{% csrf_token %}
{% if option = "vlan"%}
<tr class="no-border"><td>Numéro du vlan à ajouter :</td></tr>
<tr class="no-border"><td>{{ wifi_info.label_tag }}</td><td> {{ wifi_info.vlan_select }} {{ wifi_info.vlan_select.errors }}</td></tr>
{% elif option = "ssid_enable" or option = "ssid_disable" %}
<tr class="no-border"><td>Numéro du SSID à activer/desactiver :</td></tr>
<tr class="no-border"><td>{{ wifi_info.label_tag }}</td><td> {{ wifi_info.ssid_name }} {{ wifi_info.ssid_name.errors }}</td></tr>
{% elif option = "ssid"%}
{{ wifi_info }}
{% endif %}
<tr class="no-border"><td>{{ bornes_cibles.batiment.label_tag }}</td><td> {{ bornes_cibles.batiment }} {{ bornes_cibles.batiment.errors }}</td></tr>
<tr class="no-border"><td>{{ bornes_cibles.borne.label_tag }}</td><td> {{ bornes_cibles.borne }} {{ bornes_cibles.borne.errors }}</td></tr>
<tr><td colspan="2" style="text-align:center;"><input type="hidden" value={{ option }} name="option" /><input type="submit" value="Valider définitivement"></td></tr>
</form>
{% endif %}
</table>
</div>
</div>
{% endblock %}
......@@ -12,6 +12,12 @@
{% endblock %}
{% block content %}
{% if not public %}
<form action="/wifimap/change_conf">
{% csrf_token %}
<input type="submit" value="Changer le configuration déployée"></td></tr>
{% endif %}
Dernière mise à jour il y a <label id="last_update"> </label>
<div id="toolbar">
<div id="borne_template" class="borne template">
......
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