1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-14 10:53:30 +02:00
Mailu/admin/mailu/__init__.py

72 lines
1.9 KiB
Python
Raw Normal View History

2016-06-25 12:57:47 +02:00
import flask
import flask_sqlalchemy
import flask_bootstrap
import flask_login
import flask_script
import flask_migrate
2016-10-02 14:23:44 +02:00
import flask_babel
2016-02-20 14:57:26 +02:00
import os
2016-04-20 22:37:17 +02:00
import docker
2016-02-20 14:57:26 +02:00
from apscheduler.schedulers import background
2016-02-20 14:57:26 +02:00
# Create application
app = flask.Flask(__name__, static_url_path='/admin/app_static')
2016-02-20 14:57:26 +02:00
default_config = {
'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/main.db',
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
2016-04-20 22:37:17 +02:00
'SECRET_KEY': 'changeMe',
'DOCKER_SOCKET': 'unix:///var/run/docker.sock',
'HOSTNAME': 'mail.mailu.io',
'DOMAIN': 'mailu.io',
'POSTMASTER': 'postmaster',
2016-06-25 15:50:05 +02:00
'DEBUG': False,
'BOOTSTRAP_SERVE_LOCAL': True,
2016-06-25 15:50:05 +02:00
'DKIM_PATH': '/dkim/{domain}.{selector}.key',
2016-10-02 14:23:44 +02:00
'DKIM_SELECTOR': 'dkim',
'BABEL_DEFAULT_LOCALE': 'en',
'BABEL_DEFAULT_TIMEZONE': 'UTC'
}
# Load configuration from the environment if available
for key, value in default_config.items():
app.config[key] = os.environ.get(key, value)
# Setup components
2016-06-25 12:57:47 +02:00
flask_bootstrap.Bootstrap(app)
db = flask_sqlalchemy.SQLAlchemy(app)
migrate = flask_migrate.Migrate(app, db)
2016-03-19 21:37:48 +02:00
login_manager = flask_login.LoginManager()
login_manager.init_app(app)
2016-10-02 14:23:44 +02:00
babel = flask_babel.Babel(app)
translations = list(map(str, babel.list_translations()))
scheduler = background.BackgroundScheduler()
2016-03-19 21:37:48 +02:00
2016-06-25 12:57:47 +02:00
# Manager commnad
manager = flask_script.Manager(app)
manager.add_command('db', flask_migrate.MigrateCommand)
2016-04-20 22:37:17 +02:00
# Connect to the Docker socket
dockercli = docker.Client(base_url=app.config['DOCKER_SOCKET'])
# Task scheduling
if not app.debug or os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
scheduler.start()
# Babel configuration
@babel.localeselector
def get_locale():
return flask.request.accept_languages.best_match(translations)
# Finally setup the blueprint and redirect /
from mailu import admin
app.register_blueprint(admin.app, url_prefix='/admin')
@app.route("/")
def index():
return 1/0
return flask.redirect(flask.url_for("admin.index"))