190 lines
6.4 KiB
Python
Executable file
190 lines
6.4 KiB
Python
Executable file
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
import cherrypy, sys, os, datetime
|
|
sys.path.append('/usr/scripts/gestion/')
|
|
|
|
|
|
# ######################################################## #
|
|
# COMMAND LINE OPTION #
|
|
# ######################################################## #
|
|
#
|
|
#
|
|
|
|
from optparse import OptionParser
|
|
|
|
parser = OptionParser()
|
|
parser.add_option("-d", "--dev",
|
|
action="store_true", dest="dev", default=False,
|
|
help="launch in dev mode")
|
|
parser.add_option("-p", "--port",
|
|
action="store", type="int", dest="port",
|
|
help="change server port")
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
# ######################################################## #
|
|
# CONFIG #
|
|
# ######################################################## #
|
|
#
|
|
# mise en place de la conf
|
|
#
|
|
|
|
# on suppose qu'en version de developpement, le script est lance depuis le shell
|
|
if (options.dev):
|
|
cherrypy.config.update(file=os.getcwd() + "/conf/intranet.cfg")
|
|
cherrypy.config.update(file=os.getcwd() + "/conf/dev.cfg")
|
|
settings={'global': { 'rootDir': os.getcwd() } }
|
|
cherrypy.config.update(settings)
|
|
|
|
else:
|
|
cherrypy.config.update(file="/usr/scripts/intranet/conf/intranet.cfg")
|
|
cherrypy.config.update(file="/usr/scripts/intranet/conf/prod.cfg")
|
|
|
|
# changer le port ??
|
|
if (options.port):
|
|
settings={'global':{'server.socketPort':options.port}}
|
|
cherrypy.config.update(settings)
|
|
|
|
|
|
if (cherrypy.config.configMap["global"]["server.environment"] == "development"):
|
|
from ldap_crans_test import crans_ldap
|
|
print("settings : unsing test ldap : env=" + cherrypy.config.configMap["global"]["server.environment"])
|
|
else:
|
|
from ldap_crans import crans_ldap
|
|
print("settings : unsing prod ldap : env=" + cherrypy.config.configMap["global"]["server.environment"])
|
|
cherrypy.config.update({'global':{'crans_ldap':crans_ldap()}})
|
|
|
|
# ######################################################## #
|
|
# FILTRES MAISON #
|
|
# ######################################################## #
|
|
|
|
from plugins.domfilter import DOMFilter
|
|
from plugins.templatesfilter import TemplatesFilter
|
|
from plugins.verifdroitsfilter import VerifDroitsFilter
|
|
|
|
# ######################################################## #
|
|
# SERVER #
|
|
# ######################################################## #
|
|
class Intranet:
|
|
__ldap = None
|
|
def __init__(self):
|
|
from pages import monCompte, impression, factures, digicode
|
|
self.__ldap = cherrypy.config.configMap["global"]["crans_ldap"]
|
|
|
|
# liste des modules disponibles
|
|
self.monCompte = monCompte.monCompte()
|
|
self.sous = factures.root()
|
|
self.impression = impression.root()
|
|
|
|
# liste des modules en developpement
|
|
if (cherrypy.config.configMap["global"]["server.environment"] == "development"):
|
|
self.digicode = digicode.root()
|
|
|
|
|
|
|
|
_cpFilterList = [TemplatesFilter(), DOMFilter(), VerifDroitsFilter()]
|
|
|
|
def index(self):
|
|
return {
|
|
'template':'accueil',
|
|
'values':{},
|
|
}
|
|
index.exposed= True
|
|
|
|
def info(self):
|
|
return {
|
|
'template':'info-diverses',
|
|
'values':{}
|
|
}
|
|
info.exposed = True
|
|
|
|
|
|
def _cp_on_http_error(self, status, message):
|
|
if status==403:
|
|
cherrypy.response.body = {
|
|
'template':'error403',
|
|
'values':{'status':status, 'message':message },
|
|
'standalone':False,
|
|
}
|
|
elif status==404:
|
|
cherrypy.response.body = {
|
|
'template':'error',
|
|
'values':{'status':status, 'message':message },
|
|
'standalone':False,
|
|
}
|
|
else:
|
|
cherrypy._cputil._cp_on_http_error(status, message)
|
|
|
|
'''
|
|
def nounous(self):
|
|
return "coucou"
|
|
nounous.exposed= True
|
|
|
|
def test(self):
|
|
return {"quoi":cherrypy.request.path, "il_faut":cherrypy.config.configMap["/nounous"]["crans.droits"], "moi":cherrypy.session['droits']
|
|
}
|
|
test.exposed = True
|
|
|
|
def environment(self):
|
|
return cherrypy.config.configMap["global"]["server.environment"]
|
|
environment.exposed = True
|
|
'''
|
|
|
|
# ######################################################## #
|
|
# LOGIN MAISON #
|
|
# ######################################################## #
|
|
#
|
|
# Methode pour afficher la template de login
|
|
#
|
|
def login(from_page = '', login = None, password = '', error_msg=''):
|
|
return {
|
|
'template':'login',
|
|
'values':{'login':login, 'password':password, 'from_page':from_page, 'message':error_msg},
|
|
'standalone':True
|
|
}
|
|
#
|
|
# methode qui verifie le login
|
|
#
|
|
def verifLogin(login = '', password = ''):
|
|
message = None
|
|
if login != '' and password != '':
|
|
try:
|
|
globalLdap = cherrypy.config.configMap["global"]["crans_ldap"]
|
|
adh =globalLdap.search('uid=' + login)['adherent'][0]
|
|
if adh.checkPassword(password):
|
|
cherrypy.session['uid'] = login
|
|
cherrypy.session['session_key'] = True
|
|
cherrypy.session['droits'] = adh.droits()
|
|
return
|
|
else:
|
|
#print("bad password")
|
|
message = u"L'authentification a echoué."
|
|
except Exception, e:
|
|
#print(e)
|
|
message = u"L'authentification a echoué."
|
|
else:
|
|
#print("sth empty")
|
|
message = u"L'authentification a echoué."
|
|
return message
|
|
|
|
|
|
|
|
|
|
|
|
# on indique tout ca a cherrypy
|
|
settings={'/': {
|
|
'sessionAuthenticateFilter.checkLoginAndPassword': verifLogin,
|
|
'sessionAuthenticateFilter.loginScreen': login
|
|
}}
|
|
cherrypy.config.update(settings)
|
|
|
|
|
|
|
|
# ######################################################## #
|
|
# LANCEMENT DE CHERRYPY #
|
|
# ######################################################## #
|
|
cherrypy.root = Intranet()
|
|
cherrypy.server.start()
|