portail_captif: /enable => autorise surcis

This commit is contained in:
Daniel STAN 2014-10-01 00:01:53 +02:00
parent d947a60253
commit ee76d0dc6e

View file

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
import sys
import subprocess
import time
@ -32,6 +34,7 @@ deco={
'ex_crous': 'ERR_CUSTOM_EX_CROUS.html',
'ex_crous_enable': 'ERR_CUSTOM_EX_CROUS_ENABLE.html',
'confirmation': 'ERR_RECONNECT_CONFIRM.html',
'age': 'ERR_CUSTOM_AGE.html',
'ago': 'ERR_CUSTOM_AGO.html',
@ -48,7 +51,7 @@ deco={
'bloq':'ERR_CUSTOM_BLOQ.html',
'nouvelle_annee':'ERR_CUSTOM_NOUVELLE_ANNEE.html',
'paiement': 'ERR_CUSTOM_NOUVELLE_ANNEE.html',
'paiement': 'ERR_CUSTOM_READHESION.html',
'proxy_local':'ERR_CUSTOM_PROXY_LOCAL.html',
'virus':'ERR_CUSTOM_BL_VIRUS.html',
@ -83,7 +86,8 @@ def mac_from_ip(ip):
def enable_access(ip):
"""Lance la commande idoine pour autoriser l'adresse IP"""
p = subprocess.Popen(['sudo', '-n', '/usr/scripts/utils/install-party/ipset_allow', ip],
cmd = ['/usr/sbin/ipset', 'add', 'CONFIRMATION', ip]
p = subprocess.Popen(['sudo', '-n'] + cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
@ -169,6 +173,9 @@ def app(environ, start_response):
data = deco['ex_crous_enable']
else:
data = deco['ex_crous']
elif environ.get('RAW_URI', '').startswith('/enable'):
enable_access(ip)
data = deco['confirmation']
elif ip in cache.keys() and cache[ip]['time']>(now - cache_time):
data=cache[ip]['page']
else: