diff --git a/admin/freeposte/__init__.py b/admin/freeposte/__init__.py index 6f2cb066..96e6d564 100644 --- a/admin/freeposte/__init__.py +++ b/admin/freeposte/__init__.py @@ -10,7 +10,7 @@ import os app = Flask(__name__) default_config = { - 'SQLALCHEMY_DATABASE_URI': 'sqlite:////tmp/freeposte.db', + 'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/freeposte.db', 'SQLALCHEMY_TRACK_MODIFICATIONS': False, 'SECRET_KEY': "changeMe", 'DEBUG': False @@ -20,24 +20,12 @@ default_config = { for key, value in default_config.items(): app.config[key] = os.environ.get(key, value) -# Setup Bootstrap +# Setup components Bootstrap(app) - -# Create the database db = SQLAlchemy(app) - -# Import models once the database is ready -from freeposte import models - -# Setup Flask-login login_manager = flask_login.LoginManager() login_manager.init_app(app) -login_manager.login_view = "login" -login_manager.user_loader(models.User.get_by_email) -@app.context_processor -def inject_user(): - return dict(current_user=flask_login.current_user) - -# Finally import view -from freeposte import views +# Finally setup the blueprint +from freeposte import admin +app.register_blueprint(admin.app, url_prefix='/admin') diff --git a/admin/freeposte/admin/__init__.py b/admin/freeposte/admin/__init__.py new file mode 100644 index 00000000..92aa50a2 --- /dev/null +++ b/admin/freeposte/admin/__init__.py @@ -0,0 +1,28 @@ +from flask import Blueprint +from flask.ext import login as flask_login +from freeposte import login_manager, db + + +app = Blueprint( + 'admin', __name__, + template_folder='templates', + static_folder='static') + +# Import models +from freeposte.admin import models + +# Register the login components +login_manager.login_view = "admin.login" +login_manager.user_loader(models.User.get_by_email) + +@app.context_processor +def inject_user(): + return dict(current_user=flask_login.current_user) + +# Import views +from freeposte.admin.views import \ + administrators, \ + base, \ + aliases, \ + users, \ + domains diff --git a/admin/freeposte/forms.py b/admin/freeposte/admin/forms.py similarity index 100% rename from admin/freeposte/forms.py rename to admin/freeposte/admin/forms.py diff --git a/admin/freeposte/models.py b/admin/freeposte/admin/models.py similarity index 90% rename from admin/freeposte/models.py rename to admin/freeposte/admin/models.py index 4e92a2ba..d1464eab 100644 --- a/admin/freeposte/models.py +++ b/admin/freeposte/admin/models.py @@ -1,9 +1,11 @@ -from freeposte import db +from freeposte.admin import db from sqlalchemy.ext import declarative from passlib import context from datetime import datetime +import re + # Many-to-many association table for domain administrators admins = db.Table('admin', @@ -89,13 +91,16 @@ class User(Address): is_active = True is_anonymous = False - pw_context = context.CryptContext(["sha512_crypt", "sha256_crypt"]) + pw_context = context.CryptContext( + ["sha512_crypt", "sha256_crypt", "md5_crypt"] + ) def check_password(self, password): - return User.pw_context.verify(password, self.password) + reference = re.match('({[^}]+})?(.*)', self.password).group(2) + return User.pw_context.verify(password, reference) def set_password(self, password): - self.password = User.pw_context.encrypt(password) + self.password = '{SHA512-CRYPT}' + User.pw_context.encrypt(password) def get_managed_domains(self): if self.global_admin: diff --git a/admin/freeposte/static/adminlte/css/AdminLTE.min.css b/admin/freeposte/admin/static/adminlte/css/AdminLTE.min.css similarity index 100% rename from admin/freeposte/static/adminlte/css/AdminLTE.min.css rename to admin/freeposte/admin/static/adminlte/css/AdminLTE.min.css diff --git a/admin/freeposte/static/adminlte/css/skin-blue.min.css b/admin/freeposte/admin/static/adminlte/css/skin-blue.min.css similarity index 100% rename from admin/freeposte/static/adminlte/css/skin-blue.min.css rename to admin/freeposte/admin/static/adminlte/css/skin-blue.min.css diff --git a/admin/freeposte/static/adminlte/js/app.min.js b/admin/freeposte/admin/static/adminlte/js/app.min.js similarity index 100% rename from admin/freeposte/static/adminlte/js/app.min.js rename to admin/freeposte/admin/static/adminlte/js/app.min.js diff --git a/admin/freeposte/static/bootstrap/css/bootstrap.css.map b/admin/freeposte/admin/static/bootstrap/css/bootstrap.css.map similarity index 100% rename from admin/freeposte/static/bootstrap/css/bootstrap.css.map rename to admin/freeposte/admin/static/bootstrap/css/bootstrap.css.map diff --git a/admin/freeposte/static/bootstrap/css/bootstrap.min.css b/admin/freeposte/admin/static/bootstrap/css/bootstrap.min.css similarity index 100% rename from admin/freeposte/static/bootstrap/css/bootstrap.min.css rename to admin/freeposte/admin/static/bootstrap/css/bootstrap.min.css diff --git a/admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.eot b/admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.eot similarity index 100% rename from admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.eot rename to admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.eot diff --git a/admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.svg b/admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.svg rename to admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.svg diff --git a/admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.ttf b/admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.ttf similarity index 100% rename from admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.ttf rename to admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.ttf diff --git a/admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.woff b/admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.woff similarity index 100% rename from admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.woff rename to admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.woff diff --git a/admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.woff2 b/admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.woff2 similarity index 100% rename from admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.woff2 rename to admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.woff2 diff --git a/admin/freeposte/static/bootstrap/js/bootstrap.min.js b/admin/freeposte/admin/static/bootstrap/js/bootstrap.min.js similarity index 100% rename from admin/freeposte/static/bootstrap/js/bootstrap.min.js rename to admin/freeposte/admin/static/bootstrap/js/bootstrap.min.js diff --git a/admin/freeposte/static/jquery/js/jquery-2.2.2.min.js b/admin/freeposte/admin/static/jquery/js/jquery-2.2.2.min.js similarity index 100% rename from admin/freeposte/static/jquery/js/jquery-2.2.2.min.js rename to admin/freeposte/admin/static/jquery/js/jquery-2.2.2.min.js diff --git a/admin/freeposte/templates/admin/admins.html b/admin/freeposte/admin/templates/admin/admins.html similarity index 100% rename from admin/freeposte/templates/admin/admins.html rename to admin/freeposte/admin/templates/admin/admins.html diff --git a/admin/freeposte/templates/admin/status.html b/admin/freeposte/admin/templates/admin/status.html similarity index 100% rename from admin/freeposte/templates/admin/status.html rename to admin/freeposte/admin/templates/admin/status.html diff --git a/admin/freeposte/templates/alias/create.html b/admin/freeposte/admin/templates/alias/create.html similarity index 100% rename from admin/freeposte/templates/alias/create.html rename to admin/freeposte/admin/templates/alias/create.html diff --git a/admin/freeposte/templates/alias/edit.html b/admin/freeposte/admin/templates/alias/edit.html similarity index 100% rename from admin/freeposte/templates/alias/edit.html rename to admin/freeposte/admin/templates/alias/edit.html diff --git a/admin/freeposte/templates/alias/list.html b/admin/freeposte/admin/templates/alias/list.html similarity index 67% rename from admin/freeposte/templates/alias/list.html rename to admin/freeposte/admin/templates/alias/list.html index 8b5aab90..342b1558 100644 --- a/admin/freeposte/templates/alias/list.html +++ b/admin/freeposte/admin/templates/alias/list.html @@ -9,7 +9,7 @@ Alias list {% endblock %} {% block main_action %} -Add alias +Add alias {% endblock %} {% block box %} @@ -26,8 +26,8 @@ Alias list {% for alias in domain.aliases %} -   - +   + {{ alias }} {{ alias.destination or '-' }} diff --git a/admin/freeposte/templates/base.html b/admin/freeposte/admin/templates/base.html similarity index 88% rename from admin/freeposte/templates/base.html rename to admin/freeposte/admin/templates/base.html index af17c131..9f348bc9 100644 --- a/admin/freeposte/templates/base.html +++ b/admin/freeposte/admin/templates/base.html @@ -5,8 +5,8 @@ {% block styles %} {{super()}} - - + + {% endblock %} {% block body_attribs %} @@ -68,7 +68,7 @@ class="hold-transition skin-blue sidebar-mini" {% block scripts %} {{super()}} - + {% endblock %} {% endblock %} diff --git a/admin/freeposte/templates/domain/admins.html b/admin/freeposte/admin/templates/domain/admins.html similarity index 100% rename from admin/freeposte/templates/domain/admins.html rename to admin/freeposte/admin/templates/domain/admins.html diff --git a/admin/freeposte/templates/domain/create.html b/admin/freeposte/admin/templates/domain/create.html similarity index 100% rename from admin/freeposte/templates/domain/create.html rename to admin/freeposte/admin/templates/domain/create.html diff --git a/admin/freeposte/templates/domain/edit.html b/admin/freeposte/admin/templates/domain/edit.html similarity index 100% rename from admin/freeposte/templates/domain/edit.html rename to admin/freeposte/admin/templates/domain/edit.html diff --git a/admin/freeposte/templates/domain/list.html b/admin/freeposte/admin/templates/domain/list.html similarity index 55% rename from admin/freeposte/templates/domain/list.html rename to admin/freeposte/admin/templates/domain/list.html index adc34a27..e8ef15ea 100644 --- a/admin/freeposte/templates/domain/list.html +++ b/admin/freeposte/admin/templates/domain/list.html @@ -6,7 +6,7 @@ Domain list {% block main_action %} {% if current_user.global_admin %} -New domain +New domain {% endif %} {% endblock %} @@ -25,11 +25,11 @@ Domain list {% for domain in current_user.get_managed_domains() %} -   -   -   -   - +   +   +   +   + {{ domain.name }} {{ domain.users | count }} / {{ domain.max_users or '∞' }} diff --git a/admin/freeposte/templates/form.html b/admin/freeposte/admin/templates/form.html similarity index 100% rename from admin/freeposte/templates/form.html rename to admin/freeposte/admin/templates/form.html diff --git a/admin/freeposte/templates/helpers.html b/admin/freeposte/admin/templates/helpers.html similarity index 100% rename from admin/freeposte/templates/helpers.html rename to admin/freeposte/admin/templates/helpers.html diff --git a/admin/freeposte/templates/index.html b/admin/freeposte/admin/templates/index.html similarity index 100% rename from admin/freeposte/templates/index.html rename to admin/freeposte/admin/templates/index.html diff --git a/admin/freeposte/templates/login.html b/admin/freeposte/admin/templates/login.html similarity index 100% rename from admin/freeposte/templates/login.html rename to admin/freeposte/admin/templates/login.html diff --git a/admin/freeposte/templates/sidebar.html b/admin/freeposte/admin/templates/sidebar.html similarity index 72% rename from admin/freeposte/templates/sidebar.html rename to admin/freeposte/admin/templates/sidebar.html index b0369576..efe049f6 100644 --- a/admin/freeposte/templates/sidebar.html +++ b/admin/freeposte/admin/templates/sidebar.html @@ -4,51 +4,51 @@