#!/bin/bash
######系統配合
#下載ISO檔
# https://ftp.ubuntu-tw.org/ubuntu-releases/26.04.1/ 安裝
######鄭亮星 jls@mail.jls.idv.tw , jls550225@gmail.com , jls@acfs.tw
##設定 E-mail webmail 郵件流量
ETH0=$(ls /proc/net/dev_snmp6 |awk '{ print $1 }' |sed -n '1p')
IP=$(ifconfig $ETH0 |grep 'inet ' |awk '{print $2}')
HOSTNAME=$(/bin/hostname)
DOMAINNAME=$(/bin/hostname -d)
DATE=$(date "+%Y%m%d%H")
sync
cp -arf /etc/postfix/main.cf /etc/postfix/main.cf-$DATE
cat > /etc/postfix/main.cf << EOF
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
data_directory = /var/lib/postfix
mail_owner = postfix
myorigin = \$myhostname
inet_interfaces = all
inet_protocols = all
mydestination = \$myhostname, \$mydomain, mail.\$mydomain, localhost.\$mydomain, localhost
# masquerade_domains = $mydomain
unknown_local_recipient_reject_code = 550
relay_domains =
smtpd_banner = 愛你喔!
#relayhost = [ms25.hinet.net]
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
# body_checks = regexp:/etc/postfix/body_checks
# header_checks = regexp:/etc/postfix/header_checks
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
ddd \$daemon_directory/\$process_name \$process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
#sample_directory = /usr/share/doc/postfix/examples
#readme_directory = /usr/share/doc/postfix/README_FILES
mydomain = $DOMAINNAME
myhostname = $HOSTNAME
mailbox_size_limit = 5120000000
message_size_limit = 51200000
smtpd_recipient_limit = 200
#====================SASL========================
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain =
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_unauth_destination, check_policy_service inet:127.0.0.1:10023, permit
smtpd_sasl_security_options = noanonymous
#===================TLS parameters===============
####將 Let's Encrypt 申請到的 SSL 憑證用在 Postfix 上
smtpd_use_tls = yes
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3
#smtpd_tls_cert_file = /etc/letsencrypt/live/$DOMAINNAME/fullchain.pem
#smtpd_tls_key_file = /etc/letsencrypt/live/$DOMAINNAME/privkey.pem
#smtpd_tls_CAfile = /etc/letsencrypt/live/$DOMAINNAME/chain.pem
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_tls_protocols = !SSLv2, !SSLv3
smtpd_tls_security_level = may
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_tls_auth_only = yes
smtpd_sasl_tls_security_options = noanonymous
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtpd_tls_ciphers = high
smtp_use_tls = yes
smtp_tls_note_starttls_offer = yes
tls_random_source = dev:/dev/urandom
#always_bcc = SuperUSER
EOF
cp -arf /etc/dovecot/conf.d/10-auth.conf /etc/dovecot/conf.d/10-auth.conf-$DATE
cp -arf /etc/dovecot/conf.d/10-mail.conf /etc/dovecot/conf.d/10-mail.conf-$DATE
cp -arf /etc/dovecot/conf.d/10-ssl.conf /etc/dovecot/conf.d/10-ssl.conf-$DATE
cp -arf /etc/dovecot/conf.d/10-master.conf /etc/dovecot/conf.d/10-master.conf-$DATE
/usr/bin/sed -i '/^ # Postfix smtp-auth/i unix_listener /var/spool/postfix/private/auth {\n mode = 0666\n user = postfix\n group = postfix\n }' /etc/dovecot/conf.d/10-master.conf
find /etc/dovecot/conf.d/10-auth.conf -type f -exec perl -i -pe s/"#disable_plaintext_auth = yes"/"disable_plaintext_auth = no"/g {} \;
#find /etc/dovecot/conf.d/10-auth.conf -type f -exec perl -i -pe s/"#disable_plaintext_auth = yes"/"disable_plaintext_auth = yes"/g {} \;
find /etc/dovecot/conf.d/10-auth.conf -type f -exec perl -i -pe s/"auth_mechanisms = plain"/"auth_mechanisms = plain login"/g {} \;
#find /etc/dovecot/conf.d/10-mail.conf -type f -exec perl -i -pe s/"# mail_location = mbox:~\/mail:INBOX=\/var\/mail\/%u"/" mail_location = mbox:~\/mail:INBOX=\/var\/mail\/%u"/g {} \;
find /etc/dovecot/conf.d/10-ssl.conf -type f -exec perl -i -pe s/"ssl = required"/"ssl = yes"/g {} \;
/usr/bin/sed -i '/^ssl_cert/i####將 Letˊs Encrypt 申請到的 SSL 憑證用在 Dovecot 上\n#ssl_cert = /var/www/webmail/mail/etc/openwebmail.conf << EOF
domainnames $DOMAINNAME
auth_module auth_unix.pl
quota_module quota_du.pl
ow_cgidir /var/www/webmail/mail
ow_cgiurl /mail
ow_htmldir /var/www/webmail/data/openwebmail
ow_htmlurl /data/openwebmail
logo_link http://www.$DOMAINNAME/
logfile /var/log/openwebmail.log
spellcheck /usr/bin/aspell
quota_limit 100000000
maxbooksize 500000
attlimit 50000000
webdisk_uploadlimit 50000000
enable_viruscheck yes
viruscheck_pipe /usr/bin/clamdscan --disable-summary --stdout -
viruscheck_source_allowed all
default_filter_badaddrformat yes
default_filter_fakedsmtp yes
default_filter_fakedfrom yes
default_filter_fakedexecontenttype yes
default_viruscheck_source all
default_viruscheck_minbodysize 0
Powered By Openwebmail