[jabber] Finalisation de la migration à ejabberd

Ignore-this: e5b71a7f580e1db950bb30d9d7745fbe
 * une vcard est automatiquement créée avec FN et EMAIL
 * lostPassword.py envoie un mail aux nounous
 * images et css plus accessibles

darcs-hash:20090809213427-bd074-19f0565242fb93d2051347eb47289e096bce00d9.gz
This commit is contained in:
Antoine Durand-Gasselin 2009-08-09 23:34:27 +02:00
parent d65ba27a7f
commit 29e2ecae71
9 changed files with 84 additions and 124 deletions

View file

@ -1,70 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# # # # # # # # # # # # # #
# Génération de password #
# # # # # # # # # # # # # #
from whrandom import choice
import string
jabberuserdir='/var/lib/jabber/jabber.crans.org/'
def GenPasswd(length=8, chars=string.letters + string.digits):
return ''.join([choice(chars) for i in range(length)])
# # # # # # # # # # # # # #
# Parseur de templates #
# # # # # # # # # # # # # #
import re, sys
def parse(text, var_dictiary):
def replace(matchobj):
token = matchobj.group(1)
if var_dictiary.has_key(token):
return var_dictiary.get(token)
else:
return matchobj.group()
#raise NameError, 'parseur : variable inconnue : '+token
return re.sub('\{([^\}]+)\}',replace, text)
def parse_file(file_name, var_dictionary):
file = open(file_name, 'r')
text = file.read();
return parse(text, var_dictionary);
# # # # # # # # # # # # # #
# Modifier le fichier XML #
# # # # # # # # # # # # # #
def XMLChgePassword(XMLString, newPassword):
pattern = "<password xmlns='jabber:iq:auth'>(.*)</password>"
replace = "<password xmlns='jabber:iq:auth'>" + newPassword + "</password>"
XMLString = re.sub(pattern, replace, XMLString)
pattern = "<password xmlns='jabber:iq:auth' xdbns='jabber:iq:auth'>(.*)</password>"
replace = "<password xmlns='jabber:iq:auth' xdbns='jabber:iq:auth'>" + newPassword + "</password>"
return re.sub(pattern, replace, XMLString)
def chgePasswordForUser(user, newPassword):
fileName = jabberuserdir+user+".xml"
file=open(fileName)
xmlString=file.read()
xmlString = XMLChgePassword(xmlString, newPassword)
file=open(fileName,'w')
file.write(xmlString)
file.close()
os.chmod(fileName,0600)
# # # # # # # # # # # # # # #
# Lire le fichier XML #
# # # # # # # # # # # # # # #
def XMLMailForUser(user):
fileName = jabberuserdir+user+".xml"
file=open(fileName)
xmlString=file.read()
return re.sub("<email>([^<>]*)</email>",lambda m:m.group(1),re.search('<email>([^<>]*)</email>',xmlString).group())
import string, re, sys, os
# # # # # # # # # # # # # # #
# Envoyer des e-mails #
# # # # # # # # # # # # # # #
SENDMAIL = "/usr/sbin/sendmail" # sendmail location
import os
def sendmail(text):
p = os.popen("%s -t" % SENDMAIL, "w")
@ -72,16 +14,4 @@ def sendmail(text):
sts = p.close()
if sts != None:
print "Sendmail exit status :", sts
# # # # # # # # # # # # # # #
# ok, maintenant on vas #
# faire des trucs #
# # # # # # # # # # # # # # #
# on regarde la variable des champs renvoyŽs par l'utilisateur
# si elle est dŽfinit (donc on a reu les rŽponses ˆ un forulaire)
# on execute l'action correspondante ; sinon on affiche la page par defaut