Skip to content

Instantly share code, notes, and snippets.

@ArnaudD
Created March 15, 2011 13:31
Show Gist options
  • Save ArnaudD/870716 to your computer and use it in GitHub Desktop.
Save ArnaudD/870716 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Script utilisé pour ajouter des exceptions mod_security aux vhost en test
DEBUG=1
VHOST_BASEDIR='/nfsconfig/apache2/sites-available/'
function usage
{
echo
echo -e "Usage: \e[1m$(basename $0) <vhost> <modsec_rule_id> \e[0m"
echo " Ce script est utilisé pour ajouter des exceptions mod_security aux vhost en test"
echo
}
# Vérification des options
# ========================
# erreur si :
# - il n'y a pas exactement 2 arguments
# - le deuxième argument n'est pas un entier
# - le fichier du vhost n'existe pas
if [[ $# != 2 || $2 =~ '[^[:digit:]]' ]]; then
echo "erreur d'argument"
usage
exit 1
fi
VHOST="${VHOST_BASEDIR}$1"
if [[ ! -e "$VHOST" ]]; then
echo "Le virtual host '$VHOST' n'existe pas !"
usage
exit 1
fi
NEW_CONF=$(cat $VHOST | sed "0,/SecRuleRemoveById .*/s/\(SecRuleRemoveById.*\)/\1\n\tSecRuleRemoveById $2/")
if [[ $DEBUG == 1 ]]; then
echo "$NEW_CONF"
else
echo "$NEW_CONF" > $VHOST
/etc/init.d/apache2 reload
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment