How to Rules rules_du_jour For SA the easy way

FastAttack

Verified User
Joined
Dec 27, 2004
Messages
51
I did some slight modifications to a perl script that install Rules du jour for you the easy way.

you must be root to do this and SA must be installed

it will work with MailScanner and/or Spamblock

Code:
#wget [url]http://www.elm2.com/download/installRDJ.tar.gz[/url]
#tar zxvf installRDJ.tar.gz
#perl installRDJ.pl --install --directadmin

the script will create a cronjob that runs every night at 1am to update the rules set.

This script was not written by me, all I did was modify some of the lines to make it work with directadmin,

This script was verfied to work on CentOS 4.0
 
Last edited:
Gregory said:
Thanks mate.

I will give a try.

A little remark :

The script is called installRDJ.pl and the command "perl" is needed just once.




Thank you anyway.

lol I guess I typed it in twice didn't even pay attention to it

I'll update my original post
 
for people who would like to install this on debian edit the script on the following line:

change:
$configOptions{sa_restart} = "/sbin/service exim restart";

to:
$configOptions{sa_restart} = "/etc/init.d/exim restart";
 
DutchTSE said:
for people who would like to install this on debian edit the script on the following line:

change:
$configOptions{sa_restart} = "/sbin/service exim restart";

to:
$configOptions{sa_restart} = "/etc/init.d/exim restart";

or I can make a new option for debian :)

i'll work on it although someone will have to test it.
 
FastAttack said:
or I can make a new option for debian :)

i'll work on it although someone will have to test it.

PHP:
#!/usr/bin/perl -w
# $id: installRDJ, v 1.1.0 2006/11/13
# Script to simplify the redundant install of Rules Du Jour
# Copyright (C) 2005,2006  BJ Dierkes <[email protected]>
# Modified to work with DirectAdmin by Enrique Mertins <[email protected]>
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
#
# INFORMATION:
#
# There is nothing to be said here really 
# 
# SpamAssassin: [url]http://spamassassin.apache.org/[/url]
# Rules Du Jour: [url]http://www.exit0.us/index.php?pagename=RulesDuJour[/url]
# Rules Emporium: [url]http://www.rulesemporium.com/[/url]
# Directadmin: [url]http://www.directadmin.com/[/url]
# Please note that you need to have Directadmin's SA version installed for this script to work,
# Refer to the How to Install SA in Rules Du Jour
# Although you can use it for any version by using the --sa_dir option , it has not been tested! 


use strict;
use Getopt::Long;

my $error = "";
my %configOptions = ();
my %inputOptions = ();

# Set shell commands
my %CMD = (
	"wget"		=>	"/usr/bin/wget -q",
);


# Set Default Options
&setDefaultOptions();


# Get Options from the command line
GetOptions(	
	"install"		=>	\$inputOptions{install},
	"directadmin"		=>	\$inputOptions{directadmin},
	"directadmin_debian"	=>	\$inputOptions{directadmin_debian},
	"admin_email=s"		=>	\$inputOptions{admin_email},
	"sa_dir=s"		=>	\$inputOptions{sa_dir},
	"sa_restart=s"		=>	\$inputOptions{sa_restart},
	"rdj_url=s"		=>	\$inputOptions{rdj_url},	
	"rdj_config_dir=s"	=>	\$inputOptions{rdj_config_dir},	
	"rdj_script_path=s"	=>	\$inputOptions{rdj_script_path},	
	"cron_file=s"		=>	\$inputOptions{cron_file},
	"cron_hour=s"		=>	\$inputOptions{cron_hour},
	"list_defaults"		=>	\$inputOptions{list_defaults},
	"help"			=>	\$inputOptions{help}
	);
	



