yunohost domain dns push now accepts an --auto option

Domains can be configured to be auto-pushed by a cron job
This commit is contained in:
theo@manjaro 2022-07-06 15:52:27 +02:00
parent 01dfb778e9
commit 940af74c2d
7 changed files with 34 additions and 11 deletions

View file

@ -116,8 +116,9 @@ SHELL=/bin/bash
# - (sleep random 60 is here to spread requests over a 1-min window) # - (sleep random 60 is here to spread requests over a 1-min window)
# - if ip.yunohost.org answers ping (basic check to validate that we're connected to the internet and yunohost infra aint down) # - if ip.yunohost.org answers ping (basic check to validate that we're connected to the internet and yunohost infra aint down)
# - and if lock ain't already taken by another command # - and if lock ain't already taken by another command
# - trigger yunohost dyndns update # - check if some domains are flagged as autopush
*/10 * * * * root : YunoHost DynDNS update ; sleep \$((RANDOM\\%60)); ! ping -q -W5 -c1 ip.yunohost.org >/dev/null 2>&1 || test -e /var/run/moulinette_yunohost.lock || yunohost domain list --exclude-subdomains --output json | jq --raw-output '.domains[]' | grep -E "\.(noho\.st|nohost\.me|ynh\.fr)$" | xargs -I {} yunohost domain dns push "{}" >> /dev/null # - trigger yunohost domain dns push --auto
*/10 * * * * root : YunoHost DynDNS update ; sleep \$((RANDOM\\%60)); ! ping -q -W5 -c1 ip.yunohost.org >/dev/null 2>&1 || test -e /var/run/moulinette_yunohost.lock || !(grep -nR "autopush: 1" /etc/yunohost/domains/*.yml > /dev/null) || yunohost domain dns push --auto >> /dev/null
EOF EOF
else else
# (Delete cron if no dyndns domain found) # (Delete cron if no dyndns domain found)

View file

@ -312,6 +312,8 @@
"domain_config_auth_token": "Authentication token", "domain_config_auth_token": "Authentication token",
"domain_config_default_app": "Default app", "domain_config_default_app": "Default app",
"domain_config_features_disclaimer": "So far, enabling/disabling mail or XMPP features only impact the recommended and automatic DNS configuration, not system configurations!", "domain_config_features_disclaimer": "So far, enabling/disabling mail or XMPP features only impact the recommended and automatic DNS configuration, not system configurations!",
"domain_config_autopush": "Auto-push",
"domain_config_autopush_help": "Automatically update the domain's record",
"domain_config_mail_in": "Incoming emails", "domain_config_mail_in": "Incoming emails",
"domain_config_mail_out": "Outgoing emails", "domain_config_mail_out": "Outgoing emails",
"domain_config_xmpp": "Instant messaging (XMPP)", "domain_config_xmpp": "Instant messaging (XMPP)",

View file

@ -443,6 +443,9 @@ domain:
--exclude-subdomains: --exclude-subdomains:
help: Filter out domains that are obviously subdomains of other declared domains help: Filter out domains that are obviously subdomains of other declared domains
action: store_true action: store_true
--auto-push:
help: Only display domains that are pushed automatically
action: store_true
### domain_add() ### domain_add()
add: add:
@ -689,8 +692,8 @@ domain:
action_help: Push DNS records to registrar action_help: Push DNS records to registrar
api: POST /domains/<domain>/dns/push api: POST /domains/<domain>/dns/push
arguments: arguments:
domain: domains:
help: Domain name to push DNS conf for help: Domain names to push DNS conf for
nargs: "*" nargs: "*"
extra: extra:
pattern: *pattern_domain pattern: *pattern_domain
@ -704,6 +707,9 @@ domain:
--purge: --purge:
help: Delete all records help: Delete all records
action: store_true action: store_true
--auto:
help: Push only domains that should be pushed automatically
action: store_true
cert: cert:
subcategory_help: Manage domain certificates subcategory_help: Manage domain certificates

View file

@ -46,6 +46,13 @@ i18n = "domain_config"
default = 0 default = 0
[dns] [dns]
[dns.zone]
[dns.zone.autopush]
type = "boolean"
default = 0
help = ""
[dns.registrar] [dns.registrar]
optional = true optional = true

View file

@ -623,10 +623,11 @@ def _get_registar_settings(domain):
@is_unit_operation() @is_unit_operation()
def domain_dns_push(operation_logger, domains, dry_run=False, force=False, purge=False): def domain_dns_push(operation_logger, domains, dry_run=False, force=False, purge=False, auto=False):
# If we provide only a domain as an argument if auto:
if isinstance(domains, str): domains = domain_list(exclude_subdomains=True,auto_push=True)["domains"]
domains = [domains] elif len(domains)==0:
domains = domain_list(exclude_subdomains=True)["domains"]
error_domains = [] error_domains = []
for domain in domains: for domain in domains:
try: try:

View file

@ -52,7 +52,7 @@ DOMAIN_SETTINGS_DIR = "/etc/yunohost/domains"
domain_list_cache: Dict[str, Any] = {} domain_list_cache: Dict[str, Any] = {}
def domain_list(exclude_subdomains=False): def domain_list(exclude_subdomains=False,auto_push=False):
""" """
List domains List domains
@ -78,6 +78,8 @@ def domain_list(exclude_subdomains=False):
parent_domain = domain.split(".", 1)[1] parent_domain = domain.split(".", 1)[1]
if parent_domain in result: if parent_domain in result:
continue continue
if auto_push and not domain_config_get(domain, key="dns.zone.autopush"):
continue
result_list.append(domain) result_list.append(domain)
@ -611,7 +613,7 @@ def domain_dns_suggest(domain):
return domain_dns_suggest(domain) return domain_dns_suggest(domain)
def domain_dns_push(domain, dry_run=None, force=None, purge=None): def domain_dns_push(domains, dry_run=None, force=None, purge=None, auto=False):
from yunohost.dns import domain_dns_push from yunohost.dns import domain_dns_push
return domain_dns_push(domain, dry_run=dry_run, force=force, purge=purge) return domain_dns_push(domains, dry_run=dry_run, force=force, purge=purge, auto=auto)

View file

@ -170,6 +170,10 @@ def dyndns_subscribe(operation_logger, domain=None, key=None, password=None):
error = f'Server error, code: {r.status_code}. (Message: "{r.text}")' error = f'Server error, code: {r.status_code}. (Message: "{r.text}")'
raise YunohostError("dyndns_registration_failed", error=error) raise YunohostError("dyndns_registration_failed", error=error)
# Set the domain's config to autopush
from yunohost.domain import domain_config_set
domain_config_set(domain,key="dns.zone.autopush",value=1)
# Yunohost regen conf will add the dyndns cron job if a key exists # Yunohost regen conf will add the dyndns cron job if a key exists
# in /etc/yunohost/dyndns # in /etc/yunohost/dyndns
regen_conf(["yunohost"]) regen_conf(["yunohost"])