Skip to content

Commit

Permalink
use jinja templates for disable_ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenest committed Jul 23, 2024
1 parent 4b19465 commit d412c50
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
14 changes: 3 additions & 11 deletions cmdeploy/src/cmdeploy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand All @@ -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(
Expand Down Expand Up @@ -371,20 +369,14 @@ 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",
user="root",
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

Expand Down
4 changes: 3 additions & 1 deletion cmdeploy/src/cmdeploy/dovecot/dovecot.conf.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Dovecot configuration file

{{ listen_ipv4_only }}
{% if disable_ipv6 %}
listen = *
{% endif %}

protocols = imap lmtp

Expand Down
7 changes: 5 additions & 2 deletions cmdeploy/src/cmdeploy/nginx/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion cmdeploy/src/cmdeploy/postfix/main.cf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit d412c50

Please sign in to comment.