2016-08-29 19:24:39 +02:00
|
|
|
from freeposte.admin import app, db, models, forms, utils, access
|
2016-06-25 14:51:02 +02:00
|
|
|
from freeposte import app as flask_app
|
2016-03-19 21:37:48 +02:00
|
|
|
|
|
|
|
import os
|
|
|
|
import flask
|
2016-08-13 20:51:54 +02:00
|
|
|
import flask_login
|
2016-03-22 22:22:49 +02:00
|
|
|
import wtforms_components
|
2016-03-19 21:37:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/domain', methods=['GET'])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.authenticated
|
2016-03-19 21:37:48 +02:00
|
|
|
def domain_list():
|
|
|
|
return flask.render_template('domain/list.html')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/domain/create', methods=['GET', 'POST'])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.global_admin
|
2016-03-19 21:37:48 +02:00
|
|
|
def domain_create():
|
2016-03-22 22:22:49 +02:00
|
|
|
form = forms.DomainForm()
|
2016-03-19 21:37:48 +02:00
|
|
|
if form.validate_on_submit():
|
2016-05-01 20:09:47 +02:00
|
|
|
if models.Domain.query.get(form.name.data):
|
2016-03-19 21:37:48 +02:00
|
|
|
flask.flash('Domain %s is already used' % form.name.data, 'error')
|
|
|
|
else:
|
2016-05-01 21:12:08 +02:00
|
|
|
domain = models.Domain()
|
|
|
|
form.populate_obj(domain)
|
2016-03-19 21:37:48 +02:00
|
|
|
db.session.add(domain)
|
|
|
|
db.session.commit()
|
|
|
|
flask.flash('Domain %s created' % domain)
|
2016-03-20 16:36:56 +02:00
|
|
|
return flask.redirect(flask.url_for('.domain_list'))
|
2016-03-19 21:37:48 +02:00
|
|
|
return flask.render_template('domain/create.html', form=form)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/domain/edit/<domain_name>', methods=['GET', 'POST'])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.domain_admin(models.Domain, 'domain_name')
|
2016-03-19 21:37:48 +02:00
|
|
|
def domain_edit(domain_name):
|
2016-08-29 19:24:39 +02:00
|
|
|
domain = models.Domain.query.get(domain_name) or flask.abort(404)
|
2016-03-22 22:22:49 +02:00
|
|
|
form = forms.DomainForm(obj=domain)
|
|
|
|
wtforms_components.read_only(form.name)
|
2016-03-19 21:37:48 +02:00
|
|
|
if form.validate_on_submit():
|
2016-05-01 21:12:08 +02:00
|
|
|
form.populate_obj(domain)
|
2016-03-19 21:37:48 +02:00
|
|
|
db.session.commit()
|
|
|
|
flask.flash('Domain %s saved' % domain)
|
2016-03-20 16:36:56 +02:00
|
|
|
return flask.redirect(flask.url_for('.domain_list'))
|
2016-03-19 21:37:48 +02:00
|
|
|
return flask.render_template('domain/edit.html', form=form,
|
|
|
|
domain=domain)
|
|
|
|
|
|
|
|
|
2016-08-19 10:49:05 +02:00
|
|
|
@app.route('/domain/delete/<domain_name>', methods=['GET', 'POST'])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.global_admin
|
2016-08-19 10:49:05 +02:00
|
|
|
@utils.confirmation_required("delete {domain_name}")
|
2016-03-19 21:37:48 +02:00
|
|
|
def domain_delete(domain_name):
|
2016-08-29 19:24:39 +02:00
|
|
|
domain = models.Domain.query.get(domain_name) or flask.abort(404)
|
2016-03-19 21:37:48 +02:00
|
|
|
db.session.delete(domain)
|
|
|
|
db.session.commit()
|
|
|
|
flask.flash('Domain %s deleted' % domain)
|
2016-03-20 16:36:56 +02:00
|
|
|
return flask.redirect(flask.url_for('.domain_list'))
|
2016-06-25 14:51:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/domain/details/<domain_name>', methods=['GET'])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.domain_admin(models.Domain, 'domain_name')
|
2016-06-25 14:51:02 +02:00
|
|
|
def domain_details(domain_name):
|
2016-08-29 19:24:39 +02:00
|
|
|
domain = models.Domain.query.get(domain_name) or flask.abort(404)
|
2016-06-25 14:51:02 +02:00
|
|
|
return flask.render_template('domain/details.html', domain=domain,
|
|
|
|
config=flask_app.config)
|
2016-06-25 15:50:05 +02:00
|
|
|
|
|
|
|
|
2016-08-19 10:49:05 +02:00
|
|
|
@app.route('/domain/genkeys/<domain_name>', methods=['GET', 'POST'])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.domain_admin(models.Domain, 'domain_name')
|
2016-08-19 10:49:05 +02:00
|
|
|
@utils.confirmation_required("regenerate keys for {domain_name}")
|
2016-06-25 15:50:05 +02:00
|
|
|
def domain_genkeys(domain_name):
|
2016-08-29 19:24:39 +02:00
|
|
|
domain = models.Domain.query.get(domain_name) or flask.abort(404)
|
2016-06-25 15:50:05 +02:00
|
|
|
domain.generate_dkim_key()
|
|
|
|
return flask.redirect(
|
|
|
|
flask.url_for(".domain_details", domain_name=domain_name))
|