Browse Source

fix_dkim_dmarc simplified

main
pvincent 2 weeks ago
parent
commit
c266a61a1a
  1. 35
      sympa/miaou/miaou-install-from-import-sympa
  2. 4
      sympa/miaou/miaou-migrate-sympa-from-container
  3. 59
      sympa/recipe/sympa_fix_dkim_dmarc.recipe
  4. 27
      sympa/recipe/sympa_fix_dkim_global_on.recipe
  5. 34
      sympa/recipe/sympa_fix_dmarc_dkim_local_off.recipe

35
sympa/miaou/miaou-install-from-import-sympa

@ -47,31 +47,32 @@ function install_fake_additional {
miaou-recipe "$CONTAINER" "$BASEDIR"/../recipe/sympa_ldap_auth_remote.recipe miaou-recipe "$CONTAINER" "$BASEDIR"/../recipe/sympa_ldap_auth_remote.recipe
} }
function fix_dmarc_dkim_local_off {
echo 'fix dmarc dkim local off...'
miaou-recipe "$CONTAINER" "$BASEDIR"/../recipe/sympa_fix_dmarc_dkim_local_off.recipe
function fix_dkim_dmarc {
echo 'fix dkim global on...'
miaou-recipe "$CONTAINER" "$BASEDIR"/../recipe/sympa_fix_dkim_dmarc.recipe
} }
function fix_dkim_global_on {
echo 'fix dkim global on...'
miaou-recipe "$CONTAINER" "$BASEDIR"/../recipe/sympa_fix_dkim_global_on.recipe
function import {
echo "copy the backup to container..."
import_base=$(basename $IMPORT_FILE)
echo "copy import file: $import_base"
miaou-push $CONTAINER $IMPORT_FILE
echo "launch the import process..."
miaou-exec $CONTAINER -- /opt/miaou-sympa/tools/sympa_import.bash "/root/$import_base"
} }
function install {
"$BASEDIR"/miaou-install-sympa "$CONTAINER"
}
# MAIN # MAIN
set -Eue set -Eue
parse_options $* parse_options $*
"$BASEDIR"/miaou-install-sympa "$CONTAINER"
import_base=$(basename $IMPORT_FILE)
echo "copy import file: $import_base"
miaou-push $CONTAINER $IMPORT_FILE /root/
echo "launch the import process"
miaou-exec $CONTAINER -- /opt/miaou-sympa/tools/sympa_import.bash "/root/$import_base"
fix_dmarc_dkim_local_off
fix_dkim_global_on
install
import
fix_dkim_dmarc
install_fake_additional install_fake_additional

4
sympa/miaou/miaou-migrate-sympa-from-container

@ -67,9 +67,9 @@ function get_container_net0 {
} }
function rename_old_container { function rename_old_container {
pct-rename $CONTAINER $CONTAINER.9
pct set $OLD_VMID --delete net0 pct set $OLD_VMID --delete net0
sleep 3
pct-rename $CONTAINER $CONTAINER.9
pct-reboot $OLD_VMID
} }
function create_new_container { function create_new_container {

59
sympa/recipe/sympa_fix_dkim_dmarc.recipe

@ -0,0 +1,59 @@
#!/usr/bin/env miaou-recipe
# CONSTANTS
GLOBAL_CONF=/etc/sympa/sympa/sympa.conf
FOUND=false
# FUNCTIONS
function fix_dkim_dmarc_global {
if ! grep -q "^dkim_feature[[:space:]]*on" $GLOBAL_CONF; then
local sympa_domain=$(grep '^domain' "$GLOBAL_CONF" | cut -f2)
/opt/miaou-bash/tools/append_or_replace '^dkim_feature.*$' 'dkim_feature on' $GLOBAL_CONF
/opt/miaou-bash/tools/append_or_replace '^dkim_signature_apply_on.*$' 'dkim_signature_apply_on any' $GLOBAL_CONF
/opt/miaou-bash/tools/append_or_replace '^dkim_parameters.private_key_path.*$' 'dkim_parameters.private_key_path /etc/dkimkeys/mail.private' $GLOBAL_CONF
/opt/miaou-bash/tools/append_or_replace '^dkim_parameters.selector.*$' 'dkim_parameters.selector mail' $GLOBAL_CONF
/opt/miaou-bash/tools/append_or_replace '^dkim_parameters.signer_domain.*$' "dkim_parameters.signer_domain $sympa_domain" $GLOBAL_CONF
/opt/miaou-bash/tools/append_or_replace '^arc_feature.*$' 'arc_feature on' $GLOBAL_CONF
/opt/miaou-bash/tools/append_or_replace '^remove_dkim_headers.*$' 'remove_dkim_headers on' $GLOBAL_CONF
/opt/miaou-bash/tools/append_or_replace '^dmarc_protection.mode*$' 'dmarc_protection.mode dmarc_reject' $GLOBAL_CONF
echo 'dkim feature now enabled'
FOUND=true
else
echo 'dkim feature already enabled globally!'
fi
}
function fix_dkim_dmarc_local {
config_files=$(find $LIST_DATA_DIR -name "config" -type f)
for i in $config_files; do
if grep -q -e ^dmarc -e ^dkim $i; then
FOUND=true
echo "found problematic configuration in $i"
remove_section_from_file $i dkim
remove_section_from_file $i dmarc
fi
done
}
function remove_section_from_file {
local file=$1
local section=$2
awk "/^$section/{found=1} !found{print} /^$/{found=0}" $file > $file.new
mv $file.new $file
chown sympa:sympa $file
}
function restart_services {
$FOUND && systemctl restart sympa wwsympa.socket || true
}
# MAIN
set -Eue
fix_dkim_dmarc_global
fix_dkim_dmarc_local
restart_services

27
sympa/recipe/sympa_fix_dkim_global_on.recipe

@ -1,27 +0,0 @@
#!/usr/bin/env miaou-recipe
# CONSTANTS
GLOBAL_CONF=/etc/sympa/sympa/sympa.conf
# FUNCTIONS
function fix_dkim_global_on {
if ! grep -q "^dkim_feature[[:space:]]*on" $GLOBAL_CONF; then
local sympa_domain=$(grep '^domain' "$GLOBAL_CONF" | cut -f2)
/opt/miaou-bash/tools/append_or_replace '^dkim_feature.*$' 'dkim_feature on' $GLOBAL_CONF
/opt/miaou-bash/tools/append_or_replace '^dkim_signature_apply_on.*$' 'dkim_signature_apply_on any' $GLOBAL_CONF
/opt/miaou-bash/tools/append_or_replace '^dkim_parameters.private_key_path.*$' 'dkim_parameters.private_key_path /etc/dkimkeys/mail.private' $GLOBAL_CONF
/opt/miaou-bash/tools/append_or_replace '^dkim_parameters.selector.*$' 'dkim_parameters.selector mail' $GLOBAL_CONF
/opt/miaou-bash/tools/append_or_replace '^dkim_parameters.signer_domain.*$' "dkim_parameters.signer_domain $sympa_domain" $GLOBAL_CONF
echo 'dkim feature now enabled'
else
echo 'dkim feature already enabled globally!'
fi
}
# MAIN
set -Eue
fix_dkim_global_on
systemctl restart sympa wwsympa.socket

34
sympa/recipe/sympa_fix_dmarc_dkim_local_off.recipe

@ -1,34 +0,0 @@
#!/usr/bin/env miaou-recipe
# CONSTANTS
LIST_DATA_DIR=/var/lib/sympa/list_data
FOUND=false
# FUNCTIONS
function fix_for_local_config {
config_files=$(find $LIST_DATA_DIR -name "config" -type f)
for i in $config_files; do
if grep -q -e ^dmarc -e ^dkim $i; then
FOUND=true
echo "found problematic configuration in $i"
remove_section_from_file $i dkim
remove_section_from_file $i dmarc
fi
done
}
function remove_section_from_file {
local file=$1
local section=$2
awk "/^$section/{found=1} !found{print} /^$/{found=0}" $file > $file.new
mv $file.new $file
chown sympa:sympa $file
}
# MAIN
set -Eue
fix_for_local_config
systemctl restart sympa wwsympa.socket
Loading…
Cancel
Save