diff options
author | crupest <crupest@outlook.com> | 2024-11-11 01:12:29 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-01-20 22:34:18 +0800 |
commit | 5c76a1257b4a058bf919af3e31cc9461a39c2f33 (patch) | |
tree | cb32f0c22e5438a0ed9de4b29f58d0b7f142a58d /tools/cru-py/crupest/dns.py | |
parent | 12e1272508ba0b5909069319007d677c1c76e355 (diff) | |
download | crupest-5c76a1257b4a058bf919af3e31cc9461a39c2f33.tar.gz crupest-5c76a1257b4a058bf919af3e31cc9461a39c2f33.tar.bz2 crupest-5c76a1257b4a058bf919af3e31cc9461a39c2f33.zip |
HALF WORK: 2024.1.20 - 2
Diffstat (limited to 'tools/cru-py/crupest/dns.py')
-rw-r--r-- | tools/cru-py/crupest/dns.py | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/tools/cru-py/crupest/dns.py b/tools/cru-py/crupest/dns.py deleted file mode 100644 index 5006d5f..0000000 --- a/tools/cru-py/crupest/dns.py +++ /dev/null @@ -1,42 +0,0 @@ -from os.path import * -from io import StringIO -import re -from .nginx import * - - -def generate_dns_zone(domain: str, ip: str, /, ttl: str | int = 600, *, enable_mail: bool = True, dkim: str | None = None) -> str: - result = f"$ORIGIN {domain}.\n\n" - result += "; A records\n" - result += f"@ {ttl} IN A {ip}\n" - subdomains = list_subdomain_names() - for subdomain in subdomains: - result += f"{subdomain} {ttl} IN A {ip}\n" - - if enable_mail: - result += "\n; MX records\n" - result += f"@ {ttl} IN MX 10 mail.{domain}.\n" - result += "\n; SPF record\n" - result += f"@ {ttl} IN TXT \"v=spf1 mx ~all\"\n" - if dkim is not None: - result += "\n; DKIM record\n" - result += f"mail._domainkey {ttl} IN TEXT \"{dkim}\"" - result += "\n; DMARC record\n" - result += "_dmarc {ttl} IN TXT \"v=DMARC1; p=none; rua=mailto:dmarc.report@{domain}; ruf=mailto:dmarc.report@{domain}; sp=none; ri=86400\"\n" - return result - - -def get_dkim_from_mailserver(domain: str) -> str | None: - dkim_path = join(data_dir, "dms/config/opendkim/keys", domain, "mail.txt") - if not exists(dkim_path): - return None - - p = subprocess.run(["sudo", "cat", dkim_path], - capture_output=True, check=True) - value = "" - for match in re.finditer("\"(.*)\"", p.stdout.decode('utf-8')): - value += match.group(1) - return value - - -def generate_dns_zone_with_dkim(domain: str, ip: str, /, ttl: str | int = 600) -> str: - return generate_dns_zone(domain, ip, ttl, enable_mail=True, dkim=get_dkim_from_mailserver(domain)) |