A bit cleaning
This commit is contained in:
parent
69ac7a9537
commit
daaa867dff
@ -3,17 +3,10 @@
|
|||||||
# Copyright © 2021 Adrien Bourmault (neox@a-lec.org)
|
# Copyright © 2021 Adrien Bourmault (neox@a-lec.org)
|
||||||
# Copyright © 2021 Echolib (echolib@dismail.de)
|
# Copyright © 2021 Echolib (echolib@dismail.de)
|
||||||
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
# This program 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 Affero General Public License for more details.
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# This script is an example captcha script.
|
# This script is an example captcha script.
|
||||||
# It takes the text to recognize in the captcha image as a parameter.
|
# It takes the text to recognize in the captcha image as a parameter.
|
||||||
@ -30,9 +23,18 @@
|
|||||||
|
|
||||||
INPUT=$1
|
INPUT=$1
|
||||||
LENINPUT=${#INPUT}
|
LENINPUT=${#INPUT}
|
||||||
DIGIT=(zéros uns deux trois quatres cinqs six septs huits neufs dix)
|
DIGITS=(zéros uns deux trois quatres cinqs six septs huits neufs dix)
|
||||||
|
DIGIT=(zéro un deux trois quatre cinq six sept huit neuf dix)
|
||||||
|
|
||||||
# Loop 10 times (should be enough) to check if a TARGET number is in INPUT
|
|
||||||
|
# ****************************************************************************
|
||||||
|
#
|
||||||
|
# Tools
|
||||||
|
#
|
||||||
|
# ****************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
# Loops 10 times (should be enough) to check if a TARGET number is in INPUT
|
||||||
GENERATE__NOTIN() {
|
GENERATE__NOTIN() {
|
||||||
for i in {1..10}
|
for i in {1..10}
|
||||||
do
|
do
|
||||||
@ -42,11 +44,15 @@ do
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
#=====
|
|
||||||
# Modules
|
|
||||||
#=====
|
|
||||||
|
|
||||||
# REPLACE a random number in INPUT by another one Randomized
|
# ****************************************************************************
|
||||||
|
#
|
||||||
|
# Captcha shapes
|
||||||
|
#
|
||||||
|
# ****************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
# REPLACEs a random number in INPUT by another one randomized
|
||||||
REPLACE() {
|
REPLACE() {
|
||||||
NAME="REPLACE"
|
NAME="REPLACE"
|
||||||
PLACE=`seq 1 6 | sort -R | head -n 1`
|
PLACE=`seq 1 6 | sort -R | head -n 1`
|
||||||
@ -55,14 +61,15 @@ TARGET=`echo "$INPUT" | head -c $PLACE | tail -c 1`
|
|||||||
GENERATE__NOTIN
|
GENERATE__NOTIN
|
||||||
NAME+="-$FALSENBR-$TARGET"
|
NAME+="-$FALSENBR-$TARGET"
|
||||||
NEWINPUT=${INPUT//$TARGET/$FALSENBR}
|
NEWINPUT=${INPUT//$TARGET/$FALSENBR}
|
||||||
INSTRUCTIONS1="Remplacez les ${DIGIT[FALSENBR]} par les ${DIGIT[TARGET]}"
|
INSTRUCTIONS1="Remplacez les ${DIGITS[FALSENBR]} par des ${DIGITS[TARGET]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# REVerse INPUT. Ask to Add first or last number in random.
|
|
||||||
|
# REVERSEs INPUT. Ask to Add first or last number in random.
|
||||||
REVERSE() {
|
REVERSE() {
|
||||||
NAME="REVERSE"
|
NAME="REVERSE"
|
||||||
RFL=`seq 1 2 | sort -R | head -n 1` # Rand First (1) or Last (2)
|
RFL=`seq 1 2 | sort -R | head -n 1` # Rand First (1) or Last (2)
|
||||||
ADDNBR=${DIGIT[ADDNBR]}
|
ADDNBR=${DIGITS[ADDNBR]}
|
||||||
|
|
||||||
for ((i=$LENINPUT-1;i>=0;i--))
|
for ((i=$LENINPUT-1;i>=0;i--))
|
||||||
do
|
do
|
||||||
@ -73,18 +80,19 @@ if (( $RFL == 1 ));then
|
|||||||
ADDNBR="${INPUT:0:1}"
|
ADDNBR="${INPUT:0:1}"
|
||||||
NAME+="_FIRST"
|
NAME+="_FIRST"
|
||||||
NEWINPUT=${NEWINPUT:0:$LENINPUT-1} # Do not show first INPUT NBR
|
NEWINPUT=${NEWINPUT:0:$LENINPUT-1} # Do not show first INPUT NBR
|
||||||
INSTRUCTIONS1="Écrivez le chiffre ${DIGIT[$ADDNBR]} puis"
|
INSTRUCTIONS1="Écrivez le chiffre ${DIGITS[$ADDNBR]} puis"
|
||||||
INSTRUCTIONS2="Recopiez de DROITE à GAUCHE ←"
|
INSTRUCTIONS2="Recopiez de DROITE à GAUCHE ←"
|
||||||
else
|
else
|
||||||
ADDNBR="${INPUT:$LENINPUT-1:1}"
|
ADDNBR="${INPUT:$LENINPUT-1:1}"
|
||||||
NAME+="_LAST"
|
NAME+="_LAST"
|
||||||
NEWINPUT=${NEWINPUT:1:$LENINPUT-1} # Do not show last INPUT NBR
|
NEWINPUT=${NEWINPUT:1:$LENINPUT-1} # Do not show last INPUT NBR
|
||||||
INSTRUCTIONS1="Recopiez de DROITE à GAUCHE ←"
|
INSTRUCTIONS1="Recopiez de DROITE à GAUCHE ←"
|
||||||
INSTRUCTIONS2="Terminez par le chiffre ${DIGIT[$ADDNBR]}"
|
INSTRUCTIONS2="Terminez par le chiffre ${DIGITS[$ADDNBR]}"
|
||||||
fi
|
fi
|
||||||
NAME+="-$ADDNBR"
|
NAME+="-$ADDNBR"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Add FALSE NBR to INPUT at three randomized place
|
# Add FALSE NBR to INPUT at three randomized place
|
||||||
NOTIN() {
|
NOTIN() {
|
||||||
NAME="NOTIN"
|
NAME="NOTIN"
|
||||||
@ -101,9 +109,10 @@ do
|
|||||||
NEWINPUT="$NEWINPUT${INPUT:$i:1}"
|
NEWINPUT="$NEWINPUT${INPUT:$i:1}"
|
||||||
done
|
done
|
||||||
NAME+="-$FALSENBR"
|
NAME+="-$FALSENBR"
|
||||||
INSTRUCTIONS1="Recopiez sans les ${DIGIT[FALSENBR]}"
|
INSTRUCTIONS1="Recopiez sans les ${DIGITS[FALSENBR]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Take a random NBR from INPUT. Calculate X
|
# Take a random NBR from INPUT. Calculate X
|
||||||
CALCUL() {
|
CALCUL() {
|
||||||
PLACE=`seq 1 $((LENINPUT)) | sort -R | head -n 1`
|
PLACE=`seq 1 $((LENINPUT)) | sort -R | head -n 1`
|
||||||
@ -121,21 +130,24 @@ else
|
|||||||
if (( $FALSENBR <= $TARGET ));then
|
if (( $FALSENBR <= $TARGET ));then
|
||||||
RESULT=$(( TARGET + FALSENBR ))
|
RESULT=$(( TARGET + FALSENBR ))
|
||||||
RESUME=$(( TARGET - FALSENBR ))
|
RESUME=$(( TARGET - FALSENBR ))
|
||||||
INSTRUCTIONS1="Calculez: ${DIGIT[FALSENBR]} + ${DIGIT[RESUME]}. Copiez..."
|
INSTRUCTIONS1="Calculez: ${DIGITS[FALSENBR]} + ${DIGITS[RESUME]}. Copiez..."
|
||||||
NAME="CALCULP-$FALSENBR-$RESUME"
|
NAME="CALCULP-$FALSENBR-$RESUME"
|
||||||
else
|
else
|
||||||
RESULT=$(( FALSENBR - TARGET ))
|
RESULT=$(( FALSENBR - TARGET ))
|
||||||
RESUME=$(( TARGET - RESULT ))
|
RESUME=$(( TARGET - RESULT ))
|
||||||
INSTRUCTIONS1="Calculez: ${DIGIT[RESULT]} + ${DIGIT[RESUME]}. Copiez..."
|
INSTRUCTIONS1="Calculez: ${DIGITS[RESULT]} + ${DIGITS[RESUME]}. Copiez..."
|
||||||
NAME="CALCULP-$RESULT-$RESUME"
|
NAME="CALCULP-$RESULT-$RESUME"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
INSTRUCTIONS2="...en remplaçant chaque X par la somme"
|
INSTRUCTIONS2="...en remplaçant chaque X par la somme"
|
||||||
}
|
}
|
||||||
|
|
||||||
#=====
|
|
||||||
# Choose a random module
|
# ****************************************************************************
|
||||||
#=====
|
#
|
||||||
|
# Random captcha shape choice (aka main)
|
||||||
|
#
|
||||||
|
# ****************************************************************************
|
||||||
|
|
||||||
MODULES=(CALCUL NOTIN REPLACE REVERSE)
|
MODULES=(CALCUL NOTIN REPLACE REVERSE)
|
||||||
NBRMODULES=${#MODULES[@]}
|
NBRMODULES=${#MODULES[@]}
|
||||||
@ -143,7 +155,7 @@ RMODULE=`seq 0 $((NBRMODULES-1)) | sort -R | head -n 1`
|
|||||||
eval "${MODULES[RMODULE]}"
|
eval "${MODULES[RMODULE]}"
|
||||||
|
|
||||||
TEXT="$NEWINPUT"
|
TEXT="$NEWINPUT"
|
||||||
CHAPRILURI="$HOME/Images/Captcha/${NAME}_${NEWINPUT}_${INPUT}.png"
|
CHAPRILURI="/var/lib/ejabberd/chapril_captchas/${NAME}_${NEWINPUT}_${INPUT}.png"
|
||||||
|
|
||||||
convert -size 300x70 xc:none -pointsize 20 \
|
convert -size 300x70 xc:none -pointsize 20 \
|
||||||
\( -clone 0 -fill black \
|
\( -clone 0 -fill black \
|
||||||
|
Loading…
Reference in New Issue
Block a user