This repository has been archived by the owner on Sep 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
emails-add.py
executable file
·57 lines (45 loc) · 1.72 KB
/
emails-add.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
#-*- coding: utf8 -*-
from dialog import *
import database as db
import dbconf
import re
import sys
import os
from md5 import md5
if os.environ.has_key('SUDO_USER'):
user = os.environ['SUDO_USER']
else:
user = 'root'
userfromdb = db.select('users', where="login = '%s'" % user)
if len(userfromdb) == 0:
print 'Votre utilisateur n\'a pas été autorisé à avoir un site.'
print 'Merci de contacter l\'administrateur.'
sys.exit()
id_user = list(userfromdb)[0].id
while True:
email = text('Adresse email à ajouter :')
if not re.match(r'''^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$''', email):
print "Ça ne ressemble pas à une adresse email, veuillez réessayer"
else:
break
(username, domain) = email.split('@')
password = passwd('Mot de passe :')
domains = db.select('domains', where='name = $domain', vars=locals())
if len(domains) == 0:
id_domain = db.insert('domains', name=domain)
else:
id_domain = list(domains)[0].id
if len(db.select('mailboxes', where='domain_id = $id_domain AND user = $username', vars=locals())) > 0:
print 'Cette boite mail existe déjà !'
print
sys.exit()
db.insert('mailboxes', domain_id=id_domain, user=username, password=md5(password).hexdigest(), id_users=id_user)
print 'La nouvelle boite mail est maintenant configurée.'
print 'Pour accéder aux services associer, vos identifiants sont :'
print ' - login : %s@%s' % (username, domain)
print ' - mot de passe : %s' % password
print 'Services disponibles :'
print ' - SMTP / SMTPS (necessite une authentification) : mail.bearnaise.net'
print ' - IMAP / IMAPS : mail.bearnaise.net'
#print ' - POP3 / POP3S' # Plus tard