Crer un compte wiki partir de zamok.
Il y a aussi un lien dans /usr/local/bin. darcs-hash:20060301004732-68412-6ab83ebe896b404a585e0b8596dd1a20bace6817.gz
This commit is contained in:
parent
eba8a928ee
commit
c58ec40d15
1 changed files with 94 additions and 0 deletions
94
creer_compte_wiki.py
Executable file
94
creer_compte_wiki.py
Executable file
|
@ -0,0 +1,94 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: iso-8859-15 -*-
|
||||
|
||||
import sys, os, httplib, urllib
|
||||
from getpass import getpass
|
||||
from smtplib import SMTP
|
||||
from email.MIMEBase import MIMEBase
|
||||
from email.MIMEText import MIMEText
|
||||
from email.MIMEMultipart import MIMEMultipart
|
||||
from email.Encoders import encode_7or8bit
|
||||
|
||||
sys.path.append("/usr/scripts/gestion")
|
||||
from affich_tools import coul, prompt
|
||||
|
||||
bugmail = ["glondu@crans.org"]
|
||||
bugreport = u"""
|
||||
Nom d'utilisateur : %(username)s
|
||||
Adresse e-mail : %(email)s
|
||||
"""
|
||||
|
||||
# C'est l'encodage du wiki et des bugreports
|
||||
encoding = "utf-8"
|
||||
|
||||
def send(msg):
|
||||
msg['From'] = 'root@crans.org'
|
||||
msg['To'] = ','.join(bugmail)
|
||||
smtp = SMTP()
|
||||
smtp.connect()
|
||||
smtp.sendmail('glondu@crans.org', bugmail, msg.as_string())
|
||||
smtp.quit()
|
||||
|
||||
def creer_compte(nom, mdp, email):
|
||||
form = {'action': 'userform',
|
||||
'username': nom.encode(encoding),
|
||||
'password': mdp,
|
||||
'password2': mdp,
|
||||
'email': email.encode(encoding),
|
||||
'save': 'Create Profile'}
|
||||
params = urllib.urlencode(form)
|
||||
headers = {"Content-type": "application/x-www-form-urlencoded",
|
||||
"Accept": "text/plain"}
|
||||
conn = httplib.HTTPSConnection("wiki.crans.org")
|
||||
conn.request("POST", "/UserPreferences", params, headers)
|
||||
response = conn.getresponse()
|
||||
data = response.read()
|
||||
conn.close()
|
||||
if data.find('User preferences saved!') != -1:
|
||||
return coul(u"Compte %s créé avec succès !" % nom, "vert")
|
||||
elif data.find('This user name already belongs to somebody else.') != -1:
|
||||
return coul(u"Le compte %s existe déjà !" % nom, "rouge")
|
||||
elif data.find('This email already belongs to somebody else.') != -1:
|
||||
return coul(u"L'adresse %s est déjà utilisée !" % email, "rouge")
|
||||
else:
|
||||
html = MIMEBase('text', 'html')
|
||||
html.set_payload(data)
|
||||
html.add_header('Content-Disposition', 'attachment', filename='response.html')
|
||||
txt = MIMEText(bugreport.encode(encoding) % form, 'plain', encoding)
|
||||
msg = MIMEMultipart()
|
||||
msg['Subject'] = '[Bugreport] creer_compte_wiki.py: creer_compte'
|
||||
msg.attach(txt)
|
||||
msg.attach(html)
|
||||
send(msg)
|
||||
return coul(u"Erreur inconnue\n", "rouge") + \
|
||||
u"Un rapport de bug a été automatiquement envoyé. Réessayez plus tard."
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
try:
|
||||
nom = prompt("Nom d'utilisateur (utiliser un WikiNom) :")
|
||||
while True:
|
||||
mdp = getpass(coul("Mot de passe (ne pas utiliser le même que pour zamok) : ", "gras"))
|
||||
if getpass(coul("Confirmation du mot de passe :", "gras")) == mdp:
|
||||
break
|
||||
email = prompt("Adresse e-mail : ")
|
||||
print creer_compte(nom, mdp, email)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
os.system('clear')
|
||||
print "Interruption par l'utilisateur."
|
||||
exit = 255
|
||||
|
||||
except SystemExit, c:
|
||||
if c.__str__() == '254':
|
||||
os.system('reset')
|
||||
print "Votre session d'édition à été tuée."
|
||||
exit = c
|
||||
|
||||
except:
|
||||
import traceback
|
||||
msg = MIMEText('\n'.join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)).encode(encoding), 'plain', encoding)
|
||||
msg['Subject'] = '[Bugreport] creer_compte_wiki.py: __main__'
|
||||
send(msg)
|
||||
print coul(u"Erreur inconnue\n", "rouge") + \
|
||||
u"Un rapport de bug a été automatiquement envoyé. Réessayez plus tard."
|
Loading…
Add table
Add a link
Reference in a new issue