cmdeploy: enable running DNS commands in a docker container

This commit is contained in:
missytake
2025-08-26 10:43:24 +02:00
parent d2ff812727
commit 52d04448f2
2 changed files with 12 additions and 5 deletions

View File

@@ -7,6 +7,10 @@ from . import remote
def get_initial_remote_data(sshexec, mail_domain):
if sshexec == "docker":
return remote.rdns.perform_initial_checks(mail_domain, pre_command="docker exec chatmail ")
elif sshexec == "localhost":
return remote.rdns.perform_initial_checks(mail_domain, pre_command="running on localhost")
return sshexec.logged(
call=remote.rdns.perform_initial_checks, kwargs=dict(mail_domain=mail_domain)
)

View File

@@ -15,7 +15,7 @@ import re
from .rshell import CalledProcessError, shell
def perform_initial_checks(mail_domain):
def perform_initial_checks(mail_domain, pre_command=""):
"""Collecting initial DNS settings."""
assert mail_domain
if not shell("dig", fail_ok=True):
@@ -26,9 +26,12 @@ def perform_initial_checks(mail_domain):
WWW = query_dns("CNAME", f"www.{mail_domain}")
res = dict(mail_domain=mail_domain, A=A, AAAA=AAAA, MTA_STS=MTA_STS, WWW=WWW)
res["acme_account_url"] = shell("acmetool account-url", fail_ok=True)
if pre_command == "running on localhost":
return res
res["acme_account_url"] = shell(pre_command + "acmetool account-url", fail_ok=True)
res["dkim_entry"], res["web_dkim_entry"] = get_dkim_entry(
mail_domain, dkim_selector="opendkim"
mail_domain, pre_command, dkim_selector="opendkim"
)
if not MTA_STS or not WWW or (not A and not AAAA):
@@ -40,10 +43,10 @@ def perform_initial_checks(mail_domain):
return res
def get_dkim_entry(mail_domain, dkim_selector):
def get_dkim_entry(mail_domain, pre_command, dkim_selector):
try:
dkim_pubkey = shell(
f"openssl rsa -in /etc/dkimkeys/{dkim_selector}.private "
f"{pre_command} openssl rsa -in /etc/dkimkeys/{dkim_selector}.private "
"-pubout 2>/dev/null | awk '/-/{next}{printf(\"%s\",$0)}'"
)
except CalledProcessError: