ajout de intranet dans le cvs
darcs-hash:20060713112213-f46e9-e273e9aa5c50db9c5967b23a3ca9128a79eec800.gz
This commit is contained in:
parent
5dc32794e4
commit
6228576eee
7 changed files with 872 additions and 0 deletions
245
intranet/Root.py
Executable file
245
intranet/Root.py
Executable file
|
@ -0,0 +1,245 @@
|
||||||
|
#! /usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import cherrypy, sys, os, datetime
|
||||||
|
from Cheetah.Template import Template
|
||||||
|
sys.path.append('/usr/scripts/gestion/')
|
||||||
|
|
||||||
|
# ######################################################## #
|
||||||
|
# Configuration de Cheetah #
|
||||||
|
# ######################################################## #
|
||||||
|
|
||||||
|
def serverSidePath(self, path):
|
||||||
|
# les template se trouve dans le dossier template
|
||||||
|
return os.getcwd()+'/templates/'+path
|
||||||
|
|
||||||
|
# on surcharge cette fonction dans la classe Template
|
||||||
|
Template.serverSidePath = serverSidePath
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ######################################################## #
|
||||||
|
# FILTRES MAISON #
|
||||||
|
# ######################################################## #
|
||||||
|
|
||||||
|
from cherrypy.filters.basefilter import BaseFilter
|
||||||
|
import cherrypy._cputil
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# DomFilter
|
||||||
|
##########################
|
||||||
|
#
|
||||||
|
# transforme des objets python
|
||||||
|
# en chainses de caracteres qui peuvent
|
||||||
|
# etre parsees avec JSON/javascript
|
||||||
|
#
|
||||||
|
class DOMFilter(BaseFilter):
|
||||||
|
def beforeFinalize(self):
|
||||||
|
body = cherrypy.response.body
|
||||||
|
if isinstance(body, dict):
|
||||||
|
body = self.printAsDom(body)
|
||||||
|
cherrypy.response.body = body
|
||||||
|
|
||||||
|
def printAsDom(self, chose):
|
||||||
|
if isinstance(chose, dict):
|
||||||
|
stringList = []
|
||||||
|
for a_key in chose.keys():
|
||||||
|
stringList.append('%s:%s' % (self.printAsDom(a_key), self.printAsDom(chose[a_key])))
|
||||||
|
return "{%s}" % ','.join(stringList)
|
||||||
|
|
||||||
|
if isinstance(chose, list):
|
||||||
|
stringList = []
|
||||||
|
for an_item in chose:
|
||||||
|
stringList.append('%s' % (self.printAsDom(an_item)))
|
||||||
|
return "[%s]" % ','.join(stringList)
|
||||||
|
|
||||||
|
if isinstance(chose, str):
|
||||||
|
return '"%s"' % chose
|
||||||
|
|
||||||
|
if isinstance(chose, unicode):
|
||||||
|
return '"%s"' % chose.encode('utf8')
|
||||||
|
|
||||||
|
return str(chose)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# templatesEngine
|
||||||
|
##########################
|
||||||
|
#
|
||||||
|
# Application des templates,
|
||||||
|
# avec plein de test chians
|
||||||
|
#
|
||||||
|
class templatesEngine(BaseFilter):
|
||||||
|
|
||||||
|
def _getBodyTemplate(self, body):
|
||||||
|
if isinstance(body, dict):
|
||||||
|
if body.has_key('template'):
|
||||||
|
if body['template'].endswith(".py"):
|
||||||
|
return body['template']
|
||||||
|
elif body['template'].endswith(".tmpl"):
|
||||||
|
return body['template']
|
||||||
|
else:
|
||||||
|
return body['template'] + ".tmpl"
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _isStandaloneBody(self, body):
|
||||||
|
if isinstance(body, dict):
|
||||||
|
if body.has_key('standalone'):
|
||||||
|
return body['standalone']
|
||||||
|
if body.has_key('template'):
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _getBodyNameSpace(self, body):
|
||||||
|
if isinstance(body, dict):
|
||||||
|
if body.has_key('values'):
|
||||||
|
return body['values']
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def _useMainTemplate(self, body):
|
||||||
|
t = Template(file='main.tmpl', searchList=[body,{'login':cherrypy.session['uid'], 'environment':cherrypy.config.configMap["global"]["server.environment"]}])
|
||||||
|
return str(t)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def beforeFinalize(self):
|
||||||
|
|
||||||
|
body = cherrypy.response.body
|
||||||
|
if isinstance(body, dict):
|
||||||
|
bodyTemplate = self._getBodyTemplate(body)
|
||||||
|
if bodyTemplate:
|
||||||
|
templatevalues = self._getBodyNameSpace(body)
|
||||||
|
t = Template(file=bodyTemplate, searchList=[templatevalues])
|
||||||
|
body['page'] = str(t)
|
||||||
|
|
||||||
|
if not self._isStandaloneBody(body):
|
||||||
|
body = self._useMainTemplate(body)
|
||||||
|
else:
|
||||||
|
body = body["page"]
|
||||||
|
|
||||||
|
cherrypy.response.body = body
|
||||||
|
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# verification des droits
|
||||||
|
##########################
|
||||||
|
#
|
||||||
|
# Application des templates,
|
||||||
|
# avec plein de test chians
|
||||||
|
#
|
||||||
|
class verifDroits(BaseFilter):
|
||||||
|
|
||||||
|
def before_main(self):
|
||||||
|
if not cherrypy.config.get('sessionAuthenticateFilter.on', False):
|
||||||
|
return
|
||||||
|
if not cherrypy.session.get("session_key"):
|
||||||
|
return
|
||||||
|
droits = cherrypy.config.get('crans.droits', 'all')
|
||||||
|
if (droits != "all"):
|
||||||
|
if not droits in cherrypy.session['droits']:
|
||||||
|
raise cherrypy.HTTPError(403, "Vous n'avez pas les droits nécessaires.")
|
||||||
|
|
||||||
|
# ######################################################## #
|
||||||
|
# SERVER #
|
||||||
|
# ######################################################## #
|
||||||
|
class Intranet:
|
||||||
|
__ldap = None
|
||||||
|
def __init__(self):
|
||||||
|
import monCompte, impression, factures
|
||||||
|
self.__ldap = cherrypy.config.configMap["global"]["crans_ldap"]
|
||||||
|
|
||||||
|
# liste des modules disponibles
|
||||||
|
self.monCompte = monCompte.monCompte()
|
||||||
|
self.impression = impression.root()
|
||||||
|
self.sous = factures.root()
|
||||||
|
|
||||||
|
|
||||||
|
_cpFilterList = [templatesEngine(), DOMFilter(), verifDroits()]
|
||||||
|
|
||||||
|
def index(self):
|
||||||
|
return {
|
||||||
|
'template':'accueil',
|
||||||
|
'values':{},
|
||||||
|
}
|
||||||
|
index.exposed= True
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# ######################################################## #
|
||||||
|
# CHERRYPY #
|
||||||
|
# ######################################################## #
|
||||||
|
#
|
||||||
|
# mise en place de cherrypy + conf
|
||||||
|
#
|
||||||
|
#cherrypy.config.update(file="/home/gdetrez/intranet/dev.cfg")
|
||||||
|
cherrypy.config.update(file="/home/gdetrez/intranet/prod.cfg")
|
||||||
|
cherrypy.config.update(file="/home/gdetrez/intranet/intranet.cfg")
|
||||||
|
settings={'/': {
|
||||||
|
'sessionAuthenticateFilter.checkLoginAndPassword': verifLogin,
|
||||||
|
'sessionAuthenticateFilter.loginScreen': login
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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()}})
|
||||||
|
cherrypy.root = Intranet()
|
||||||
|
|
||||||
|
cherrypy.server.start()
|
33
intranet/dev.cfg
Normal file
33
intranet/dev.cfg
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# The configuration file called myconfigfile.conf
|
||||||
|
[global]
|
||||||
|
server.socketPort=8080
|
||||||
|
server.socketHost=""
|
||||||
|
server.socketFile=""
|
||||||
|
server.socketQueueSize=5
|
||||||
|
server.protocolVersion="HTTP/1.0"
|
||||||
|
server.logToScreen=True
|
||||||
|
server.logFile=""
|
||||||
|
server.reverseDNS=False
|
||||||
|
server.threadPool=10
|
||||||
|
server.environment="development"
|
||||||
|
server.log_config_options= True
|
||||||
|
logDebugInfoFilter.on = False
|
||||||
|
|
||||||
|
sessionAuthenticateFilter.on=True
|
||||||
|
sessionFilter.on = True
|
||||||
|
sessionFilter.locking = "implicit"
|
||||||
|
|
||||||
|
#base_url_filter.on = True
|
||||||
|
#base_url_filter.base_url = "https://intranet2.crans.org/"
|
||||||
|
#base_url_filter.use_x_forwarded_host = True
|
||||||
|
|
||||||
|
[/]
|
||||||
|
# Now we can work on our filter as with the standard filters
|
||||||
|
templatesEngine.on = True
|
||||||
|
|
||||||
|
[/static]
|
||||||
|
sessionAuthenticateFilter.on=False
|
||||||
|
sessionFilter.on = False
|
||||||
|
server.output_filters.templatesEngine.on = False
|
||||||
|
staticFilter.on = True
|
||||||
|
staticFilter.dir = "/home/gdetrez/intranet/static/"
|
78
intranet/factures.py
Executable file
78
intranet/factures.py
Executable file
|
@ -0,0 +1,78 @@
|
||||||
|
#! /usr/bin/env python
|
||||||
|
# -*- coding: iso-8859-15 -*-
|
||||||
|
# ##################################################################################################### #
|
||||||
|
# Factures #
|
||||||
|
# ##################################################################################################### #
|
||||||
|
# Description: #
|
||||||
|
# Affiche la liste des factures et l'historique de débits/crédits de l'adhérent. #
|
||||||
|
# Informations: #
|
||||||
|
# Pas d'AJAX ici en principe #
|
||||||
|
# Pages: #
|
||||||
|
# index:liste des factures #
|
||||||
|
# historique: historique des débits/crédits #
|
||||||
|
# ##################################################################################################### #
|
||||||
|
import cherrypy, sys, os, datetime
|
||||||
|
|
||||||
|
class root:
|
||||||
|
__ldap = None
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.__ldap = cherrypy.config.configMap["global"]["crans_ldap"]
|
||||||
|
|
||||||
|
def index(self, message = '', error = ''):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||||
|
t = {}
|
||||||
|
t['message'] = message
|
||||||
|
t['error'] = error
|
||||||
|
|
||||||
|
############## liste des factures ##############
|
||||||
|
listeFactures = []
|
||||||
|
for f in adh.factures():
|
||||||
|
facture = {}
|
||||||
|
facture['no'] = f.numero()
|
||||||
|
facture['intitule'] = f.articles()[0]['designation']
|
||||||
|
facture['details'] = [
|
||||||
|
{
|
||||||
|
'intitule':art['designation'],
|
||||||
|
'quantite':art['nombre'],
|
||||||
|
'prixUnitaire':art['pu'],
|
||||||
|
'prixTotal':art['pu']*art['nombre'],
|
||||||
|
} for art in f.articles()]
|
||||||
|
facture['montant'] = f.total()
|
||||||
|
facture['paypal'] = f.urlPaypal()
|
||||||
|
facture['payee'] = f.recuPaiement()
|
||||||
|
listeFactures.append(facture)
|
||||||
|
t['listeFactures'] = listeFactures
|
||||||
|
|
||||||
|
return {
|
||||||
|
'template' :'factures',
|
||||||
|
'values' :t,
|
||||||
|
'stylesheets' :['cransFactures.css'],
|
||||||
|
'scripts' :[],
|
||||||
|
}
|
||||||
|
index.exposed = True
|
||||||
|
|
||||||
|
def historique(self):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||||
|
|
||||||
|
lst = [ x for x in adh.historique() if x.split(u' : ',2)[1].startswith(u'credit') or x.split(u' : ',2)[1].startswith(u'debit') ]
|
||||||
|
histLst = []
|
||||||
|
for anItem in lst:
|
||||||
|
#11/06/2006 01:40, gdetrez : credit 10.0 Euros [Facture n°1 : Impression]
|
||||||
|
aLine = {}
|
||||||
|
aLine["date"] = anItem.split(u",")[0]
|
||||||
|
aLine["type"] = anItem.split(u' : ',2)[1].split(u' ')[0]
|
||||||
|
aLine["montant"] = anItem.split(u' : ',2)[1].split(u' ')[1]
|
||||||
|
try:
|
||||||
|
aLine["intitule"] = anItem.split(u'[')[1].split(u']')[0]
|
||||||
|
except Exception:
|
||||||
|
aLine["intitule"] = ""
|
||||||
|
histLst.append(aLine)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'template' :'factures-historique',
|
||||||
|
'values' :{'liste':lst, 'historic_items':histLst},
|
||||||
|
'stylesheets' :['cransFactures.css'],
|
||||||
|
'scripts' :[],
|
||||||
|
}
|
||||||
|
historique.exposed = True
|
30
intranet/impression.py
Executable file
30
intranet/impression.py
Executable file
|
@ -0,0 +1,30 @@
|
||||||
|
#! /usr/bin/env python
|
||||||
|
import cherrypy
|
||||||
|
|
||||||
|
class root:
|
||||||
|
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# affichage
|
||||||
|
##########################
|
||||||
|
#
|
||||||
|
# methode qui affiche la template avec toutes les infos de
|
||||||
|
# l'adherent + les formulaires
|
||||||
|
#
|
||||||
|
def index(self, submit = None, fileList = None, newFile = None ):
|
||||||
|
data = {}
|
||||||
|
if (submit == None):
|
||||||
|
data['fileList'] = self.getUploadedFileListFor(cherrypy.session['uid'])
|
||||||
|
else:
|
||||||
|
data['fileName'] = "file1-name.pdf"
|
||||||
|
|
||||||
|
return {'template':'impression',
|
||||||
|
'values':data,
|
||||||
|
'stylesheets':['impression.css'],
|
||||||
|
'scripts':['impression.js', 'popup.js'],
|
||||||
|
}
|
||||||
|
index.exposed = True
|
||||||
|
|
||||||
|
|
||||||
|
def getUploadedFileListFor(self, adh):
|
||||||
|
return ['file1.pdf', 'file2.pdf', 'file3.pdf', 'file4.pdf', 'file5.pdf']
|
2
intranet/intranet.cfg
Normal file
2
intranet/intranet.cfg
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[/nounous]
|
||||||
|
crans.droits="nounou"
|
450
intranet/monCompte.py
Executable file
450
intranet/monCompte.py
Executable file
|
@ -0,0 +1,450 @@
|
||||||
|
#! /usr/bin/env python
|
||||||
|
# -*- coding: iso-8859-15 -*-
|
||||||
|
|
||||||
|
import cherrypy, sys, os, datetime
|
||||||
|
# libraries crans
|
||||||
|
sys.path.append('/usr/scripts/gestion/')
|
||||||
|
from config_mail import MailConfig
|
||||||
|
if (cherrypy.config.configMap["global"]["server.environment"] == "development"):
|
||||||
|
from ldap_crans_test import *
|
||||||
|
print("monCompte : unsing test ldap : env=" + cherrypy.config.configMap["global"]["server.environment"])
|
||||||
|
else:
|
||||||
|
from ldap_crans import *
|
||||||
|
print("monCompte : unsing prod ldap : env=" + cherrypy.config.configMap["global"]["server.environment"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class monCompte:
|
||||||
|
__ldap = None
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.__ldap = cherrypy.config.configMap["global"]["crans_ldap"]
|
||||||
|
|
||||||
|
|
||||||
|
def getCurrentAdministrativeYear(self):
|
||||||
|
'''
|
||||||
|
premiere partie de l''annee scolaire en cours
|
||||||
|
ex : le 5 juin 2006 retourne 2005
|
||||||
|
'''
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
currentYear = int(now.strftime("%Y"))
|
||||||
|
currentMonth = int(now.strftime("%m"))
|
||||||
|
if currentMonth > 8:
|
||||||
|
administrativeYear = currentYear
|
||||||
|
else:
|
||||||
|
administrativeYear = currentYear - 1
|
||||||
|
return administrativeYear
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# affichage
|
||||||
|
##########################
|
||||||
|
#
|
||||||
|
# methode qui affiche la template avec toutes les infos de
|
||||||
|
# l'adherent + les formulaires
|
||||||
|
#
|
||||||
|
def index(self, message = '', error = '', currentTab = 'mainTab'):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||||
|
t = {}
|
||||||
|
t['message'] = message
|
||||||
|
t['error'] = error
|
||||||
|
|
||||||
|
|
||||||
|
############## info adherent ##############
|
||||||
|
adherent = {}
|
||||||
|
# nom, prenom, chambre, tel, solde, droits, mail
|
||||||
|
adherent['prenom'] = adh.prenom()
|
||||||
|
adherent['nom'] = adh.nom()
|
||||||
|
adherent['chambre'] = adh.chbre()
|
||||||
|
adherent['telephone'] = adh.tel
|
||||||
|
adherent['solde'] = adh.solde
|
||||||
|
adherent['droits'] = u", ".join(adh.droits())
|
||||||
|
adherent['mail'] = adh.email()
|
||||||
|
# cotisation
|
||||||
|
administrativeYear = self.getCurrentAdministrativeYear()
|
||||||
|
if administrativeYear in adh.paiement():
|
||||||
|
adherent['cotisationOK'] = 'OK'
|
||||||
|
else:
|
||||||
|
adherent['cotisationOK'] = None
|
||||||
|
# carte etudiant
|
||||||
|
if administrativeYear in adh.carteEtudiant():
|
||||||
|
adherent['carteOK'] = 'OK'
|
||||||
|
else:
|
||||||
|
adherent['carteOK'] = None
|
||||||
|
# annee scolaire (ex 2001-2002)
|
||||||
|
adherent['anneeScolaire'] = str(administrativeYear) + '-' + str(administrativeYear + 1)
|
||||||
|
t['adherent'] = adherent
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
############## info machines ##############
|
||||||
|
machines = []
|
||||||
|
for une_machine in adh.machines():
|
||||||
|
machineInfos = {}
|
||||||
|
# nom, mac, mid, ip
|
||||||
|
machineInfos['id'] = une_machine.nom
|
||||||
|
machineInfos['nom'] = une_machine.nom
|
||||||
|
machineInfos['nomCourt'] = une_machine.nom().split('.',1)[0]
|
||||||
|
machineInfos['mac'] = une_machine.mac
|
||||||
|
machineInfos['mid'] = une_machine.id()
|
||||||
|
machineInfos['ip'] = une_machine.ip()
|
||||||
|
# type
|
||||||
|
if une_machine.objectClass == 'machineFixe':
|
||||||
|
machineInfos['type'] = 'Machine fixe'
|
||||||
|
else:
|
||||||
|
machineInfos['type'] = 'Machine wifi'
|
||||||
|
# clef ipsec
|
||||||
|
try:
|
||||||
|
machineInfos['ipsec'] = une_machine.ipsec
|
||||||
|
except:
|
||||||
|
machineInfos['ipsec'] = ''
|
||||||
|
machines.append(machineInfos)
|
||||||
|
t['machines'] = machines
|
||||||
|
|
||||||
|
############## info mail ##############
|
||||||
|
mailInfos = {}
|
||||||
|
#try:
|
||||||
|
mailConfig = MailConfig(cherrypy.session['uid'])
|
||||||
|
mailInfos['forwarding_address'] = mailConfig['forward']
|
||||||
|
mailInfos['spam'] = {}
|
||||||
|
mailInfos['spam']['no'] = mailConfig['spam'] == 'accepte'
|
||||||
|
mailInfos['spam']['mark'] = mailConfig['spam'] == 'marque'
|
||||||
|
mailInfos['spam']['drop'] = mailConfig['spam'] == 'supprime'
|
||||||
|
#except Exception, e:
|
||||||
|
# t['mailError'] = u"Erreur:fichiers de configuration mail incompréhensibles"
|
||||||
|
|
||||||
|
mailInfos['alias'] = adh.alias()
|
||||||
|
mailInfos['contourneGreylist'] = adh.contourneGreylist()
|
||||||
|
mailInfos['rewriteMailHeaders'] = adh.rewriteMailHeaders()
|
||||||
|
t['mailInfos'] = mailInfos
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
'template' :'monCompte',
|
||||||
|
'values' :t,
|
||||||
|
'stylesheets' :['monCompte.css'],
|
||||||
|
# 'scripts':['crans.js','passwordGenerator.js'],
|
||||||
|
'scripts':['crans_domtab.js','crans.js','passwordGenerator.js'],
|
||||||
|
}
|
||||||
|
index.exposed = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def listeMachines(self):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||||
|
machines = []
|
||||||
|
for une_machine in adh.machines():
|
||||||
|
machineInfos = {}
|
||||||
|
# nom, mac, mid, ip
|
||||||
|
machineInfos['nom'] = une_machine.nom()
|
||||||
|
machineInfos['nomCourt'] = une_machine.nom().split('.',1)[0]
|
||||||
|
machineInfos['mac'] = une_machine.mac()
|
||||||
|
machineInfos['mid'] = une_machine.id()
|
||||||
|
machineInfos['ip'] = une_machine.ip()
|
||||||
|
# type
|
||||||
|
if une_machine.objectClass == 'machineFixe':
|
||||||
|
machineInfos['type'] = 'Machine fixe'
|
||||||
|
else:
|
||||||
|
machineInfos['type'] = 'Machine wifi'
|
||||||
|
# clef ipsec
|
||||||
|
try:
|
||||||
|
machineInfos['ipsec'] = une_machine.ipsec()
|
||||||
|
except:
|
||||||
|
machineInfos['ipsec'] = ''
|
||||||
|
machines.append(machineInfos)
|
||||||
|
return {'machines':machines}
|
||||||
|
listeMachines.exposed = True
|
||||||
|
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# paypal
|
||||||
|
##########################
|
||||||
|
#
|
||||||
|
# methode qui affiche successivement les
|
||||||
|
# templates du popup pour recharger son compte impression
|
||||||
|
# via paypal
|
||||||
|
#
|
||||||
|
def rechargerCompteImpression(self, etape = '1', combien = None):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||||
|
if (etape == "1"): # Introduction
|
||||||
|
return {
|
||||||
|
'template' :'MonCompteRechargePaypal1',
|
||||||
|
'standalone' :True,
|
||||||
|
'values' :{},
|
||||||
|
}
|
||||||
|
elif (etape == "2"): # choix montant
|
||||||
|
return {
|
||||||
|
'template' :'MonCompteRechargePaypal2',
|
||||||
|
'standalone' :True,
|
||||||
|
'values' :{},
|
||||||
|
}
|
||||||
|
elif (etape == "3"): # confirmer facture
|
||||||
|
# creer objet facture
|
||||||
|
f = Facture(adh)
|
||||||
|
# /!\ verifier que combien est un nombre
|
||||||
|
# et qu'il n'y a pas plus de 2 chiffres après le point...
|
||||||
|
# (ce serait bien aussi si on pouvait mettre une virgue a la place du point)
|
||||||
|
try:
|
||||||
|
# remplacage des virgules
|
||||||
|
combien = combien.replace(u',', u'.')
|
||||||
|
# convertissage
|
||||||
|
combien = float(combien)
|
||||||
|
# arrondissage-tronquage :
|
||||||
|
combien = float(int(combien*100)/100.0)
|
||||||
|
except Exception:
|
||||||
|
return {
|
||||||
|
'template' :'MonCompteRechargePaypal2',
|
||||||
|
'standalone' :True,
|
||||||
|
'values' :{'error':"Le montant doit être un nombre !", 'combien':combien},
|
||||||
|
}
|
||||||
|
f.ajoute({'nombre': 1, 'code': 'SOLDE', 'designation': 'Credit du compte impression (intranet)', 'pu': combien})
|
||||||
|
cherrypy.session['freshFacture'] = f
|
||||||
|
pageData = {}
|
||||||
|
pageData['details'] = [
|
||||||
|
{
|
||||||
|
'intitule':art['designation'],
|
||||||
|
'quantite':art['nombre'],
|
||||||
|
'prixUnitaire':art['pu'],
|
||||||
|
'prixTotal':art['pu']*art['nombre'],
|
||||||
|
} for art in f.articles()]
|
||||||
|
pageData['total'] = f.total()
|
||||||
|
return {
|
||||||
|
'template' :'MonCompteRechargePaypal3',
|
||||||
|
'standalone' :True,
|
||||||
|
'values' :pageData,
|
||||||
|
}
|
||||||
|
elif (etape == "4"): # payer maintenant ?
|
||||||
|
# sauver objet facture
|
||||||
|
f = cherrypy.session['freshFacture']
|
||||||
|
f.save()
|
||||||
|
return {
|
||||||
|
'template' :'MonCompteRechargePaypal4',
|
||||||
|
'standalone' :True,
|
||||||
|
'values' :{'lienPaypal' : f.urlPaypal()},
|
||||||
|
}
|
||||||
|
rechargerCompteImpression.exposed = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
# methodes pour changer
|
||||||
|
# des valeurs
|
||||||
|
###########################################################################
|
||||||
|
#
|
||||||
|
# En fait, les methodes recoivent les valeurs d'un formulaire
|
||||||
|
# (ou equivalent de javascript), font la modification puis
|
||||||
|
# appellent la methode principale d'affichage
|
||||||
|
# en lui passant eventuellement un message a afficher
|
||||||
|
# (pour indiquer la reussite ou non de l'operation)
|
||||||
|
#
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# Adherent:nom
|
||||||
|
##########################
|
||||||
|
def changeNomAdherent(self, nouveauNom):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'], 'w')['adherent'][0]
|
||||||
|
try:
|
||||||
|
adh.nom(nouveauNom)
|
||||||
|
adh.save()
|
||||||
|
except ValueError, e:
|
||||||
|
return self.index(error=e.args[0])
|
||||||
|
del adh
|
||||||
|
return self.index(message=u'Modification réussie')
|
||||||
|
changeNomAdherent.exposed = True
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# Adherent:password
|
||||||
|
##########################
|
||||||
|
def changePasswordAdherent(self, ancienPassword, nouveauPassword1, nouveauPassword2):
|
||||||
|
if ancienPassword=='':
|
||||||
|
msg = 'Erreur, mot de passe incorrect'
|
||||||
|
return self.index(error=msg)
|
||||||
|
if nouveauPassword1=='':
|
||||||
|
msg = 'Erreur, le nouveau mot de passe ne doit pas ètre vide.'
|
||||||
|
return self.index(error=msg)
|
||||||
|
if nouveauPassword1!=nouveauPassword2:
|
||||||
|
msg = 'Erreur, la confirmation ne correspond pas au nouveau mot de passe.'
|
||||||
|
return self.index(error=msg)
|
||||||
|
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'],'w')['adherent'][0]
|
||||||
|
if adh.checkPassword(ancienPassword):
|
||||||
|
adh.changePasswd(nouveauPassword1)
|
||||||
|
adh.save()
|
||||||
|
msg = u'Changement effectué'
|
||||||
|
else:
|
||||||
|
msg = 'Erreur, mot de passe incorrect'
|
||||||
|
return self.index(error=msg)
|
||||||
|
del adh
|
||||||
|
return self.index(message=msg)
|
||||||
|
changePasswordAdherent.exposed = True
|
||||||
|
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# Adherent:prenom
|
||||||
|
##########################
|
||||||
|
def changePrenomAdherent(self, nouveauPrenom):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'], 'w')['adherent'][0]
|
||||||
|
try:
|
||||||
|
adh.prenom(nouveauPrenom)
|
||||||
|
adh.save()
|
||||||
|
except ValueError, e:
|
||||||
|
return self.index(error=e.args[0])
|
||||||
|
del adh
|
||||||
|
return self.index(message=u'Modification réussie')
|
||||||
|
changePrenomAdherent.exposed = True
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# Adherent:tel
|
||||||
|
##########################
|
||||||
|
def changeTelAdherent(self, nouveauTel):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'], 'w')['adherent'][0]
|
||||||
|
try:
|
||||||
|
adh.tel(nouveauTel)
|
||||||
|
adh.save()
|
||||||
|
except ValueError, e:
|
||||||
|
return self.index(error=e.args[0])
|
||||||
|
del adh
|
||||||
|
return self.index(message=u'Modification réussie')
|
||||||
|
changeTelAdherent.exposed = True
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# machine:nom
|
||||||
|
##########################
|
||||||
|
def changeNomMachine(self, mid, nouveauNom):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||||
|
mach = self.__ldap.search('mid=' + mid, 'w')['machine'][0]
|
||||||
|
# tester si c'est bien la machine de l'adherent
|
||||||
|
if mach.proprietaire().compte() != cherrypy.session['uid']:
|
||||||
|
del adh, mach
|
||||||
|
raise Exception(u"L'uid de l'adherent ne correspond mas au proprietaire de la machine.")
|
||||||
|
try:
|
||||||
|
mach.nom(nouveauNom)
|
||||||
|
mach.save()
|
||||||
|
del mach
|
||||||
|
except ValueError, e:
|
||||||
|
del mach
|
||||||
|
return {'error':e.args[0]}
|
||||||
|
return {'message':u"Modification réussie"}
|
||||||
|
changeNomMachine.exposed = True
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# machine:mac
|
||||||
|
##########################
|
||||||
|
def changeMACMachine(self, mid, nouvelleMAC):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||||
|
mach = self.__ldap.search('mid=' + mid, 'w')['machine'][0]
|
||||||
|
# tester si c'est bien la machine de l'adherent
|
||||||
|
if mach.proprietaire().compte() != cherrypy.session['uid']:
|
||||||
|
del adh, mach
|
||||||
|
raise Exception(u"L'uid de l'adherent ne correspond mas au proprietaire de la machine.")
|
||||||
|
|
||||||
|
try:
|
||||||
|
mach.mac(nouvelleMAC)
|
||||||
|
mach.save()
|
||||||
|
del mach
|
||||||
|
except ValueError, e:
|
||||||
|
del mach
|
||||||
|
return {'error':e.args[0]}
|
||||||
|
return {'message':u"Modification réussie"}
|
||||||
|
changeMACMachine.exposed = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# machine:suppression
|
||||||
|
##########################
|
||||||
|
def supprimeMachine(self, mid):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||||
|
mach = self.__ldap.search('mid=' + mid, 'w')['machine'][0]
|
||||||
|
# tester si c'est bien la machine de l'adherent
|
||||||
|
if mach.proprietaire().compte() != cherrypy.session['uid']:
|
||||||
|
del adh, mach
|
||||||
|
raise Exception(u"L'uid de l'adherent ne correspond mas au proprietaire de la machine.")
|
||||||
|
try:
|
||||||
|
mach.delete()
|
||||||
|
except ValueError, e:
|
||||||
|
return {'error':e.args[0]}
|
||||||
|
return {'message':u"Machine supprimée"}
|
||||||
|
supprimeMachine.exposed = True
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# machine:creation
|
||||||
|
##########################
|
||||||
|
def creerMachine(self, nomNouvelleMachine, MACNouvelleMachine, estMachineWifi='0'):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||||
|
try:
|
||||||
|
if estMachineWifi=='true':
|
||||||
|
m = MachineWifi(adh)
|
||||||
|
else:
|
||||||
|
m = MachineFixe(adh)
|
||||||
|
m.nom(nomNouvelleMachine)
|
||||||
|
m.mac(MACNouvelleMachine)
|
||||||
|
m.ip("<automatique>")
|
||||||
|
message = m.save()
|
||||||
|
del m
|
||||||
|
except ValueError, e:
|
||||||
|
del m
|
||||||
|
return {'error':e.args[0]}
|
||||||
|
return {'message':u"Machine enregistrée avec succès"}
|
||||||
|
creerMachine.exposed = True
|
||||||
|
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# mail:alias:creation
|
||||||
|
##########################
|
||||||
|
def newAlias(self, alias):
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'],'w')['adherent'][0]
|
||||||
|
if adh.alias().__len__() >= 3:
|
||||||
|
return self.index(error=u"Vous avez plus de 2 alias. Demander à un câbleur pour en rajouter.")
|
||||||
|
try:
|
||||||
|
adh.alias(alias)
|
||||||
|
adh.save()
|
||||||
|
del adh
|
||||||
|
except ValueError, e:
|
||||||
|
return self.index(error=e.args[0])
|
||||||
|
except RuntimeError:
|
||||||
|
return self.index(error=u"Vous possédez déjà cet alias")
|
||||||
|
except EnvironmentError:
|
||||||
|
return self.index(error=u"Vous possédez déjà cet alias")
|
||||||
|
return self.index(message=u'Alias enregistré')
|
||||||
|
newAlias.exposed = True
|
||||||
|
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# mail:sauver
|
||||||
|
##########################
|
||||||
|
def saveMailPrefs(self, forwarding_address, spanTreatment=None, contourneGreylist=False, rewriteMailHeaders=False):
|
||||||
|
if spanTreatment == 'no':
|
||||||
|
spanTreatment = 'accepte'
|
||||||
|
if spanTreatment == 'mark':
|
||||||
|
spanTreatment = 'marque'
|
||||||
|
if spanTreatment == 'drop':
|
||||||
|
spanTreatment = 'supprime'
|
||||||
|
|
||||||
|
if contourneGreylist == 'oui':
|
||||||
|
contourneGreylist = True
|
||||||
|
if rewriteMailHeaders == 'oui':
|
||||||
|
rewriteMailHeaders = True
|
||||||
|
|
||||||
|
try:
|
||||||
|
adh = self.__ldap.search('uid=' + cherrypy.session['uid'],'w')['adherent'][0]
|
||||||
|
MailConfig(cherrypy.session['uid'], forward=forwarding_address, spam=spanTreatment)
|
||||||
|
adh.contourneGreylist(contourneGreylist)
|
||||||
|
adh.rewriteMailHeaders(rewriteMailHeaders)
|
||||||
|
adh.save()
|
||||||
|
del adh
|
||||||
|
except ValueError, e:
|
||||||
|
return self.index(error=e.args[0])
|
||||||
|
except Exception, e:
|
||||||
|
return self.index(error=u"Une erreur est survenue lors de lenregistrement. Vérifiez que l'adresse mail fournie est correcte.")
|
||||||
|
return self.index(message=u'Vos préférences ont été enregistrées')
|
||||||
|
saveMailPrefs.exposed = True
|
||||||
|
|
34
intranet/prod.cfg
Normal file
34
intranet/prod.cfg
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
# The configuration file called myconfigfile.conf
|
||||||
|
[global]
|
||||||
|
server.socketPort=8080
|
||||||
|
server.socketHost=""
|
||||||
|
server.socketFile=""
|
||||||
|
server.socketQueueSize=10
|
||||||
|
server.protocolVersion="HTTP/1.0"
|
||||||
|
server.logToScreen=False
|
||||||
|
server.logFile=""
|
||||||
|
server.reverseDNS=False
|
||||||
|
server.threadPool=10
|
||||||
|
server.environment="production"
|
||||||
|
server.show_tracebacks= False
|
||||||
|
server.log_config_options= False
|
||||||
|
logDebugInfoFilter.on = False
|
||||||
|
|
||||||
|
sessionAuthenticateFilter.on=True
|
||||||
|
sessionFilter.on = True
|
||||||
|
sessionFilter.locking = "implicit"
|
||||||
|
|
||||||
|
base_url_filter.on = True
|
||||||
|
base_url_filter.base_url = "https://intranet2.crans.org/"
|
||||||
|
base_url_filter.use_x_forwarded_host = True
|
||||||
|
|
||||||
|
[/]
|
||||||
|
# Now we can work on our filter as with the standard filters
|
||||||
|
templatesEngine.on = True
|
||||||
|
|
||||||
|
[/static]
|
||||||
|
sessionAuthenticateFilter.on=False
|
||||||
|
sessionFilter.on = False
|
||||||
|
server.output_filters.templatesEngine.on = False
|
||||||
|
staticFilter.on = True
|
||||||
|
staticFilter.dir = "/home/gdetrez/intranet/static/"
|
Loading…
Add table
Add a link
Reference in a new issue