X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Fprivate%2Fmail%2Fpostfix.nix;h=6623735c2e35c46d13a07a820499fd2256fb6a13;hb=87a8bffd2dd9fc0cab3ede58d39c6fe963969ff0;hp=9fdc7bde8e05f0d3b99aff974cc5a164bac4d43a;hpb=8415083eb6acc343dfa404dbbc12fa0171a48a20;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/private/mail/postfix.nix b/modules/private/mail/postfix.nix index 9fdc7bd..6623735 100644 --- a/modules/private/mail/postfix.nix +++ b/modules/private/mail/postfix.nix @@ -1,7 +1,7 @@ -{ lib, pkgs, config, myconfig, ... }: +{ lib, pkgs, config, nodes, ... }: { config = lib.mkIf config.myServices.mail.enable { - services.backup.profiles.mail.excludeFile = '' + services.duplyBackup.profiles.mail.excludeFile = '' + /var/lib/postfix ''; secrets.keys = [ @@ -13,10 +13,10 @@ text = '' # We need to specify that option to trigger ssl connection tls_ciphers = TLSv1.2 - user = ${myconfig.env.mail.postfix.mysql.user} - password = ${myconfig.env.mail.postfix.mysql.password} - hosts = unix:${myconfig.env.mail.postfix.mysql.socket} - dbname = ${myconfig.env.mail.postfix.mysql.database} + user = ${config.myEnv.mail.postfix.mysql.user} + password = ${config.myEnv.mail.postfix.mysql.password} + hosts = unix:${config.myEnv.mail.postfix.mysql.socket} + dbname = ${config.myEnv.mail.postfix.mysql.database} query = SELECT DISTINCT destination FROM forwardings_merge WHERE @@ -41,10 +41,10 @@ text = '' # We need to specify that option to trigger ssl connection tls_ciphers = TLSv1.2 - user = ${myconfig.env.mail.postfix.mysql.user} - password = ${myconfig.env.mail.postfix.mysql.password} - hosts = unix:${myconfig.env.mail.postfix.mysql.socket} - dbname = ${myconfig.env.mail.postfix.mysql.database} + user = ${config.myEnv.mail.postfix.mysql.user} + password = ${config.myEnv.mail.postfix.mysql.password} + hosts = unix:${config.myEnv.mail.postfix.mysql.socket} + dbname = ${config.myEnv.mail.postfix.mysql.database} result_format = /%d/%u query = SELECT DISTINCT '%s' FROM mailboxes @@ -68,10 +68,10 @@ text = '' # We need to specify that option to trigger ssl connection tls_ciphers = TLSv1.2 - user = ${myconfig.env.mail.postfix.mysql.user} - password = ${myconfig.env.mail.postfix.mysql.password} - hosts = unix:${myconfig.env.mail.postfix.mysql.socket} - dbname = ${myconfig.env.mail.postfix.mysql.database} + user = ${config.myEnv.mail.postfix.mysql.user} + password = ${config.myEnv.mail.postfix.mysql.password} + hosts = unix:${config.myEnv.mail.postfix.mysql.socket} + dbname = ${config.myEnv.mail.postfix.mysql.database} query = SELECT DISTINCT destination FROM forwardings_merge WHERE @@ -80,6 +80,93 @@ UNION SELECT '%s' AS destination ''; } + { + dest = "postfix/mysql_sender_relays_maps"; + user = config.services.postfix.user; + group = config.services.postfix.group; + permissions = "0440"; + text = '' + # We need to specify that option to trigger ssl connection + tls_ciphers = TLSv1.2 + user = ${config.myEnv.mail.postfix.mysql.user} + password = ${config.myEnv.mail.postfix.mysql.password} + hosts = unix:${config.myEnv.mail.postfix.mysql.socket} + dbname = ${config.myEnv.mail.postfix.mysql.database} + # INSERT INTO sender_relays + # (`from`, owner, relay, login, password, regex, active) + # VALUES + # ( 'sender@otherhost.org' + # , 'me@mail.immae.eu' + # , '[otherhost.org]:587' + # , 'otherhostlogin' + # , AES_ENCRYPT('otherhostpassword', '${config.myEnv.mail.postfix.mysql.password_encrypt}') + # , '0' + # , '1'); + + query = SELECT DISTINCT `owner` + FROM sender_relays + WHERE + ((regex = 1 AND '%s' REGEXP CONCAT('^',`from`,'$') ) OR (regex = 0 AND `from` = '%s')) + AND active = 1 + ''; + } + { + dest = "postfix/mysql_sender_relays_hosts"; + user = config.services.postfix.user; + group = config.services.postfix.group; + permissions = "0440"; + text = '' + # We need to specify that option to trigger ssl connection + tls_ciphers = TLSv1.2 + user = ${config.myEnv.mail.postfix.mysql.user} + password = ${config.myEnv.mail.postfix.mysql.password} + hosts = unix:${config.myEnv.mail.postfix.mysql.socket} + dbname = ${config.myEnv.mail.postfix.mysql.database} + + query = SELECT DISTINCT relay + FROM sender_relays + WHERE + ((regex = 1 AND '%s' REGEXP CONCAT('^',`from`,'$') ) OR (regex = 0 AND `from` = '%s')) + AND active = 1 + ''; + } + { + dest = "postfix/mysql_sender_relays_creds"; + user = config.services.postfix.user; + group = config.services.postfix.group; + permissions = "0440"; + text = '' + # We need to specify that option to trigger ssl connection + tls_ciphers = TLSv1.2 + user = ${config.myEnv.mail.postfix.mysql.user} + password = ${config.myEnv.mail.postfix.mysql.password} + hosts = unix:${config.myEnv.mail.postfix.mysql.socket} + dbname = ${config.myEnv.mail.postfix.mysql.database} + + query = SELECT DISTINCT CONCAT(`login`, ':', AES_DECRYPT(`password`, '${config.myEnv.mail.postfix.mysql.password_encrypt}')) + FROM sender_relays + WHERE + ((regex = 1 AND '%s' REGEXP CONCAT('^',`from`,'$') ) OR (regex = 0 AND `from` = '%s')) + AND active = 1 + ''; + } + { + dest = "postfix/ldap_ejabberd_users_immae_fr"; + user = config.services.postfix.user; + group = config.services.postfix.group; + permissions = "0440"; + text = '' + server_host = ldaps://${config.myEnv.jabber.ldap.host}:636 + search_base = ${config.myEnv.jabber.ldap.base} + query_filter = ${config.myEnv.jabber.postfix_user_filter} + domain = immae.fr + bind_dn = ${config.myEnv.jabber.ldap.dn} + bind_pw = ${config.myEnv.jabber.ldap.password} + result_attribute = immaeXmppUid + result_format = ejabberd@localhost + version = 3 + ''; + } ]; networking.firewall.allowedTCPPorts = [ 25 465 587 ]; @@ -94,9 +181,47 @@ config.secrets.fullPaths."postfix/mysql_alias_maps" config.secrets.fullPaths."postfix/mysql_mailbox_maps" config.secrets.fullPaths."postfix/mysql_sender_login_maps" + config.secrets.fullPaths."postfix/ldap_ejabberd_users_immae_fr" ]; }; services.postfix = { + extraAliases = let + toScript = name: script: pkgs.writeScript name '' + #! ${pkgs.stdenv.shell} + mail=$(${pkgs.coreutils}/bin/cat -) + output=$(echo "$mail" | ${script} 2>&1) + ret=$? + + if [ "$ret" != "0" ]; then + echo "$mail" \ + | ${pkgs.procmail}/bin/formail -i "X-Return-Code: $ret" \ + | /run/wrappers/bin/sendmail -i scripts_error+${name}@mail.immae.eu + + messageId=$(echo "$mail" | ${pkgs.procmail}/bin/formail -x "Message-Id:") + repeat=$(echo "$mail" | ${pkgs.procmail}/bin/formail -X "From:" -X "Received:") + + ${pkgs.coreutils}/bin/cat <