rougail/data/diag.py

65 lines
2 KiB
Python
Raw Normal View History

2019-11-23 08:17:35 +01:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###########################################################################
# Eole NG - 2009
# Copyright Pole de Competence Eole (Ministere Education - Academie Dijon)
# http://eole.orion.education.fr - eole@ac-dijon.fr
#
# Licence CeCill
# cf: http://www.cecill.info/licences.fr.html
###########################################################################
import sys
import socket
from os.path import isfile
from os import system, stat
from pyeole.httprequest import HTTPRequest
from creole.config import configeol
from creole.client import CreoleClient
client = CreoleClient()
# adresse IP et port du serveur d'enregistrement
server = "http://194.167.18.21/apps/AutoDiag/index.n/diagnose"
md5file = "/etc/eole/.server.MD5"
module = "%s-%s" % (client.get_creole('eole_module'), client.get_creole('eole_version'))
def get_md5():
""" calcul de l'identifiant md5 """
if not isfile(md5file) or stat(md5file).st_size == 0:
system("md5sum %s | awk '{print $1}' > %s" % (configeol, md5file))
fp = file(md5file)
return (fp.read().split()[0])
def get_proxy():
""" récupération du proxy à utiliser """
if client.get_creole('activer_proxy_client') == 'oui':
return "http://{0}:{1}".format(
client.get_creole('proxy_client_adresse'),
client.get_creole('proxy_client_port'))
return ''
if __name__ == "__main__":
id5 = get_md5()
rne = client.get_creole('numero_etab')
data = {"ID5":id5, "module":module, "rne":rne, "dep":rne[0:3]}
socket.setdefaulttimeout(5)
proxy = get_proxy()
if proxy != '':
# essai avec proxy
try:
req = HTTPRequest(proxy={'http':proxy})
req.request(server, post_datas=data)
except:
pass
else:
sys.exit(0)
# essai sans proxy
try:
req = HTTPRequest()
req.request(server, post_datas=data)
except:
sys.exit(1)
else:
sys.exit(0)