1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
#!/bin/sh
################################################################################
# #
# Copyright (C) 2008-2014 LABBE Corentin <clabbe.montjoie@gmail.com>
#
# YASAT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YASAT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YASAT. If not, see <http://www.gnu.org/licenses/>.
# #
################################################################################
#for LOCATION in ${POSSIBLE_APACHE_CONFIG_LOCATION}
#do
# if [ -d "${LOCATION}/" ]
# then
# APACHE_CONF_REP="${LOCATION}"
# fi
#done
Find_apache_conf_location
Title "Check Apache configuration"
TESTNAME='YASAT_TEST_APACHE_CONF_1 test the presence of apache.conf'
if [ ! -d "$APACHE_CONF_REP" ] ;then
Display --indent 2 --text "No apache found" --result NOTFOUND --color BLUE
return 1;
else
Display --indent 2 --text "$APACHE_CONF_REP " --result FOUND --color GREEN
fi
prepare_apache_conf $APACHE_CONF_REP
APACHE_CONF_LOCATION_TO_TEST="${TEMPYASATDIR}/apache.conf"
if [ ! -e "$APACHE_CONF_LOCATION_TO_TEST" ] ;then
echo "Error no $APACHE_CONF_LOCATION_TO_TEST"
return 1;
fi
if [ -e "${PLUGINS_REP}/apache_conf.data" ] ;then
for i in `grep -v '^\#' $PLUGINS_REP/apache_conf.data`
do
ldirective=`echo $i | cut -f1 -d\|`
lparam=`echo $i | cut -f2 -d\|`
loption=`echo $i | cut -f3 -d\|`
ltestoptional=`echo $i | cut -f4 -d\|`
OPT_ADVICE=''
OPT_ADVICE="`echo $i | cut -f5 -d\|`"
lnsagid="`echo $i | cut -f6 -d\|`"
lcceid="`echo $i | cut -f7 -d\|`"
if [ -z "$lnsagid" ] ; then
lnsagid=0
fi
if [ -z "$lcceid" ] ; then
lcceid=0
fi
# FindValueOf $APACHE_CONF_REP $ldirective JUSTTEST
FindValueOf $APACHE_CONF_LOCATION_TO_TEST $ldirective JUSTTEST
if [ -z "$RESULTAT" ] ; then
if [ -z "$FINDERROR" ] ; then
if [ "$ltestoptional" = "Y" ] ; then
Display --indent 2 --text "Missing declaration of $ldirective " --result OPTIONAL --color BLUE
else
Display --indent 2 --text "Missing declaration of $ldirective " --result WARNING --color RED --advice $OPT_ADVICE
fi
else
if [ "$FINDERROR" = 'MULTIPLE' ] ; then
Display --indent 2 --text "Multiple declaration of $ldirective " --result WARNING --color RED --advice $OPT_ADVICE
else
echo "Arg a bug, unknown FINDERROR";
fi
fi
else
VAL="$RESULTAT"
case $loption in
S)#string equal
if [ "$VAL" != "$lparam" ] ;then
Display --indent 2 --text "$ldirective != $lparam" --result "$VAL" --color RED --advice "$OPT_ADVICE"
Compliance --result NOK --plugin apache --nsag $lnsagid --cce $lcceid
else
Display --indent 2 --text "$ldirective " --result "$VAL" --color GREEN
Compliance --result OK --plugin apache --nsag $lnsagid --cce $lcceid
fi
;;
s)
#string equal case insensitive
VAL=`echo $RESULTAT | tr A-Z a-z`
if [ "$VAL" != "$lparam" ] ; then
Display --indent 2 --text "$ldirective != $lparam" --result "$VAL" --color RED --advice "$OPT_ADVICE"
find_file_with_directive "$APACHE_CONF_REP" "^[[:space:]]*$ldirective"
add_correction "sed -i 's/^[[:space:]]*$ldirective.*/$ldirective $lparam/' $RES_FILE_WITH_DIRECTIVE"
Compliance --result NOK --plugin apache --nsag $lnsagid --cce $lcceid
else
Display --indent 2 --text "$ldirective " --result "$VAL" --color GREEN
Compliance --result OK --plugin apache --nsag $lnsagid --cce $lcceid
fi
;;
snot)#not string case insensitive
VAL=`echo $RESULTAT | tr A-Z a-z`
if [ "$VAL" = "$lparam" ]
then
Display --indent 2 --text "$ldirective != $lparam" --result "$VAL" --color RED --advice "$OPT_ADVICE"
else
Display --indent 2 --text "$ldirective " --result "$VAL" --color GREEN
fi
;;
NM)#Numeric max
### FindValueOf $APACHE_CONF_REP $ldirective
if [ -z "$RESULTAT" ] ;then
Display --indent 2 --text "Missing declaration of $ldirective " --result WARNING --color RED --advice $OPT_ADVICE
else
if [ $RESULTAT -ge $lparam ] ;then
Display --indent 2 --text "$ldirective <= $lparam" --result "$VAL" --color RED --advice $OPT_ADVICE
find_file_with_directive "$APACHE_CONF_REP" "^[[:space:]]*$ldirective"
add_correction "sed -i 's/^[[:space:]]*$ldirective.*/$ldirective $lparam/' $RES_FILE_WITH_DIRECTIVE"
else
Display --indent 2 --text "$ldirective " --result "$VAL" --color GREEN
fi
fi
;;
*)
echo "Unknown option $loption"
;;
esac
fi
done
else
echo "No apache_conf.data"
fi
#ErrorDocument\ 404|/error/http_not_found.html.var|snot|W
FindValueOf $APACHE_CONF_LOCATION_TO_TEST 'ErrorDocument\ 404' JUSTTEST
if [ ! -z "$RESULTAT" ];then
if [ "$RESULTAT" = '/error/HTTP_NOT_FOUND.html.var' ] ;then
Display --indent 2 --text "ErrorDocument 404" --result FOUND --color ORANGE --advice APACHE_ERRORDOC_CUSTOM
fi
else
Display --indent 2 --text "ErrorDocument 500" --result NOTFOUND --color ORANGE --advice APACHE_ERRORDOC_CUSTOM
fi
FindValueOf $APACHE_CONF_LOCATION_TO_TEST 'ErrorDocument\ 500' JUSTTEST
if [ ! -z "$RESULTAT" ];then
if [ "$RESULTAT" = '/error/HTTP_INTERNAL_SERVER_ERROR.html.var' ] ;then
Display --indent 2 --text "ErrorDocument 500" --result FOUND --color ORANGE --advice APACHE_ERRORDOC_CUSTOM
fi
else
Display --indent 2 --text "ErrorDocument 500" --result NOTFOUND --color ORANGE --advice APACHE_ERRORDOC_CUSTOM
fi
return 0;
|