mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Run black
& revert misguidedly cosmetic changes
An obscur plugin must have done this...
This commit is contained in:
parent
e40f8fb861
commit
ced4da4171
1 changed files with 102 additions and 57 deletions
|
@ -43,7 +43,7 @@ from yunohost.app import (
|
||||||
_installed_apps,
|
_installed_apps,
|
||||||
_get_app_settings,
|
_get_app_settings,
|
||||||
_get_conflicting_apps,
|
_get_conflicting_apps,
|
||||||
_parse_args_in_yunohost_format
|
_parse_args_in_yunohost_format,
|
||||||
)
|
)
|
||||||
from yunohost.regenconf import regen_conf, _force_clear_hashes, _process_regen_conf
|
from yunohost.regenconf import regen_conf, _force_clear_hashes, _process_regen_conf
|
||||||
from yunohost.utils.network import get_public_ip
|
from yunohost.utils.network import get_public_ip
|
||||||
|
@ -56,6 +56,7 @@ logger = getActionLogger("yunohost.domain")
|
||||||
DOMAIN_SETTINGS_PATH = "/etc/yunohost/domains.yml"
|
DOMAIN_SETTINGS_PATH = "/etc/yunohost/domains.yml"
|
||||||
REGISTRAR_LIST_PATH = "/usr/share/yunohost/other/providers_list.yml"
|
REGISTRAR_LIST_PATH = "/usr/share/yunohost/other/providers_list.yml"
|
||||||
|
|
||||||
|
|
||||||
def domain_list(exclude_subdomains=False):
|
def domain_list(exclude_subdomains=False):
|
||||||
"""
|
"""
|
||||||
List domains
|
List domains
|
||||||
|
@ -109,6 +110,7 @@ def domain_add(operation_logger, domain, dyndns=False):
|
||||||
from yunohost.hook import hook_callback
|
from yunohost.hook import hook_callback
|
||||||
from yunohost.app import app_ssowatconf
|
from yunohost.app import app_ssowatconf
|
||||||
from yunohost.utils.ldap import _get_ldap_interface
|
from yunohost.utils.ldap import _get_ldap_interface
|
||||||
|
from yunohost.certificate import _certificate_install_selfsigned
|
||||||
|
|
||||||
if domain.startswith("xmpp-upload."):
|
if domain.startswith("xmpp-upload."):
|
||||||
raise YunohostValidationError("domain_cannot_add_xmpp_upload")
|
raise YunohostValidationError("domain_cannot_add_xmpp_upload")
|
||||||
|
@ -142,14 +144,13 @@ def domain_add(operation_logger, domain, dyndns=False):
|
||||||
|
|
||||||
if dyndns:
|
if dyndns:
|
||||||
from yunohost.dyndns import dyndns_subscribe
|
from yunohost.dyndns import dyndns_subscribe
|
||||||
|
|
||||||
# Actually subscribe
|
# Actually subscribe
|
||||||
dyndns_subscribe(domain=domain)
|
dyndns_subscribe(domain=domain)
|
||||||
|
|
||||||
|
_certificate_install_selfsigned([domain], False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import yunohost.certificate
|
|
||||||
|
|
||||||
yunohost.certificate._certificate_install_selfsigned([domain], False)
|
|
||||||
|
|
||||||
attr_dict = {
|
attr_dict = {
|
||||||
"objectClass": ["mailDomain", "top"],
|
"objectClass": ["mailDomain", "top"],
|
||||||
"virtualdomain": domain,
|
"virtualdomain": domain,
|
||||||
|
@ -176,13 +177,13 @@ def domain_add(operation_logger, domain, dyndns=False):
|
||||||
regen_conf(names=["nginx", "metronome", "dnsmasq", "postfix", "rspamd"])
|
regen_conf(names=["nginx", "metronome", "dnsmasq", "postfix", "rspamd"])
|
||||||
app_ssowatconf()
|
app_ssowatconf()
|
||||||
|
|
||||||
except Exception:
|
except Exception as e:
|
||||||
# Force domain removal silently
|
# Force domain removal silently
|
||||||
try:
|
try:
|
||||||
domain_remove(domain, force=True)
|
domain_remove(domain, force=True)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
raise
|
raise e
|
||||||
|
|
||||||
hook_callback("post_domain_add", args=[domain])
|
hook_callback("post_domain_add", args=[domain])
|
||||||
|
|
||||||
|
@ -234,21 +235,37 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False):
|
||||||
settings = _get_app_settings(app)
|
settings = _get_app_settings(app)
|
||||||
label = app_info(app)["name"]
|
label = app_info(app)["name"]
|
||||||
if settings.get("domain") == domain:
|
if settings.get("domain") == domain:
|
||||||
apps_on_that_domain.append((app, " - %s \"%s\" on https://%s%s" % (app, label, domain, settings["path"]) if "path" in settings else app))
|
apps_on_that_domain.append(
|
||||||
|
(
|
||||||
|
app,
|
||||||
|
' - %s "%s" on https://%s%s'
|
||||||
|
% (app, label, domain, settings["path"])
|
||||||
|
if "path" in settings
|
||||||
|
else app,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if apps_on_that_domain:
|
if apps_on_that_domain:
|
||||||
if remove_apps:
|
if remove_apps:
|
||||||
if msettings.get('interface') == "cli" and not force:
|
if msettings.get("interface") == "cli" and not force:
|
||||||
answer = msignals.prompt(m18n.n('domain_remove_confirm_apps_removal',
|
answer = msignals.prompt(
|
||||||
|
m18n.n(
|
||||||
|
"domain_remove_confirm_apps_removal",
|
||||||
apps="\n".join([x[1] for x in apps_on_that_domain]),
|
apps="\n".join([x[1] for x in apps_on_that_domain]),
|
||||||
answers='y/N'), color="yellow")
|
answers="y/N",
|
||||||
|
),
|
||||||
|
color="yellow",
|
||||||
|
)
|
||||||
if answer.upper() != "Y":
|
if answer.upper() != "Y":
|
||||||
raise YunohostError("aborting")
|
raise YunohostError("aborting")
|
||||||
|
|
||||||
for app, _ in apps_on_that_domain:
|
for app, _ in apps_on_that_domain:
|
||||||
app_remove(app)
|
app_remove(app)
|
||||||
else:
|
else:
|
||||||
raise YunohostValidationError('domain_uninstall_app_first', apps="\n".join([x[1] for x in apps_on_that_domain]))
|
raise YunohostValidationError(
|
||||||
|
"domain_uninstall_app_first",
|
||||||
|
apps="\n".join([x[1] for x in apps_on_that_domain]),
|
||||||
|
)
|
||||||
|
|
||||||
operation_logger.start()
|
operation_logger.start()
|
||||||
|
|
||||||
|
@ -261,7 +278,7 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False):
|
||||||
os.system("rm -rf /etc/yunohost/certs/%s" % domain)
|
os.system("rm -rf /etc/yunohost/certs/%s" % domain)
|
||||||
|
|
||||||
# Delete dyndns keys for this domain (if any)
|
# Delete dyndns keys for this domain (if any)
|
||||||
os.system('rm -rf /etc/yunohost/dyndns/K%s.+*' % domain)
|
os.system("rm -rf /etc/yunohost/dyndns/K%s.+*" % domain)
|
||||||
|
|
||||||
# Sometime we have weird issues with the regenconf where some files
|
# Sometime we have weird issues with the regenconf where some files
|
||||||
# appears as manually modified even though they weren't touched ...
|
# appears as manually modified even though they weren't touched ...
|
||||||
|
@ -475,7 +492,9 @@ def _build_dns_conf(domains):
|
||||||
extra = []
|
extra = []
|
||||||
ipv4 = get_public_ip()
|
ipv4 = get_public_ip()
|
||||||
ipv6 = get_public_ip(6)
|
ipv6 = get_public_ip(6)
|
||||||
owned_dns_zone = "owned_dns_zone" in domains[root] and domains[root]["owned_dns_zone"]
|
owned_dns_zone = (
|
||||||
|
"owned_dns_zone" in domains[root] and domains[root]["owned_dns_zone"]
|
||||||
|
)
|
||||||
|
|
||||||
root_prefix = root.partition(".")[0]
|
root_prefix = root.partition(".")[0]
|
||||||
child_domain_suffix = ""
|
child_domain_suffix = ""
|
||||||
|
@ -486,14 +505,13 @@ def _build_dns_conf(domains):
|
||||||
if domain_name == root:
|
if domain_name == root:
|
||||||
name = root_prefix if not owned_dns_zone else "@"
|
name = root_prefix if not owned_dns_zone else "@"
|
||||||
else:
|
else:
|
||||||
name = domain_name[0:-(1 + len(root))]
|
name = domain_name[0 : -(1 + len(root))]
|
||||||
if not owned_dns_zone:
|
if not owned_dns_zone:
|
||||||
name += "." + root_prefix
|
name += "." + root_prefix
|
||||||
|
|
||||||
if name != "@":
|
if name != "@":
|
||||||
child_domain_suffix = "." + name
|
child_domain_suffix = "." + name
|
||||||
|
|
||||||
|
|
||||||
###########################
|
###########################
|
||||||
# Basic ipv4/ipv6 records #
|
# Basic ipv4/ipv6 records #
|
||||||
###########################
|
###########################
|
||||||
|
@ -530,8 +548,18 @@ def _build_dns_conf(domains):
|
||||||
########
|
########
|
||||||
if domain["xmpp"]:
|
if domain["xmpp"]:
|
||||||
xmpp += [
|
xmpp += [
|
||||||
[f"_xmpp-client._tcp{child_domain_suffix}", ttl, "SRV", f"0 5 5222 {domain_name}."],
|
[
|
||||||
[f"_xmpp-server._tcp{child_domain_suffix}", ttl, "SRV", f"0 5 5269 {domain_name}."],
|
f"_xmpp-client._tcp{child_domain_suffix}",
|
||||||
|
ttl,
|
||||||
|
"SRV",
|
||||||
|
f"0 5 5222 {domain_name}.",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
f"_xmpp-server._tcp{child_domain_suffix}",
|
||||||
|
ttl,
|
||||||
|
"SRV",
|
||||||
|
f"0 5 5269 {domain_name}.",
|
||||||
|
],
|
||||||
["muc" + child_domain_suffix, ttl, "CNAME", name],
|
["muc" + child_domain_suffix, ttl, "CNAME", name],
|
||||||
["pubsub" + child_domain_suffix, ttl, "CNAME", name],
|
["pubsub" + child_domain_suffix, ttl, "CNAME", name],
|
||||||
["vjud" + child_domain_suffix, ttl, "CNAME", name],
|
["vjud" + child_domain_suffix, ttl, "CNAME", name],
|
||||||
|
@ -542,7 +570,6 @@ def _build_dns_conf(domains):
|
||||||
# Extra #
|
# Extra #
|
||||||
#########
|
#########
|
||||||
|
|
||||||
|
|
||||||
if ipv4:
|
if ipv4:
|
||||||
extra.append([f"*{child_domain_suffix}", ttl, "A", ipv4])
|
extra.append([f"*{child_domain_suffix}", ttl, "A", ipv4])
|
||||||
|
|
||||||
|
@ -729,7 +756,13 @@ def _load_domain_settings():
|
||||||
new_domains[domain] = {}
|
new_domains[domain] = {}
|
||||||
# new_domains[domain] = { "main": is_maindomain }
|
# new_domains[domain] = { "main": is_maindomain }
|
||||||
# Set other values (default value if missing)
|
# Set other values (default value if missing)
|
||||||
for setting, default in [ ("xmpp", is_maindomain), ("mail", True), ("owned_dns_zone", default_owned_dns_zone), ("ttl", 3600), ("provider", False)]:
|
for setting, default in [
|
||||||
|
("xmpp", is_maindomain),
|
||||||
|
("mail", True),
|
||||||
|
("owned_dns_zone", default_owned_dns_zone),
|
||||||
|
("ttl", 3600),
|
||||||
|
("provider", False),
|
||||||
|
]:
|
||||||
if domain_in_old_domains and setting in old_domains[domain].keys():
|
if domain_in_old_domains and setting in old_domains[domain].keys():
|
||||||
new_domains[domain][setting] = old_domains[domain][setting]
|
new_domains[domain][setting] = old_domains[domain][setting]
|
||||||
else:
|
else:
|
||||||
|
@ -737,6 +770,7 @@ def _load_domain_settings():
|
||||||
|
|
||||||
return new_domains
|
return new_domains
|
||||||
|
|
||||||
|
|
||||||
def domain_setting(domain, key, value=None, delete=False):
|
def domain_setting(domain, key, value=None, delete=False):
|
||||||
"""
|
"""
|
||||||
Set or get an app setting value
|
Set or get an app setting value
|
||||||
|
@ -785,6 +819,7 @@ def domain_setting(domain, key, value=None, delete=False):
|
||||||
domain_settings[key] = value
|
domain_settings[key] = value
|
||||||
_set_domain_settings(domain, domain_settings)
|
_set_domain_settings(domain, domain_settings)
|
||||||
|
|
||||||
|
|
||||||
def _get_domain_settings(domain, subdomains):
|
def _get_domain_settings(domain, subdomains):
|
||||||
"""
|
"""
|
||||||
Get settings of a domain
|
Get settings of a domain
|
||||||
|
@ -826,9 +861,10 @@ def _set_domain_settings(domain, domain_settings):
|
||||||
domains[domain] = domain_settings
|
domains[domain] = domain_settings
|
||||||
|
|
||||||
# Save the settings to the .yaml file
|
# Save the settings to the .yaml file
|
||||||
with open(DOMAIN_SETTINGS_PATH, 'w') as file:
|
with open(DOMAIN_SETTINGS_PATH, "w") as file:
|
||||||
yaml.dump(domains, file, default_flow_style=False)
|
yaml.dump(domains, file, default_flow_style=False)
|
||||||
|
|
||||||
|
|
||||||
# def domain_get_registrar():
|
# def domain_get_registrar():
|
||||||
def domain_registrar_set(domain, registrar, args):
|
def domain_registrar_set(domain, registrar, args):
|
||||||
|
|
||||||
|
@ -844,37 +880,31 @@ def domain_registrar_set(domain, registrar, args):
|
||||||
parameters = registrars[registrar]
|
parameters = registrars[registrar]
|
||||||
ask_args = []
|
ask_args = []
|
||||||
for parameter in parameters:
|
for parameter in parameters:
|
||||||
ask_args.append({
|
ask_args.append(
|
||||||
'name' : parameter,
|
{
|
||||||
'type': 'string',
|
"name": parameter,
|
||||||
'example': '',
|
"type": "string",
|
||||||
'default': '',
|
"example": "",
|
||||||
})
|
"default": "",
|
||||||
|
}
|
||||||
|
)
|
||||||
args_dict = (
|
args_dict = (
|
||||||
{} if not args else dict(urllib.parse.parse_qsl(args, keep_blank_values=True))
|
{} if not args else dict(urllib.parse.parse_qsl(args, keep_blank_values=True))
|
||||||
)
|
)
|
||||||
parsed_answer_dict = _parse_args_in_yunohost_format(args_dict, ask_args)
|
parsed_answer_dict = _parse_args_in_yunohost_format(args_dict, ask_args)
|
||||||
|
|
||||||
domain_provider = {
|
domain_provider = {"name": registrar, "options": {}}
|
||||||
'name': registrar,
|
|
||||||
'options': {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for arg_name, arg_value_and_type in parsed_answer_dict.items():
|
for arg_name, arg_value_and_type in parsed_answer_dict.items():
|
||||||
domain_provider['options'][arg_name] = arg_value_and_type[0]
|
domain_provider["options"][arg_name] = arg_value_and_type[0]
|
||||||
|
|
||||||
domain_settings = domains[domain]
|
domain_settings = domains[domain]
|
||||||
domain_settings["provider"] = domain_provider
|
domain_settings["provider"] = domain_provider
|
||||||
|
|
||||||
# Save the settings to the .yaml file
|
# Save the settings to the .yaml file
|
||||||
with open(DOMAIN_SETTINGS_PATH, 'w') as file:
|
with open(DOMAIN_SETTINGS_PATH, "w") as file:
|
||||||
yaml.dump(domains, file, default_flow_style=False)
|
yaml.dump(domains, file, default_flow_style=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def domain_push_config(domain):
|
def domain_push_config(domain):
|
||||||
"""
|
"""
|
||||||
Send DNS records to the previously-configured registrar of the domain.
|
Send DNS records to the previously-configured registrar of the domain.
|
||||||
|
@ -893,7 +923,6 @@ def domain_push_config(domain):
|
||||||
# FIXME add locales
|
# FIXME add locales
|
||||||
raise YunohostValidationError("registrar_is_not_set", domain=domain)
|
raise YunohostValidationError("registrar_is_not_set", domain=domain)
|
||||||
|
|
||||||
|
|
||||||
# Flatten the DNS conf
|
# Flatten the DNS conf
|
||||||
flatten_dns_conf = []
|
flatten_dns_conf = []
|
||||||
for key in dns_conf:
|
for key in dns_conf:
|
||||||
|
@ -929,16 +958,20 @@ def domain_push_config(domain):
|
||||||
"action": "list",
|
"action": "list",
|
||||||
"type": key,
|
"type": key,
|
||||||
}
|
}
|
||||||
final_lexicon = ConfigResolver().with_dict(dict_object=base_config).with_dict(dict_object=record_config)
|
final_lexicon = (
|
||||||
|
ConfigResolver()
|
||||||
|
.with_dict(dict_object=base_config)
|
||||||
|
.with_dict(dict_object=record_config)
|
||||||
|
)
|
||||||
# print('final_lexicon:', final_lexicon);
|
# print('final_lexicon:', final_lexicon);
|
||||||
client = Client(final_lexicon)
|
client = Client(final_lexicon)
|
||||||
distant_records[key] = client.execute()
|
distant_records[key] = client.execute()
|
||||||
|
|
||||||
for key in types:
|
for key in types:
|
||||||
for distant_record in distant_records[key]:
|
for distant_record in distant_records[key]:
|
||||||
logger.debug(f"distant_record: {distant_record}");
|
logger.debug(f"distant_record: {distant_record}")
|
||||||
for local_record in flatten_dns_conf:
|
for local_record in flatten_dns_conf:
|
||||||
print('local_record:', local_record);
|
print("local_record:", local_record)
|
||||||
|
|
||||||
# Push the records
|
# Push the records
|
||||||
for record in flatten_dns_conf:
|
for record in flatten_dns_conf:
|
||||||
|
@ -948,7 +981,10 @@ def domain_push_config(domain):
|
||||||
# is_the_same_record = False
|
# is_the_same_record = False
|
||||||
|
|
||||||
for distant_record in distant_records[record["type"]]:
|
for distant_record in distant_records[record["type"]]:
|
||||||
if distant_record["type"] == record["type"] and distant_record["name"] == record["name"]:
|
if (
|
||||||
|
distant_record["type"] == record["type"]
|
||||||
|
and distant_record["name"] == record["name"]
|
||||||
|
):
|
||||||
it_exists = True
|
it_exists = True
|
||||||
# see previous TODO
|
# see previous TODO
|
||||||
# if distant_record["ttl"] = ... and distant_record["name"] ...
|
# if distant_record["ttl"] = ... and distant_record["name"] ...
|
||||||
|
@ -956,8 +992,12 @@ def domain_push_config(domain):
|
||||||
|
|
||||||
# Finally, push the new record or update the existing one
|
# Finally, push the new record or update the existing one
|
||||||
record_config = {
|
record_config = {
|
||||||
"action": "update" if it_exists else "create", # create, list, update, delete
|
"action": "update"
|
||||||
"type": record["type"], # specify a type for record filtering, case sensitive in some cases.
|
if it_exists
|
||||||
|
else "create", # create, list, update, delete
|
||||||
|
"type": record[
|
||||||
|
"type"
|
||||||
|
], # specify a type for record filtering, case sensitive in some cases.
|
||||||
"name": record["name"],
|
"name": record["name"],
|
||||||
"content": record["value"],
|
"content": record["value"],
|
||||||
# FIXME Removed TTL, because it doesn't work with Gandi.
|
# FIXME Removed TTL, because it doesn't work with Gandi.
|
||||||
|
@ -965,11 +1005,16 @@ def domain_push_config(domain):
|
||||||
# But I think there is another issue with Gandi. Or I'm misusing the API...
|
# But I think there is another issue with Gandi. Or I'm misusing the API...
|
||||||
# "ttl": record["ttl"],
|
# "ttl": record["ttl"],
|
||||||
}
|
}
|
||||||
final_lexicon = ConfigResolver().with_dict(dict_object=base_config).with_dict(dict_object=record_config)
|
final_lexicon = (
|
||||||
|
ConfigResolver()
|
||||||
|
.with_dict(dict_object=base_config)
|
||||||
|
.with_dict(dict_object=record_config)
|
||||||
|
)
|
||||||
client = Client(final_lexicon)
|
client = Client(final_lexicon)
|
||||||
print('pushed_record:', record_config, "→", end=' ')
|
print("pushed_record:", record_config, "→", end=" ")
|
||||||
results = client.execute()
|
results = client.execute()
|
||||||
print('results:', results);
|
print("results:", results)
|
||||||
# print("Failed" if results == False else "Ok")
|
# print("Failed" if results == False else "Ok")
|
||||||
|
|
||||||
|
|
||||||
# def domain_config_fetch(domain, key, value):
|
# def domain_config_fetch(domain, key, value):
|
||||||
|
|
Loading…
Add table
Reference in a new issue