diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index 21b7dcf4..eb4f3589 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -269,7 +269,7 @@ def _configure_postfix(config: Config, debug: bool = False) -> bool: group="root", mode="644", config=config, - inet_protocols=inet_protocols, + disable_ipv6=config.disable_ipv6, ) need_restart |= main_config.changed @@ -312,8 +312,6 @@ def _configure_dovecot(config: Config, debug: bool = False) -> bool: """Configures Dovecot IMAP server.""" need_restart = False - listen_ipv4_only = "listen = *" if config.disable_ipv6 else "" - main_config = files.template( src=importlib.resources.files(__package__).joinpath("dovecot/dovecot.conf.j2"), dest="/etc/dovecot/dovecot.conf", @@ -322,7 +320,7 @@ def _configure_dovecot(config: Config, debug: bool = False) -> bool: mode="644", config=config, debug=debug, - listen_ipv4_only=listen_ipv4_only, + disable_ipv6=config.disable_ipv6, ) need_restart |= main_config.changed auth_config = files.put( @@ -371,11 +369,6 @@ def _configure_nginx(config: Config, debug: bool = False) -> bool: """Configures nginx HTTP server.""" need_restart = False - listen_default_server = ( - "" if config.disable_ipv6 else "listen [::]:8443 ssl default_server;" - ) - listen_redirect = "" if config.disable_ipv6 else "listen [::]:8443 ssl;" - main_config = files.template( src=importlib.resources.files(__package__).joinpath("nginx/nginx.conf.j2"), dest="/etc/nginx/nginx.conf", @@ -383,8 +376,7 @@ def _configure_nginx(config: Config, debug: bool = False) -> bool: group="root", mode="644", config={"domain_name": config.mail_domain}, - listen_default_server=listen_default_server, - listen_redirect=listen_redirect, + disable_ipv6=config.disable_ipv6, ) need_restart |= main_config.changed diff --git a/cmdeploy/src/cmdeploy/dovecot/dovecot.conf.j2 b/cmdeploy/src/cmdeploy/dovecot/dovecot.conf.j2 index 78c53033..e8301a6e 100644 --- a/cmdeploy/src/cmdeploy/dovecot/dovecot.conf.j2 +++ b/cmdeploy/src/cmdeploy/dovecot/dovecot.conf.j2 @@ -1,6 +1,8 @@ ## Dovecot configuration file -{{ listen_ipv4_only }} +{% if disable_ipv6 %} +listen = * +{% endif %} protocols = imap lmtp diff --git a/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 b/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 index ac69c326..d331c42e 100644 --- a/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 +++ b/cmdeploy/src/cmdeploy/nginx/nginx.conf.j2 @@ -45,7 +45,8 @@ http { server { listen 8443 ssl default_server; - {{ listen_default_server }} + {% if not disable_ipv6 %} + listen [::]:8443 ssl default_server root /var/www/html; @@ -97,7 +98,9 @@ http { # Redirect www. to non-www server { listen 8443 ssl; - {{ listen_redirect }} + {% if not disable_ipv6 %} + listen [::]:8443 ssl; + {% endif %} server_name www.{{ config.domain_name }}; return 301 $scheme://{{ config.domain_name }}$request_uri; access_log syslog:server=unix:/dev/log,facility=local7; diff --git a/cmdeploy/src/cmdeploy/postfix/main.cf.j2 b/cmdeploy/src/cmdeploy/postfix/main.cf.j2 index 93ac1f70..dee4566f 100644 --- a/cmdeploy/src/cmdeploy/postfix/main.cf.j2 +++ b/cmdeploy/src/cmdeploy/postfix/main.cf.j2 @@ -66,7 +66,11 @@ mailbox_size_limit = 0 message_size_limit = 31457280 recipient_delimiter = + inet_interfaces = all -inet_protocols = {{ inet_protocols }} +{% if disable_ipv6 %} +inet_protocols = ipv4 +{% else} +inet_protocols = all +{% endif} virtual_transport = lmtp:unix:private/dovecot-lmtp virtual_mailbox_domains = {{ config.mail_domain }}