Merge branch 'feature/ssl_email' into develop
This commit is contained in:
commit
11dcffd3f3
|
@ -5,7 +5,7 @@
|
|||
|
||||
"""
|
||||
from .logger import getLogger
|
||||
from geruecht.controller import dbConfig
|
||||
from geruecht.controller import dbConfig, ldapConfig
|
||||
from flask_mysqldb import MySQL
|
||||
from flask_ldapconn import LDAPConn
|
||||
|
||||
|
@ -24,9 +24,9 @@ app.config['MYSQL_USER'] = dbConfig['user']
|
|||
app.config['MYSQL_PASSWORD'] = dbConfig['passwd']
|
||||
app.config['MYSQL_DB'] = dbConfig['database']
|
||||
app.config['MYSQL_CURSORCLASS'] = 'DictCursor'
|
||||
app.config['LDAP_SERVER'] = '192.168.5.128'
|
||||
app.config['LDAP_PORT'] = 389
|
||||
app.config['LDAP_BINDDN'] = 'dc=ldap,dc=example,dc=local'
|
||||
app.config['LDAP_SERVER'] = ldapConfig['URL']
|
||||
app.config['LDAP_PORT'] = ldapConfig['port']
|
||||
app.config['LDAP_BINDDN'] = ldapConfig['dn']
|
||||
app.config['LDAP_USE_TLS'] = False
|
||||
app.config['FORCE_ATTRIBUTE_VALUE_AS_LIST'] = True
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ default = {
|
|||
'port': 0,
|
||||
'user': '',
|
||||
'passwd': '',
|
||||
'email': ''
|
||||
'email': '',
|
||||
'crypt': 'STARTTLS'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +33,9 @@ class ConifgParser():
|
|||
self.__error__('Wrong Configuration for LDAP. You should configure ldapconfig with "URL" and "dn"')
|
||||
if 'URL' not in self.config['LDAP'] or 'dn' not in self.config['LDAP']:
|
||||
self.__error__('Wrong Configuration for LDAP. You should configure ldapconfig with "URL" and "dn"')
|
||||
if 'port' not in self.config['LDAP']:
|
||||
LOGGER.info('No Config for port in LDAP found. Set it to default: {}'.format(389))
|
||||
self.config['LDAP']['port'] = 389
|
||||
self.ldap = self.config['LDAP']
|
||||
LOGGER.info("Set LDAPconfig: {}".format(self.ldap))
|
||||
if 'AccessTokenLifeTime' in self.config:
|
||||
|
@ -61,6 +65,9 @@ class ConifgParser():
|
|||
if 'email' not in self.config['Mail']:
|
||||
self.config['Mail']['email'] = default['Mail']['email']
|
||||
LOGGER.info("No Config for email in Mail found. Set it to default")
|
||||
if 'crypt' not in self.config['Mail']:
|
||||
self.config['Mail']['crypt'] = default['Mail']['crypt']
|
||||
LOGGER.info("No Config for crypt in Mail found. Set it to default")
|
||||
self.mail = self.config['Mail']
|
||||
LOGGER.info('Set Mailconfig: {}'.format(self.mail))
|
||||
|
||||
|
|
|
@ -3,24 +3,38 @@ from datetime import datetime
|
|||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from email.header import Header
|
||||
from . import LOGGER
|
||||
from geruecht import getLogger
|
||||
|
||||
LOGGER = getLogger('E-MailController')
|
||||
|
||||
class EmailController():
|
||||
|
||||
def __init__(self, smtpServer, user, passwd, port = 587, email = ""):
|
||||
def __init__(self, smtpServer, user, passwd, crypt, port=587, email=""):
|
||||
self.smtpServer = smtpServer
|
||||
self.port = port
|
||||
self.user = user
|
||||
self.passwd = passwd
|
||||
self.crypt = crypt
|
||||
if email:
|
||||
self.email = email
|
||||
else:
|
||||
self.email = user
|
||||
LOGGER.debug('Init EmailController with smtpServer={}, port={}, user={}, crypt={}, email={}'.format(smtpServer, user, port, crypt, self.email))
|
||||
|
||||
def __connect__(self):
|
||||
LOGGER.info('Connect to E-Mail-Server')
|
||||
if self.crypt == 'SSL':
|
||||
self.smtp = smtplib.SMTP_SSL(self.smtpServer, self.port)
|
||||
log = self.smtp.ehlo()
|
||||
LOGGER.debug(log)
|
||||
if self.crypt == 'STARTTLS':
|
||||
self.smtp = smtplib.SMTP(self.smtpServer, self.port)
|
||||
self.smtp.starttls()
|
||||
self.smtp.login(self.user, self.passwd)
|
||||
log = self.smtp.ehlo()
|
||||
LOGGER.debug(log)
|
||||
log = self.smtp.starttls()
|
||||
LOGGER.debug(log)
|
||||
log = self.smtp.login(self.user, self.passwd)
|
||||
LOGGER.debug(log)
|
||||
|
||||
def sendMail(self, user):
|
||||
try:
|
||||
|
|
|
@ -38,8 +38,10 @@ class LDAPController(metaclass=Singleton):
|
|||
'dn': self.ldap.connection.response[0]['dn'],
|
||||
'firstname': user['givenName'][0],
|
||||
'lastname': user['sn'][0],
|
||||
'uid': username
|
||||
'uid': username,
|
||||
}
|
||||
if user['mail']:
|
||||
retVal['mail'] = user['mail'][0]
|
||||
return retVal
|
||||
except:
|
||||
raise PermissionDenied("No User exists with this uid.")
|
||||
|
|
|
@ -10,7 +10,7 @@ from geruecht.exceptions import UsernameExistLDAP, UsernameExistDB, DatabaseExec
|
|||
|
||||
db = dc.DatabaseController()
|
||||
ldap = lc.LDAPController(ldapConfig['dn'])
|
||||
emailController = ec.EmailController(mailConfig['URL'], mailConfig['user'], mailConfig['passwd'], mailConfig['port'], mailConfig['email'])
|
||||
emailController = ec.EmailController(mailConfig['URL'], mailConfig['user'], mailConfig['passwd'], mailConfig['crypt'], mailConfig['port'], mailConfig['email'])
|
||||
|
||||
class UserController(metaclass=Singleton):
|
||||
|
||||
|
@ -110,6 +110,14 @@ class UserController(metaclass=Singleton):
|
|||
db.updateUser(user)
|
||||
return self.getUser(username)
|
||||
|
||||
def __updateDataFromLDAP(self, user):
|
||||
groups = ldap.getGroup(user.uid)
|
||||
user_data = ldap.getUserData(user.uid)
|
||||
user_data['gruppe'] = groups
|
||||
user_data['group'] = groups
|
||||
user.updateData(user_data)
|
||||
db.updateUser(user)
|
||||
|
||||
def autoLock(self, user):
|
||||
if user.autoLock:
|
||||
if user.getGeruecht(year=datetime.now().year).getSchulden() <= (-1*user.limit):
|
||||
|
@ -141,6 +149,10 @@ class UserController(metaclass=Singleton):
|
|||
def getAllUsersfromDB(self):
|
||||
users = db.getAllUser()
|
||||
for user in users:
|
||||
try:
|
||||
self.__updateDataFromLDAP(user)
|
||||
except:
|
||||
pass
|
||||
self.__updateGeruechte(user)
|
||||
return db.getAllUser()
|
||||
|
||||
|
|
Loading…
Reference in New Issue