2018-10-18 15:57:43 +02:00
|
|
|
from mailu import models
|
2018-09-27 16:09:38 +02:00
|
|
|
from mailu.internal import internal
|
2018-10-18 15:57:43 +02:00
|
|
|
from flask import current_app as app
|
2018-09-27 16:09:38 +02:00
|
|
|
|
|
|
|
import flask
|
2018-10-17 21:21:00 +02:00
|
|
|
import socket
|
2018-10-31 17:47:05 +02:00
|
|
|
import os
|
2018-09-27 16:09:38 +02:00
|
|
|
|
|
|
|
@internal.route("/dovecot/passdb/<user_email>")
|
|
|
|
def dovecot_passdb_dict(user_email):
|
|
|
|
user = models.User.query.get(user_email) or flask.abort(404)
|
2018-10-17 21:21:00 +02:00
|
|
|
allow_nets = []
|
|
|
|
allow_nets.append(
|
|
|
|
app.config.get("POD_ADDRESS_RANGE") or
|
|
|
|
socket.gethostbyname(app.config["HOST_FRONT"])
|
|
|
|
)
|
2018-10-31 17:47:05 +02:00
|
|
|
if os.environ["WEBMAIL"] != "none":
|
|
|
|
allow_nets.append(socket.gethostbyname(app.config["HOST_WEBMAIL"]))
|
2018-10-17 21:21:00 +02:00
|
|
|
print(allow_nets)
|
2018-09-27 16:09:38 +02:00
|
|
|
return flask.jsonify({
|
2018-10-17 21:21:00 +02:00
|
|
|
"password": None,
|
|
|
|
"nopassword": "Y",
|
|
|
|
"allow_nets": ",".join(allow_nets)
|
2018-09-27 16:09:38 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
@internal.route("/dovecot/userdb/<user_email>")
|
|
|
|
def dovecot_userdb_dict(user_email):
|
|
|
|
user = models.User.query.get(user_email) or flask.abort(404)
|
|
|
|
return flask.jsonify({
|
|
|
|
"quota_rule": "*:bytes={}".format(user.quota_bytes)
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
@internal.route("/dovecot/quota/<ns>/<user_email>", methods=["POST"])
|
|
|
|
def dovecot_quota(ns, user_email):
|
|
|
|
user = models.User.query.get(user_email) or flask.abort(404)
|
|
|
|
if ns == "storage":
|
|
|
|
user.quota_bytes_used = flask.request.get_json()
|
2018-10-18 15:57:43 +02:00
|
|
|
models.db.session.commit()
|
2018-09-27 16:09:38 +02:00
|
|
|
return flask.jsonify(None)
|
|
|
|
|
|
|
|
|
|
|
|
@internal.route("/dovecot/sieve/name/<script>/<user_email>")
|
|
|
|
def dovecot_sieve_name(script, user_email):
|
|
|
|
return flask.jsonify(script)
|
|
|
|
|
|
|
|
|
|
|
|
@internal.route("/dovecot/sieve/data/default/<user_email>")
|
|
|
|
def dovecot_sieve_data(user_email):
|
|
|
|
user = models.User.query.get(user_email) or flask.abort(404)
|
|
|
|
return flask.jsonify(flask.render_template("default.sieve", user=user))
|