selfprivacy-rest-api/selfprivacy_api/resources/services/mailserver.py

40 lines
952 B
Python
Raw Normal View History

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-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-11 18:31:28 +00:00
domain = get_domain()
2021-11-16 16:14:01 +00:00
cat_process = subprocess.Popen(
2021-11-11 18:31:28 +00:00
["cat", "/var/dkim/" + domain + ".selector.txt"], stdout=subprocess.PIPE
)
2021-11-16 16:14:01 +00:00
dkim = cat_process.communicate()[0]
2021-11-11 18:31:28 +00:00
dkim = base64.b64encode(dkim)
dkim = str(dkim, "utf-8")
return dkim
api.add_resource(DKIMKey, "/mailserver/dkim")