I wrote tiny bash script for checkin files contains black listed words or not.
The aim of this script is to automate verifying php or javascript files does not have any debugging code, such as "var_dump","alert" etc.
The aim of this script is to automate verifying php or javascript files does not have any debugging code, such as "var_dump","alert" etc.
#!/bin/bash
PHP_BLACK_LIST_WORDS=("var_dump(")
JAVASCRIPT_BLACK_LIST_WORDS=("alert(")
verify_words_are_not_contained(){
words="$1"
len=${#words[@]}
if [ $len -ge 0 ]
then
grep_words=""
for word in "${words[@]}"
do
grep_words+="$word\|"
done
# remove last 2 characters
grep_words=${grep_words%?}
grep_words=${grep_words%?}
grep_command="grep \"$grep_words\" $2 -nr --include=$3 > $OUTPUT_DIR/$4"
echo "running $grep_command"
eval $grep_command
fi
}
setup_output_dir(){
target_dir_name=${1##*/}
OUTPUT_DIR=$target_dir_name"_detected_black_list_words"
echo "$OUTPUT_DIR"
rm -r -f "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
}
set -e
set -o pipefail
if [ $# -ne 1 ]
then
echo "please specify target directory"
exit 1
fi
TARGET_DIR=$1
setup_output_dir "$TARGET_DIR"
verify_words_are_not_contained $PHP_BLACK_LIST_WORDS $TARGET_DIR "*.php" "php_black_list_words.txt"
verify_words_are_not_contained $JAVASCRIPT_BLACK_LIST_WORDS $TARGET_DIR "*.js" "javascript_black_list_words.txt"
コメント