Commit ab7dac28 authored by Gabriel Detraz's avatar Gabriel Detraz

Adaptation pour utlisation en proxy_pass sans dump

parent 85dc8dcb
......@@ -23,52 +23,52 @@ next_cleanup=time.time() + cleanup_time
def cleanup(now):
global cleanup_time, cache, cache_time, next_cleanup
if next_cleanup < now:
for ip in cache.keys():
for ip in cache.keys():
if cache[ip]['time']<(now - cache_time):
del cache[ip]
next_cleanup=time.time() + cleanup_time
deco={
'non_inscrit': 'ERR_CUSTOM_NON_INSCRIT.html',
'inscrit': 'ERR_CUSTOM_INSCRIT.html',
'age': 'ERR_CUSTOM_AGE.html',
'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',
'autodisc_p2p': 'ERR_CUSTOM_BL_AUTO_P2P.html',
'p2p':'ERR_CUSTOM_BL_P2P.html',
'autodisc_upload':'ERR_CUSTOM_BL_AUTO_UPLOAD.html',
'upload':'ERR_CUSTOM_BL_UPLOAD.html',
'chambre_invalide': 'ERR_CUSTOM_BL_CHAMBRE.html',
'carte_etudiant':'ERR_CUSTOM_BL_NO_CARTE.html',
'mail_invalide':'ERR_CUSTOM_BL_NO_MAIL.html',
'mail_invalide_inscription':'ERR_DISABLED_CUSTOM_BL_NO_MAIL.html',
'warez':'ERR_CUSTOM_BL_WAREZ.html',
'bloq':'ERR_CUSTOM_BLOQ.html',
'nouvelle_annee':'ERR_CUSTOM_NOUVELLE_ANNEE.html',
'paiement':'ERR_CUSTOM_NOUVELLE_ANNEE.html',
'non_inscrit': 'ERR_CUSTOM_NON_INSCRIT',
'inscrit': 'ERR_CUSTOM_INSCRIT',
'age': 'ERR_CUSTOM_AGE',
'ex_crous': 'ERR_CUSTOM_EX_CROUS',
'ex_crous_enable': 'ERR_CUSTOM_EX_CROUS_ENABLE',
'confirmation': 'ERR_RECONNECT_CONFIRM',
'age': 'ERR_CUSTOM_AGE',
'ago': 'ERR_CUSTOM_AGO',
'autodisc_p2p': 'ERR_CUSTOM_BL_AUTO_P2P',
'p2p':'ERR_CUSTOM_BL_P2P',
'autodisc_upload':'ERR_CUSTOM_BL_AUTO_UPLOAD',
'upload':'ERR_CUSTOM_BL_UPLOAD',
'chambre_invalide': 'ERR_CUSTOM_BL_CHAMBRE',
'carte_etudiant':'ERR_CUSTOM_BL_NO_CARTE',
'mail_invalide':'ERR_CUSTOM_BL_NO_MAIL',
'mail_invalide_inscription':'ERR_DISABLED_CUSTOM_BL_NO_MAIL',
'warez':'ERR_CUSTOM_BL_WAREZ',
'bloq':'ERR_CUSTOM_BLOQ',
'nouvelle_annee':'ERR_CUSTOM_NOUVELLE_ANNEE',
'paiement':'ERR_CUSTOM_NOUVELLE_ANNEE',
# en cas de sursis, la page donne une url pour continuer à naviguer
# sur Internet
'paiement_sursis': 'ERR_CUSTOM_READHESION.html',
'proxy_local':'ERR_CUSTOM_PROXY_LOCAL.html',
'virus':'ERR_CUSTOM_BL_VIRUS.html',
'ipv6_ra':'ERR_CUSTOM_RA.html',
'autodisc_virus':'ERR_CUSTOM_BL_AUTO_VIRUS.html',
'paiement_sursis': 'ERR_CUSTOM_READHESION',
'proxy_local':'ERR_CUSTOM_PROXY_LOCAL',
'virus':'ERR_CUSTOM_BL_VIRUS',
'ipv6_ra':'ERR_CUSTOM_RA',
'autodisc_virus':'ERR_CUSTOM_BL_AUTO_VIRUS',
}
for bl in deco.keys():
deco[bl]="/crans-deco/%s" % deco[bl]
blacklist_key = [
'non_inscrit',
'age','ago',
......@@ -85,7 +85,7 @@ def mac_from_ip(ip):
cmd = '/usr/sbin/arp -na %s' % ip
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
output, errors = p.communicate()
if output is not None :
if output is not None :
mac_addr = output.split()[3]
return mac_addr.strip()
else:
......@@ -113,7 +113,7 @@ def get(str):
except ldap.SERVER_DOWN:
QUERY = _get_ldap_connection()
return QUERY.search(str)
def get_machine_by_mac(ip):
mac_addr=mac_from_ip(ip)
machines = get(u'macAddress=%s' % mac_addr)
......@@ -122,11 +122,11 @@ def get_machine_by_mac(ip):
# machine = QUERY.search(u'macAddress=%s' % mac_addr, mode='rw')[0]
# machine.set_ipv4()
return machines
def get_machine_by_ip(ip):
return get(u'ipHostNumber=%s' % ip)
def get_page(ip, by_mac=False, accueil=False):
try:
if by_mac:
......@@ -164,8 +164,8 @@ def special(action, ip, environ, start_response):
("Content-Length", 0)
])
return ""
def app(environ, start_response):
if 'HTTP_K_REAL_IP' in environ.keys():
ip=environ['HTTP_K_REAL_IP']
......
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