# Do It
if (defined $inputOptions{help}) {
	&helpMenu();	
	
	
} elsif (defined $inputOptions{list_defaults}) {
	
	&setDefaultOptions;	
	foreach (keys %configOptions) {
		print $_ . " = " . $configOptions{$_} . "\n";
	}
	

} elsif (defined $inputOptions{install}) {
	
	if(defined $inputOptions{directadmin}) {	
		$configOptions{sa_dir} = "/etc/mail/spamassassin/";
		$configOptions{sa_restart} = "/sbin/service exim restart";
	}
	if(defined $inputOptions{directadmin_debian}) {	
		$configOptions{sa_dir} = "/etc/mail/spamassassin/";
		$configOptions{sa_restart} = "/etc/init.d/exim restart";
	}
	if(&setFinalOptions()) {
		if(&checkVars()) {
			print "\n";
			if(&install()) {
				print "\n\n";
				print "[FAILURE] There was an error during installation\n";
				print $error;
				print "\n\n";
				exit 1;
			} else {
				print "\n";
				print "[SUMMARY] The script completed successfully\n";
				print " + RDJ SCRIPT: $configOptions{rdj_script_path}\n";
				print " + RDJ CONFIG: " .  $configOptions{rdj_config_dir} . "/config\n";
				print " + RDJ CRONFILE: " . $configOptions{cron_file} . "\n";
				print " + RDJ CRONHOUR: " . $configOptions{cron_hour} . "\n";
				print " + SA RULES DIR: " .  $configOptions{sa_dir} . "\n";

				print "\n";
				print "[CONFIGURATION NOTE] Please read the following\n";
				print " + Please note that Rules Du Jour has been configured with\n";
				print " + fairly strict TRUSTED_RULESETS.  Please edit the configuration\n";
				print " + file to modify this setting\n\n";
				print "\n\n";
				print " + Would you like to run rules_du_jour now? (type \"yes\"):    ";
				my $response = <>;
				chomp $response;
				if ($response eq "yes") {
					system($configOptions{rdj_script_path});
				} else {
					print "\n\n[WHAT?]  Invalid response\n";
					print " + You did not respond \"yes\".  Please run rules_du_jour manually\n";
					print " + Command: $configOptions{rdj_script_path}\n";
					print " + Thank you, come again\n\n";
				}
			}
		} else {
			print "\n";
			print "[FAILURE] There was a failure before installation\n";
			print $error;
			print "\n\n";
			exit 1;
		}
	} else {
		print "\n";
		print "[FAILURE] There was a failure before installation\n";
		print " + Unknown error\n";
		print "\n\n";
		exit 1;
	}
											 

} else {
	&helpMenu();

}





#
# Sub Routines
#

sub helpMenu() {

	my $option = "";
	my $description = "";
	my %helpTable;

	print "\n";
	print "USAGE:\n\n";
	print "./installRDJ.pl --install [--flag] [--option=\"value\"]\n";
	print "\n----------------------------------------------------------------\n";

			
format STDOUT =
@<<<<<<<<<<<<<<<    @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$option,			$description

.
	
	%helpTable = (
		"OPTION"		=>	"DESCRIPTION",
		"--install"		=>	"Install Rules Du Jour",
		"--directadmin"		=>	"Overrides Directadmin Specific Options (--sa_dir, --sa_restart)",
		"--directadmin_debian"	=>	"Overrides Directadmin Specific Options For Debian(--sa_dir, --sa_restart)",
		"--admin_email" 	=>  	"Email where reports are sent to (default: root)",
		"--sa_dir"		=>	"SpamAssassin Config Dir (default: /etc/spamassassin)",
		"--sa_restart"		=>	"Command executed after update",
		"--rdj_url"		=>	"URL to the Rules Du Jour script",
		"--rdj_config_dir"	=>	"Config dir for Rules Du Jour (default: /etc/rulesdujour)",
		"--rdj_script_path"	=>	"Rules Du Jour script path", 
		"--cron_file"		=>	"File that cronjob is created in",
		"--cron_hour"		=>	"Hour that Rules Du Jour runs during the day",
		"--list_defaults"	=>	"List The default options to this script",
		"--help"		=>	"You're looking at it"
	);


	foreach (keys %helpTable) {
		$option = $_;
		$description = $helpTable{$_};
		write();
	}

	print "\n----------------------------------------------------------------\n";
	print "\n";
	print "Example 1:  ./installRDJ.pl --install\n\n";
	print "Example 2:  ./installRDJ.pl --install --directadmin --admin_email=johnny\@domain.com\n\n";
	print "\n----------------------------------------------------------------\n\n";
	print "Original Author maybe contacted at:BJ Dierkes <wdierkes\@5dollarwhitebox.org>\n\n";
        print "Directadmin Mod questions can be directed to fastattack in the Directadmin Forum \n\n";

}


sub install() {

	print "[INSTALL] We are now continuing with installation . . .\n";
	


	# Get the script
	my $cmd = $CMD{wget} . " " . $configOptions{rdj_url};
	print " + \"$cmd\":    ";
	if(system($cmd)) {
		print "[FAILED]\n";
		$error .= " + Command Failed:  \"${cmd}\"\n";
		return 1;
	} else {
		print "OK\n";
	}
	
	# Install Script 
	$cmd = "mv rules_du_jour " . $configOptions{rdj_script_path};
	print " + \"$cmd\":    ";
	unless(rename "rules_du_jour", $configOptions{rdj_script_path}) {
		print "[FAILED]\n";
		$error .= " + Command Failed:  \"${cmd}\"\n";
		return 1;
	} else {
		print "OK\n";
	}
	
	# Chmod Script 
	$cmd = "chmod 750 " . $configOptions{rdj_script_path};
	print " + \"$cmd\":    ";
	unless(chmod 0750, $configOptions{rdj_script_path}) {
		print "[FAILED]\n";
		$error .= " + Command Failed:  \"${cmd}\"\n";
		return 1;
	} else {
		print "OK\n";
	}

	# Create the config
	my $config_file = $configOptions{rdj_config_dir} . "/config";
	
	if(!-e $configOptions{rdj_config_dir}) {
		print " + \"mkdir $configOptions{rdj_config_dir}\":    ";
		unless(mkdir $configOptions{rdj_config_dir}, 750) {
			print "FAILED";
			$error .= " + Failed to create directory: $configOptions{rdj_config_dir}\n";
			return 1;
		} else {
			print "OK\n";
		}
	} else {
		print " + Config dir \"$configOptions{rdj_config_dir}\" already exists\n";
	}

	if(-e $config_file) {
		print " + $config_file exists, moving to ${config_file}.bak:    ";
		unless(rename "$config_file", "${config_file}.bak") {
			print "FAILED\n";
			$error .= " + Error backing up \"$config_file\"\n";
			return 1;
		} else {
			print "OK\n";
			&createConfigFile();
		}
	} else {
		&createConfigFile();
	}

	
	# Create Cron Job
	my $cron_file = $configOptions{cron_file};

	if (-e $cron_file) {
		print " + Cron file \"$cron_file\" exists, moving to \"/root/rules_du_jour_cronjob.bak\":    ";
		unless(rename "$cron_file", "/root/rules_du_jour_cronjob.bak") {
			print "FAILED\n";
			$error .= " + Error backing up \"$cron_file\"\n";
			return 1;
		} else {
			print "OK\n";
			if(&createCronFile()) {
				return 1;
			} else {
				return 0;
			}
		}
	} else {
		if(&createCronFile()) {
			return 1;
		} else {
			return 0;
		}
	}

}


sub createCronFile() {
	my $cron_file = $configOptions{cron_file};
	print " + Creating Cronjob File: \"$configOptions{cron_file}\":    ";
	
	unless(open(CRONFILE, ">$cron_file")) {
		print "FAILED\n";
		$error .= " + Error creating cronjob file: \"$cron_file\"\n";
		return 1;
	} else {
		print CRONFILE "1 " . $configOptions{cron_hour} . " * * * root " . $configOptions{rdj_script_path} . " 2>&1 >> /dev/null\n";
		close (CRONFILE);
		print "OK\n";
		return 0;
	}
	
}



sub createConfigFile() {

	my $config_file = $configOptions{rdj_config_dir} . "/config";

	print " + Creating config file: \"$configOptions{rdj_config_dir}" . "/config\":    "; 

	unless(open(CONFIGFILE, ">$config_file")) { 
		print "FAILED\n";
		$error .= " + Error creating config file: $config_file\n";
		return 1;
	} else {

		print CONFIGFILE "SA_DIR=\"" . $configOptions{sa_dir} . "\"\n";
		print CONFIGFILE "MAIL_ADDRESS=\"" . $configOptions{admin_email} . "\"\n";
		print CONFIGFILE "SINGLE_EMAIL_ONLY=\"true\"\n";
		print CONFIGFILE "SA_RESTART=\"" . $configOptions{sa_restart} . "\"\n\n";
		print CONFIGFILE "# Ruleset descriptions found at [url]http://www.rulesemporium.com\n[/url]";
		print CONFIGFILE "TRUSTED_RULESETS=\"TRIPWIRE ANTIDRUG SARE_EVILNUMBERS0 RANDOMVAL SARE_ADULT SARE_FRAUD SARE_BML SARE_SPOOF SARE_BAYES_POISON_NXM SARE_OEM SARE_RANDOM SARE_OBFU0 SARE_SPAMCOP_TOP200\"\n";
		close (CONFIGFILE);
		print "OK\n";
	}

}



