mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Add loading of domain settings. Generate defaults for missing entries (and backward-compability)
This commit is contained in:
parent
9a8cbbd883
commit
1a4d02c9bf
2 changed files with 77 additions and 2 deletions
|
@ -460,6 +460,12 @@ domain:
|
|||
help: Do not ask confirmation to remove apps
|
||||
action: store_true
|
||||
|
||||
settings:
|
||||
action_help: Get settings for a domain
|
||||
api: GET /domains/<domain>/settings
|
||||
arguments:
|
||||
domain:
|
||||
help: Target domain
|
||||
### domain_dns_conf()
|
||||
dns-conf:
|
||||
action_help: Generate sample DNS configuration for a domain
|
||||
|
|
|
@ -45,7 +45,7 @@ from yunohost.hook import hook_callback
|
|||
|
||||
logger = getActionLogger("yunohost.domain")
|
||||
|
||||
DOMAIN_SETTINGS_PATH = "/etc/yunohost/domains/"
|
||||
DOMAIN_SETTINGS_PATH = "/etc/yunohost/domains.yml"
|
||||
|
||||
def domain_list(exclude_subdomains=False):
|
||||
"""
|
||||
|
@ -661,7 +661,7 @@ def _get_DKIM(domain):
|
|||
|
||||
|
||||
def _get_domain_and_subdomains_settings(domain):
|
||||
"""
|
||||
"""
|
||||
Give data about a domain and its subdomains
|
||||
"""
|
||||
return {
|
||||
|
@ -680,3 +680,72 @@ def _get_domain_and_subdomains_settings(domain):
|
|||
},
|
||||
}
|
||||
|
||||
def _load_domain_settings():
|
||||
"""
|
||||
Retrieve entries in domains.yml
|
||||
And fill the holes if any
|
||||
"""
|
||||
# Retrieve entries in the YAML
|
||||
if os.path.exists(DOMAIN_SETTINGS_PATH) and os.path.isfile(DOMAIN_SETTINGS_PATH):
|
||||
old_domains = yaml.load(open(DOMAIN_SETTINGS_PATH, "r+"))
|
||||
else:
|
||||
old_domains = dict()
|
||||
|
||||
# Create sanitized data
|
||||
new_domains = dict()
|
||||
|
||||
get_domain_list = domain_list()
|
||||
|
||||
# Load main domain
|
||||
maindomain = get_domain_list["main"]
|
||||
|
||||
for domain in get_domain_list["domains"]:
|
||||
# Update each setting if not present
|
||||
new_domains[domain] = {
|
||||
# Set "main" value
|
||||
"main": True if domain == maindomain else False
|
||||
}
|
||||
# Set other values (default value if missing)
|
||||
for setting, default in [ ("xmpp", True), ("mail", True), ("owned_dns_zone", True), ("ttl", 3600) ]:
|
||||
if domain in old_domains.keys() and setting in old_domains[domain].keys():
|
||||
new_domains[domain][setting] = old_domains[domain][setting]
|
||||
else:
|
||||
new_domains[domain][setting] = default
|
||||
|
||||
return new_domains
|
||||
|
||||
|
||||
def domain_settings(domain):
|
||||
"""
|
||||
Get settings of a domain
|
||||
|
||||
Keyword arguments:
|
||||
domain -- The domain name
|
||||
"""
|
||||
return _get_domain_settings(domain, False)
|
||||
|
||||
def _get_domain_settings(domain, subdomains):
|
||||
"""
|
||||
Get settings of a domain
|
||||
|
||||
Keyword arguments:
|
||||
domain -- The domain name
|
||||
subdomains -- Do we include the subdomains? Default is False
|
||||
|
||||
"""
|
||||
domains = _load_domain_settings()
|
||||
if not domain in domains.keys():
|
||||
return {}
|
||||
|
||||
only_wanted_domains = dict()
|
||||
for entry in domains.keys():
|
||||
if subdomains:
|
||||
if domain in entry:
|
||||
only_wanted_domains[entry] = domains[entry]
|
||||
else:
|
||||
if domain == entry:
|
||||
only_wanted_domains[entry] = domains[entry]
|
||||
|
||||
|
||||
return only_wanted_domains
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue