#!/bin/bash
#Apache version
HTTPD=`ps aux|grep http|grep bin|head -1|awk '{ print $11}'`
VERSION=`$HTTPD -V|grep version|awk '{print $3}'|cut -d"/" -f2|cut -d"." -f1`
echo -e "\e[0;31m Apache $VERSION \e[0m is running in the server"
APACHE_CONF=`$HTTPD -V|grep HTTPD_ROOT|cut -d"=" -f2|sed s/\"//gi`\/`httpd -V|grep SERVER_CONFIG_FILE|cut -d"=" -f2|sed s/\"//g`
if [ "`grep mod_evasive $APACHE_CONF`" ]
then
echo "mod_evasive is already installed in the server"
exit
else "Starting installation of mod_evasive"
fi
echo "Downloading source..."
cd /usr/src
wget http://www.zdziarski.com/projects/mod_evasive/mod_evasive_1.10.1.tar.gz
if [ -f /usr/src/mod_evasive_1.10.1.tar.gz ]
then
tar xfz mod_evasive_1.10.1.tar.gz
cd mod_evasive
else
echo -e "\e[0;31m ERROR: Could not download source \e[0m"
fi
# Need to install httpd-devel in Plesk server
if [ -d /usr/local/psa ]
then
yum install httpd-devel*
fi
APXS=`ps aux|grep http|grep bin|head -1|awk '{ print $11}'|sed s/httpd/apxs/g`
#Add the directives in apache conf
case $VERSION
in
1) $APXS -cia mod_evasive.c ;
echo \
echo DOSHashTableSize 3097 >>$APACHE_CONF;
echo DOSPageCount 6 >>$APACHE_CONF;
echo DOSSiteCount 100 >>$APACHE_CONF;
echo DOSPageInterval 2 >>$APACHE_CONF;
echo DOSSiteInterval 2 >>$APACHE_CONF;
echo DOSBlockingPeriod 600 >>$APACHE_CONF;
echo \
2) $APXS -cia mod_evasive20.c ;
echo \
echo DOSHashTableSize 3097 >>$APACHE_CONF;
echo DOSPageCount 6 >>$APACHE_CONF;
echo DOSSiteCount 100 >>$APACHE_CONF;
echo DOSPageInterval 2 >>$APACHE_CONF;
echo DOSSiteInterval 2 >>$APACHE_CONF;
echo DOSBlockingPeriod 600 >>$APACHE_CONF;
echo \
*) echo -e "\e[0;31mERROR: Apache version is not compatible\e[0m"
esac
#Restart Apache
service httpd restart
echo -e "\e[0;31m Mod_evasive is installed successfully..\e[0m"