Greylisting on a Plesk VPS

 
Post new topic   Reply to topic    34SP.com Forum Index // VPS (Virtual Private Server)
View previous topic :: View next topic  
Author Message
imknight
Administrator
Administrator


Joined: 16 Mar 2001
Posts: 3627
Location: Stroud,Gloucestershire

PostPosted: Wed Dec 12, 2007 12:43 pm    Post subject: Greylisting on a Plesk VPS Reply with quote
All 34SP.com servers use the greylisting feature that Brent Meisher put together for Plesk systems to reduce levels of spam. You can read the full details on his website at http://meshier.com/2006/09/18/adding-greylisting-support-to-qmail-on-plesk-8/

Below is a guide that should get you underway with this on your server.

First install some dependecies (if you dont have yum available to you let us know - or follow the guide in this forum)

Code:

yum install mysql-devel openssl-devel gcc


Depending on repositories you have used in the past you may have also just updated mysql to version 5 so restart mysqld to be sure

Code:

service mysqld restart


Next, get the source files and extract them into a directory:

<wget http.... is all on one line in the extract below>
Code:

cd /root/
wget http://meshier.com/wp-content/uploads/2006/09/qmail-103-greylist-psa8.tar.gz
tar xvfz qmail-103-greylist-psa8.tar.gz
<lots of files will show on terminal>
cd /root/qmail-1.03


Now edit the file 'local_scan.c' to give it some database details. You can alter the timeout blocks as well should you wish.

Quote:

#define MYSQLHOST "localhost"
#define MYSQLUSER "milter"
#define MYSQLPASS "greylist"
#define MYSQLDB "qmail"
#define BLOCK_EXPIRE 5 /* minutes until email is accepted */
#define RECORD_EXPIRE 1500 /* minutes until record expires */
#define RECORD_EXPIRE_GOOD 36 /* days until record expires after accepting email */


You can edit this with vi on the VPS. If you're not comfortable with vi, download winscp so you can log in as root user and edit within Windows.

It is advisable to change the username/password in the above as this is on a public site and could lead to abuse if found.

Based on you changing the username and password now do the following:

Code:

mysql -u admin -p
<you will be prompted for a password>

Run the following commands (substituting the USER/PASS for the same ones you put in the file above):
Code:

CREATE DATABASE qmail;
GRANT ALL ON qmail.* TO 'USER'@'localhost' IDENTIFIED BY 'PASS';
FLUSH PRIVILEGES;


You can just create the database table now if you wish (see below first) using the following:

Code:


use qmail;
CREATE TABLE relaytofrom (
id bigint(20) NOT NULL auto_increment,
relay_ip varchar(16) default NULL,
mail_from varchar(255) default NULL,
rcpt_to varchar(255) default NULL,
block_expires datetime NOT NULL default '0000-00-00 00:00:00',
record_expires datetime NOT NULL default '0000-00-00 00:00:00',
blocked_count bigint(20) NOT NULL default '0',
passed_count bigint(20) NOT NULL default '0',
aborted_count bigint(20) NOT NULL default '0',
origin_type enum('MANUAL','AUTO') NOT NULL default 'MANUAL',
create_time datetime NOT NULL default '0000-00-00 00:00:00',
last_update timestamp(14) NOT NULL,
PRIMARY KEY  (id),
KEY relay_ip (relay_ip),
KEY mail_from (mail_from(20)),
KEY rcpt_to (rcpt_to(20))
) TYPE=MyISAM;
exit;


Alternatively if you wish to use the 34SP file, this contains a serious of servers that are whitelisted by default (not all the big ISPs servers behave perfectly with greylisting)

exit from mysql (using the command exit);

Code:

cd /root
wget http://support.34sp.com/greylist.sql

mysql -u MYSQLUSER -p qmail < greylist.sql
<enter MYSQLPASS>


Now the database side of things is finished, lets actually make the changes to the qmail binaries themselves.

Code:

cd /root/qmail-1.03/
make
<this should end without listing an error at the bottom>


Once it has compiled do the following (please accept that you will be overwriting a file with the qmail-smtpd file):

Code:

service qmail stop
cp qmail-envelope-scanner /var/qmail/bin/.
cp -f qmail-smtpd /var/qmail/bin/.
chown root.qmail /var/qmail/bin/qmail-envelope-scanner
chown root.qmail /var/qmail/bin/qmail-smtpd
service qmail start



You now should have greylisting running.

Send an email to an account on the server and you should get an entry in the 'debug log'

Quote:

[root@testvps qmail-1.03]# tail -f /tmp/greylist_dbg.txt
protocol = notneeded4qmail ian@34spexample.com
ian@34sp.com -> xxx (80.82.115.206) Whitelist IP Accept id = 88
--------


(as i sent from our smtp servers which are whitelisted it got through without any checks)

If it was from a non whitelisted IP (removed from database to demonstrate)

Quote:

protocol = notneeded4qmail ian@34spexample.com
ian@34sp.com -> test@34sptestaccount.co.uk (80.82.115.206) Doesn't Exists Block
--------

(the mailserver should now continue to try sending and eventually deliver when it tries again)
Quote:

--------
protocol = notneeded4qmail ian@34spexample.com
ian@34sp.com -> test@34sptestaccount.co.uk (80.82.115.206) Exists Accept id = 139 expire = 1
--------


Thats the majority of greylisting finished, we just need to do a few cleanup routines so that the database doesn't get too big.

Using the following code, create a file in /etc/cron.daily/cleanqmail using vi or winscp (remember to replace the username / password accordingly):

Code:

#!/usr/bin/perl
use strict;
use warnings;

use constant DBD => 'DBI:mysql:qmail:localhost:3306';
use constant DBUSER => 'milter';
use constant DBPASS => 'greylist';

use DBI;

system ("cat /dev/null > /tmp/greylist_dbg.txt");

my $dbh = DBI->connect(DBD,DBUSER,DBPASS) or die "can't connect to db ", $DBI::errstr, ":$!";

$dbh->do("DELETE FROM relaytofrom WHERE record_expires < NOW() - INTERVAL 1 HOUR AND origin_type = 'AUTO'");
$dbh->do("OPTIMIZE TABLE relaytofrom");

$dbh->disconnect;

exit;


and then make sure it's executable:

Code:

chmod 755 /etc/cron.daily/cleanqmail


That's it! All finished!

Should you want to whitelist/blacklist anything have a read of this webpage:
http://meshier.com/2006/12/20/using-whitelist-blacklist-with-greylisting/
_________________
Ian
34SP.com
Easy script installers for a small number of popular scripts are now available at http://scripts.34sp.com
Used our script installers? Please post your site here

| Wordpress Hosting |


Last edited by imknight on Wed Aug 20, 2008 9:15 am; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
garethw
34SP Newbie
34SP Newbie


Joined: 06 Dec 2007
Posts: 54
Location: Stafford, Staffordshire, UK

PostPosted: Sun Dec 23, 2007 2:05 pm    Post subject: Reply with quote
need a slight alteration to the cleanqmail script.

line 13
need to change (DBD,USER,PASS) to (DBD,DBUSER,DBPASS)

seems to work better now.

Code:

cd /etc/cron.daily &&
mv cleanqmail cleanqmail.orig &&
sed 's/DBD,USER,PASS/DBD,DBUSER,DBPASS/' cleanqmail.orig > cleanqmail
chmod 755 cleanqmail

_________________
--
Gareth Westwood
WFF Systems LTD
Back to top
View user's profile Send private message Visit poster's website
imknight
Administrator
Administrator


Joined: 16 Mar 2001
Posts: 3627
Location: Stroud,Gloucestershire

PostPosted: Sun Dec 23, 2007 4:03 pm    Post subject: Reply with quote
garethw wrote:
need a slight alteration to the cleanqmail script.

line 13
need to change (DBD,USER,PASS) to (DBD,DBUSER,DBPASS)


Well spotted - that will teach me to just copy/paste that part from the website - the rest i worked through personally


Have now updated the main post to reflect this change.
_________________
Ian
34SP.com
Easy script installers for a small number of popular scripts are now available at http://scripts.34sp.com
Used our script installers? Please post your site here

| Wordpress Hosting |
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
garethw
34SP Newbie
34SP Newbie


Joined: 06 Dec 2007
Posts: 54
Location: Stafford, Staffordshire, UK

PostPosted: Mon Dec 24, 2007 10:37 am    Post subject: Reply with quote
NP, anytime.
_________________
--
Gareth Westwood
WFF Systems LTD
Back to top
View user's profile Send private message Visit poster's website
bytte
Junior Member
Junior Member


Joined: 05 Sep 2001
Posts: 156

PostPosted: Mon Apr 23, 2012 9:45 pm    Post subject: Reply with quote
Would it still make sense to install this using the above procedure?
Back to top
View user's profile Send private message
garethw
34SP Newbie
34SP Newbie


Joined: 06 Dec 2007
Posts: 54
Location: Stafford, Staffordshire, UK

PostPosted: Tue May 01, 2012 1:02 pm    Post subject: Reply with quote
I'm still using this graylisting on my vps so I guess so. I have just had another vps come online and was planning on setting this up.

When I get around to it I'll post back and let you know how it went.....
_________________
--
Gareth Westwood
WFF Systems LTD
Back to top
View user's profile Send private message Visit poster's website
Post new topic   Reply to topic    34SP.com Forum Index // VPS (Virtual Private Server) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Powered by phpBB © 2001, 2002 phpBB Group