mirror of
https://github.com/novatiq/packages.git
synced 2026-04-29 23:18:42 +01:00
ddns-scripts: multiple fixes
* replace shell based urlencoder with an awk variant * fix write_log function/syslog output in case of an error * protect answer string with double quotes in update_route53 * remove bogus set/IFS options in update_route53 * clean-up update_route53 a little bit This patchset finally fix #6977 Many thanks to @mark0n & @a-bali for testing & debugging Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
. /lib/functions/network.sh
|
||||
|
||||
# GLOBAL VARIABLES #
|
||||
VERSION="2.7.8-4"
|
||||
VERSION="2.7.8-5"
|
||||
SECTION_ID="" # hold config's section name
|
||||
VERBOSE=0 # default mode is log to console, but easily changed with parameter
|
||||
MYPROG=$(basename $0) # my program call name
|
||||
@@ -282,11 +282,11 @@ write_log() {
|
||||
[ $__LEVEL -eq 7 ] && return # no syslog for debug messages
|
||||
__CMD=$(echo -e "$__CMD" | tr -d '\n' | tr '\t' ' ') # remove \n \t chars
|
||||
[ $__EXIT -eq 1 ] && {
|
||||
$__CMD # force syslog before exit
|
||||
eval "$__CMD" # force syslog before exit
|
||||
exit 1
|
||||
}
|
||||
[ $use_syslog -eq 0 ] && return
|
||||
[ $((use_syslog + __LEVEL)) -le 7 ] && $__CMD
|
||||
[ $((use_syslog + __LEVEL)) -le 7 ] && eval "$__CMD"
|
||||
|
||||
return
|
||||
}
|
||||
@@ -301,32 +301,12 @@ write_log() {
|
||||
urlencode() {
|
||||
# $1 Name of Variable to store encoded string to
|
||||
# $2 string to encode
|
||||
local __STR __LEN __CHAR __OUT
|
||||
local __ENC=""
|
||||
local __POS=1
|
||||
local __ENC
|
||||
|
||||
[ $# -ne 2 ] && write_log 12 "Error calling 'urlencode()' - wrong number of parameters"
|
||||
|
||||
__STR="$2" # read string to encode
|
||||
__LEN=${#__STR} # get string length
|
||||
|
||||
while [ $__POS -le $__LEN ]; do
|
||||
# read one chat of the string
|
||||
__CHAR=$(expr substr "$__STR" $__POS 1)
|
||||
|
||||
case "$__CHAR" in
|
||||
[-_.~a-zA-Z0-9] )
|
||||
# standard char
|
||||
__OUT="${__CHAR}"
|
||||
;;
|
||||
* )
|
||||
# special char get %hex code
|
||||
__OUT=$(printf '%%%02x' "'$__CHAR" )
|
||||
;;
|
||||
esac
|
||||
__ENC="${__ENC}${__OUT}" # append to encoded string
|
||||
__POS=$(( $__POS + 1 )) # increment position
|
||||
done
|
||||
__ENC="$(awk -v str="$2" 'BEGIN{ORS="";for(i=32;i<=127;i++)lookup[sprintf("%c",i)]=i
|
||||
for(k=1;k<=length(str);++k){enc=substr(str,k,1);if(enc!~"[-_.~a-zA-Z0-9]")enc=sprintf("%%%02x", lookup[enc]);print enc}}')"
|
||||
|
||||
eval "$1=\"$__ENC\"" # transfer back to variable
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user