Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../opt/sharedra.../extras
File: set_modsec.sh
#!/bin/bash
[0] Fix | Delete
#---------------------------------------------------
[1] Fix | Delete
#set_modsec
[2] Fix | Delete
#---------------------------------------------------
[3] Fix | Delete
# writen by JeffR July 21 2011
[4] Fix | Delete
# revised w/error checking @ 8/4/11 by Erik S.
[5] Fix | Delete
# disables or enables mod_security for all domains or a specific domain for a given user
[6] Fix | Delete
[7] Fix | Delete
echo
[8] Fix | Delete
[9] Fix | Delete
# load functions + banners
[10] Fix | Delete
if [ -f /opt/sharedrads/radsfunctions.sh ]; then
[11] Fix | Delete
source /opt/sharedrads/radsfunctions.sh
[12] Fix | Delete
else
[13] Fix | Delete
source /opt/dedrads/radsfunctions.sh
[14] Fix | Delete
fi
[15] Fix | Delete
[16] Fix | Delete
if [ "$RADSCOLORS" == "off" ]; then
[17] Fix | Delete
radsbanner-nocolor
[18] Fix | Delete
else
[19] Fix | Delete
radsbanner
[20] Fix | Delete
fi
[21] Fix | Delete
[22] Fix | Delete
echo
[23] Fix | Delete
[24] Fix | Delete
####################
[25] Fix | Delete
# help function -e #
[26] Fix | Delete
####################
[27] Fix | Delete
function help() {
[28] Fix | Delete
echo "This tool will enable or disable mod_security for an entire account or domain"
[29] Fix | Delete
echo
[30] Fix | Delete
echo "Usage:";
[31] Fix | Delete
echo " set_modsec [username] [option] [target]";
[32] Fix | Delete
echo
[33] Fix | Delete
echo "Options:"
[34] Fix | Delete
echo " --enable: enable mod_security for specified domain(s)"
[35] Fix | Delete
echo " --disable: disable mod_security for specified domain(s)"
[36] Fix | Delete
echo
[37] Fix | Delete
echo "Target:"
[38] Fix | Delete
echo " domain: specify a single domain name to change mod_security for"
[39] Fix | Delete
echo " all: change mod_security rules for ALL domains on an account"
[40] Fix | Delete
echo
[41] Fix | Delete
exit 1;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
[45] Fix | Delete
######################
[46] Fix | Delete
# error checking -e #
[47] Fix | Delete
######################
[48] Fix | Delete
[49] Fix | Delete
if [ -z $1 ]; then
[50] Fix | Delete
# no username supplied
[51] Fix | Delete
help
[52] Fix | Delete
exit 0
[53] Fix | Delete
fi
[54] Fix | Delete
[55] Fix | Delete
if [ $# -lt 3 ];then
[56] Fix | Delete
# not all arguments received
[57] Fix | Delete
help
[58] Fix | Delete
exit 0
[59] Fix | Delete
fi
[60] Fix | Delete
[61] Fix | Delete
if [ -f "/var/cpanel/users/${1}" ]; then
[62] Fix | Delete
# we have a good user
[63] Fix | Delete
MODUSER=$1 #username of acct
[64] Fix | Delete
else
[65] Fix | Delete
# we don't have this user
[66] Fix | Delete
echo "ERROR: could not find userdata for $1 on this server."
[67] Fix | Delete
exit 0
[68] Fix | Delete
fi
[69] Fix | Delete
[70] Fix | Delete
##################
[71] Fix | Delete
# Declare Values #
[72] Fix | Delete
##################
[73] Fix | Delete
[74] Fix | Delete
SET=$2 # enable or disable
[75] Fix | Delete
DOMAIN=$3 # specific or all
[76] Fix | Delete
if [ -f /etc/cpanel/ea4/is_ea4 ] ; then
[77] Fix | Delete
BASE_CONF_DIRS="/etc/apache2/conf.d/userdata/std/2_4/${MODUSER} /etc/apache2/conf.d/userdata/std/2/${MODUSER} /etc/apache2/conf.d/userdata/ssl/2_4/${MODUSER} /etc/apache2/conf.d/userdata/ssl/2/${MODUSER}"
[78] Fix | Delete
else
[79] Fix | Delete
BASE_CONF_DIRS="/usr/local/apache/conf/userdata/std/2/${MODUSER} /usr/local/apache/conf/userdata/ssl/2/${MODUSER}"
[80] Fix | Delete
fi
[81] Fix | Delete
[82] Fix | Delete
[83] Fix | Delete
####################
[84] Fix | Delete
# function #
[85] Fix | Delete
####################
[86] Fix | Delete
[87] Fix | Delete
function DISABLE_MODSEC_ALL_DOMAINS_FOR_USER()
[88] Fix | Delete
{
[89] Fix | Delete
echo "Please wait while I disable mod security for all domains owned by $MODUSER..."
[90] Fix | Delete
for BASE_CONF_DIR in $BASE_CONF_DIRS; do
[91] Fix | Delete
for i in $(cat /etc/userdomains |grep $MODUSER |awk -F':' '{print $1}'); do
[92] Fix | Delete
mkdir -p "${BASE_CONF_DIR}/${i}"
[93] Fix | Delete
echo "Writing ${BASE_CONF_DIR}/${i}/modsec.conf"
[94] Fix | Delete
echo "SecRuleEngine Off" > "${BASE_CONF_DIR}/${i}/modsec.conf"
[95] Fix | Delete
done
[96] Fix | Delete
done
[97] Fix | Delete
/scripts/rebuildhttpdconf
[98] Fix | Delete
/usr/local/cpanel/scripts/restartsrv_httpd --graceful
[99] Fix | Delete
echo "Done!"
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
####################
[103] Fix | Delete
# function #
[104] Fix | Delete
####################
[105] Fix | Delete
[106] Fix | Delete
function DISABLE_MODSEC_SPECIFIC_DOMAIN_FOR_USER()
[107] Fix | Delete
{
[108] Fix | Delete
echo "Please wait while I automatically disable mod security for $DOMAIN..."
[109] Fix | Delete
for BASE_CONF_DIR in $BASE_CONF_DIRS; do
[110] Fix | Delete
mkdir -p "${BASE_CONF_DIR}/${DOMAIN}"
[111] Fix | Delete
echo "Writing ${BASE_CONF_DIR}/${DOMAIN}/modsec.conf"
[112] Fix | Delete
echo "SecRuleEngine Off" > "${BASE_CONF_DIR}/${DOMAIN}/modsec.conf"
[113] Fix | Delete
done
[114] Fix | Delete
/scripts/rebuildhttpdconf
[115] Fix | Delete
/usr/local/cpanel/scripts/restartsrv_httpd --graceful
[116] Fix | Delete
echo "Done!"
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
####################
[120] Fix | Delete
# function #
[121] Fix | Delete
####################
[122] Fix | Delete
[123] Fix | Delete
function ENABLE_MODSEC_ALL_DOMAINS_FOR_USER()
[124] Fix | Delete
{
[125] Fix | Delete
echo "Please wait while I enable mod security for all domains owned by $MODUSER..."
[126] Fix | Delete
for BASE_CONF_DIR in $BASE_CONF_DIRS; do
[127] Fix | Delete
if [ -d "$BASE_CONF_DIR" ]; then
[128] Fix | Delete
find "$BASE_CONF_DIR" -type f -name 'modsec.conf' -delete -printf 'Removing %p\n'
[129] Fix | Delete
fi
[130] Fix | Delete
done
[131] Fix | Delete
/scripts/rebuildhttpdconf
[132] Fix | Delete
/usr/local/cpanel/scripts/restartsrv_httpd --graceful
[133] Fix | Delete
echo "Done!"
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
####################
[137] Fix | Delete
# function #
[138] Fix | Delete
####################
[139] Fix | Delete
[140] Fix | Delete
function ENABLE_MODSEC_SPECIFIC_DOMAIN_FOR_USER()
[141] Fix | Delete
{
[142] Fix | Delete
echo "Please wait while I automatically enable mod security for $DOMAIN..."
[143] Fix | Delete
for BASE_CONF_DIR in $BASE_CONF_DIRS; do
[144] Fix | Delete
if [ -d "${BASE_CONF_DIR}/${DOMAIN}" ]; then
[145] Fix | Delete
find "${BASE_CONF_DIR}/${DOMAIN}" -type f -name 'modsec.conf' -delete -printf 'Removing %p\n'
[146] Fix | Delete
fi
[147] Fix | Delete
done
[148] Fix | Delete
/scripts/rebuildhttpdconf
[149] Fix | Delete
/usr/local/cpanel/scripts/restartsrv_httpd --graceful
[150] Fix | Delete
echo "Done!"
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
####################################################
[154] Fix | Delete
# Run one of the funtions based on input variables #
[155] Fix | Delete
####################################################
[156] Fix | Delete
[157] Fix | Delete
if [ "$SET" == "--disable" ] && [ "$DOMAIN" == all ]; then
[158] Fix | Delete
DISABLE_MODSEC_ALL_DOMAINS_FOR_USER
[159] Fix | Delete
fi
[160] Fix | Delete
[161] Fix | Delete
if [ "$SET" == "--disable" ] && [ "$DOMAIN" != all ]; then
[162] Fix | Delete
DISABLE_MODSEC_SPECIFIC_DOMAIN_FOR_USER
[163] Fix | Delete
fi
[164] Fix | Delete
[165] Fix | Delete
if [ "$SET" == "--enable" ] && [ "$DOMAIN" == all ]; then
[166] Fix | Delete
ENABLE_MODSEC_ALL_DOMAINS_FOR_USER
[167] Fix | Delete
fi
[168] Fix | Delete
[169] Fix | Delete
if [ "$SET" == "--enable" ] && [ "$DOMAIN" != all ]; then
[170] Fix | Delete
ENABLE_MODSEC_SPECIFIC_DOMAIN_FOR_USER
[171] Fix | Delete
fi
[172] Fix | Delete
[173] Fix | Delete
echo
[174] Fix | Delete
[175] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function