diff options
author | root <root@jones.dk> | 2016-10-25 17:31:41 +0200 |
---|---|---|
committer | root <root@jones.dk> | 2016-10-25 17:31:41 +0200 |
commit | 83813564669cdc6e162615f045615e41aec73553 (patch) | |
tree | 07e60f378005e29d83f05f702f9fe0b4f08a6cf4 /spamassassin | |
parent | b9b13958bd509ef159c799b9f869141ba53a302d (diff) |
Add draft tweak for networks.
Diffstat (limited to 'spamassassin')
-rwxr-xr-x | spamassassin/tweak.d/networks.sh | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spamassassin/tweak.d/networks.sh b/spamassassin/tweak.d/networks.sh new file mode 100755 index 0000000..25ac109 --- /dev/null +++ b/spamassassin/tweak.d/networks.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# +# Tweak SpamAssassin settings internal_networks trusted_networks + +set -e + +exit1() { + response="${1:+Error: }${1:-Internal error!}" + echo "$response" >&2 + exit 1 +} + +firstitem() { + file="$1" + + cat "$file" | grep -v '^#' | sed 's/#.*//' | head -n 1 +} + +items() { + file="$1" + + cat "$file" | grep -v '^#' | sed 's/#.*//' +} + +items_singleline() { + perl -0777 -ne 'print join " ",m/^\s*([^#\s]+)/gm' "$1" +} + +addoroverwritewithindents() { + set -e + file="$1" + export token="$2" + # provide replacement as STDIN + perl -0777 -pi \ + -E 'BEGIN{ $s=<STDIN>; chomp $s }'\ + -E 's/$ENV{"token"}.*(?:\n\h.*)+\n/$s/m and $seen=1;'\ + -E 'END{ unless ($seen) { print $s } }'\ + "$file" +} + +REDPILL=$(firstitem "/etc/local-ORG/redpill") +redpilldir="/etc/local-$REDPILL/" +REALMS="$(items "$redpilldir/realms")" +REALM="$(cat /etc/local-ORG/realm || dnsdomainname | tr '[a-z]' '[A-Z]')" +for realm in $REALMS; do + realmdir="$redpilldir/$realm" + [ -d "$realmdir" ] || continue + mailnets=$(items_singleline "$realmdir/mailnetworks") #' + if [ "$REALM" = "$realm" ]; then + ournets="${ournets:+$ournets }$mailnets" + [ ! -f "$realmdir/localnetworks" ] || ournets="${ournets:+$ournets }$(items "$realmdir/localnetworks")" + ournets="${ournets:+$ournets }127.0.0.1" + else + redpillnets="${redpillnets:+$redpillnets }$mailnets" + fi +done + +echo "FIXME: Add these to /etc/spamassassin/local.cf:" +echo "internal_networks $ournets" +echo "trusted_networks $redpillnets" |