|
@@ -173,6 +173,45 @@ critical_error() {
|
173
|
173
|
exit 1 # critical error -> leave here
|
174
|
174
|
}
|
175
|
175
|
|
|
176
|
+# replace all special chars to their %hex value
|
|
177
|
+# used for USERNAME and PASSWORD in update_url
|
|
178
|
+# unchanged: "-"(minus) "_"(underscore) "."(dot) "~"(tilde)
|
|
179
|
+# to verify: "'"(single quote) '"'(double quote) # because shell delimiter
|
|
180
|
+# "$"(Dollar) # because used as variable output
|
|
181
|
+# tested with the following string stored via Luci Application as password / username
|
|
182
|
+# A B!"#AA$1BB%&'()*+,-./:;<=>?@[\]^_`{|}~ without problems at Dollar or quotes
|
|
183
|
+__urlencode() {
|
|
184
|
+ # $1 Name of Variable to store encoded string to
|
|
185
|
+ # $2 string to encode
|
|
186
|
+ local __STR __LEN __CHAR __OUT
|
|
187
|
+ local __ENC=""
|
|
188
|
+ local __POS=1
|
|
189
|
+
|
|
190
|
+ __STR="$2" # read string to encode
|
|
191
|
+ __LEN=${#__STR} # get string length
|
|
192
|
+
|
|
193
|
+ while [ $__POS -le $__LEN ]; do
|
|
194
|
+ # read one chat of the string
|
|
195
|
+ __CHAR=$(expr substr "$__STR" $__POS 1)
|
|
196
|
+
|
|
197
|
+ case "$__CHAR" in
|
|
198
|
+ [-_.~a-zA-Z0-9] )
|
|
199
|
+ # standard char
|
|
200
|
+ __OUT="${__CHAR}"
|
|
201
|
+ ;;
|
|
202
|
+ * )
|
|
203
|
+ # special char get %hex code
|
|
204
|
+ __OUT=$(printf '%%%02x' "'$__CHAR" )
|
|
205
|
+ ;;
|
|
206
|
+ esac
|
|
207
|
+ __ENC="${__ENC}${__OUT}" # append to encoded string
|
|
208
|
+ __POS=$(( $__POS + 1 )) # increment position
|
|
209
|
+ done
|
|
210
|
+
|
|
211
|
+ eval "$1='$__ENC'" # transfer back to variable
|
|
212
|
+ return 0
|
|
213
|
+}
|
|
214
|
+
|
176
|
215
|
# extract update_url for given DDNS Provider from
|
177
|
216
|
# file /usr/lib/ddns/services for IPv4 or from
|
178
|
217
|
# file /usr/lib/ddns/services_ipv6 for IPv6
|
|
@@ -550,7 +589,7 @@ __do_transfer() {
|
550
|
589
|
|
551
|
590
|
send_update() {
|
552
|
591
|
# $1 # IP to set at DDNS service provider
|
553
|
|
- local __IP __URL __ANSWER __ERR
|
|
592
|
+ local __IP __URL __ANSWER __ERR __USER __PASS
|
554
|
593
|
|
555
|
594
|
# verify given IP / no private IPv4's / no IPv6 addr starting with fxxx of with ":"
|
556
|
595
|
[ $use_ipv6 -eq 0 ] && __IP=$(echo $1 | grep -v -E "(^0|^10\.|^127|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-1]\.|^192\.168)")
|
|
@@ -558,7 +597,9 @@ send_update() {
|
558
|
597
|
[ -z "$__IP" ] && critical_error "Invalid or no IP '$1' given"
|
559
|
598
|
|
560
|
599
|
# do replaces in URL
|
561
|
|
- __URL=$(echo $update_url | sed -e "s#\[USERNAME\]#$username#g" -e "s#\[PASSWORD\]#$password#g" \
|
|
600
|
+ __urlencode __USER "$username" # encode username, might be email or something like this
|
|
601
|
+ __urlencode __PASS "$password" # encode password, might have special chars for security reason
|
|
602
|
+ __URL=$(echo $update_url | sed -e "s#\[USERNAME\]#$__USER#g" -e "s#\[PASSWORD\]#$__PASS#g" \
|
562
|
603
|
-e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__IP#g")
|
563
|
604
|
[ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#')
|
564
|
605
|
|