From 543ba30f8c916812ea0a74e4d6f929810e11090c Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 18 Aug 2022 10:19:43 +0200 Subject: [PATCH] reorganize --- seed/base-machine/dictionaries/12-base.xml | 30 ++----- seed/base-machine/funcs/funcs.py | 24 +---- seed/base/funcs/base.py | 25 +++++- .../dictionaries/14-dns-external.xml | 9 +- seed/dns-local/dictionaries/13-dns-local.xml | 14 +-- seed/dns-local/templates/dns-local.yml | 4 +- seed/dovecot/applicationservice.yml | 3 +- seed/dovecot/dictionaries/26_dovecot.xml | 88 +++++-------------- seed/dovecot/funcs/dovecot.py | 29 ++++-- seed/dovecot/templates/dovecot-ldap.conf.ext | 2 +- seed/dovecot/templates/ldapsource.cf | 2 +- seed/gitea/dictionaries/31_gitea.xml | 8 +- seed/gitea/templates/app.ini | 6 +- seed/gitea/templates/gitea.yml | 3 +- .../dictionaries/21-machined.xml | 6 +- .../extras/machined/00-machined.xml | 14 +-- .../dictionaries/21_imap_client.xml | 9 +- .../dictionaries/21_ldap-client.xml | 59 +++++++------ seed/ldap-client/funcs/openldap_client.py | 22 +++++ seed/ldap-client/templates/ldap.conf | 2 +- seed/lemonldap/applicationservice.yml | 1 - .../dictionaries/70_lemonldap_ng.xml | 9 +- seed/lemonldap/extras/oauth2/00_oauth2.xml | 27 +++--- .../lemonldap-ng-fastcgi-server.service | 2 +- seed/lemonldap/templates/lemonldap.yml | 2 +- seed/lemonldap/templates/lmConf-1.json | 16 ++-- seed/lemonldap/templates/portal-nginx.conf | 2 +- seed/letsencrypt/funcs/letsencrypt.py | 3 +- seed/mailman/applicationservice.yml | 2 +- seed/mailman/extras/mailman/20_mailman.xml | 14 +-- seed/mailman/templates/postorius-settings.py | 6 +- seed/mailman/templates/postorius.service | 2 +- .../dictionaries/20_mariadb.xml | 29 +++--- seed/mariadb/applicationservice.yml | 2 - seed/mariadb/extras/accounts/00_accounts.xml | 10 +++ seed/nextcloud/dictionaries/31_nextcloud.xml | 28 +----- seed/nextcloud/templates/nextcloud-config.php | 4 +- seed/nextcloud/templates/nextcloud.init | 6 +- seed/nextcloud/templates/nextcloud.service | 2 +- .../applicationservice.yml | 1 - .../dictionaries/25_nginx.xml | 32 +------ .../extras/nginx/00-nginx.xml | 40 +++++++-- seed/nginx-reverse-proxy/funcs/nginx.py | 16 ++-- .../templates/nginx.service | 6 +- .../templates/reverse-proxy.yml | 12 +-- .../templates/revprox-nginx.conf | 44 ++++++---- seed/nsd/applicationservice.yml | 1 - seed/nsd/dictionaries/20_nsd.xml | 71 ++++++--------- seed/nsd/extras/nsd/00_nsd.xml | 14 +-- seed/nsd/funcs/funcs.py | 19 +++- seed/nsd/templates/nsd.reverse | 2 +- seed/nsd/templates/nsd.yml | 2 +- seed/nsd/templates/risotto.conf | 6 +- .../dictionaries/30_oauth2_client.xml | 54 +++--------- seed/oauth2-client/funcs/oauth2_client.py | 2 + seed/openldap/applicationservice.yml | 1 - .../dictionaries/21_openldap-server.xml | 24 ++--- seed/openldap/extras/accounts/00_account.xml | 24 ++--- seed/openldap/funcs/ldap.py | 13 --- seed/openldap/templates/config_acl.ldif | 13 +-- seed/openldap/templates/openldap.yml | 8 +- seed/openldap/templates/users.ldif | 4 +- seed/openldap/templates/users_mod.ldif | 4 +- seed/peertube/templates/nginx.peertube.conf | 4 +- seed/peertube/templates/production.yaml | 2 +- seed/piwigo/dictionaries/31_piwigo.xml | 2 +- seed/piwigo/funcs/{piwigo.sh => piwigo.py} | 0 seed/piwigo/templates/piwigo.service | 2 +- .../postfix-lmtp-relay/applicationservice.yml | 2 + .../extras/lmtp/00-lmtp.xml | 4 +- seed/postfix-relay/DEBUG.md | 6 ++ seed/postfix-relay/applicationservice.yml | 4 +- .../postfix-relay/dictionaries/30_postfix.xml | 13 +-- seed/postfix-relay/templates/main.cf | 2 +- seed/postfix-relay/templates/postfix.service | 2 +- .../dictionaries/23_postgresql.xml | 21 +++-- seed/postgresql/applicationservice.yml | 2 - .../postgresql/dictionaries/22_postgresql.xml | 2 +- .../extras/accounts/00_accounts.xml | 16 ++-- seed/postgresql/templates/postgresql.service | 2 +- .../dictionaries/10-machined.xml | 2 +- .../dictionaries/16-machined.xml | 58 ++---------- seed/redis-client/dictionaries/23_redis.xml | 34 +++---- seed/redis/applicationservice.yml | 1 - seed/redis/extras/account/00_account.xml | 16 ++-- seed/relay-lmtp-client/applicationservice.yml | 4 + .../dictionaries/30_lmtp.xml | 12 +++ .../dictionaries/20_smtp_client.xml | 32 +++---- .../dictionaries/21_nginx_client.xml | 44 +++------- seed/roundcube/dictionaries/31_roundcube.xml | 10 ++- seed/server/applicationservice.yml | 2 - seed/server/doc.md | 6 -- seed/unbound/applicationservice.yml | 1 - seed/unbound/dictionaries/20_unbound.xml | 14 +-- .../dictionaries/40_vaultwarden.xml | 17 ++-- seed/vaultwarden/funcs/vaultwarden.py | 8 ++ seed/vaultwarden/templates/vaultwarden.yml | 3 +- .../templates/vaultwarden_config.env | 4 +- 98 files changed, 537 insertions(+), 756 deletions(-) create mode 100644 seed/mariadb/extras/accounts/00_accounts.xml rename seed/piwigo/funcs/{piwigo.sh => piwigo.py} (100%) create mode 100644 seed/postfix-lmtp-relay/applicationservice.yml rename seed/{postfix-relay => postfix-lmtp-relay}/extras/lmtp/00-lmtp.xml (87%) rename seed/{server => postgresql}/extras/accounts/00_accounts.xml (50%) create mode 100644 seed/relay-lmtp-client/applicationservice.yml create mode 100644 seed/relay-lmtp-client/dictionaries/30_lmtp.xml delete mode 100644 seed/server/applicationservice.yml delete mode 100644 seed/server/doc.md diff --git a/seed/base-machine/dictionaries/12-base.xml b/seed/base-machine/dictionaries/12-base.xml index 168801c2..f2dbdf3e 100644 --- a/seed/base-machine/dictionaries/12-base.xml +++ b/seed/base-machine/dictionaries/12-base.xml @@ -10,39 +10,25 @@ False - - - zones_name - zones_list - - - zones_name - interfaces_list - - server_name + domain_name_eth ip_eth - - - server_name - extra_domainnames - - domain_name_eth - - zones_name + zones_list zone_name_eth diff --git a/seed/base-machine/funcs/funcs.py b/seed/base-machine/funcs/funcs.py index 848abfaf..8e67ffdc 100644 --- a/seed/base-machine/funcs/funcs.py +++ b/seed/base-machine/funcs/funcs.py @@ -6,7 +6,7 @@ from os.path import dirname as _dirname, abspath as _abspath, join as _join, isf from os import makedirs as _makedirs -from risotto.utils import ZONES_SERVER +#from risotto.utils import ZONES_SERVER _HERE = _dirname(_abspath(__main__.__file__)) @@ -81,30 +81,8 @@ def _set_password(server_name: str, return file_content -def get_range(lst): - return list(range(max(1, len(lst)))) - - def get_zone_name(zones: list, index: str, ): if zones is not None: return zones[int(index)] - - -def get_domain_name(server_name: str, - extra_domainnames: list, - suffix: str, - ) -> str: - index = int(suffix) - if index == 0: - return server_name - return extra_domainnames[index - 1] - - -def get_provider_name(network_name: str, - provider: str, - ) -> str: - if network_name not in ZONES_SERVER['providers'] or provider not in ZONES_SERVER['providers'][network_name]: - return - return ZONES_SERVER['providers'][network_name][provider][0] diff --git a/seed/base/funcs/base.py b/seed/base/funcs/base.py index 10a4031f..6e3dde36 100644 --- a/seed/base/funcs/base.py +++ b/seed/base/funcs/base.py @@ -1,9 +1,26 @@ from typing import List from risotto.utils import load_domains, DOMAINS +from risotto.utils import multi_function as _multi_function +@_multi_function def get_ip(server_name: str) -> str: - load_domains() - host_name, domain_name = server_name.split('.', 1) - domain = DOMAINS[domain_name] - return domain[1][domain[0].index(host_name)] + if server_name is None: + return + if isinstance(server_name, list): + return_list = True + else: + return_list = False + server_name = [server_name] + lst = [] + for s_name in server_name: + host_name, domain_name = s_name.split('.', 1) + if not domain_name in DOMAINS: + raise ValueError(f'cannot find IP in domain name "{domain_name}" (for "{s_name}")') + domain = DOMAINS[domain_name] + ret = domain[1][domain[0].index(host_name)] + if not return_list: + return ret + if ret not in lst: + lst.append(ret) + return lst diff --git a/seed/dns-external/dictionaries/14-dns-external.xml b/seed/dns-external/dictionaries/14-dns-external.xml index 9cdb18b2..06f3b086 100644 --- a/seed/dns-external/dictionaries/14-dns-external.xml +++ b/seed/dns-external/dictionaries/14-dns-external.xml @@ -5,14 +5,7 @@ False - + - - - zone_name_eth0 - ExternalDNS - dns_client_address - - diff --git a/seed/dns-local/dictionaries/13-dns-local.xml b/seed/dns-local/dictionaries/13-dns-local.xml index 129bfc85..fb58cb48 100644 --- a/seed/dns-local/dictionaries/13-dns-local.xml +++ b/seed/dns-local/dictionaries/13-dns-local.xml @@ -10,21 +10,13 @@ - + diff --git a/seed/ldap-client/funcs/openldap_client.py b/seed/ldap-client/funcs/openldap_client.py index 59789164..e67591b7 100644 --- a/seed/ldap-client/funcs/openldap_client.py +++ b/seed/ldap-client/funcs/openldap_client.py @@ -11,6 +11,8 @@ def calc_ldapclient_base_dn(ldap_base_dn: str, base: bool=False, group: bool=False, ) -> str: + if ldap_base_dn is None: + return if family_name == 'all': family_name = None base = True @@ -28,3 +30,23 @@ def calc_ldapclient_base_dn(ldap_base_dn: str, if family_name != '-': base_name = f'ou={family_name},{base_name}' return base_name + + +class _Undefined: + pass + + +_undefined = _Undefined() + + +def get_default_base_dn(server_name: str) -> str: + if not server_name or '.' not in server_name: + return None + values = server_name.split('.') + # cannot calculated base dn should be server.domain.tld + # remove 'server' in dn + if len(values) < 3: + return None + domain = ['ou=' + domain for domain in values[1:-2]] + domain.append(f'o={values[-2]},o={values[-1]}') + return ','.join(domain) diff --git a/seed/ldap-client/templates/ldap.conf b/seed/ldap-client/templates/ldap.conf index 7c40a7f5..3a65745d 100644 --- a/seed/ldap-client/templates/ldap.conf +++ b/seed/ldap-client/templates/ldap.conf @@ -6,7 +6,7 @@ # This file should be world readable but not world writable. #BASE dc=example,dc=com -BASE %%ldapclient_base_dn +BASE %%ldapclient_search_dn #URI ldap://ldap.example.com ldap://ldap-master.example.com:666 URI ldaps://%%ldap_server_address:%%ldap_port diff --git a/seed/lemonldap/applicationservice.yml b/seed/lemonldap/applicationservice.yml index f715b6a0..723261ea 100644 --- a/seed/lemonldap/applicationservice.yml +++ b/seed/lemonldap/applicationservice.yml @@ -6,4 +6,3 @@ depends: - reverse-proxy-client - relay-mail-client - nginx-common -provider: OAuth2 diff --git a/seed/lemonldap/dictionaries/70_lemonldap_ng.xml b/seed/lemonldap/dictionaries/70_lemonldap_ng.xml index bf229ac1..37b7de86 100644 --- a/seed/lemonldap/dictionaries/70_lemonldap_ng.xml +++ b/seed/lemonldap/dictionaries/70_lemonldap_ng.xml @@ -28,6 +28,7 @@ False +