Actually bind flask-admin to the mail servers

master
Pierre Jaury 9 years ago
parent 61c99c7014
commit 48fbf737ce

@ -1,14 +1,22 @@
from flask import Flask from flask import Flask
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
import os
# Create application # Create application
app = Flask(__name__) app = Flask(__name__)
app.config.update({ default_config = {
'SQLALCHEMY_DATABASE_URI': 'sqlite:////tmp/freeposte.db' '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 # Create the database
db = SQLAlchemy(app) db = SQLAlchemy(app)

@ -1,6 +1,7 @@
from freeposte import db from freeposte import db
class Domain(db.Model): class Domain(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80)) 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') 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 pass
class UserModelView(sqla.ModelView): class UserModelView(BaseModelView):
pass pass
class AliasModelView(sqla.ModelView): class AliasModelView(BaseModelView):
pass pass

@ -1,2 +1,4 @@
Flask Flask
Flask-Admin
Flask-SQLAlchemy 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__': 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 # Return the user hashed password
password_query = \ password_query = \
SELECT password \ SELECT password \
FROM users INNER JOIN domains ON users.domain_id = domains.id \ FROM user INNER JOIN domain ON user.domain_id = domains.id \
WHERE domains.name = '%d' \ WHERE domain.name = '%d' \
AND users.username = '%n' AND user.username = '%n'
# Mostly get the user quota # Mostly get the user quota
user_query = \ user_query = \
SELECT '*:bytes=' || users.quota_bytes AS quota_rule \ SELECT '*:bytes=' || user.quota_bytes AS quota_rule \
FROM users INNER JOIN domains ON users.domain_id = domains.id \ FROM user INNER JOIN domain ON user.domain_id = domain.id \
WHERE domains.name = '%d' \ WHERE domain.name = '%d' \
AND users.username = '%n' AND user.username = '%n'

@ -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 alias_maps = hash:/etc/aliases
# SQLite configuration # SQLite configuration
sql = sqlite:${config_directory}/ sql = sqlite:${config_directory}/
# Only accept virtual emails
mydestination =
############### ###############
# TLS # TLS

@ -1,6 +1,6 @@
dbpath = /data/freeposte.db dbpath = /data/freeposte.db
query = \ query =
SELECT destination \ SELECT destination
FROM aliases INNER JOIN domains ON aliases.domain_id = domains.id \ FROM alias INNER JOIN domain ON alias.domain_id = domain.id
WHERE domains.name = '%d' \ WHERE domain.name = '%d'
AND aliases.localpart = '%n' AND alias.localpart = '%u'

@ -1,2 +1,2 @@
dbpath = /data/freeposte.db 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] [supervisord]
nodaemon = true nodaemon = true
logfile = /var/log/supervisor/supervisord.log
[program:postfix] [program:postfix]
command = /usr/lib/postfix/master -d command = /usr/lib/postfix/master -d
@ -12,3 +13,9 @@ command = /usr/sbin/spamd
[program:rsyslog] [program:rsyslog]
command = rsyslogd -n command = rsyslogd -n
[program:admin]
command = uwsgi --yaml /etc/uwsgi/apps-enabled/freeposte.yml
[program:nginx]
command = nginx -g 'daemon off;'

@ -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…
Cancel
Save