Commit 5b7a00fe authored by PENGUEN Julien's avatar PENGUEN Julien
Browse files

ajout securité pour la gestion des arguments et options

parent e90e1ea0
......@@ -15,7 +15,7 @@ function_build_tab_hach()
# - tab_values: array of argument need for each option present on $@
# - tab_weight: array of weight need for each option present on $@
# - val_error: TRUE or FALSE depending on error
# - val_element: in case of error, element causing the error
# - message: in case of error, error message
# ---------------------- #
# ARRAY[key]=value
......@@ -89,6 +89,7 @@ function_build_tab_hach()
# -------- #
val_error="FALSE"
elements_ok=0
for elem in ${!ARRAY[*]} ; do
......@@ -99,6 +100,7 @@ function_build_tab_hach()
if [ "${elem}" == $param ]; then
#if option of ARRAY is find among input argument
elements_ok=$(($elements_ok + 1))
tab_keys[$indice]=$elem
tab_values[$indice]="None"
tab_weight[$indice]=${ARGS_WEIGHT[${elem}]}
......@@ -109,11 +111,14 @@ function_build_tab_hach()
FOUND=$(echo ${!ARRAY[*]} | grep -- "${tab_params[$indice +1]}")
if [[ ${tab_params[$indice +1]} != "" && $FOUND == "" && ${tab_params[$indice +1]} != -* ]]; then
#if [[ ${tab_params[$indice +1]} != "" && $FOUND == "" ]]; then
#case argument needed for the option is present on input argument
tab_values[$indice]=${tab_params[$indice +1]}
elements_ok=$(($elements_ok + 1))
else
#case argument needed for the option is missing on input argument
val_element=${elem}
#val_element=${elem}
message="Missing argument for the option "${elem}
val_error="TRUE"
fi
......@@ -126,8 +131,22 @@ function_build_tab_hach()
done
done
# echo "elements_ok="$elements_ok
# echo "total ${#@}"
echo "${tab_keys[@]},${tab_values[@]},${tab_weight[@]},$val_error,$val_element"
if [ "$val_error" == "FALSE" ]; then
# echo "val_error false"
if [ "$elements_ok" -ne "${#@}" ]; then
# echo "val_error true"
val_error="TRUE"
message="Option not found"
else
val_error="FALSE"
fi
fi
echo "${tab_keys[@]},${tab_values[@]},${tab_weight[@]},$val_error,$message"
}
......@@ -226,7 +245,7 @@ function_build_image()
list_jar=$(sort -r .temp | awk '{print $1}')
rm .temp
present=$(echo $list_jar| grep $version)
present=$(echo $list_jar| grep "^$version$")
if [ $? -eq 1 ]; then
......@@ -363,6 +382,7 @@ done
# call function_sort_tab
RESULTAT=`function_build_tab_hach $@`
#function_build_tab_hach $@
tab_arg_keys=`echo $RESULTAT | cut --delimiter=, -f 1`
tab_arg_values=`echo $RESULTAT | cut --delimiter=, -f 2`
......@@ -373,13 +393,13 @@ val_error=`echo $RESULTAT | cut --delimiter=, -f 4`
#check if val_error is TRUE
if [ $val_error == "TRUE" ]; then
val_element=`echo $RESULTAT | cut --delimiter=, -f 5`
error_message=`echo $RESULTAT | cut --delimiter=, -f 5`
echo ""
echo "------------------------------------"
echo ""
echo -e "\033[31m========================================================="
echo -e "WARNING => Missing argument for the option ${val_element}"
echo -e "WARNING => ${error_message}"
echo -e "=========================================================\033[0m"
echo ""
echo "------------------------------------"
......@@ -415,34 +435,127 @@ if [ $val_error == "TRUE" ]; then
fi
#------------------------------------#
#check if --select argument is present
#check options presents
if [[ " ${tab_arg_keys[@]} " =~ "--select" ]]; then
arg_keys=( ${tab_arg_keys// / } )
arg_values=( ${tab_arg_values// / } )
arg_weight=( ${tab_arg_weight// / } )
else
tab2_arg_keys[0]="--no_select"
tab2_arg_values[0]="$ALADIN_VERSION"
tab2_arg_weight[0]=0
tab2_arg_keys[1]=${tab_arg_keys}
tab2_arg_values[1]=${tab_arg_values}
tab2_arg_weight[1]=${tab_arg_weight}
arg_keys=( ${tab2_arg_keys[@]// / } )
arg_values=( ${tab2_arg_values[@]// / } )
arg_weight=( ${tab2_arg_weight[@]// / } )
fi
tempo_arg_weight=( ${tab_arg_weight// / } )
tempo_arg_keys=( ${tab_arg_keys// / } )
#------------------------------------#
taille=${#tempo_arg_weight[@]}
case $taille in
"0")
#---------------------#
#case 0 input argument
#---------------------#
tab_arg_keys[0]="--no_select"
tab_arg_values[0]="$ALADIN_VERSION"
tab_arg_weight[0]=0
arg_keys=( ${tab_arg_keys[@]// / } )
arg_values=( ${tab_arg_values[@]// / } )
arg_weight=( ${tab_arg_weight[@]// / } )
;;
"1")
#---------------------#
#case 1 input argument
#---------------------#
if [ "${tempo_arg_weight[0]}" -eq 0 ]; then
# case option with weight=0 ('--select')
arg_keys=( ${tab_arg_keys// / } )
arg_values=( ${tab_arg_values// / } )
arg_weight=( ${tab_arg_weight// / } )
elif [ "${tempo_arg_weight[0]}" -eq 1 ]; then
#case option with weight=1
if [ "${tempo_arg_keys[0]}" == '--force-all' ]; then
#case '--force_all'
tab2_arg_keys[0]="--no_select"
tab2_arg_values[0]="$ALADIN_VERSION"
tab2_arg_weight[0]=0
tab2_arg_keys[1]=${tab_arg_keys}
tab2_arg_values[1]=${tab_arg_values}
tab2_arg_weight[1]=${tab_arg_weight}
arg_keys=( ${tab2_arg_keys[@]// / } )
arg_values=( ${tab2_arg_values[@]// / } )
arg_weight=( ${tab2_arg_weight[@]// / } )
else
#case '-i','--infos','-u','--update','-h','-v','--version'
arg_keys=( ${tab_arg_keys// / } )
arg_values=( ${tab_arg_values// / } )
arg_weight=( ${tab_arg_weight// / } )
fi
else
echo '=> No case possible for the moment'
fi
;;
*)
#-----------------------------#
#case 2 or more input arguments
#-----------------------------#
for p in ${!tempo_arg_keys[*]}
do
echo "${tempo_arg_keys[$p]}"
if [ ${tempo_arg_weight[$p]} -eq 0 ]; then
tempo_weight_0="TRUE"
elif [ ${tempo_arg_weight[$p]} -eq 1 ]; then
tempo_weight_1="TRUE"
indice_tempo_weight_1=$p
elif [ ${tempo_arg_weight[$p]} -eq 2 ]; then
tempo_weight_2="TRUE"
fi
done
if [[ "$tempo_weight_0" == 'TRUE' && "$tempo_weight_2" == 'FALSE' ]]; then
#case '--select'
arg_keys=( ${tab_arg_keys// / } )
arg_values=( ${tab_arg_values// / } )
arg_weight=( ${tab_arg_weight// / } )
fi
if [ "$tempo_weight_1" == 'TRUE' ]; then
if [ "${tempo_arg_keys[$indice_tempo_weight_1]}" == '--force-all' ]; then
#case '--force_all'
tab2_arg_keys[0]="--no_select"
tab2_arg_values[0]="$ALADIN_VERSION"
tab2_arg_weight[0]=0
tab2_arg_keys[1]=${tab_arg_keys}
tab2_arg_values[1]=${tab_arg_values}
tab2_arg_weight[1]=${tab_arg_weight}
arg_keys=( ${tab2_arg_keys[@]// / } )
arg_values=( ${tab2_arg_values[@]// / } )
arg_weight=( ${tab2_arg_weight[@]// / } )
else
#case '-i','--infos','-u','--update','-h','-v','--version'
arg_keys=( ${tab_arg_keys// / } )
arg_values=( ${tab_arg_values// / } )
arg_weight=( ${tab_arg_weight// / } )
fi
fi
;;
esac
# for l in ${!arg_keys[*]}
# do
# echo "arg_keys[$l]=${arg_keys[$l]}"
# echo "arg_values[$l]=${arg_values[$l]}"
# echo "arg_weight[$l]=${arg_weight[$l]}"
# done
#
# echo "@="$@
#---------------------#
# sort the arrays arguments
......@@ -461,20 +574,12 @@ sort_arg_weight=( ${tab_sort_arg_weight// / } )
#---------------------#
# --no_select management
if [ ${sort_arg_keys[0]} == "--no_select" ]; then
echo "NO SELECT OPTION!!!!"
if [ "${sort_arg_keys[0]}" == "--no_select" ]; then
sort_arg_keys[0]=""
sort_arg_values[0]=""
sort_arg_weight[0]=0
fi
#---------------------#
for k in ${!sort_arg_weight[*]}
do
echo "sort_arg_keys[$k]=${sort_arg_keys[$k]}"
echo "sort_arg_values[$k]=${sort_arg_values[$k]}"
echo "sort_arg_weight[$k]=${sort_arg_weight[$k]}"
done
#---------------------#
case ${sort_arg_keys[0]} in
......@@ -521,7 +626,7 @@ case ${sort_arg_keys[0]} in
curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/<!--/d'| sed '/last/!d' | cut -d">" -f3 | cut -d"<" -f1 | sed 's/\.jar//' | sed 's/Aladin//' >> .temp
list_jar=$(sort -r .temp | awk '{print $1}')
rm .temp
present=$(echo $list_jar| grep $2)
present=$(echo $list_jar| grep "^${sort_arg_values[0]}$")
if [ $? -eq 1 ]; then
......@@ -649,8 +754,6 @@ case ${sort_arg_keys[0]} in
echo "============================="
echo "${list_zone[$k]}"
echo "============================="
echo ${#list_zone[@]}
echo $((${#list_zone[@]} -1))
#------------------------#
if [ "${sort_arg_keys[1]}" == "--force-all" ]; then
......@@ -849,7 +952,7 @@ echo $((${#list_zone[@]} -1))
curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/<!--/d'| sed '/last/!d' | cut -d">" -f3 | cut -d"<" -f1 | sed 's/\.jar//' | sed 's/Aladin//' >> .temp
list_jar=$(sort -r .temp | awk '{print $1}')
rm .temp
present=$(echo $list_jar| grep $2)
present=$(echo $list_jar| grep "^${sort_arg_values[0]}$")
if [ $? -eq 1 ]; then
echo ''
......@@ -876,7 +979,7 @@ echo $((${#list_zone[@]} -1))
#---------------------------------#
list_jar=$(sudo docker images | awk '/^image_photos_montage_aladin-/{print $1}')
present=$(echo $list_jar| grep $version)
present=$(echo $list_jar| grep "^$version$")
if [ $? -eq 1 ]; then
......@@ -1025,7 +1128,7 @@ echo $((${#list_zone[@]} -1))
list_image_version=$(sudo docker images | awk '/^image_photos_montage_aladin-/{print $1}')
present=$(echo $list_image_version| grep $version)
present=$(echo $list_image_version| grep "^$version$")
if [ $? -eq 1 ]; then
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment