Results 1 to 13 of 13

Thread: Enable Spamassassin for all users

  1. #1
    Join Date
    Mar 2009
    Location
    The Netherlands
    Posts
    30

    Question Enable Spamassassin for all users

    We are using some scripts to make sure all users are using Spamassassin.

    We make sure spam=ON is in the
    /usr/local/directadmin/data/users/USERNAME/user.conf
    And we make sure that the following is set in the
    /etc/virtual/DOMAINNAME/filter.conf
    high_score=5
    high_score_block=yes
    where=delete
    After that we run
    echo "action=rewrite&value=filter" >> /usr/local/directadmin/data/task.queue
    And I login in the username and I look under "Spamassassin Setup" it still says:

    SpamAssassin is not currently enabled.
    Click "Save" (below) to enable it.
    How can I automate with a script that all the Spamassassins for all the users are being enabled?

    Thanks

  2. #2
    Join Date
    Oct 2004
    Location
    A Coruña, Spain
    Posts
    6,786
    Use the user_create_post.sh script, i do use that for this purpose.

    Here the guide:
    http://help.directadmin.com/item.php?id=117

    Regards
    SeLLeRoNe - Andrea Iannucci
    Head of Managed Service - Senior DevOps Engineer
    If you need my support write me an E-Mail to Support@CrazyNetwork.it

  3. #3
    Join Date
    Apr 2009
    Posts
    2,418
    Thank you for the link, SeLLeRoNe. I have read somehwere before in the forum that you have edited the spamassassin settings for new domains. I have read this link http://help.directadmin.com/item.php?id=304

    Would it be possible for you to share your custom domain_create_post.sh that give custom spamassassin settings for new domain, and some instructions for the setup? That would help a lot. It would be very kind of you.

  4. #4
    Join Date
    Oct 2004
    Location
    A Coruña, Spain
    Posts
    6,786
    The link i posted in post #2 is the way i did use... just changed to fit domain_create_post.sh

    Here it is:

    Code:
    #!/bin/sh
    
    \cp MY_CUSTOM_FILTER_FILE /etc/virtual/$domain/filter
    \cp MY_CUSTOM_FILTER.CONF_FILE /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;
    Regards
    SeLLeRoNe - Andrea Iannucci
    Head of Managed Service - Senior DevOps Engineer
    If you need my support write me an E-Mail to Support@CrazyNetwork.it

  5. #5
    Join Date
    Apr 2009
    Posts
    2,418
    Thanks a lot! So the code you posted is placed in domain_create_post.sh file, or is it placed in user_create_post.sh? I just need a these example before I can be able to test, because I am not sure about this.

  6. #6
    Join Date
    Oct 2004
    Location
    A Coruña, Spain
    Posts
    6,786
    domain_create_post.sh

    Regards
    SeLLeRoNe - Andrea Iannucci
    Head of Managed Service - Senior DevOps Engineer
    If you need my support write me an E-Mail to Support@CrazyNetwork.it

  7. #7
    Join Date
    Apr 2009
    Posts
    2,418
    I am trying to look into this now, but have a hard time. Regarding this:

    Code:
    \cp MY_CUSTOM_FILTER_FILE /etc/virtual/$domain/filter
    \cp MY_CUSTOM_FILTER.CONF_FILE /etc/virtual/$domain/filter.conf
    1: Is this "\cp" correct, or did you make a mistake when pasting it in the forums? I have never seen the "\" used before. But don't know.

    2: Regarding MY_CUSTOM_FILTER_FILE and MY_CUSTOM_FILTER.CONF_FILE, at what path have you added those two files?

    3: Your code is very different from the code in the example at http://help.directadmin.com/item.php?id=117 - is it not needed to have this at the end?:
    Code:
    fi
    Also you don't turn SpamAssassin on as default for new users in this code?

    This is a little over my head, I think I need more detailed guide. All I want is that all user accounts created has SpamAssassin enabled as default, and that all domains added have my preferred SpamAssassin settings. But the example at http://help.directadmin.com/item.php?id=117 and your code, does not seem to be enough for me to understand all I need to do.

  8. #8
    Join Date
    Oct 2004
    Location
    A Coruña, Spain
    Posts
    6,786
    Well, the code i posted is for add standard filter to new domain, for new users you need to use the guide link i posted.

    the "fi" statement is not needed since i dont use any if statement.

    you can choose what path you want for the filter and filter.conf standard file

    the \cp just mean that if destination file exist it overwrite without ask.

    If you are not able to do those two file by yourself you should consider hire an administrator that do this job for you.

    Me, Zeiter, nobaloney and other offer this kind of services as payd service.

    Regards
    SeLLeRoNe - Andrea Iannucci
    Head of Managed Service - Senior DevOps Engineer
    If you need my support write me an E-Mail to Support@CrazyNetwork.it

  9. #9
    Join Date
    Apr 2009
    Posts
    2,418
    Thank for for additional information. I will figure out the rest myself.

  10. #10
    Join Date
    Apr 2009
    Posts
    2,418
    Here is a old, but useful forum post by John about .sh scripts etc: http://forum.directadmin.com/showthr...0237#post10237 - however please note that in John's post, he say to chmod domain_create_post.sh to 755. I don't think that is needed. I have set my custom user_create_post.sh and domain_create_post.sh to 0700 on my servers, and it works.

    I have tested a lot, and have setup custom user_create_post.sh and domain_create_post.sh to automatically enable SpamAssassin on new accounts, and automatically have my settings when customer add a new domain. It might help someone, so here I post my setup:

    Create /root/.spamassassin/user_prefs and add this content in it:
    Code:
    required_score 7.5
    report_safe     1
    Create /root/.spamassassin/filter.conf and add this content in it:
    Code:
    high_score=15
    high_score_block=yes
    where=userspamfolder
    Create /usr/local/directadmin/scripts/custom/user_create_post.sh , set owner/group to diradmin diradmin and chmod 0700, and add this content in it:
    Code:
    #!/bin/sh
    if [ "$spam" = "ON" ]; then
    DIR=/home/$username/.spamassassin
    mkdir  $DIR
    \cp /root/.spamassassin/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;
    Create /usr/local/directadmin/scripts/custom/domain_create_post.sh , set owner/group to diradmin diradmin and chmod 0700, and add this content in it:
    Code:
    #!/bin/sh
    \cp /root/.spamassassin/filter.conf /etc/virtual/$domain/filter.conf
    chown mail:mail /etc/virtual/$domain/filter.conf
    chmod 600 /etc/virtual/$domain/filter.conf
    exit 0;
    Thats it! Please note that in this guide http://help.directadmin.com/item.php?id=117 the example of user_create_post.sh has these three lines wich I did not add in my file:
    Code:
    touch $DIR/spam
    chown  mail:$username $DIR/spam
    chmod 660 $DIR/spam
    The reason I did not add them, was because of initial testing I did, show that default it is not added a "spam" file when enabling SpamAssassin, therfor I think the example is outdated, and it is not needed to create that file. So I have removed those three lines from my code.

  11. #11
    Join Date
    Mar 2009
    Location
    The Netherlands
    Posts
    30
    Hi ditto, nice job on updating the files!

    I'm missing a script to update all the existing /etc/virtual/*/filter.conf files so I created one using your domain_create_post.sh:

    So for everyone who wants to use it:

    Code:
    vi /opt/update_filterconf.sh
    Paste:

    Code:
    #!/bin/sh
    for i in `ls /etc/virtual`; do
    {
      domain=$i /usr/local/directadmin/scripts/custom/domain_create_post.sh
    };
    done;
    exit 0;
    Save with :wq and run:

    Code:
    chmod 700 /opt/update_filterconf.sh
    And run it:

    Code:
    /opt/update_filterconf.sh
    Would there still be the need of running the following?

    Code:
    echo "action=rewrite&value=filter" >> /usr/local/directadmin/data/task.queue
    Last edited by Trans-IX B.V.; 07-19-2013 at 05:49 AM.

  12. #12
    Join Date
    Apr 2009
    Posts
    2,418
    Quote Originally Posted by Trans-IX B.V. View Post
    [..]Would there still be the need of running the following?

    Code:
    echo "action=rewrite&value=filter" >> /usr/local/directadmin/data/task.queue
    I don't know, but hopefully someone else knows and will answer ... I have a question related to spam management in DirectAdmin, hope somone knows:

    When SpamAssassin settings in DirectAdmin is set to send spam to spamfolder (filter.conf has where=userspamfolder), what happens to the spam when a customer setup a email forwarder in DirectAdmin, is the spam that is sent to userspamfolder also forwarded, or is it not forwarded? I hope it is not forwarded to the forwarder email address, because if it is, I would have to change all customers SpamAssassin settings to delete the spam without sending it to spam folder.

  13. #13
    Join Date
    Apr 2007
    Location
    Spain
    Posts
    63

    Red face 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 "root@hostname.domain.tld", CSF/LFD notifications for example, EXIM gives an error and can not send mail:
    Code:
    Failed to find user "" from expanded string "${lookup{$domain}lsearch{/etc/virtual/domainowners}{$value}}" for the domain_filter router
    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.
    Last edited by Yoshua; 04-26-2014 at 12:33 AM. Reason: Small problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •