mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge branch 'enh-dns-autoconf' of https://github.com/MercierCorentin/yunohost into enh-dns-autoconf
This commit is contained in:
commit
4876860b47
2 changed files with 41 additions and 1 deletions
|
@ -42,6 +42,7 @@ from yunohost.app import (
|
|||
)
|
||||
from yunohost.regenconf import regen_conf, _force_clear_hashes, _process_regen_conf
|
||||
from yunohost.utils.network import get_public_ip
|
||||
from yunohost.utils.dns import get_public_suffix
|
||||
from yunohost.log import is_unit_operation
|
||||
from yunohost.hook import hook_callback
|
||||
|
||||
|
@ -703,12 +704,13 @@ def _load_domain_settings():
|
|||
|
||||
for domain in get_domain_list["domains"]:
|
||||
is_maindomain = domain == maindomain
|
||||
default_owned_dns_zone = True if domain == get_public_suffix(domain) else False
|
||||
domain_in_old_domains = domain in old_domains.keys()
|
||||
# Update each setting if not present
|
||||
new_domains[domain] = {}
|
||||
# new_domains[domain] = { "main": is_maindomain }
|
||||
# Set other values (default value if missing)
|
||||
for setting, default in [ ("xmpp", is_maindomain), ("mail", is_maindomain), ("owned_dns_zone", True), ("ttl", 3600) ]:
|
||||
for setting, default in [ ("xmpp", is_maindomain), ("mail", is_maindomain), ("owned_dns_zone", default_owned_dns_zone), ("ttl", 3600) ]:
|
||||
if domain_in_old_domains and setting in old_domains[domain].keys():
|
||||
new_domains[domain][setting] = old_domains[domain][setting]
|
||||
else:
|
||||
|
|
38
src/yunohost/utils/dns.py
Normal file
38
src/yunohost/utils/dns.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
""" License
|
||||
|
||||
Copyright (C) 2018 YUNOHOST.ORG
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, see http://www.gnu.org/licenses
|
||||
|
||||
"""
|
||||
from publicsuffix import PublicSuffixList
|
||||
|
||||
YNH_DYNDNS_DOMAINS = ["nohost.me", "noho.st", "ynh.fr"]
|
||||
|
||||
def get_public_suffix(domain):
|
||||
"""get_public_suffix("www.example.com") -> "example.com"
|
||||
|
||||
Return the public suffix of a domain name based
|
||||
"""
|
||||
# Load domain public suffixes
|
||||
psl = PublicSuffixList()
|
||||
|
||||
public_suffix = psl.get_public_suffix(domain)
|
||||
if public_suffix in YNH_DYNDNS_DOMAINS:
|
||||
domain_prefix = domain_name[0:-(1 + len(public_suffix))]
|
||||
public_suffix = domain_prefix.plit(".")[-1] + "." + public_suffix
|
||||
|
||||
return public_suffix
|
Loading…
Add table
Reference in a new issue