Skip to content

Instantly share code, notes, and snippets.

@rushipkar90
Last active September 25, 2015 16:29
Show Gist options
  • Save rushipkar90/f15e3eca59fef46dd807 to your computer and use it in GitHub Desktop.
Save rushipkar90/f15e3eca59fef46dd807 to your computer and use it in GitHub Desktop.
disablemodsecurity.sh
## Script By Aress Guys ##
## Verifying Parameters ##
if [[ "$1" == *.* || "$1" == *.*.* && $2 != "" && "$3" == "ssl" || "$3" == 'std' ]]; then
echo "!! Wait !!"
echo ""
sleep 1
else
echo "Incorrect Parameters"
echo ""
echo "Usage : sh disablemodsecurity.sh <domain name> <ID> <ssl or std>"
exit 1
fi
## Verifiying User in two levels ##
username=$(cat /etc/userdomains |grep -m 1 $1 | awk '{print $2}')
if [[ $username == "" ]];then
echo "!!!! Incorrect Domain Name !!!!"
exit
else
if [ ! -d /home/$username ]; then
echo "Something is wrong ; there is folder of user $username in /home"
exit
fi
fi
## Main Code ##
if [[ $3 == std ]];then
if [[ ! -d "/usr/local/apache/conf/userdata/std/2/$username/$1" ]]; then
echo "User directory doesn't exists! Creating !"
path="/usr/local/apache/conf/userdata/std/2/$username/$1"
mkdir -p "$path"
echo "Creating modsecurity file"
touch /usr/local/apache/conf/userdata/std/2/$username/$1/mod_security2.conf
echo "Adding Code"
echo SecRuleRemoveById $2 >> /usr/local/apache/conf/userdata/std/2/$username/$1/mod_security2.conf
echo "Rule $2 has been disabled"
restartservice=1
else
if [[ ! -f /usr/local/apache/conf/userdata/std/2/$username/$1/mod_security2.conf ]]; then
touch /usr/local/apache/conf/userdata/std/2/$username/$1/mod_security2.conf
fi
n=$(/bin/egrep -w $2 /usr/local/apache/conf/userdata/std/2/$username/$1/mod_security2.conf |sort -u)
if [[ $n == "" ]]; then
echo SecRuleRemoveById $2 >> /usr/local/apache/conf/userdata/std/2/$username/$1/mod_security2.conf
echo "Disabled rule $2"
restartservice=1
else
echo "Rule ID $2 is already disabled"
fi
fi
else
if [[ ! -d "/usr/local/apache/conf/userdata/ssl/2/$username/$1" ]]; then
echo "User directory doesn't exists! Creating !"
path="/usr/local/apache/conf/userdata/ssl/2/$username/$1"
mkdir -p "$path"
echo "Creating modsecurity file"
touch /usr/local/apache/conf/userdata/ssl/2/$username/$1/mod_security2.conf
echo "Adding Code"
echo SecRuleRemoveById $2 >> /usr/local/apache/conf/userdata/ssl/2/$username/$1/mod_security2.conf
echo "Rule $2 has been disabled"
restartservice=1
else
if [[ ! -f /usr/local/apache/conf/userdata/ssl/2/$username/$1/mod_security2.conf ]]; then
touch /usr/local/apache/conf/userdata/ssl/2/$username/$1/mod_security2.conf
fi
n=$(/bin/egrep -w $2 /usr/local/apache/conf/userdata/ssl/2/$username/$1/mod_security2.conf |sort -u)
if [[ $n == "" ]]; then
echo SecRuleRemoveById $2 >> /usr/local/apache/conf/userdata/ssl/2/$username/$1/mod_security2.conf
echo "Disabled rule $2"
restartservice=1
else
echo "Rule ID $2 is already disabled"
fi
fi
fi
if [[ "$restartservice" == 1 ]];then
echo "Restaring service"
/scripts/ensure_vhost_includes --user=$username
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment