diff --git a/SubModules/postfix/CMSHook-conf.sh b/SubModules/postfix/CMSHook-conf.sh new file mode 100644 index 0000000..5164b4a --- /dev/null +++ b/SubModules/postfix/CMSHook-conf.sh @@ -0,0 +1,23 @@ +#ADD DOMAIN +sudo --user opendkim mkdir /etc/opendkim/keys/"$maildomain" +sudo --user opendkim opendkim-genkey -r -D /etc/opendkim/keys/"$maildomain" -d "$maildomain" -s vps +echo "$maildomain" >> /etc/opendkim/TrustedHosts +echo "vps._domainkey."$maildomain" "$maildomain":vps:/etc/opendkim/keys/"$maildomain"/vps.private" >> /etc/opendkim/KeyTable + +if [ $webserv != nginx_nonphp ]; then + echo "php_admin_value[mail.force_extra_parameters] = \"-f$mailas -F'$maildomain'\"" >> "$phpPoolDir"/"$sitename".conf +fi + + +curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/postfix/config/opendkim-init.sh -o ~/OpenDKIMInit-$sitename.sh +sed -i -e 's/DOMAINname/'$domain'/' 's/SITEName/'$sitename'/' ~/OpenDKIMInit-$sitename.sh + +cat << EOF > /etc/update-motd.d/51-opendkim-"$sitename" +#!/bin/sh +red='\e[1;31m%s\e[0m\n' +printf "\n" +printf \$red "To enable mail for $domain please run please run bash ~/OpenDKIMInit-$sitename.sh" +printf "\n" +EOF +chmod +x /etc/update-motd.d/51-opendkim-"$sitename" +systemctl reload opendkim $phpFPMService \ No newline at end of file diff --git a/SubModules/postfix/CMSHook-preconf.sh b/SubModules/postfix/CMSHook-preconf.sh new file mode 100644 index 0000000..a95924d --- /dev/null +++ b/SubModules/postfix/CMSHook-preconf.sh @@ -0,0 +1,27 @@ +if [ -z "${sitename}" ]; then sitename=${domain//./_};fi +if [ $IMODE = n ]; then + if (whiptail --title "Config" --yesno " Send mail as info@$domain of $domain" 11 78); then + mailas=info@$domain + maildomain=$domain +else + mailas=$(whiptail --nocancel --inputbox " Enter mail addres for sending mail" 11 78 --title "Config" 3>&1 1>&2 2>&3) + sed -e 's/[^@]*@//' <<< "$mail" +fi + +fi +if [ $IMODE = l ]; then + while true; do + read -p "Hostname with nxdi.nl -> yes/no?" yn + case $yn in + [Yy]* ) + mailas=info@$domain + maildomain=$domain + break;; + [Nn]* ) + echo 'Enter full hostname:' + read hostname + break;; + * )echo "Choose yes or no.";; + esac + done +fi diff --git a/SubModules/postfix/appendCMS-Pre_conf.sh b/SubModules/postfix/appendCMS-Pre_conf.sh deleted file mode 100644 index 7657c89..0000000 --- a/SubModules/postfix/appendCMS-Pre_conf.sh +++ /dev/null @@ -1,18 +0,0 @@ -if [ -z "${sitename}" ]; then sitename=${domain//./_};fi -#ADD DOMAIN -sudo --user opendkim mkdir /etc/opendkim/keys/"$domain" -sudo --user opendkim opendkim-genkey -r -D /etc/opendkim/keys/"$domain" -d "$domain" -s vps -echo "$domain" >> /etc/opendkim/TrustedHosts -echo "vps._domainkey."$domain" "$domain":vps:/etc/opendkim/keys/"$domain"/vps.private" >> /etc/opendkim/KeyTable - -curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/postfix/config/opendkim-init.sh -o ~/OpenDKIMInit-$sitename.sh -sed -i -e 's/DOMAINname/'$domain'/' 's/SITEName/'$sitename'/' ~/OpenDKIMInit-$sitename.sh - -cat << EOF > /etc/update-motd.d/51-opendkim-"$sitename" -#!/bin/sh -red='\e[1;31m%s\e[0m\n' -printf "\n" -printf \$red "To enable mail for $domain please run Please run bash ~/OpenDKIMInit-$sitename.sh after the first wordpress login" -printf "\n" -EOF -chmod +x /etc/update-motd.d/51-opendkim-"$sitename" \ No newline at end of file diff --git a/SubModules/postfix/conf.sh b/SubModules/postfix/conf.sh index 4a041d5..e6cabcc 100644 --- a/SubModules/postfix/conf.sh +++ b/SubModules/postfix/conf.sh @@ -10,7 +10,11 @@ sed -i "/^inet_interfaces =/c\inet_interfaces = loopback-only" /etc/postfix/main sed -i "/recipient_delimiter =/c\recipient_delimiter = +" /etc/postfix/main.cf sed -i "/^mydestination =/c\mydestination = \"$hostname\", localhost.\"$hostname\", \"$hostname\"" /etc/postfix/main.cf echo "$hostname" > /etc/mailname -echo "bounce_notice_recipient = info@$domain" >> /etc/postfix/main.cf +if [ "$(echo "$hostname" | grep -o "\." | wc -l)" -eq 1 ]; then + echo "bounce_notice_recipient = admin@$hostname" >> /etc/postfix/main.cf +else + echo "bounce_notice_recipient = admin@$(sed 's/.*\.\(.*\..*\)/\1/' <<< $hostname)" >> /etc/postfix/main.cf +fi cat < /etc/aliases # See man 5 aliases for format postmaster: root @@ -34,6 +38,7 @@ adduser postfix opendkim mkdir /etc/opendkim/keys chown opendkim:opendkim /etc/opendkim/keys -R curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/postfix/config/opendkim.conf -o /etc/opendkim.conf +dkimname sed 's/\..*$//' <<< "$url" cat < /etc/opendkim/TrustedHosts 127.0.0.1 ::1 @@ -53,11 +58,21 @@ if [ "$shortdist" = "ubu1804" ] || [ "$shortdist" = "ubu2004" ] || [ "$shortdist systemctl daemon-reload fi +$odksec=$(sed 's/\..*$//' <<< $hostname) +sudo --user opendkim mkdir /etc/opendkim/keys/"$hostname" +sudo --user opendkim opendkim-genkey -r -D /etc/opendkim/keys/"$hostname" -d "$hostname" -s $odksec +echo ""$odksec"._domainkey."$hostname" "$hostname":"$odksec":/etc/opendkim/keys/"$hostname"/"$odksec".private" >> /etc/opendkim/KeyTable +curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/postfix/config/opendkim-init.sh -o ~/OpenDKIMInit-host.sh +sed -i -e 's/DOMAINname/'$hostname'/' 's/SITEName/'host'/' 's/vps/'$odksec'/' ~/OpenDKIMInit-host.sh +unset odksec + + cat << EOF > /etc/update-motd.d/51-generalSPF #!/bin/sh red='\e[1;31m%s\e[0m\n' printf "\n" printf \$red "To enable mail for this server add \"ip4:\$(curl -s -4 icanhazip.com) ip6:\$(curl -s -6 icanhazip.com)\" to $hostname SPF" +printf \$red "to enable DKKIM for the hostname run bash ~/OpenDKIMInit-host.sh" printf \$red "remove notice this by running \"rm /etc/update-motd.d/51-generalSPF\"" printf "\n" EOF @@ -65,3 +80,12 @@ chmod +x /etc/update-motd.d/51-generalSPF systemctl start postfix opendkim systemctl enable postfix opendkim + +#if using Append module run for existing cms/sites +if [ -z "${postfixappended}" ]; then + for sitename in /etc/ICTM/sites/*; do + domain=${sitename//_/.} + source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/postfix/appendCMS-preconf.sh) + source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/postfix/appendCMS-conf.sh) + done +fi \ No newline at end of file diff --git a/SubModules/postfix/opendkim-init.sh b/SubModules/postfix/opendkim-init.sh index 34b4c48..ba52059 100644 --- a/SubModules/postfix/opendkim-init.sh +++ b/SubModules/postfix/opendkim-init.sh @@ -2,7 +2,7 @@ if [ -n "$1" ]; then if [[ "$1" = "--enable" ]]; then echo "Enableing DKIM" - echo "*@DOMAINname vps._domainkey.DOMAINname >>/etc/opendkim/SigningTable\ + echo "*@DOMAINname vps._domainkey.DOMAINname" >>/etc/opendkim/SigningTable systemctl reload opendkim #Remove script while true; do diff --git a/SubModules/postfix/preconf.sh b/SubModules/postfix/preconf.sh index 1d01d0c..0276a07 100644 --- a/SubModules/postfix/preconf.sh +++ b/SubModules/postfix/preconf.sh @@ -1,13 +1,8 @@ if [ -z "${domain}" ]; then - if [ $IMODE = n ]; then - domain=$(whiptail --nocancel --inputbox " Enter the domain without WWW " 11 82 --title "Config" 3>&1 1>&2 2>&3) - elif [ $IMODE = l ]; then - echo "Enter the domain without WWW:" - read domain - fi + postfixappended=1 fi if [ "$shortdist" = "ubu1804" ] || [ "$shortdist" = "ubu2004" ] || [ "$shortdist" = "deb10" ] ; then - debconf-set-selections <<< "postfix postfix/mailname string $domain" + debconf-set-selections <<< "postfix postfix/mailname string $hostname" debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'" fi \ No newline at end of file