Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ######### for test
- # SGERROR_FILE="/home/mario.q/myScripts/sgerror.php"
- # MY_GET_ERROR_PAGE="/home/mario.q/myScripts/personalSgerror.php"
- #########
- ######### real file on pfsense
- SGERROR_FILE="/usr/local/www/sgerror.php"
- MY_GET_ERROR_PAGE="/home/mario.q/myScripts/my_get_error_page.php"
- #########
- ########################################
- ########################################
- #
- # da qui in poi non dovresti modificare niente
- # from here on you should not change anything
- #
- ########################################
- ########################################
- PFS="`cat /etc/platform`"
- if [ "$PFS" != "pfSense" ]; then
- echo "This script work on pfSense"
- exit 101
- fi
- if [ ! -w "$SGERROR_FILE" -o ! -r "$MY_GET_ERROR_PAGE" ]; then
- echo "####"
- if [ ! -w "$SGERROR_FILE" ]; then
- # CK_SGERROR_FILE="`ls -lh "$SGERROR_FILE" 2>&1`"
- CK_SGERROR_FILE="`stat -x "$SGERROR_FILE" 2>&1 |\
- sed 's/:[[:space:]]\{1,100\}/:/g ;\
- /Device/,/Change/d ;\
- /Size/d ;\
- s/[[:space:]]\{2,100\}/ /g'`"
- echo -e "You cannot edit the file in var SGERROR_FILE=\"$SGERROR_FILE\"\n$CK_SGERROR_FILE"
- else
- echo -e " SGERROR_FILE=\"$SGERROR_FILE\"\n OK"
- fi
- echo " ####"
- if [ ! -r "$MY_GET_ERROR_PAGE" ]; then
- CK_MY_GET_ERROR_PAGE="`ls -lh "$MY_GET_ERROR_PAGE" 2>&1`"
- echo -e " MY_GET_ERROR_PAGE=\"$MY_GET_ERROR_PAGE\"\n $CK_MY_GET_ERROR_PAGE\n The file exist ?? you can read it ??"
- else
- echo -e " MY_GET_ERROR_PAGE=\"$MY_GET_ERROR_PAGE\"\n OK"
- fi
- echo "####"
- exit 1
- fi
- FUNCTION_ORIGINAL="function get_error_page("
- FUNCTION_RENAMED="function NO_get_error_page_NO("
- BLOCK_START="start - this include replace the original function ---------"
- BLOCK_END="end - this include replace the original function ---------"
- SGERROR_TMP="`cat $SGERROR_FILE`"
- ERROR=0
- case $1 in
- install|i)
- if [ "`echo "$SGERROR_TMP" | grep "$FUNCTION_ORIGINAL"`" ]; then
- echo "$SGERROR_TMP" |\
- sed "s/`echo "$FUNCTION_ORIGINAL"`/`echo "$FUNCTION_RENAMED"`/" |\
- sed "/`echo "$FUNCTION_RENAMED"`/ i \\
- `echo "// $BLOCK_START"`\\
- `echo "// modified by \\"$(readlink -f $0)\\""`\\
- `echo "include \\"$MY_GET_ERROR_PAGE\\";"`\\
- `echo "// $BLOCK_END"`\\
- " >$SGERROR_FILE
- echo "#### OK"
- else
- echo -e "####\n \"$FUNCTION_ORIGINAL...\"\n Function to replace not found"
- ERROR=15
- if [ "`echo "$SGERROR_TMP" | grep "include \\"$MY_GET_ERROR_PAGE\\";"`" ]; then
- echo -e " Your personal function is active.\n include \"$MY_GET_ERROR_PAGE\";"
- ERROR=0
- fi
- echo "####"
- fi
- ;;
- uninstall|u)
- if [ "`echo "$SGERROR_TMP" | grep "$BLOCK_START"`" -a \
- "`echo "$SGERROR_TMP" | grep "include \\"$MY_GET_ERROR_PAGE\\";"`" -a \
- "`echo "$SGERROR_TMP" | grep "$BLOCK_END"`" ]; then
- echo "$SGERROR_TMP" |\
- sed "/`echo "$BLOCK_START"`/,/`echo "$BLOCK_END"`/d" |\
- sed "s/`echo "$FUNCTION_RENAMED"`/`echo "$FUNCTION_ORIGINAL"`/" >$SGERROR_FILE
- echo "#### OK"
- else
- echo -e "####\nnot found\n // $BLOCK_START\n include \"$MY_GET_ERROR_PAGE\";\n // $BLOCK_END"
- ERROR=20
- if [ "`echo "$SGERROR_TMP" | grep "$FUNCTION_ORIGINAL"`" ]; then
- echo -e " ####\n the function for the error page is \"$FUNCTION_ORIGINAL...\""
- else
- echo -e " Not found \"$FUNCTION_ORIGINAL...\"\n not found include \"$MY_GET_ERROR_PAGE\";"
- echo " ? ?? ???? ?????? ????????"
- ERROR=100
- fi
- echo "####"
- fi
- ;;
- *)
- cat <<USE_H
- ####
- $0 [i|install] [u|uninstall]
- ####
- `basename $0` i|install
- Edit the file "$SGERROR_FILE"
- Rename the function "$FUNCTION_ORIGINAL..."
- and replaces it with the file "$MY_GET_ERROR_PAGE"
- ####
- `basename $0` u|uninstall
- Removes the changes to the file "$SGERROR_FILE"
- and restores the original function "$FUNCTION_ORIGINAL..."
- ####
- USE_H
- ERROR=1
- ;;
- esac
- exit $ERROR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement