My steps
Hello,
First thank you very much to all for your contributions.
I recently needed to do this myself and with the help of Directadmin, plus the contributions of you, I have successfully completed the task with a few modifications.
I share my steps:
Use an existing user account to activate and configure Spamassassin filters and actions as we want to be the default settings for all new and/or existing users.
Copy the configuration created by directadmin in sample user:
# cp /etc/virtual/USER_DOMAIN/filter /usr/local/directadmin/scripts/custom/default_filter
# cp /etc/virtual/USER_DOMAIN/filter.conf /usr/local/directadmin/scripts/custom/default_filter.conf
# cp /home/USER/.spamassassin/user_prefs /usr/local/directadmin/scripts/custom/default_user_prefs
We create the scripts that Directadmin use when a new user and a new domain is creared:
# cd /usr/local/directadmin/scripts/custom/
# nano user_create_post.sh
Code:
#!/bin/sh
if [ "$spam" = "ON" ]; then
DIR=/home/$username/.spamassassin
DEFAULTDIR=/usr/local/directadmin/scripts/custom
mkdir $DIR
\cp $DEFAULTDIR/default_user_prefs $DIR/user_prefs
chown ${username}:mail $DIR
chmod 771 $DIR
chown $username:$username $DIR/user_prefs
chmod 755 $DIR/user_prefs
fi
exit 0;
# chmod +x user_create_post.sh
# chown diradmin.diradmin user_create_post.sh
# nano domain_create_post.sh
Code:
#!/bin/sh
DEFAULTDIR=/usr/local/directadmin/scripts/custom
\cp -f $DEFAULTDIR/default_filter /etc/virtual/$domain/filter
\cp -f $DEFAULTDIR/default_filter.conf /etc/virtual/$domain/filter.conf
chown mail:mail /etc/virtual/$domain/filter
chown mail:mail /etc/virtual/$domain/filter.conf
chmod 640 /etc/virtual/$domain/filter
chmod 600 /etc/virtual/$domain/filter.conf
exit 0;
# chmod +x domain_create_post.sh
# chown diradmin.diradmin domain_create_post.sh
Now all new Users and domains that are created, have enabled by default Spamassassin and the setup we have set by default.
If you also want to enable Spamassassin and apply these settings to all existing users, these are the steps that I used.
We create the scripts for manually run Spamassassin activation and copy the default filters to existing users:
# nano spam.sh
Code:
#!/bin/sh
for i in `ls /usr/local/directadmin/data/users`; do
{
username=$i spam=ON /usr/local/directadmin/scripts/custom/user_create_post.sh
};
done;
exit 0;
# chmod +x spam.sh
# nano update_filters.sh
Code:
#!/bin/sh
for i in `cat /etc/virtual/domains`; do
{
domain=$i /usr/local/directadmin/scripts/custom/domain_create_post.sh
};
done;
exit 0;
# chmod +x update_filters.sh
And then run:
# ./spam.sh
# ./update_filters.sh
These steps have helped me to such purpose without problem and everything is working properly as I wanted (or so I think at the moment), but would appreciate any advice to improve the process or warnings of potential failures.
Thank you very much to all ...and sorry for my bad English!
Greetings.
NOTE: Ok at the moment I found a small problem that has been driving me crazy for a few minutes.
If you copy the files "
filter" and "
filter.conf" in the folder "
/etc/virtual/hostname.domain.tld/" when a mail is sending from "
[email protected]", CSF/LFD notifications for example, EXIM gives an error and can not send mail:
Code:
[COLOR=#000000][FONT=verdana]Failed to find user "" from expanded string "${lookup{$domain}lsearch{/etc/virtual/domainowners}{$value}}" for the domain_filter router[/FONT][/COLOR]
Delete these two files in this folder fix the problem, but would have to improve my method to get the list of domains to avoid this problem.
Sorry.