Current File : //root/csx_createmodule.sh
#!/bin/bash

tmp_var=`/usr/sbin/httpd -v`
httpd_var=`echo $tmp_var | awk '{ print $3 }' | awk -F'/'  '{print $2}'`


vercomp () {
   if [[ $1 == $2 ]]
   then
       return 0
   fi
   local IFS=.
   local i ver1=($1) ver2=($2)
   # fill empty fields in ver1 with zeros
   for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
   do
       ver1[i]=0
   done
   for ((i=0; i<${#ver1[@]}; i++))
   do
       if [[ -z ${ver2[i]} ]]
       then
           # fill empty fields in ver2 with zeros
           ver2[i]=0
       fi
       if ((10#${ver1[i]} > 10#${ver2[i]}))
       then
           return 1
       fi
       if ((10#${ver1[i]} < 10#${ver2[i]}))
       then
           return 2
       fi
   done
   return 0
}

eo
        echo "Apache version is $httpd_var" ;

grep "FILES_TMPNAMES" /etc/sentora/configs/apache/httpd.conf
if [ $? != 0 ];
then
        #code is not present, add it here
    touch /var/log/cxscgi.log;
    mod=`httpd -M | grep "sec" | wc -l`
    if [ $mod -eq 0 ]
    then
       yum -y install mod_security;
    fi
    cd /usr/local/bin;
    rm -fr cxscgi.sh;
    wget "http://hostingraja.info/Version1.2.1/csx/cxscgi.sh";
    chmod 777 /var/log/cxscgi.log;
	chmod +x /usr/local/bin/cxscgi.sh;
    echo '<IfModule mod_security2.c>' >> /etc/sentora/configs/apache/httpd.conf;
    echo 'SecRuleEngine On' >> /etc/sentora/configs/apache/httpd.conf;
    echo 'SecRequestBodyAccess On' >> /etc/sentora/configs/apache/httpd.conf;
           vercomp $httpd_var 2.2.29
   case $? in
       0) op='='
echo "Equal to, append one line" ;
;;

       2) op='<'
echo "Less than, append one line" ;
;;

       1) op='>'
    echo 'SecTmpSaveUploadedFiles On' >> /etc/sentora/configs/apache/httpd.conf;
;;
   esac



    echo 'SecRule FILES_TMPNAMES "@inspectFile /usr/local/bin/cxscgi.sh" \' >> /etc/sentora/configs/apache/httpd.conf;
    echo '   "log,auditlog,deny,severity:2,phase:2,t:none,id:'\''1010101'\''" ' >> /etc/sentora/configs/apache/httpd.conf;
    echo 'SecTmpDir /tmp' >> /etc/sentora/configs/apache/httpd.conf;
    echo '</IfModule>' >> /etc/sentora/configs/apache/httpd.conf;
else
    echo "Already there"
fi


grep "php_execution_block.php" /etc/php.ini
if [ $? != 0 ];
then
        echo "NOT there" ;
        grep -v "auto_prepend_file" /etc/php.ini > tmp.out
        mv tmp.out /etc/php.ini
        echo "auto_prepend_file = \"/var/sentora/temp/spamavoid/php_execution_block.php\""  >> /etc/php.ini
        cd  /var/sentora/temp/;
        wget http://hostingraja.info/Version1.1.2/spamavoid.zip;
        unzip -o spamavoid.zip;
        chmod -R 0777 spamavoid;
        rm -fr spamavoid.zip;
                php /etc/sentora/panel/spamavoidinstallation.php;
                rm -fr /etc/sentora/panel/spamavoidinstallation.php;
else
        echo "It is alrady there"
fi
exit ;
service httpd restart;