mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
First implementation of configurable dns conf generation
This commit is contained in:
parent
9a8cbbd883
commit
c111b9c6c2
2 changed files with 83 additions and 70 deletions
|
@ -467,13 +467,6 @@ domain:
|
||||||
arguments:
|
arguments:
|
||||||
domain:
|
domain:
|
||||||
help: Target domain
|
help: Target domain
|
||||||
-t:
|
|
||||||
full: --ttl
|
|
||||||
help: Time To Live (TTL) in second before DNS servers update. Default is 3600 seconds (i.e. 1 hour).
|
|
||||||
extra:
|
|
||||||
pattern:
|
|
||||||
- !!str ^[0-9]+$
|
|
||||||
- "pattern_positive_number"
|
|
||||||
|
|
||||||
### domain_maindomain()
|
### domain_maindomain()
|
||||||
main-domain:
|
main-domain:
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
from moulinette import m18n, msettings, msignals
|
from moulinette import m18n, msettings, msignals
|
||||||
from moulinette.core import MoulinetteError
|
from moulinette.core import MoulinetteError
|
||||||
|
@ -275,22 +276,21 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False):
|
||||||
logger.success(m18n.n("domain_deleted"))
|
logger.success(m18n.n("domain_deleted"))
|
||||||
|
|
||||||
|
|
||||||
def domain_dns_conf(domain, ttl=None):
|
def domain_dns_conf(domain):
|
||||||
"""
|
"""
|
||||||
Generate DNS configuration for a domain
|
Generate DNS configuration for a domain
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
domain -- Domain name
|
domain -- Domain name
|
||||||
ttl -- Time to live
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if domain not in domain_list()["domains"]:
|
if domain not in domain_list()["domains"]:
|
||||||
raise YunohostError("domain_name_unknown", domain=domain)
|
raise YunohostError("domain_name_unknown", domain=domain)
|
||||||
|
|
||||||
ttl = 3600 if ttl is None else ttl
|
domains_settings = _get_domain_and_subdomains_settings(domain)
|
||||||
|
|
||||||
dns_conf = _build_dns_conf(domain, ttl)
|
dns_conf = _build_dns_conf(domains_settings)
|
||||||
|
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ def _get_maindomain():
|
||||||
return maindomain
|
return maindomain
|
||||||
|
|
||||||
|
|
||||||
def _build_dns_conf(domain, ttl=3600, include_empty_AAAA_if_no_ipv6=False):
|
def _build_dns_conf(domains):
|
||||||
"""
|
"""
|
||||||
Internal function that will returns a data structure containing the needed
|
Internal function that will returns a data structure containing the needed
|
||||||
information to generate/adapt the dns configuration
|
information to generate/adapt the dns configuration
|
||||||
|
@ -451,72 +451,92 @@ def _build_dns_conf(domain, ttl=3600, include_empty_AAAA_if_no_ipv6=False):
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
root = min(domains.keys(), key=(lambda k: len(k)))
|
||||||
|
|
||||||
|
basic = []
|
||||||
|
mail = []
|
||||||
|
xmpp = []
|
||||||
|
extra = []
|
||||||
ipv4 = get_public_ip()
|
ipv4 = get_public_ip()
|
||||||
ipv6 = get_public_ip(6)
|
ipv6 = get_public_ip(6)
|
||||||
|
|
||||||
###########################
|
name_prefix = root.partition(".")[0]
|
||||||
# Basic ipv4/ipv6 records #
|
|
||||||
###########################
|
|
||||||
|
|
||||||
basic = []
|
|
||||||
if ipv4:
|
|
||||||
basic.append(["@", ttl, "A", ipv4])
|
|
||||||
|
|
||||||
if ipv6:
|
for domain_name, domain in domains.items():
|
||||||
basic.append(["@", ttl, "AAAA", ipv6])
|
print(domain_name)
|
||||||
elif include_empty_AAAA_if_no_ipv6:
|
ttl = domain["ttl"]
|
||||||
basic.append(["@", ttl, "AAAA", None])
|
|
||||||
|
|
||||||
#########
|
owned_dns_zone = "owned_dns_zone" in domains[root] and domains[root]["owned_dns_zone"] == True
|
||||||
# Email #
|
if domain_name == root:
|
||||||
#########
|
name = name_prefix if not owned_dns_zone else "@"
|
||||||
|
else:
|
||||||
|
name = domain_name[0:-(1 + len(root))]
|
||||||
|
if not owned_dns_zone:
|
||||||
|
name += "." + name_prefix
|
||||||
|
|
||||||
mail = [
|
###########################
|
||||||
["@", ttl, "MX", "10 %s." % domain],
|
# Basic ipv4/ipv6 records #
|
||||||
["@", ttl, "TXT", '"v=spf1 a mx -all"'],
|
###########################
|
||||||
]
|
if ipv4:
|
||||||
|
basic.append([name, ttl, "A", ipv4])
|
||||||
|
|
||||||
# DKIM/DMARC record
|
if ipv6:
|
||||||
dkim_host, dkim_publickey = _get_DKIM(domain)
|
basic.append([name, ttl, "AAAA", ipv6])
|
||||||
|
# TODO
|
||||||
|
# elif include_empty_AAAA_if_no_ipv6:
|
||||||
|
# basic.append(["@", ttl, "AAAA", None])
|
||||||
|
|
||||||
if dkim_host:
|
#########
|
||||||
mail += [
|
# Email #
|
||||||
[dkim_host, ttl, "TXT", dkim_publickey],
|
#########
|
||||||
["_dmarc", ttl, "TXT", '"v=DMARC1; p=none"'],
|
if domain["mail"] == True:
|
||||||
]
|
|
||||||
|
|
||||||
########
|
mail += [
|
||||||
# XMPP #
|
[name, ttl, "MX", "10 %s." % domain],
|
||||||
########
|
[name, ttl, "TXT", '"v=spf1 a mx -all"'],
|
||||||
|
]
|
||||||
|
|
||||||
xmpp = [
|
# DKIM/DMARC record
|
||||||
["_xmpp-client._tcp", ttl, "SRV", "0 5 5222 %s." % domain],
|
dkim_host, dkim_publickey = _get_DKIM(domain)
|
||||||
["_xmpp-server._tcp", ttl, "SRV", "0 5 5269 %s." % domain],
|
|
||||||
["muc", ttl, "CNAME", "@"],
|
|
||||||
["pubsub", ttl, "CNAME", "@"],
|
|
||||||
["vjud", ttl, "CNAME", "@"],
|
|
||||||
["xmpp-upload", ttl, "CNAME", "@"],
|
|
||||||
]
|
|
||||||
|
|
||||||
#########
|
if dkim_host:
|
||||||
# Extra #
|
mail += [
|
||||||
#########
|
[dkim_host, ttl, "TXT", dkim_publickey],
|
||||||
|
["_dmarc", ttl, "TXT", '"v=DMARC1; p=none"'],
|
||||||
|
]
|
||||||
|
|
||||||
extra = []
|
########
|
||||||
|
# XMPP #
|
||||||
|
########
|
||||||
|
if domain["xmpp"] == True:
|
||||||
|
xmpp += [
|
||||||
|
["_xmpp-client._tcp", ttl, "SRV", "0 5 5222 %s." % domain_name],
|
||||||
|
["_xmpp-server._tcp", ttl, "SRV", "0 5 5269 %s." % domain_name],
|
||||||
|
["muc", ttl, "CNAME", name],
|
||||||
|
["pubsub", ttl, "CNAME", name],
|
||||||
|
["vjud", ttl, "CNAME", name],
|
||||||
|
["xmpp-upload", ttl, "CNAME", name],
|
||||||
|
]
|
||||||
|
|
||||||
if ipv4:
|
#########
|
||||||
extra.append(["*", ttl, "A", ipv4])
|
# Extra #
|
||||||
|
#########
|
||||||
|
|
||||||
if ipv6:
|
|
||||||
extra.append(["*", ttl, "AAAA", ipv6])
|
|
||||||
elif include_empty_AAAA_if_no_ipv6:
|
|
||||||
extra.append(["*", ttl, "AAAA", None])
|
|
||||||
|
|
||||||
extra.append(["@", ttl, "CAA", '128 issue "letsencrypt.org"'])
|
if ipv4:
|
||||||
|
extra.append(["*", ttl, "A", ipv4])
|
||||||
|
|
||||||
####################
|
if ipv6:
|
||||||
# Standard records #
|
extra.append(["*", ttl, "AAAA", ipv6])
|
||||||
####################
|
elif include_empty_AAAA_if_no_ipv6:
|
||||||
|
extra.append(["*", ttl, "AAAA", None])
|
||||||
|
|
||||||
|
extra.append([name, ttl, "CAA", '128 issue "letsencrypt.org"'])
|
||||||
|
|
||||||
|
####################
|
||||||
|
# Standard records #
|
||||||
|
####################
|
||||||
|
|
||||||
records = {
|
records = {
|
||||||
"basic": [
|
"basic": [
|
||||||
|
@ -665,17 +685,17 @@ def _get_domain_and_subdomains_settings(domain):
|
||||||
Give data about a domain and its subdomains
|
Give data about a domain and its subdomains
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
"cmercier.fr" : {
|
"node.cmercier.fr" : {
|
||||||
"main": true,
|
"main": True,
|
||||||
"xmpp": true,
|
"xmpp": True,
|
||||||
"mail": true,
|
"mail": True,
|
||||||
"owned_dns_zone": true,
|
"owned_dns_zone": True,
|
||||||
"ttl": 3600,
|
"ttl": 3600,
|
||||||
},
|
},
|
||||||
"node.cmercier.fr" : {
|
"sub.node.cmercier.fr" : {
|
||||||
"main": false,
|
"main": False,
|
||||||
"xmpp": false,
|
"xmpp": True,
|
||||||
"mail": false,
|
"mail": False,
|
||||||
"ttl": 3600,
|
"ttl": 3600,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue