2018-10-18 15:57:43 +02:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_CONFIG = {
|
|
|
|
# Specific to the admin UI
|
|
|
|
'DOCKER_SOCKET': 'unix:///var/run/docker.sock',
|
|
|
|
'BABEL_DEFAULT_LOCALE': 'en',
|
|
|
|
'BABEL_DEFAULT_TIMEZONE': 'UTC',
|
|
|
|
'BOOTSTRAP_SERVE_LOCAL': True,
|
|
|
|
'RATELIMIT_STORAGE_URL': 'redis://redis/2',
|
|
|
|
'QUOTA_STORAGE_URL': 'redis://redis/1',
|
|
|
|
'DEBUG': False,
|
|
|
|
'DOMAIN_REGISTRATION': False,
|
2018-10-18 17:55:07 +02:00
|
|
|
'TEMPLATES_AUTO_RELOAD': True,
|
2018-11-14 14:58:54 +02:00
|
|
|
# Database settings
|
|
|
|
'DB_FLAVOR': 'sqlite',
|
|
|
|
'DB_USER': 'mailu',
|
|
|
|
'DB_PW': '',
|
|
|
|
'DB_URL': 'database',
|
|
|
|
'DB_NAME': 'mailu',
|
|
|
|
'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/main.db',
|
|
|
|
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
|
2018-10-18 15:57:43 +02:00
|
|
|
# Statistics management
|
|
|
|
'INSTANCE_ID_PATH': '/data/instance',
|
|
|
|
'STATS_ENDPOINT': '0.{}.stats.mailu.io',
|
|
|
|
# Common configuration variables
|
|
|
|
'SECRET_KEY': 'changeMe',
|
|
|
|
'DOMAIN': 'mailu.io',
|
|
|
|
'HOSTNAMES': 'mail.mailu.io,alternative.mailu.io,yetanother.mailu.io',
|
|
|
|
'POSTMASTER': 'postmaster',
|
|
|
|
'TLS_FLAVOR': 'cert',
|
|
|
|
'AUTH_RATELIMIT': '10/minute;1000/hour',
|
|
|
|
'DISABLE_STATISTICS': 'False',
|
|
|
|
# Mail settings
|
|
|
|
'DMARC_RUA': None,
|
|
|
|
'DMARC_RUF': None,
|
|
|
|
'WELCOME': 'False',
|
|
|
|
'WELCOME_SUBJECT': 'Dummy welcome topic',
|
|
|
|
'WELCOME_BODY': 'Dummy welcome body',
|
|
|
|
'DKIM_SELECTOR': 'dkim',
|
|
|
|
'DKIM_PATH': '/dkim/{domain}.{selector}.key',
|
|
|
|
'DEFAULT_QUOTA': 1000000000,
|
|
|
|
# Web settings
|
|
|
|
'SITENAME': 'Mailu',
|
|
|
|
'WEBSITE': 'https://mailu.io',
|
|
|
|
'WEB_ADMIN': '/admin',
|
|
|
|
'WEB_WEBMAIL': '/webmail',
|
|
|
|
'RECAPTCHA_PUBLIC_KEY': '',
|
|
|
|
'RECAPTCHA_PRIVATE_KEY': '',
|
|
|
|
# Advanced settings
|
|
|
|
'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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-08 21:29:52 +02:00
|
|
|
class ConfigManager(dict):
|
2018-10-18 15:57:43 +02:00
|
|
|
""" Naive configuration manager that uses environment only
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
2018-10-18 17:55:07 +02:00
|
|
|
self.config = dict()
|
2018-11-20 18:18:33 +02:00
|
|
|
self.parse_env()
|
2018-10-18 17:55:07 +02:00
|
|
|
|
|
|
|
def init_app(self, app):
|
|
|
|
self.config.update(app.config)
|
2018-11-20 18:18:33 +02:00
|
|
|
self.parse_env()
|
|
|
|
if self.config['DB_FLAVOR'] != 'sqlite':
|
|
|
|
self.setsql()
|
|
|
|
app.config = self
|
|
|
|
|
|
|
|
def parse_env(self):
|
2018-10-18 17:55:07 +02:00
|
|
|
self.config.update({
|
|
|
|
key: os.environ.get(key, value)
|
2018-10-18 15:57:43 +02:00
|
|
|
for key, value in DEFAULT_CONFIG.items()
|
2018-10-18 17:55:07 +02:00
|
|
|
})
|
|
|
|
|
2018-11-19 19:10:38 +02:00
|
|
|
def setsql(self):
|
|
|
|
if not self.config['DB_PW']:
|
2018-11-14 14:58:54 +02:00
|
|
|
self.config['DB_PW'] = self.config['SECRET_KEY']
|
2018-11-19 19:10:38 +02:00
|
|
|
self.config['SQLALCHEMY_DATABASE_URI'] = '{driver}://{user}:{pw}@{url}/{db}'.format(
|
|
|
|
driver=self.config['DB_FLAVOR'],
|
|
|
|
user=self.config['DB_USER'],
|
|
|
|
pw=self.config['DB_PW'],
|
|
|
|
url=self.config['DB_URL'],
|
|
|
|
db=self.config['DB_NAME']
|
|
|
|
)
|
2018-11-14 14:58:54 +02:00
|
|
|
|
2018-10-18 17:55:07 +02:00
|
|
|
def setdefault(self, key, value):
|
|
|
|
if key not in self.config:
|
|
|
|
self.config[key] = value
|
|
|
|
return self.config[key]
|
2018-10-18 15:57:43 +02:00
|
|
|
|
|
|
|
def get(self, *args):
|
|
|
|
return self.config.get(*args)
|
|
|
|
|
2018-11-08 21:29:52 +02:00
|
|
|
def keys(self):
|
|
|
|
return self.config.keys()
|
|
|
|
|
2018-10-18 15:57:43 +02:00
|
|
|
def __getitem__(self, key):
|
2018-10-18 17:55:07 +02:00
|
|
|
return self.config.get(key)
|
|
|
|
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
self.config[key] = value
|
|
|
|
|
|
|
|
def __contains__(self, key):
|
|
|
|
return key in self.config
|