mirror of
https://github.com/Mailu/Mailu.git
synced 2025-01-26 03:52:50 +02:00
Actually bind flask-admin to the mail servers
This commit is contained in:
parent
61c99c7014
commit
48fbf737ce
@ -1,14 +1,22 @@
|
||||
from flask import Flask
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
import os
|
||||
|
||||
|
||||
# Create application
|
||||
app = Flask(__name__)
|
||||
|
||||
app.config.update({
|
||||
'SQLALCHEMY_DATABASE_URI': 'sqlite:////tmp/freeposte.db'
|
||||
})
|
||||
default_config = {
|
||||
'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/freeposte.db',
|
||||
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
|
||||
'SECRET_KEY': None
|
||||
}
|
||||
|
||||
# Load configuration from the environment if available
|
||||
for key, value in default_config.items():
|
||||
app.config[key] = os.environ.get(key, value)
|
||||
|
||||
|
||||
# Create the database
|
||||
db = SQLAlchemy(app)
|
||||
|
@ -1,6 +1,7 @@
|
||||
from freeposte import db
|
||||
|
||||
|
||||
|
||||
class Domain(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(80))
|
||||
|
@ -8,15 +8,24 @@ from freeposte import app, db, models
|
||||
admin = admin.Admin(app, name='Freeposte.io', template_mode='bootstrap3')
|
||||
|
||||
|
||||
class DomainModelView(sqla.ModelView):
|
||||
class BaseModelView(sqla.ModelView):
|
||||
|
||||
def after_model_change(self, form, model, is_created):
|
||||
db.session.commit()
|
||||
|
||||
def after_model_delete(self, model):
|
||||
db.session.commit()
|
||||
|
||||
|
||||
class DomainModelView(BaseModelView):
|
||||
pass
|
||||
|
||||
|
||||
class UserModelView(sqla.ModelView):
|
||||
class UserModelView(BaseModelView):
|
||||
pass
|
||||
|
||||
|
||||
class AliasModelView(sqla.ModelView):
|
||||
class AliasModelView(BaseModelView):
|
||||
pass
|
||||
|
||||
|
||||
|
@ -1,2 +1,4 @@
|
||||
Flask
|
||||
Flask-Admin
|
||||
Flask-SQLAlchemy
|
||||
uwsgi
|
||||
|
@ -1,4 +1,9 @@
|
||||
from freeposte import app
|
||||
from freeposte import app, db
|
||||
|
||||
|
||||
# Initialize the database if required (first launch)
|
||||
db.create_all()
|
||||
db.session.commit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1,7 +0,0 @@
|
||||
from freeposte import db, models
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
db.drop_all()
|
||||
db.create_all()
|
||||
db.session.commit()
|
@ -4,13 +4,13 @@ connect = /data/freeposte.db
|
||||
# Return the user hashed password
|
||||
password_query = \
|
||||
SELECT password \
|
||||
FROM users INNER JOIN domains ON users.domain_id = domains.id \
|
||||
WHERE domains.name = '%d' \
|
||||
AND users.username = '%n'
|
||||
FROM user INNER JOIN domain ON user.domain_id = domains.id \
|
||||
WHERE domain.name = '%d' \
|
||||
AND user.username = '%n'
|
||||
|
||||
# Mostly get the user quota
|
||||
user_query = \
|
||||
SELECT '*:bytes=' || users.quota_bytes AS quota_rule \
|
||||
FROM users INNER JOIN domains ON users.domain_id = domains.id \
|
||||
WHERE domains.name = '%d' \
|
||||
AND users.username = '%n'
|
||||
SELECT '*:bytes=' || user.quota_bytes AS quota_rule \
|
||||
FROM user INNER JOIN domain ON user.domain_id = domain.id \
|
||||
WHERE domain.name = '%d' \
|
||||
AND user.username = '%n'
|
||||
|
28
config/nginx/nginx.conf
Normal file
28
config/nginx/nginx.conf
Normal file
@ -0,0 +1,28 @@
|
||||
user www-data;
|
||||
worker_processes 1;
|
||||
|
||||
error_log /var/log/nginx/error.log info;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
access_log /var/log/nginx/access.log;
|
||||
sendfile on;
|
||||
keepalive_timeout 65;
|
||||
server_tokens off;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
location /admin {
|
||||
include uwsgi_params;
|
||||
uwsgi_modifier1 30;
|
||||
uwsgi_pass unix:/var/run/freeposte.sock;
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,8 @@ mynetworks = /data/relaynets
|
||||
alias_maps = hash:/etc/aliases
|
||||
# SQLite configuration
|
||||
sql = sqlite:${config_directory}/
|
||||
# Only accept virtual emails
|
||||
mydestination =
|
||||
|
||||
###############
|
||||
# TLS
|
||||
|
@ -1,6 +1,6 @@
|
||||
dbpath = /data/freeposte.db
|
||||
query = \
|
||||
SELECT destination \
|
||||
FROM aliases INNER JOIN domains ON aliases.domain_id = domains.id \
|
||||
WHERE domains.name = '%d' \
|
||||
AND aliases.localpart = '%n'
|
||||
query =
|
||||
SELECT destination
|
||||
FROM alias INNER JOIN domain ON alias.domain_id = domain.id
|
||||
WHERE domain.name = '%d'
|
||||
AND alias.localpart = '%u'
|
||||
|
@ -1,2 +1,2 @@
|
||||
dbpath = /data/freeposte.db
|
||||
query = SELECT name FROM domains WHERE domain='%s'
|
||||
query = SELECT name FROM domain WHERE name='%s'
|
||||
|
@ -1,5 +1,6 @@
|
||||
[supervisord]
|
||||
nodaemon = true
|
||||
logfile = /var/log/supervisor/supervisord.log
|
||||
|
||||
[program:postfix]
|
||||
command = /usr/lib/postfix/master -d
|
||||
@ -12,3 +13,9 @@ command = /usr/sbin/spamd
|
||||
|
||||
[program:rsyslog]
|
||||
command = rsyslogd -n
|
||||
|
||||
[program:admin]
|
||||
command = uwsgi --yaml /etc/uwsgi/apps-enabled/freeposte.yml
|
||||
|
||||
[program:nginx]
|
||||
command = nginx -g 'daemon off;'
|
||||
|
16
config/uwsgi/apps-enabled/freeposte.yml
Normal file
16
config/uwsgi/apps-enabled/freeposte.yml
Normal file
@ -0,0 +1,16 @@
|
||||
uwsgi:
|
||||
socket: /var/run/freeposte.sock
|
||||
chown-socket: www-data:www-data
|
||||
pidfile: /var/run/freeposte.pid
|
||||
master: true
|
||||
workers: 2
|
||||
|
||||
vacuum: true
|
||||
plugins: python
|
||||
wsgi-file: /admin/run.py
|
||||
callable: app
|
||||
processes: 1
|
||||
pythonpath: /usr/lib/python2.7/site-packages
|
||||
pythonpath: /admin
|
||||
catch-exceptions: true
|
||||
post-buffering: 8192
|
Loading…
x
Reference in New Issue
Block a user