sub setDefaultOptions() {

	# Set the defaults
	%configOptions = (
		"admin_email"		=>	"root\@localhost",
		"sa_dir"		=>	"/etc/mail/spamassassin",
		"sa_restart"		=>	"/etc/init.d/spamassassin restart",
		"rdj_url"		=>	"http:\/\/sandgnat.com/rdj/rules_du_jour",
		"rdj_config_dir"	=>	"/etc/rulesdujour",
		"rdj_script_path"	=>	"/usr/local/sbin/rules_du_jour",
		"cron_hour"		=>	"1",
		"cron_file"		=>	"/etc/cron.d/rules_du_jour"
		);

}


# Put the user supplied options into effect
sub setFinalOptions() {
	foreach (keys %inputOptions) {
		$configOptions{$_} = $inputOptions{$_} if (defined $inputOptions{$_});
	}
	return 1;
}



# Check variables and settings
sub checkVars () {

	print "[CHECK] Checking Vars to avoid error\n";
	
	# Make sure we have a SpamAssassin Installation
	print " + " . $configOptions{sa_dir} . " Exist:    ";
	if (-e $configOptions{sa_dir}) {
		print "OK\n";
	} else {
		print "FAILED\n";
		$error .= " + SpamAssassin Dir \"$configOptions{sa_dir}\" doesn't exists\n";
	} 

	# Make sure we have commands 
	foreach (keys %CMD) {
		my @line = split(' ', $CMD{$_});
		
		my $tmp_command = $line[0];
		print " + " . $tmp_command . " Exists:    ";
		if (-e $tmp_command) {
			print "OK\n";
		} else {
			print "FAILED\n";
			$error .= " + Command \"$tmp_command\" doesn't exists\n";
		} 
	}
	
	# Make sure the SA_RESTART command exists 
	my @line = split(' ', $configOptions{sa_restart});
		
	my $tmp_command = $line[0];
	print " + " . $tmp_command . " Exists:    ";
	if (-e $tmp_command) {
		print "OK\n";
	} else {
		print "FAILED\n";
		$error .= " + Command \"$tmp_command\" doesn't exists\n";
	}

	if ($error ne "") {
		return 0; 
	} else {
		return 1;
	}

}

the above is untested.. I haven't even ran it through the compiler to see if my rusty coding works..
lol
\
 
Hi,

When running RDJ the script generates a line:
curl_output: 304

What does this mean?


and i am getting an daily email with the following notification:

Subject of the mail: Cron <root@mydomain> /usr/local/sbin/rules_du_jour 2>&1 >>
/dev/null

Content of the mail:
sh: mail: command not found

Somehow something is wrong? Can anyone help here?
Thank you
 
Heuveltje said:
Hi,

When running RDJ the script generates a line:
curl_output: 304

What does this mean?


and i am getting an daily email with the following notification:

Subject of the mail: Cron <root@mydomain> /usr/local/sbin/rules_du_jour 2>&1 >>
/dev/null

Content of the mail:
sh: mail: command not found

Somehow something is wrong? Can anyone help here?
Thank you

what flavor of Linux are you running?
 
I think the general idea of the rules_du_jour cron job is to update the rule sets. When this is done the script probably wants to send out a confirmation on what has been changed. This action generates this faulty email.

So i dont want to disable this ruleset, because it is not a ruleset. The cron generates this error, simply said it think it somehow cant find the mail program. But since i have no knowledge of cronjobs i ask here :)
 
The mail command is the command that you use to send email from the command line.

A default (even minimal) CentOS command should have the mail command.

Try, logging in as shell as admin:

$ mail

and

again as root:

# mail

(you do not type the $ or the #; they're just to show you're either root or not)

and see if you get something or an error. If you get an error you may not have a proper installation.

Either way, exit the program with control-C, and then do:

$ whereis mail

and post the results.

Jeff
 
Heuveltje said:
I think the general idea of the rules_du_jour cron job is to update the rule sets. When this is done the script probably wants to send out a confirmation on what has been changed. This action generates this faulty email.

So i dont want to disable this ruleset, because it is not a ruleset. The cron generates this error, simply said it think it somehow cant find the mail program. But since i have no knowledge of cronjobs i ask here :)
it does send out a daily digest to root user

if you want to edit the user email after using this install script you can go to bin folder and edit the rules_du_jour script via nano or your favorite editor.. and look for the email to line.
 
hehachris said:
is it possible to remove the rules set?

you can add or remove the rule sets you want to use, although I don't know why you would remove them, I would probably add upon the rules sets

to edit the rules set you can just edit the script to add your own trusted sets.
 
Back
Top