From 50343311319104495281a3a7a2a1848cb94ac480 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Wed, 21 Aug 2019 19:06:09 -0600 Subject: [PATCH] net: init-metrics.sh - urlencode influx password (#5594) * net: init-metrics.sh - urlencode influx password * old backticks bad! * Move urlencode() to common.sh * Make urlencode() vars local Co-Authored-By: Michael Vines --- net/common.sh | 18 ++++++++++++++++++ net/init-metrics.sh | 2 ++ 2 files changed, 20 insertions(+) diff --git a/net/common.sh b/net/common.sh index a55ec89427..73d6257085 100644 --- a/net/common.sh +++ b/net/common.sh @@ -76,3 +76,21 @@ loadConfigFile() { buildSshOptions configureMetrics } + +# https://gist.github.com/cdown/1163649 +urlencode() { + declare s="$1" + declare l=$((${#s} - 1)) + for i in $(seq 0 $l); do + declare c="${s:$i:1}" + case $c in + [a-zA-Z0-9.~_-]) + echo -n "$c" + ;; + *) + printf '%%%02X' "'$c" + ;; + esac + done +} + diff --git a/net/init-metrics.sh b/net/init-metrics.sh index ae29ffba68..d68e9d7659 100755 --- a/net/init-metrics.sh +++ b/net/init-metrics.sh @@ -60,6 +60,8 @@ else [[ -n $password ]] || { echo "Password not specified"; exit 1; } echo + password="$(urlencode "$password")" + query() { echo "$*" curl -XPOST \