From c0e86ac02247a0c28fa297c750cf8b5038b03c10 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Tue, 31 Mar 2020 21:44:55 +0200 Subject: Support special symbols in ADEI password --- lib/adei/adei.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/adei/adei.sh b/lib/adei/adei.sh index fa9dfc3..2bdc150 100644 --- a/lib/adei/adei.sh +++ b/lib/adei/adei.sh @@ -13,6 +13,14 @@ adei_default_timeout=${default_timeout:-120} shopt -s nocasematch; +function adei_curl { + if [ -n "$adei_auth" ]; then + curl -u "$adei_auth" "$@" + else + curl "$@" + fi +} + # Auth with redirect (-L/--location-trusted) not working. Credentials are lost on hops. function adei_query { local resp @@ -21,12 +29,12 @@ function adei_query { local err=0 if [ "$2" == "ecode" ]; then url="$1&mysql=master" -# resp=$(curl --proxy "" -f -m "$timeout" "$url" 2>&1 | grep "returned error") - resp=$(curl --proxy "" --location-trusted -sf -m "$timeout" -w "%{http_code}" -o /dev/null "$url" 2>&1); +# resp=$(adei_curl --proxy "" -f -m "$timeout" "$url" 2>&1 | grep "returned error") + resp=$(adei_curl --proxy "" --location-trusted -sf -m "$timeout" -w "%{http_code}" -o /dev/null "$url" 2>&1); [ -z "$resp" -o "$resp" = "000" ] && resp="10" # error code 1 elif [ "$2" == "emsg" ]; then url="$1&mysql=master" - resp=$(curl --proxy "" --location-trusted -f -m "$timeout" "$url" 2>&1 | grep -o "curl.*") + resp=$(adei_curl --proxy "" --location-trusted -f -m "$timeout" "$url" 2>&1 | grep -o "curl.*") [ -z "$resp" ] && resp="No response from" else if [ "$2" == "slave" ]; then @@ -35,7 +43,7 @@ function adei_query { url="$1&mysql=master" fi - resp=$(curl --proxy "" --location-trusted -sf -m "$timeout" "$url"); err=$? + resp=$(adei_curl --proxy "" --location-trusted -sf -m "$timeout" "$url"); err=$? if [ $err -ne 0 ]; then resp=$(adei_query "$1" "ecode" "$timeout") err=$(($(($resp / 10)) + $(($resp % 10)))) @@ -61,7 +69,7 @@ function adei_format_query { local url="${6:-$adei_url}" auth="" - [ $with_auth -gt 0 ] && auth="$adei_auth" + [ $with_auth -gt 0 ] && auth="${adei_auth}@" if [[ "$query" =~ \? ]]; then echo "http://${auth}${url}/${query}${source}" else @@ -70,7 +78,7 @@ function adei_format_query { } function adei_simple_query { - local req=$(adei_format_query 1 "$@") + local req=$(adei_format_query 0 "$@") local database=${2:-master} adei_query "$req" $database "$timeout"; err=$? return $err @@ -246,7 +254,6 @@ function adei_init_ { # In some case we miss here "setup", but surely then the password is resolved host-based adei_auth=$(adei_resolve_id "security/adei.txt" "$id" "$host" "$setup") - [ -n "$adei_auth" ] && adei_auth="$adei_auth@" # Now build ADEI url adei_setup="$setup" -- cgit v1.2.1