Merge branch 'master' into fix-sender-checks
This commit is contained in:
@@ -7,7 +7,7 @@ COPY requirements-prod.txt requirements.txt
|
||||
RUN apk add --no-cache openssl \
|
||||
&& apk add --no-cache --virtual build-dep openssl-dev libffi-dev python-dev build-base \
|
||||
&& pip install -r requirements.txt \
|
||||
&& apk del build-dep
|
||||
&& apk del --no-cache build-dep
|
||||
|
||||
COPY mailu ./mailu
|
||||
COPY migrations ./migrations
|
||||
|
||||
@@ -12,7 +12,7 @@ import docker
|
||||
import socket
|
||||
import uuid
|
||||
|
||||
from werkzeug.contrib import fixers
|
||||
from werkzeug.contrib import fixers, profiler
|
||||
|
||||
# Create application
|
||||
app = flask.Flask(__name__)
|
||||
@@ -57,12 +57,15 @@ default_config = {
|
||||
'RECAPTCHA_PUBLIC_KEY': '',
|
||||
'RECAPTCHA_PRIVATE_KEY': '',
|
||||
# Advanced settings
|
||||
'PASSWORD_SCHEME': 'SHA512-CRYPT',
|
||||
'PASSWORD_SCHEME': 'BLF-CRYPT',
|
||||
# Host settings
|
||||
'HOST_IMAP': 'imap',
|
||||
'HOST_POP3': 'imap',
|
||||
'HOST_SMTP': 'smtp',
|
||||
'HOST_WEBMAIL': 'webmail',
|
||||
'HOST_FRONT': 'front',
|
||||
'HOST_AUTHSMTP': os.environ.get('HOST_SMTP', 'smtp'),
|
||||
'POD_ADDRESS_RANGE': None
|
||||
}
|
||||
|
||||
# Load configuration from the environment if available
|
||||
@@ -80,6 +83,10 @@ if app.config.get("DEBUG"):
|
||||
import flask_debugtoolbar
|
||||
toolbar = flask_debugtoolbar.DebugToolbarExtension(app)
|
||||
|
||||
# Profiler
|
||||
if app.config.get("DEBUG"):
|
||||
app.wsgi_app = profiler.ProfilerMiddleware(app.wsgi_app, restrictions=[30])
|
||||
|
||||
# Manager commnad
|
||||
manager = flask_script.Manager(app)
|
||||
manager.add_command('db', flask_migrate.MigrateCommand)
|
||||
@@ -129,4 +136,5 @@ class PrefixMiddleware(object):
|
||||
environ['SCRIPT_NAME'] = prefix
|
||||
return self.app(environ, start_response)
|
||||
|
||||
|
||||
app.wsgi_app = PrefixMiddleware(fixers.ProxyFix(app.wsgi_app))
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
from mailu import db, models
|
||||
from mailu import db, models, app
|
||||
from mailu.internal import internal
|
||||
|
||||
import flask
|
||||
import socket
|
||||
|
||||
|
||||
@internal.route("/dovecot/passdb/<user_email>")
|
||||
def dovecot_passdb_dict(user_email):
|
||||
user = models.User.query.get(user_email) or flask.abort(404)
|
||||
allow_nets = []
|
||||
allow_nets.append(
|
||||
app.config.get("POD_ADDRESS_RANGE") or
|
||||
socket.gethostbyname(app.config["HOST_FRONT"])
|
||||
)
|
||||
allow_nets.append(socket.gethostbyname(app.config["HOST_WEBMAIL"]))
|
||||
print(allow_nets)
|
||||
return flask.jsonify({
|
||||
"password": user.password,
|
||||
"password": None,
|
||||
"nopassword": "Y",
|
||||
"allow_nets": ",".join(allow_nets)
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -287,8 +287,10 @@ class User(Base, Email):
|
||||
|
||||
def get_id(self):
|
||||
return self.email
|
||||
|
||||
scheme_dict = {'SHA512-CRYPT': "sha512_crypt",
|
||||
|
||||
scheme_dict = {'PBKDF2': "pbkdf2_sha512",
|
||||
'BLF-CRYPT': "bcrypt",
|
||||
'SHA512-CRYPT': "sha512_crypt",
|
||||
'SHA256-CRYPT': "sha256_crypt",
|
||||
'MD5-CRYPT': "md5_crypt",
|
||||
'CRYPT': "des_crypt"}
|
||||
@@ -298,8 +300,14 @@ class User(Base, Email):
|
||||
)
|
||||
|
||||
def check_password(self, password):
|
||||
context = User.pw_context
|
||||
reference = re.match('({[^}]+})?(.*)', self.password).group(2)
|
||||
return User.pw_context.verify(password, reference)
|
||||
result = context.verify(password, reference)
|
||||
if result and context.identify(reference) != context.default_scheme():
|
||||
self.set_password(password)
|
||||
db.session.add(self)
|
||||
db.session.commit()
|
||||
return result
|
||||
|
||||
def set_password(self, password, hash_scheme=app.config['PASSWORD_SCHEME'], raw=False):
|
||||
"""Set password for user with specified encryption scheme
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
alembic==0.9.9
|
||||
asn1crypto==0.24.0
|
||||
Babel==2.5.3
|
||||
bcrypt==3.1.4
|
||||
blinker==1.4
|
||||
certifi==2018.4.16
|
||||
cffi==1.11.5
|
||||
|
||||
@@ -17,3 +17,4 @@ tabulate
|
||||
PyYAML
|
||||
PyOpenSSL
|
||||
dnspython
|
||||
bcrypt
|
||||
|
||||
Reference in New Issue
Block a user