[jabber] ajout du cgi pour créer un compte jabber

darcs-hash:20090728100655-bd074-9a4cf910f821f6b2dc69d8e9c74fe496ea6a37d7.gz
This commit is contained in:
Antoine Durand-Gasselin 2009-07-28 12:06:55 +02:00
parent e5d6982a1e
commit aaf52989f6
9 changed files with 521 additions and 0 deletions

87
jabber/fonctions.py Executable file
View file

@ -0,0 +1,87 @@
#!/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())
# # # # # # # # # # # # # # #
# Envoyer des e-mails #
# # # # # # # # # # # # # # #
SENDMAIL = "/usr/sbin/sendmail" # sendmail location
import os
def sendmail(text):
p = os.popen("%s -t" % SENDMAIL, "w")
p.write(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