Skip to content

Commit 4f546ba

Browse files
Add optional support deleting spam for score > 10 (hestiacp#2206)
* Add optional delete spam Optional delete email if SPAM is greater than 10.00 points. Add "*** SPAM ***" to the subject to emails considered SPAM (more than 5.0 points). Add "*** VIRUS ***" to the subject if you have detected a virus. @madito * Update installers * Add upgrade script * Update upgrade script start editing UI * Fix shell check bug * New bug in code * Spacing * Spacing Co-authored-by: Raphael <rs@scit.ch>
1 parent afbfa89 commit 4f546ba

File tree

15 files changed

+257
-35
lines changed

15 files changed

+257
-35
lines changed

bin/v-add-mail-domain-reject

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
# info: add mail domain reject spam
3+
# options: USER DOMAIN
4+
# labels: mail
5+
#
6+
# example: v-add-mail-domain-antivirus admin mydomain.tld
7+
#
8+
# The function enables clamav scan for incoming emails.
9+
10+
11+
#----------------------------------------------------------#
12+
# Variable&Function #
13+
#----------------------------------------------------------#
14+
15+
# Argument definition
16+
user=$1
17+
domain=$2
18+
domain_idn=$2
19+
20+
# Includes
21+
# shellcheck source=/etc/hestiacp/hestia.conf
22+
source /etc/hestiacp/hestia.conf
23+
# shellcheck source=/usr/local/hestia/func/main.sh
24+
source $HESTIA/func/main.sh
25+
# shellcheck source=/usr/local/hestia/func/domain.sh
26+
source $HESTIA/func/domain.sh
27+
# load config file
28+
source_conf "$HESTIA/conf/hestia.conf"
29+
30+
# Additional argument formatting
31+
format_domain
32+
format_domain_idn
33+
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
34+
35+
36+
#----------------------------------------------------------#
37+
# Verifications #
38+
#----------------------------------------------------------#
39+
40+
check_args '2' "$#" 'USER DOMAIN'
41+
is_format_valid 'user' 'domain'
42+
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
43+
is_object_valid 'user' 'USER' "$user"
44+
is_object_unsuspended 'user' 'USER' "$user"
45+
is_object_valid 'mail' 'DOMAIN' "$domain"
46+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
47+
is_object_value_empty 'mail' 'DOMAIN' "$domain" '$REJECT'
48+
49+
# Perform verification if read-only mode is enabled
50+
check_hestia_demo_mode
51+
52+
53+
#----------------------------------------------------------#
54+
# Action #
55+
#----------------------------------------------------------#
56+
57+
# Adding antivirus flag
58+
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
59+
# Reject spam > 10 when enabled
60+
touch $HOMEDIR/$user/conf/mail/$domain/reject_spam
61+
fi
62+
63+
64+
#----------------------------------------------------------#
65+
# Hestia #
66+
#----------------------------------------------------------#
67+
68+
# Adding antivirus in config
69+
update_object_value 'mail' 'DOMAIN' "$domain" '$REJECT' 'yes'
70+
71+
# Logging
72+
$BIN/v-log-action "$user" "Info" "Mail" "Anti-virus scanning enabled (Domain: $domain)."
73+
log_event "$OK" "$ARGUMENTS"
74+
75+
exit

bin/v-delete-mail-domain-reject

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
# info: delete mail domain reject spam support
3+
# options: USER DOMAIN
4+
# labels: mail
5+
#
6+
# example: v-delete-mail-domain-antispam admin mydomain.tld
7+
#
8+
# The function disable spamassasin for incoming emails.
9+
10+
11+
#----------------------------------------------------------#
12+
# Variable&Function #
13+
#----------------------------------------------------------#
14+
15+
# Argument definition
16+
user=$1
17+
domain=$2
18+
domain_idn=$2
19+
20+
# Includes
21+
# shellcheck source=/etc/hestiacp/hestia.conf
22+
source /etc/hestiacp/hestia.conf
23+
# shellcheck source=/usr/local/hestia/func/main.sh
24+
source $HESTIA/func/main.sh
25+
# shellcheck source=/usr/local/hestia/func/domain.sh
26+
source $HESTIA/func/domain.sh
27+
# load config file
28+
source_conf "$HESTIA/conf/hestia.conf"
29+
# Additional argument formatting
30+
format_domain
31+
format_domain_idn
32+
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
33+
34+
35+
#----------------------------------------------------------#
36+
# Verifications #
37+
#----------------------------------------------------------#
38+
39+
check_args '2' "$#" 'USER DOMAIN'
40+
is_format_valid 'user' 'domain'
41+
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
42+
is_object_valid 'user' 'USER' "$user"
43+
is_object_unsuspended 'user' 'USER' "$user"
44+
is_object_valid 'mail' 'DOMAIN' "$domain"
45+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
46+
is_object_value_exist 'mail' 'DOMAIN' "$domain" '$REJECT'
47+
48+
# Perform verification if read-only mode is enabled
49+
check_hestia_demo_mode
50+
51+
52+
#----------------------------------------------------------#
53+
# Action #
54+
#----------------------------------------------------------#
55+
56+
# Delete antispam flag
57+
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
58+
# Reject spam > 10 when enabled
59+
rm -f $HOMEDIR/$user/conf/mail/$domain/reject_spam
60+
fi
61+
62+
63+
#----------------------------------------------------------#
64+
# Hestia #
65+
#----------------------------------------------------------#
66+
67+
# Delete antispam in config
68+
update_object_value 'mail' 'DOMAIN' "$domain" '$REJECT' 'no'
69+
70+
# Logging
71+
$BIN/v-log-action "$user" "Info" "Mail" "Anti-spam protection disabled (Domain: $domain)."
72+
log_event "$OK" "$ARGUMENTS"
73+
74+
exit

bin/v-list-mail-domain

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ json_list() {
3434
"CATCHALL": "'$CATCHALL'",
3535
"ACCOUNTS": "'$ACCOUNTS'",
3636
"RATE_LIMIT": "'$RATE_LIMIT'",
37+
"REJECT": "'$REJECT'",
3738
"U_DISK": "'$U_DISK'",
3839
"SSL": "'$SSL'",
3940
"LETSENCRYPT": "'$LETSENCRYPT'",
@@ -60,6 +61,8 @@ shell_list() {
6061
echo "ACCOUNTS: $ACCOUNTS"
6162
echo "DISK: $U_DISK"
6263
echo "SSL: $SSL"
64+
echo "RATE_LIMIT: $RATE_LIMIT"
65+
echo "REJECT: $REJECT"
6366
echo "LETSENCRYPT: $LETSENCRYPT"
6467
echo "SUSPENDED: $SUSPENDED"
6568
echo "TIME: $TIME"

func/rebuild.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ rebuild_mail_domain_conf() {
566566
rm -f $HOMEDIR/$user/conf/mail/$domain/accounts
567567
rm -f $HOMEDIR/$user/conf/mail/$domain/aliases
568568
rm -f $HOMEDIR/$user/conf/mail/$domain/antispam
569+
rm -f $HOMEDIR/$user/conf/mail/$domain/reject_spam
569570
rm -f $HOMEDIR/$user/conf/mail/$domain/antivirus
570571
rm -f $HOMEDIR/$user/conf/mail/$domain/protection
571572
rm -f $HOMEDIR/$user/conf/mail/$domain/passwd
@@ -592,6 +593,11 @@ rebuild_mail_domain_conf() {
592593
if [ "$ANTIVIRUS" = 'yes' ]; then
593594
touch $HOMEDIR/$user/conf/mail/$domain/antivirus
594595
fi
596+
597+
# Adding reject spam protection
598+
if [ "$REJECT" = 'yes' ]; then
599+
touch $HOMEDIR/$user/conf/mail/$domain/reject_spam
600+
fi
595601

596602
# Adding dkim
597603
if [ "$DKIM" = 'yes' ]; then

func/syshealth.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function syshealth_update_mail_config_format() {
8383
# MAIL DOMAINS
8484
# Create array of known keys in configuration file
8585
system="mail"
86-
known_keys="DOMAIN ANTIVIRUS ANTISPAM DKIM WEBMAIL SSL LETSENCRYPT CATCHALL ACCOUNTS RATE_LIMIT U_DISK SUSPENDED TIME DATE"
86+
known_keys="DOMAIN ANTIVIRUS ANTISPAM DKIM WEBMAIL SSL LETSENCRYPT CATCHALL ACCOUNTS RATE_LIMIT REJECT U_DISK SUSPENDED TIME DATE"
8787
write_kv_config_file
8888
unset system
8989
unset known_keys

install/deb/exim/exim4.conf.4.94.template

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#SPAMASSASSIN = yes
88
#SPAM_SCORE = 50
9+
#SPAM_REJECT_SCORE = 100
910
#CLAMD = yes
1011

1112
smtp_banner = $smtp_active_hostname
@@ -176,10 +177,12 @@ acl_check_rcpt:
176177
.endif
177178

178179
.ifdef SPAMASSASSIN
179-
warn set acl_m1 = no
180-
181-
warn condition = ${if exists {/etc/exim4/domains/$domain/antispam}{yes}{no}}
182-
set acl_m1 = yes
180+
warn set acl_m1 = no
181+
set acl_m3 = no
182+
warn condition = ${if exists {/etc/exim4/domains/$domain/antispam}{yes}{no}}
183+
set acl_m1 = yes
184+
warn condition = ${if exists {/etc/exim4/domains/$domain/reject_spam}{yes}{no}}
185+
set acl_m3 = yes
183186
.endif
184187

185188
accept
@@ -193,20 +196,26 @@ acl_check_data:
193196
.endif
194197

195198
.ifdef SPAMASSASSIN
196-
warn !authenticated = *
197-
hosts = !+relay_from_hosts
198-
condition = ${if < {$message_size}{1024K}}
199-
condition = ${if eq{$acl_m1}{yes}{yes}{no}}
200-
spam = debian-spamd:true/defer_ok
201-
add_header = X-Spam-Score: $spam_score_int
202-
add_header = X-Spam-Bar: $spam_bar
203-
add_header = X-Spam-Report: $spam_report
204-
set acl_m2 = $spam_score_int
205-
206-
warn condition = ${if !eq{$acl_m2}{} {yes}{no}}
207-
condition = ${if >{$acl_m2}{SPAM_SCORE} {yes}{no}}
208-
add_header = X-Spam-Status: Yes
209-
message = SpamAssassin detected spam (from $sender_address to $recipients).
199+
warn !authenticated = *
200+
hosts = !+relay_from_hosts
201+
condition = ${if < {$message_size}{1024K}}
202+
condition = ${if eq{$acl_m1}{yes}{yes}{no}}
203+
spam = debian-spamd:true/defer_ok
204+
add_header = X-Spam-Score: $spam_score_int
205+
add_header = X-Spam-Bar: $spam_bar
206+
add_header = X-Spam-Report: $spam_report
207+
set acl_m2 = $spam_score_int
208+
209+
warn condition = ${if !eq{$acl_m2}{} {yes}{no}}
210+
condition = ${if >{$acl_m2}{SPAM_SCORE} {yes}{no}}
211+
add_header = X-Spam-Status: Yes
212+
message = SpamAssassin detected spam (from $sender_address to $recipients).
213+
214+
# Deny spam at high score if spam score > SPAM_REJECT_SCORE and delete_spam is enabled
215+
deny message = This message scored $spam_score spam points
216+
spam = debian-spamd:true
217+
condition = ${if eq{$acl_m3}{yes}{yes}{no}}
218+
condition = ${if >{$spam_score_int}{SPAM_REJECT_SCORE}{1}{0}}
210219
.endif
211220

212221
accept

install/deb/exim/exim4.conf.template

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#SPAMASSASSIN = yes
88
#SPAM_SCORE = 50
9+
#SPAM_REJECT_SCORE = 100
910
#CLAMD = yes
1011

1112
smtp_banner = $smtp_active_hostname
@@ -81,6 +82,10 @@ SMTP_RELAY_PORT = ${lookup{port}lsearch{SMTP_RELAY_FILE}}
8182
SMTP_RELAY_USER = ${lookup{user}lsearch{SMTP_RELAY_FILE}}
8283
SMTP_RELAY_PASS = ${lookup{pass}lsearch{SMTP_RELAY_FILE}}
8384

85+
# Custom Filter
86+
system_filter = /etc/exim4/system.filter
87+
system_filter_user = Debian-exim
88+
8489
######################################################################
8590
# ACL CONFIGURATION #
8691
# Specifies access control lists for incoming SMTP mail #
@@ -177,11 +182,14 @@ acl_check_rcpt:
177182

178183
.ifdef SPAMASSASSIN
179184
warn set acl_m1 = no
180-
185+
set acl_m3 = no
181186
warn condition = ${if exists {/etc/exim4/domains/$domain/antispam}{yes}{no}}
182187
set acl_m1 = yes
188+
warn condition = ${if exists {/etc/exim4/domains/$domain/reject_spam}{yes}{no}}
189+
set acl_m3 = yes
183190
.endif
184191

192+
185193
accept
186194

187195

@@ -207,8 +215,15 @@ acl_check_data:
207215
condition = ${if >{$acl_m2}{SPAM_SCORE} {yes}{no}}
208216
add_header = X-Spam-Status: Yes
209217
message = SpamAssassin detected spam (from $sender_address to $recipients).
218+
219+
# Deny spam at high score if spam score > SPAM_REJECT_SCORE and delete_spam is enabled
220+
deny message = This message scored $spam_score spam points
221+
spam = debian-spamd:true
222+
condition = ${if eq{$acl_m3}{yes}{yes}{no}}
223+
condition = ${if >{$spam_score_int}{SPAM_REJECT_SCORE}{1}{0}}
210224
.endif
211225

226+
212227
accept
213228

214229

install/deb/exim/system.filter

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
if $h_X-Spam-Status: contains "Yes"
2+
then
3+
headers add "Old-Subject: $h_subject"
4+
headers remove "Subject"
5+
headers add "Subject: *** SPAM *** $h_old-subject"
6+
headers remove "Old-Subject"
7+
endif
8+
9+
# X-Anti-Virus: infected
10+
if $h_X-Anti-Virus: contains "infected"
11+
then
12+
headers add "Old-Subject: $h_subject"
13+
headers remove "Subject"
14+
headers add "Subject: *** VIRUS *** $h_old-subject"
15+
headers remove "Old-Subject"
16+
endif

install/hst-install-debian.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,8 @@ if [ "$exim" = 'yes' ]; then
16751675
fi
16761676
cp -f $HESTIA_INSTALL_DIR/exim/dnsbl.conf /etc/exim4/
16771677
cp -f $HESTIA_INSTALL_DIR/exim/spam-blocks.conf /etc/exim4/
1678-
cp -f $HESTIA_INSTALL_DIR/exim/limit.conf /etc/exim4/
1678+
cp -f $HESTIA_INSTALL_DIR/exim/limit.conf /etc/exim4/
1679+
cp -f $HESTIA_INSTALL_DIR/exim/system.filter /etc/exim4/
16791680
touch /etc/exim4/white-blocks.conf
16801681

16811682
if [ "$spamd" = 'yes' ]; then

install/hst-install-ubuntu.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,8 @@ if [ "$exim" = 'yes' ]; then
16991699
cp -f $HESTIA_INSTALL_DIR/exim/exim4.conf.template /etc/exim4/
17001700
cp -f $HESTIA_INSTALL_DIR/exim/dnsbl.conf /etc/exim4/
17011701
cp -f $HESTIA_INSTALL_DIR/exim/spam-blocks.conf /etc/exim4/
1702-
cp -f $HESTIA_INSTALL_DIR/exim/limit.conf /etc/exim4/
1702+
cp -f $HESTIA_INSTALL_DIR/exim/limit.conf /etc/exim4/
1703+
cp -f $HESTIA_INSTALL_DIR/exim/system.filter /etc/exim4/
17031704
touch /etc/exim4/white-blocks.conf
17041705

17051706
if [ "$spamd" = 'yes' ]; then

0 commit comments

Comments
 (0)