From 8b042f702013d66bea06fb215fba97236d8852c0 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 14 Jan 2021 18:14:39 +0100 Subject: [PATCH] Captcha : instructions are now italic --- captcha/captcha.sh | 36 ++++++++++++++++++++++-------------- captcha/experimental.sh | 36 +++++++++++++++++------------------- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/captcha/captcha.sh b/captcha/captcha.sh index 6070072..f2af170 100755 --- a/captcha/captcha.sh +++ b/captcha/captcha.sh @@ -37,10 +37,9 @@ INTRUS() LENGTH=${#INPUT} NUMBERS=$(echo $INPUT | grep -o . | tr '\n' ' ') SORTED_UNIQ_NUM=$(echo "${NUMBERS[@]}" | sort -u | tr '\n' ' ') - RANDOM_DIGITS=$(echo 123456789 | grep -o . | sort -R | tr '\n' ' ') INTRUS=-1 - for i in ${RANDOM_DIGITS[@]} + for i in 1 2 3 4 5 6 7 8 9 do if [[ ! " ${SORTED_UNIQ_NUM[@]} " =~ " ${i} " ]]; then INTRUS=$i @@ -71,9 +70,9 @@ INTRUS() R=$(($R % 100)) if [[ $R -lt 50 ]]; then - echo "Tapez $NEWINPUT en\n supprimant les ${DIGIT[$INTRUS]}" + echo "Tapez | $NEWINPUT | en supprimant les ${DIGIT[$INTRUS]}" else - echo "Saisissez $NEWINPUT en\n enlevant les ${DIGIT[$INTRUS]}" + echo "Saisissez | $NEWINPUT | en enlevant les ${DIGIT[$INTRUS]}" fi } @@ -96,36 +95,45 @@ SOMME() R=$(($R % 100)) if [[ $R -lt 25 ]]; then - echo "Tapez le résultat\n de $A + $B" + echo "Tapez le résultat de | $A + $B" elif [[ $R -lt 50 ]]; then - echo "Sommez\n $A et $B" + echo "Sommez | $A et $B" elif [[ $R -lt 75 ]]; then - echo "Additionnez\n $A et $B" + echo "Additionnez | $A et $B" else - echo "Saisissez le résultat\n de $A + $B" + echo "Saisissez le résultat de | $A + $B" fi } -get_random -RAND_ITALIC=$(($R % 25)) get_random RAND_ANGLE=$(($R % 3)) get_random RAND_INDEX=$(($R % ${#TRANSFORMATIONS[@]})) -convert -size 300x60 xc:none -pointsize 20 \ +INSTRUCTIONS=$(echo "$(${TRANSFORMATIONS[$RAND_INDEX]})" | cut -d "|" -f 1) +INSTRUCTIONS2=$(echo "$(${TRANSFORMATIONS[$RAND_INDEX]})" | cut -d "|" -f 3) +TEXT=$(echo "$(${TRANSFORMATIONS[$RAND_INDEX]})" | cut -d "|" -f 2) +echo " $INSTRUCTIONS" +echo "$TEXT" +echo "$INSTRUCTIONS2" + +convert -size 300x70 xc:none -pointsize 20 \ \( -clone 0 -fill black \ -stroke black -strokewidth 1 \ - -annotate "${RAND_ANGLE}x${RAND_ITALIC}+0+0" "\n $(${TRANSFORMATIONS[$RAND_INDEX]})" \ + -annotate "${RAND_ANGLE}x25+0+0" "\n $INSTRUCTIONS" \ + -annotate "${RAND_ANGLE}x0+0+20" "\n $TEXT" \ + -annotate "${RAND_ANGLE}x25+0+40" "\n $INSTRUCTIONS2" \ -roll +$ROLL_X+0 \ -wave "$WAVE1_AMPLITUDE"x"$WAVE1_LENGTH" \ -roll -$ROLL_X+0 \) \ -flatten -crop 300x60 +repage -quality 500 -depth 11 png:"/var/lib/ejabberd/chapril_captchas/$(date "+%Y-%m-%d-%H%M%S")_${INPUT}.png" -convert -size 300x60 xc:none -pointsize 20 \ +convert -size 300x70 xc:none -pointsize 20 \ \( -clone 0 -fill black \ -stroke black -strokewidth 1 \ - -annotate "${RAND_ANGLE}x${RAND_ITALIC}+0+0" "\n $(${TRANSFORMATIONS[$RAND_INDEX]})" \ + -annotate "${RAND_ANGLE}x25+0+0" "\n $INSTRUCTIONS" \ + -annotate "${RAND_ANGLE}x0+0+20" "\n $TEXT" \ + -annotate "${RAND_ANGLE}x25+0+40" "\n $INSTRUCTIONS2" \ -roll +$ROLL_X+0 \ -wave "$WAVE1_AMPLITUDE"x"$WAVE1_LENGTH" \ -roll -$ROLL_X+0 \) \ diff --git a/captcha/experimental.sh b/captcha/experimental.sh index e772fd1..2e644b8 100755 --- a/captcha/experimental.sh +++ b/captcha/experimental.sh @@ -70,9 +70,9 @@ INTRUS() R=$(($R % 100)) if [[ $R -lt 50 ]]; then - echo "Tapez $NEWINPUT en\n supprimant les ${DIGIT[$INTRUS]}" + echo "Tapez | $NEWINPUT | en supprimant les ${DIGIT[$INTRUS]}" else - echo "Saisissez $NEWINPUT en\n enlevant les ${DIGIT[$INTRUS]}" + echo "Saisissez | $NEWINPUT | en enlevant les ${DIGIT[$INTRUS]}" fi } @@ -95,37 +95,35 @@ SOMME() R=$(($R % 100)) if [[ $R -lt 25 ]]; then - echo "Tapez le résultat\n de $A + $B" + echo "Tapez le résultat de | $A + $B" elif [[ $R -lt 50 ]]; then - echo "Sommez\n $A et $B" + echo "Sommez | $A et $B" elif [[ $R -lt 75 ]]; then - echo "Additionnez\n $A et $B" + echo "Additionnez | $A et $B" else - echo "Saisissez le résultat\n de $A + $B" + echo "Saisissez le résultat de | $A + $B" fi } -get_random -RAND_ITALIC=$(($R % 25)) get_random RAND_ANGLE=$(($R % 3)) get_random RAND_INDEX=$(($R % ${#TRANSFORMATIONS[@]})) -convert -size 300x60 xc:none -pointsize 20 \ - \( -clone 0 -fill black \ - -stroke black -strokewidth 1 \ - -annotate "${RAND_ANGLE}x${RAND_ITALIC}+0+0" "\n $(${TRANSFORMATIONS[$RAND_INDEX]})" \ - -roll +$ROLL_X+0 \ - -wave "$WAVE1_AMPLITUDE"x"$WAVE1_LENGTH" \ - -roll -$ROLL_X+0 \) \ - -flatten -crop 300x60 +repage -quality 500 -depth 11 png:"/var/lib/ejabberd/chapril_captchas/EXPERIMENTAL_$(date "+%Y-%m-%d-%H%M%S")_{INPUT}.png" +INSTRUCTIONS=$(echo "$(${TRANSFORMATIONS[$RAND_INDEX]})" | cut -d "|" -f 1) +INSTRUCTIONS2=$(echo "$(${TRANSFORMATIONS[$RAND_INDEX]})" | cut -d "|" -f 3) +TEXT=$(echo "$(${TRANSFORMATIONS[$RAND_INDEX]})" | cut -d "|" -f 2) +echo " $INSTRUCTIONS" +echo "$TEXT" +echo "$INSTRUCTIONS2" -convert -size 300x60 xc:none -pointsize 20 \ +convert -size 300x70 xc:none -pointsize 20 \ \( -clone 0 -fill black \ -stroke black -strokewidth 1 \ - -annotate "${RAND_ANGLE}x${RAND_ITALIC}+0+0" "\n $(${TRANSFORMATIONS[$RAND_INDEX]})" \ + -annotate "${RAND_ANGLE}x25+0+0" "\n $INSTRUCTIONS" \ + -annotate "${RAND_ANGLE}x0+0+20" "\n $TEXT" \ + -annotate "${RAND_ANGLE}x25+0+40" "\n $INSTRUCTIONS2" \ -roll +$ROLL_X+0 \ -wave "$WAVE1_AMPLITUDE"x"$WAVE1_LENGTH" \ -roll -$ROLL_X+0 \) \ - -flatten -crop 300x60 +repage -quality 500 -depth 11 png:- + -flatten -crop 300x70 +repage -quality 500 -depth 11 png:"/var/lib/ejabberd/chapril_captchas/EXPERIMENTAL_$(date "+%Y-%m-%d-%H%M%S")_${INPUT}.png"