diff --git a/include/mua.sh b/include/mua.sh index a42c0710..65323de5 100755 --- a/include/mua.sh +++ b/include/mua.sh @@ -40,22 +40,26 @@ test_imap_openssl() EOF } -test_imap_curl() +get_curl_cmd() { - local _test_uri - _test_uri="imaps://$(uriencode $MUA_TEST_USER):$(uriencode $MUA_TEST_PASS)@${MUA_TEST_HOST}/" - if [ -x /usr/local/bin/curl ]; then - curl -k -v --login-options 'AUTH=PLAIN' "$_test_uri" + echo "curl" elif [ -x "$STAGE_MNT/usr/local/bin/curl" ]; then - _test_uri="imaps://$(uriencode $MUA_TEST_USER):$(uriencode $MUA_TEST_PASS)@localhost/" - stage_exec curl -k -v --login-options 'AUTH=PLAIN' "$_test_uri" + echo "stage_exec curl" else - pkg install -y curl - curl -k -v --login-options 'AUTH=PLAIN' "$_test_uri" + pkg install -qy curl + echo "curl" fi } +test_imap_curl() +{ + local _test_uri + _test_uri="imaps://$(uriencode $MUA_TEST_USER):$(uriencode $MUA_TEST_PASS)@${MUA_TEST_HOST}/" + _curl_cmd="$(get_curl_cmd)" + $_curl_cmd -k -v --login-options 'AUTH=PLAIN' "$_test_uri" +} + test_imap() { echo "testing IMAP AUTH as $MUA_TEST_USER" @@ -90,9 +94,11 @@ test_pop3_empty() test_pop3() { + local _test_uri + _test_uri="pop3s://$(uriencode $MUA_TEST_USER):$(uriencode $MUA_TEST_PASS)@${MUA_TEST_HOST}/" + _curl_cmd="$(get_curl_cmd)" # shellcheck disable=2001 - curl -k -v --login-options 'AUTH=PLAIN' \ - "pop3s://$(uriencode $MUA_TEST_USER):$(uriencode $MUA_TEST_PASS)@${MUA_TEST_HOST}/" + $_curl_cmd -k -v --login-options 'AUTH=PLAIN' "$_test_uri" } uriencode() { diff --git a/include/nginx.sh b/include/nginx.sh index f30bb879..c94c088c 100755 --- a/include/nginx.sh +++ b/include/nginx.sh @@ -37,8 +37,10 @@ install_nginx() install_nginx_newsyslog() { + stage_enable_newsyslog + tell_status "enabling nginx log file rotation" - tee "$STAGE_MNT/etc/newsyslog.conf.d/nginx" <> ${LOGDIR}/${pem}.log + echo "= $(date)" >> "$LOGDIR/${pem}.log" # Get the OCSP URL from the certificate ocsp_url=$($OPENSSL x509 -noout -ocsp_uri -in $pem) @@ -318,10 +322,10 @@ for pem in *.pem; do done if [ $UPDATED -gt 0 ]; then - echo "= $(date) - Updated $UPDATED OCSP responses" >> ${LOGDIR}/${pem}.log - service haproxy reload > ${LOGDIR}/service-reload.log 2>&1 + echo "= $(date) - Updated $UPDATED OCSP responses" >> "$LOGDIR/${pem}.log" + service haproxy reload > $LOGDIR/service-reload.log 2>&1 else - echo "= $(date) - No updates" >> ${LOGDIR}/${pem}.log + echo "= $(date) - No updates" >> $LOGDIR/${pem}.log fi EO_OCSP @@ -329,20 +333,16 @@ EO_OCSP configure_haproxy_tls() { - if [ ! -f "$STAGE_MNT/etc/ssl/private/server.pem" ]; then - tell_status "concatenating TLS key and crt to PEM" - cat /etc/ssl/private/server.key /etc/ssl/certs/server.crt \ - > "$STAGE_MNT/etc/ssl/private/server.pem" - fi - - if [ ! -d "$ZFS_DATA_MNT/haproxy/ssl" ]; then - tell_status "creating /data/ssl" - mkdir -p "$ZFS_DATA_MNT/haproxy/ssl" + local _tls_dir="$ZFS_DATA_MNT/haproxy/etc/tls.d" + if [ ! -d "$_tls_dir" ]; then + tell_status "creating $_tls_dir" + mkdir -p "$_tls_dir" fi - if [ ! -d "$ZFS_DATA_MNT/haproxy/ssl.d" ]; then - tell_status "creating /data/ssl.d" - mkdir -p "$ZFS_DATA_MNT/haproxy/ssl.d" + if [ ! -f "$_tls_dir/$TOASTER_HOSTNAME.pem" ]; then + tell_status "concatenating TLS key and crt to PEM" + cat /etc/ssl/private/server.key /etc/ssl/certs/server.crt \ + > "$_tls_dir/$TOASTER_HOSTNAME.pem" fi install_ocsp_stapler "$STAGE_MNT/usr/local/etc/periodic/daily/501.ocsp-staple.sh" diff --git a/provision/haraka.sh b/provision/haraka.sh index 2b403c3d..3b3b7abd 100755 --- a/provision/haraka.sh +++ b/provision/haraka.sh @@ -377,7 +377,8 @@ configure_haraka_watch() fi if [ ! -f "$HARAKA_CONF/watch.ini" ]; then - echo '[wss]' > "$HARAKA_CONF/watch.ini" + echo "[wss] +url=wss://$TOASTER_DOMAIN_NAME/watch" > "$HARAKA_CONF/watch.ini" fi } @@ -601,13 +602,6 @@ order=fail,pass,msg EO_RESULTS } -enable_newsyslog() { - tell_status "enabling newsyslog" - stage_sysrc newsyslog_enable=YES - sed -i.bak \ - -e '/^#0.*newsyslog/ s/^#0/0/' \ - "$STAGE_MNT/etc/crontab" -} configure_haraka_log_reader() { @@ -621,11 +615,11 @@ configure_haraka_log_reader() configure_haraka_log_rotation() { - enable_newsyslog + stage_enable_newsyslog tell_status "configuring haraka.log rotation" mkdir -p "$STAGE_MNT/etc/newsyslog.conf.d" - tee -a "$STAGE_MNT/etc/newsyslog.conf.d/haraka.log" < "$STAGE_MNT/usr/local/etc/newsyslog.conf.d/mongod" + > "$STAGE_MNT/usr/local/etc/newsyslog.conf.d/mongod.conf" } start_mongodb() diff --git a/provision/mysql.sh b/provision/mysql.sh index 2117d0dc..422fa78d 100755 --- a/provision/mysql.sh +++ b/provision/mysql.sh @@ -170,7 +170,7 @@ migrate_mysql_dbs() exit 1 fi - if jls -j mysql | grep -qs mysql; then + if jail_is_running mysql; then echo "mysql jail is running" _my_ver=$(pkg -j mysql info | grep mysql | grep server | cut -f1 -d' ' | cut -d- -f3) diff --git a/provision/redis.sh b/provision/redis.sh index 9fb4b33b..c78b6112 100755 --- a/provision/redis.sh +++ b/provision/redis.sh @@ -1,6 +1,8 @@ #!/bin/sh -. mail-toaster.sh || exit +set -e + +. mail-toaster.sh export JAIL_START_EXTRA="" export JAIL_CONF_EXTRA="" @@ -17,11 +19,13 @@ configure_redis() tell_status "configuring redis" for _dir in db log etc; do - mkdir -p "$STAGE_MNT/data/$_dir" || exit + mkdir -p "$STAGE_MNT/data/$_dir" done - mkdir -p "$STAGE_MNT/usr/local/etc/newsyslog.conf.d" || exit - stage_exec chown redis:redis /data/db /data/log /data/etc || exit + stage_enable_newsyslog + + mkdir -p "$STAGE_MNT/usr/local/etc/newsyslog.conf.d" + stage_exec chown redis:redis /data/db /data/log /data/etc sed -i.bak \ -e '/^stop-writes-on-bgsave-error/ s/yes/no/' \ @@ -33,7 +37,7 @@ configure_redis() "$STAGE_MNT/usr/local/etc/redis.conf" echo '/data/log/redis.log redis:redis 644 7 * @T00 JC /var/run/redis/redis.pid' \ - > "$STAGE_MNT/usr/local/etc/newsyslog.conf.d/redis" + > "$STAGE_MNT/usr/local/etc/newsyslog.conf.d/redis.conf" } start_redis() @@ -49,7 +53,7 @@ test_redis() stage_listening 6379 3 2 } -base_snapshot_exists || exit +base_snapshot_exists create_staged_fs redis start_staged_jail redis install_redis diff --git a/provision/roundcube.sh b/provision/roundcube.sh index 87bcc9f7..5ac1d71b 100755 --- a/provision/roundcube.sh +++ b/provision/roundcube.sh @@ -196,6 +196,19 @@ configure_roundcube_plugins() -e "/'password_driver'/s/sql/vpopmaild/" \ -e "/'password_vpopmaild_host'/s/localhost/vpopmail/" \ "$STAGE_MNT/usr/local/www/roundcube/plugins/password/config.inc.php" + + tell_status "configure the SA UserPrefs plugin" + if [ ! -f "$STAGE_MNT/usr/local/www/roundcube/plugins/sauserprefs/config.inc.php" ]; then + cp "$STAGE_MNT/usr/local/www/roundcube/plugins/sauserprefs/config.inc.php.dist" \ + "$STAGE_MNT/usr/local/www/roundcube/plugins/sauserprefs/config.inc.php" + fi + local _sapass + _sapass=$(grep user_scores_sql_password /data/spamassassin/etc/sql.cf | awk '{ print $2 }') + if [ -n "$_sapass" ]; then + sed -i.bak \ + -e "/'sauserprefs_db_dsnw'/s|mysql://username:password@localhost/database|mysql://spamassassin:${_sapass}@mysql/spamassassin|" \ + "$STAGE_MNT/usr/local/www/roundcube/plugins/sauserprefs/config.inc.php" + fi } configure_roundcube() @@ -233,7 +246,7 @@ configure_roundcube() -e "/'smtp_host'/ s/localhost:587/ssl:\/\/$TOASTER_MSA:465/" \ -e "/'smtp_user'/ s/'';/'%u';/" \ -e "/'smtp_pass'/ s/'';/'%p';/" \ - -e "/'archive',/ s/,$/, 'managesieve',/" \ + -e "/'archive',/ s|,$|, 'managesieve', 'sauserprefs',|" \ -e "/'product_name'/ s|'Roundcube Webmail'|'$ROUNDCUBE_PRODUCT_NAME'|" \ "$_stage_cfg" diff --git a/provision/rspamd.sh b/provision/rspamd.sh index f2b1ed92..68b7249e 100755 --- a/provision/rspamd.sh +++ b/provision/rspamd.sh @@ -144,7 +144,7 @@ level = "notice"; EO_SYSLOG else tell_status "configuring log rotation" - stage_sysrc newsyslog_enable="YES" + stage_enable_newsyslog fi } diff --git a/provision/snappymail.sh b/provision/snappymail.sh index d3477b51..4328edd0 100755 --- a/provision/snappymail.sh +++ b/provision/snappymail.sh @@ -76,10 +76,6 @@ configure_nginx_server() fastcgi_pass php; } - location ~ /\.ht { - deny all; - } - location ^~ /data { deny all; } diff --git a/provision/spamassassin.sh b/provision/spamassassin.sh index bd31b4a8..073fedc1 100755 --- a/provision/spamassassin.sh +++ b/provision/spamassassin.sh @@ -89,12 +89,14 @@ install_spamassassin_razor() '/^logfile/ s/= /= \/var\/log\//' \ "$STAGE_MNT/etc/razor/razor-agent.conf" + stage_enable_newsyslog + tell_status "setting up razor-agent log rotation" - if [ ! -d "$STAGE_MNT/etc/newsyslog.conf.d" ]; then - mkdir "$STAGE_MNT/etc/newsyslog.conf.d" + if [ ! -d "$STAGE_MNT/usr/local/etc/newsyslog.conf.d" ]; then + mkdir -p "$STAGE_MNT/usr/local/etc/newsyslog.conf.d" fi - tee "$STAGE_MNT/etc/newsyslog.conf.d/razor-agent" < - +
@@ -273,6 +361,31 @@ body { EO_INDEX } +configure_webmail_pf() +{ + _pf_etc="$ZFS_DATA_MNT/webmail/etc/pf.conf.d" + + if [ "$TOASTER_WEBMAIL_PROXY" = "nginx" ]; then + store_config "$_pf_etc/rdr.conf" < port { 80 443 } -> \$int_ip4 +rdr inet6 proto tcp from any to port { 80 443 } -> \$int_ip6 +EO_HTTP_RDR + fi + + store_config "$_pf_etc/allow.conf" < persist { \$int_ip4, \$int_ip6 } + +pass in quick proto tcp from any to port { 80 443 } +pass in quick proto tcp from any to port { 80 443 } +EO_HTTP_ALLOW +} + configure_webmail() { if [ "$WEBMAIL_HTTPD" = "lighttpd" ]; then @@ -282,10 +395,11 @@ configure_webmail() configure_nginx_server fi - _htdocs="$ZFS_DATA_MNT/webmail/htdocs" - if [ ! -d "$_htdocs" ]; then - mkdir -p "$_htdocs" - fi + configure_webmail_pf + + _data="$ZFS_DATA_MNT/webmail" + _htdocs="$_data/htdocs" + if [ ! -d "$_htdocs" ]; then mkdir -p "$_htdocs"; fi if [ -f "$_htdocs/index.html" ]; then tell_status "backing up index.html"