|
|
@ -9,6 +9,8 @@ import flask_limiter
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import docker
|
|
|
|
import docker
|
|
|
|
|
|
|
|
import socket
|
|
|
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
|
|
# Create application
|
|
|
|
# Create application
|
|
|
|
app = flask.Flask(__name__)
|
|
|
|
app = flask.Flask(__name__)
|
|
|
@ -16,6 +18,8 @@ app = flask.Flask(__name__)
|
|
|
|
default_config = {
|
|
|
|
default_config = {
|
|
|
|
'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/main.db',
|
|
|
|
'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/main.db',
|
|
|
|
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
|
|
|
|
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
|
|
|
|
|
|
|
|
'INSTANCE_ID_PATH': '/data/instance',
|
|
|
|
|
|
|
|
'STATS_ENDPOINT': '0.{}.stats.mailu.io',
|
|
|
|
'SECRET_KEY': 'changeMe',
|
|
|
|
'SECRET_KEY': 'changeMe',
|
|
|
|
'DOCKER_SOCKET': 'unix:///var/run/docker.sock',
|
|
|
|
'DOCKER_SOCKET': 'unix:///var/run/docker.sock',
|
|
|
|
'HOSTNAMES': 'mail.mailu.io',
|
|
|
|
'HOSTNAMES': 'mail.mailu.io',
|
|
|
@ -50,6 +54,19 @@ db = flask_sqlalchemy.SQLAlchemy(app)
|
|
|
|
migrate = flask_migrate.Migrate(app, db)
|
|
|
|
migrate = flask_migrate.Migrate(app, db)
|
|
|
|
limiter = flask_limiter.Limiter(app, key_func=lambda: current_user.username)
|
|
|
|
limiter = flask_limiter.Limiter(app, key_func=lambda: current_user.username)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Run statistics
|
|
|
|
|
|
|
|
if os.path.isfile(app.config["INSTANCE_ID_PATH"]):
|
|
|
|
|
|
|
|
with open(app.config["INSTANCE_ID_PATH"], "r") as handle:
|
|
|
|
|
|
|
|
instance_id = handle.read()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
instance_id = str(uuid.uuid4())
|
|
|
|
|
|
|
|
with open(app.config["INSTANCE_ID_PATH"], "w") as handle:
|
|
|
|
|
|
|
|
handle.write(instance_id)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
socket.gethostbyname(app.config["STATS_ENDPOINT"].format(instance_id))
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
# Debugging toolbar
|
|
|
|
# Debugging toolbar
|
|
|
|
if app.config.get("DEBUG"):
|
|
|
|
if app.config.get("DEBUG"):
|
|
|
|
import flask_debugtoolbar
|
|
|
|
import flask_debugtoolbar
|
|
|
|