2021-11-11 18:31:28 +00:00
|
|
|
#!/usr/bin/env python3
|
2021-11-16 16:14:01 +00:00
|
|
|
"""Mail server management module"""
|
2021-11-11 18:31:28 +00:00
|
|
|
import base64
|
|
|
|
import subprocess
|
2021-11-29 19:16:08 +00:00
|
|
|
import os
|
2021-11-16 16:14:01 +00:00
|
|
|
from flask_restful import Resource
|
2021-11-11 18:31:28 +00:00
|
|
|
|
|
|
|
from selfprivacy_api.resources.services import api
|
|
|
|
|
|
|
|
from selfprivacy_api.utils import get_domain
|
|
|
|
|
2021-11-16 16:14:01 +00:00
|
|
|
|
2021-11-11 18:31:28 +00:00
|
|
|
class DKIMKey(Resource):
|
2021-11-16 16:14:01 +00:00
|
|
|
"""Get DKIM key from file"""
|
|
|
|
|
2021-11-11 18:31:28 +00:00
|
|
|
def get(self):
|
2021-11-16 16:14:01 +00:00
|
|
|
"""
|
|
|
|
Get DKIM key from file
|
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- Email
|
|
|
|
security:
|
|
|
|
- bearerAuth: []
|
|
|
|
responses:
|
|
|
|
200:
|
|
|
|
description: DKIM key encoded in base64
|
|
|
|
401:
|
|
|
|
description: Unauthorized
|
2021-11-29 19:16:08 +00:00
|
|
|
404:
|
|
|
|
description: DKIM key not found
|
2021-11-16 16:14:01 +00:00
|
|
|
"""
|
2021-11-11 18:31:28 +00:00
|
|
|
domain = get_domain()
|
2021-11-29 19:16:08 +00:00
|
|
|
|
|
|
|
if os.path.exists("/var/dkim/" + domain + ".selector.txt"):
|
|
|
|
cat_process = subprocess.Popen(
|
|
|
|
["cat", "/var/dkim/" + domain + ".selector.txt"], stdout=subprocess.PIPE
|
|
|
|
)
|
|
|
|
dkim = cat_process.communicate()[0]
|
|
|
|
dkim = base64.b64encode(dkim)
|
|
|
|
dkim = str(dkim, "utf-8")
|
|
|
|
return dkim
|
|
|
|
return "DKIM file not found", 404
|
2021-11-11 18:31:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
api.add_resource(DKIMKey, "/mailserver/dkim")
|