2021-10-14 23:25:42 +02:00
|
|
|
from mailu import models
|
2021-10-14 19:07:11 +02:00
|
|
|
from mailu.internal import internal
|
|
|
|
|
|
|
|
import flask
|
|
|
|
|
|
|
|
def vault_error(*messages, status=404):
|
|
|
|
return flask.make_response(flask.jsonify({'errors':messages}), status)
|
|
|
|
|
|
|
|
# rspamd key format:
|
|
|
|
# {"selectors":[{"pubkey":"...","domain":"...","valid_start":TS,"valid_end":TS,"key":"...","selector":"...","bits":...,"alg":"..."}]}
|
|
|
|
|
|
|
|
# hashicorp vault answer format:
|
|
|
|
# {"request_id":"...","lease_id":"","renewable":false,"lease_duration":2764800,"data":{...see above...},"wrap_info":null,"warnings":null,"auth":null}
|
|
|
|
|
2021-10-15 13:16:37 +02:00
|
|
|
@internal.route("/rspamd/vault/v1/dkim/<domain_name>", methods=['GET'])
|
2021-10-14 19:07:11 +02:00
|
|
|
def rspamd_dkim_key(domain_name):
|
2021-11-08 10:34:02 +02:00
|
|
|
selectors = []
|
|
|
|
if domain := models.Domain.query.get(domain_name):
|
|
|
|
if key := domain.dkim_key:
|
|
|
|
selectors.append(
|
2021-10-14 19:07:11 +02:00
|
|
|
{
|
|
|
|
'domain' : domain.name,
|
|
|
|
'key' : key.decode('utf8'),
|
2021-10-14 23:25:42 +02:00
|
|
|
'selector': flask.current_app.config.get('DKIM_SELECTOR', 'dkim'),
|
2021-10-14 19:07:11 +02:00
|
|
|
}
|
2021-11-08 10:34:02 +02:00
|
|
|
)
|
|
|
|
return flask.jsonify({'data': {'selectors': selectors}})
|
2022-10-19 15:28:20 +02:00
|
|
|
|
|
|
|
@internal.route("/rspamd/local_domains", methods=['GET'])
|
|
|
|
def rspamd_local_domains():
|
2022-10-24 19:31:53 +02:00
|
|
|
return '\n'.join(domain[0] for domain in models.Domain.query.with_entities(models.Domain.name).all() + models.Alternative.query.with_entities(models.Alternative.name).all())
|