├── README.md ├── csfpost.sh ├── csfpre.sh └── install.sh /README.md: -------------------------------------------------------------------------------- 1 | # ConfigServer Security & Firewall (CSF) - csfpre.sh / csfpost.sh 2 | 3 | ## Install 4 | Installation is quite straightforward: 5 | 6 | ``` 7 | # cd /usr/local/src 8 | # git clone https://github.com/juliengk/csf-pre_post_sh.git 9 | # cd csf-pre_post_sh 10 | # sh install.sh 11 | ``` 12 | 13 | ## User Feedback 14 | ### Issues 15 | 16 | If you have any problems with or questions about this image, please contact us through a [GitHub](https://github.com/juliengk/csf-pre_post_sh/issues) issue. 17 | -------------------------------------------------------------------------------- /csfpost.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | CSFPOSTD_PATH="/usr/local/include/csf/post.d" 4 | 5 | if [ -d ${CSFPOSTD_PATH} ]; then 6 | for i in ${CSFPOSTD_PATH}/*.sh; do 7 | if [ -r $i ]; then 8 | . $i 9 | fi 10 | done 11 | 12 | unset i 13 | fi 14 | -------------------------------------------------------------------------------- /csfpre.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | CSFPRED_PATH="/usr/local/include/csf/pre.d" 4 | 5 | if [ -d ${CSFPRED_PATH} ]; then 6 | for i in ${CSFPRED_PATH}/*.sh; do 7 | if [ -r $i ]; then 8 | . $i 9 | fi 10 | done 11 | 12 | unset i 13 | fi 14 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CSF_BIN_PATH="/usr/local/csf/bin" 4 | CSFPRESH_SCRIPT="${CSF_BIN_PATH}/csfpre.sh" 5 | CSFPOSTSH_SCRIPT="${CSF_BIN_PATH}/csfpost.sh" 6 | 7 | CSFPRED_PATH="/usr/local/include/csf/pre.d" 8 | CSFPOSTD_PATH="/usr/local/include/csf/post.d" 9 | 10 | function copy_script { 11 | local csf_script=$1 12 | local csf_dst_path=$2 13 | 14 | if [ -f ${csf_dst_path} ]; then 15 | md5_0=`md5sum ${csf_script} | awk '{ print $1 }'` 16 | md5_1=`md5sum ${csf_dst_path} | awk '{ print $1 }'` 17 | 18 | if [ ${md5_0} == ${md5_1} ]; then 19 | echo "The script ${csf_script} already exists and is up to date" 20 | exit 0 21 | else 22 | ok=0 23 | while [ ${ok} -eq 0 ]; do 24 | clear 25 | 26 | echo "** Warning! **" 27 | echo "A different version of the script ${csf_script} is already present" 28 | echo "Do you want to replace it (y/n)?" 29 | 30 | read answer 31 | 32 | if [ ${answer} == "y" -o ${answer} == "n" ]; then 33 | ok=1 34 | fi 35 | done 36 | 37 | if [ ${answer} == "n" ]; then 38 | exit 1 39 | fi 40 | fi 41 | fi 42 | 43 | cp -f ${csf_script} ${csf_dst_path} 44 | chown root:root ${csf_dst_path} 45 | chmod 700 ${csf_dst_path} 46 | } 47 | 48 | # Verify /bin/bash is linked to /bin/sh 49 | shell="bash" 50 | sh_shell=`ls -l /bin/sh | awk '{ print $NF }'` 51 | 52 | if [ ${sh_shell} != ${shell} -a ${sh_shell} != "/bin/${shell}" ]; then 53 | echo "** Critical! **" 54 | echo "/bin/sh is not linked to /bin/${shell}. Yours is ${sh_shell}." 55 | echo "Only /bin/${shell} is supported" 56 | 57 | exit 1 58 | fi 59 | 60 | # Create directories needed for custom csf{pre,post} 61 | if [ ! -d ${CSFPRED_PATH} ]; then 62 | mkdir -p ${CSFPRED_PATH} 63 | fi 64 | 65 | if [ ! -d ${CSFPOSTD_PATH} ]; then 66 | mkdir -p ${CSFPOSTD_PATH} 67 | fi 68 | 69 | # Copy scripts 70 | copy_script "csfpre.sh" ${CSFPRESH_SCRIPT} 71 | copy_script "csfpost.sh" ${CSFPOSTSH_SCRIPT} 72 | 73 | exit 0 74 | --------------------------------------------------------------------------------