1
0
mirror of https://github.com/EV21/dynb.git synced 2025-12-26 16:39:32 +01:00

🎨 fix shell style

This commit is contained in:
2021-09-13 13:36:12 +02:00
parent d92cdb2652
commit 24aa20be3b

136
dynb.sh
View File

@@ -108,32 +108,36 @@ function logtime() {
# The main domain as an identifier for the dns zone is required for the updateRecord call
function getMainDomain() {
request=$( echo "{}" | \
jq '(.method="nameserver.list")' | \
jq "(.params.user=\"$DYNB_USERNAME\")" | \
request=$(
echo "{}" |
jq '(.method="nameserver.list")' |
jq "(.params.user=\"$DYNB_USERNAME\")" |
jq "(.params.pass=\"$DYNB_PASSWORD\")"
)
_response=$(curl --silent \
_response=$(
curl --silent \
"$_interface_str" \
--user-agent "$_userAgent" \
--header "Content-Type: application/json" \
--request POST $_INWX_JSON_API_URL \
--data "$request" | jq ".resData.domains[] | select(inside(.domain=\"$DYNB_DYN_DOMAIN\"))"
)
_main_domain=$( echo "$_response" | jq --raw-output '.domain' )
_main_domain=$(echo "$_response" | jq --raw-output '.domain')
}
function fetchDNSRecords() {
request=$( echo "{}" | \
jq '(.method="'nameserver.info'")' | \
jq "(.params.user=\"$DYNB_USERNAME\")" | \
jq "(.params.pass=\"$DYNB_PASSWORD\")" | \
jq "(.params.domain=\"$_main_domain\")" | \
request=$(
echo "{}" |
jq '(.method="'nameserver.info'")' |
jq "(.params.user=\"$DYNB_USERNAME\")" |
jq "(.params.pass=\"$DYNB_PASSWORD\")" |
jq "(.params.domain=\"$_main_domain\")" |
jq "(.params.name=\"$DYNB_DYN_DOMAIN\")"
)
_response=$( curl --silent \
_response=$(
curl --silent \
"$_interface_str" \
--user-agent "$_userAgent" \
--header "Content-Type: application/json" \
@@ -141,7 +145,7 @@ function fetchDNSRecords() {
--data "$request"
)
_dns_records=$( echo "$_response" | jq '.resData.record[]' )
_dns_records=$(echo "$_response" | jq '.resData.record[]')
}
# requires parameter A or AAAA
@@ -187,16 +191,18 @@ function updateRecord() {
IP=$_new_IPv6
fi
if [[ $IP != "" ]]; then
request=$( echo "{}" | \
jq '(.method="nameserver.updateRecord")' | \
jq "(.params.user=\"$DYNB_USERNAME\")" | \
jq "(.params.pass=\"$DYNB_PASSWORD\")" | \
jq "(.params.id=\"$ID\")" | \
jq "(.params.content=\"$IP\")" | \
request=$(
echo "{}" |
jq '(.method="nameserver.updateRecord")' |
jq "(.params.user=\"$DYNB_USERNAME\")" |
jq "(.params.pass=\"$DYNB_PASSWORD\")" |
jq "(.params.id=\"$ID\")" |
jq "(.params.content=\"$IP\")" |
jq "(.params.ttl=\"$TTL\")"
)
_response=$(curl --silent \
_response=$(
curl --silent \
"$_interface_str" \
--user-agent "$_userAgent" \
--header "Content-Type: application/json" \
@@ -219,23 +225,23 @@ function dynupdate() {
DYNV6_DYNDNS_UPDATE_URL="https://dynv6.com/api/update?zone=$DYNB_DYN_DOMAIN&token=$DYNB_TOKEN&"
case $DYNB_SERVICE_PROVIDER in
inwx* | INWX* )
inwx* | INWX*)
dyndns_update_url=$INWX_DYNDNS_UPDATE_URL
;;
deSEC* | desec* | dedyn* )
deSEC* | desec* | dedyn*)
dyndns_update_url="${DESEC_DYNDNS_UPDATE_URL}"
;;
dynv6* )
dynv6*)
dyndns_update_url="${DYNV6_DYNDNS_UPDATE_URL}"
myip_str=ipv4
myipv6_str=ipv6
;;
DuckDNS* | duckdns* )
DuckDNS* | duckdns*)
dyndns_update_url="${DUCKDNS_DYNDNS_UPDATE_URL}"
myip_str=ipv4
myipv6_str=ipv6
;;
* )
*)
errorMessage "$DYNB_SERVICE_PROVIDER is not supported"
exit 1
;;
@@ -255,21 +261,22 @@ function dynupdate() {
## request ##
case $DYNB_SERVICE_PROVIDER in
inwx* | INWX* )
inwx* | INWX*)
_response=$(curl --silent "$_interface_str" \
--user-agent "$_userAgent" \
--user "$DYNB_USERNAME":"$DYNB_PASSWORD" \
"${dyndns_update_url}" )
"${dyndns_update_url}")
;;
deSEC* | desec* | dedyn* )
deSEC* | desec* | dedyn*)
_response=$(curl --silent "$_interface_str" \
--user-agent "$_userAgent" \
--header "Authorization: Token $DYNB_TOKEN" \
--get --data-urlencode "hostname=$DYNB_DYN_DOMAIN" \
"${dyndns_update_url}" )
"${dyndns_update_url}")
;;
dynv6* | duckDNS* | duckdns* )
_response=$(curl --silent "$_interface_str" \
dynv6* | duckDNS* | duckdns*)
_response=$(
curl --silent "$_interface_str" \
--user-agent "$_userAgent" \
"${dyndns_update_url}"
)
@@ -277,7 +284,7 @@ function dynupdate() {
esac
case $_response in
good* | OK* | "addresses updated" )
good* | OK* | "addresses updated")
if [[ $_response == "good 127.0.0.1" ]]; then
errorMessage "$_response: Request ignored."
return 1
@@ -287,51 +294,51 @@ function dynupdate() {
return 0
fi
;;
nochg* )
nochg*)
infoMessage "$_response: Nothing has changed, IP addresses are still up to date."
return 1
;;
abuse )
abuse)
errorMessage "$_response: Username is blocked due to abuse."
return 1
;;
badauth | 401 )
badauth | 401)
errorMessage "$_response: Invalid username password combination."
return 1
;;
badagent )
badagent)
errorMessage "$_response: Client disabled. Something is very wrong!"
return 1
;;
!donator )
!donator)
errorMessage "$_response: An update request was sent, including a feature that is not available to that particular user such as offline options."
return 1
;;
!yours )
!yours)
errorMessage "$_response: The domain does not belong to your user account"
return 1
;;
notfqdn )
notfqdn)
errorMessage "$_response: Hostname $DYNB_DYN_DOMAIN is invalid"
return 1
;;
nohost )
nohost)
errorMessage "$_response: Hostname supplied does not exist under specified account, enter new login credentials before performing an additional request."
return 1
;;
numhost )
numhost)
errorMessage "$_response: Too many hostnames have been specified for this update"
return 1
;;
dnserr )
dnserr)
errorMessage "$_response: There is an internal error in the dyndns update system. Retry update no sooner than 30 minutes."
return 1
;;
911 | 5* )
911 | 5*)
errorMessage "$_response: A fatal error on provider side such as a database outage. Retry update no sooner than 30 minutes."
return 1
;;
* )
*)
if [[ "$_response" == "$_status" ]]; then
errorMessage "An unknown response code has been received. $_response"
return 1
@@ -344,21 +351,21 @@ function dynupdate() {
}
function setStatus() {
echo "_status=$1; _eventTime=$2; _errorCounter=$3; _statusHostname=$4; _statusUsername=$5; _statusPassword=$6" > /tmp/dynb.status
echo "_status=$1; _eventTime=$2; _errorCounter=$3; _statusHostname=$4; _statusUsername=$5; _statusPassword=$6" >/tmp/dynb.status
}
# handle errors from past update requests
function checkStatus() {
case $_status in
nochg* )
nochg*)
if [[ _errorCounter -gt 1 ]]; then
errorMessage "The update client was spamming unnecessary update requests, something might be wrong with your IP-Check site."
errorMessage "Fix your config an then delete $_statusFile or restart your docker container"
return 1
fi
;;
nohost | !yours )
if [[ "$_statusHostname" == "$DYNB_DYN_DOMAIN" && ( "$_statusUsername" == "$DYNB_USERNAME" || $_statusUsername == "$DYNB_TOKEN" ) ]]; then
nohost | !yours)
if [[ "$_statusHostname" == "$DYNB_DYN_DOMAIN" && ("$_statusUsername" == "$DYNB_USERNAME" || $_statusUsername == "$DYNB_TOKEN") ]]; then
errorMessage "Hostname supplied does not exist under specified account, enter new login credentials before performing an additional request."
return 1
else
@@ -366,7 +373,7 @@ function checkStatus() {
fi
return 0
;;
badauth | 401 )
badauth | 401)
if [[ "$_statusUsername" == "$DYNB_USERNAME" && "$_statusPassword" == "$DYNB_PASSWORD" ]]; then
errorMessage "Invalid username password combination."
return 1
@@ -375,26 +382,26 @@ function checkStatus() {
fi
return 0
;;
badagent )
badagent)
errorMessage "Client is deactivated by provider."
echo "Fix your config and then manually remove $_statusFile to reset the client blockade."
echo "If it still fails file an issue at github or try another client :)"
return 1
;;
!donator )
!donator)
errorMessage "An update request was sent, including a feature that is not available to that particular user such as offline options."
echo "Fix your config and then manually remove $_statusFile to reset the client blockade"
echo "If it still fails file an issue at github or try another client :)"
return 1
;;
abuse )
abuse)
errorMessage "Username is blocked due to abuse."
echo "Fix your config and then manually remove $_statusFile to reset the client blockade"
echo "If it still fails file an issue at github or try another client :)"
return 1
;;
911 | 5* )
delta=$(( $(date +%s) - _eventTime ))
911 | 5*)
delta=$(($(date +%s) - _eventTime))
if [[ $delta -lt 1800 ]]; then
errorMessage "$_status: The provider currently has an fatal error. DynB will wait for next update until 30 minutes have passed since last request, $(date --date=@$delta -u +%M) minutes already passed."
return 1
@@ -403,7 +410,7 @@ function checkStatus() {
fi
return 0
;;
* )
*)
if [[ _errorCounter -gt 1 ]]; then
errorMessage "An unknown response code has repeatedly been received. $_response"
return 1
@@ -573,13 +580,13 @@ function checkDependencies() {
for i in curl dig; do
if ! command -v $i >/dev/null 2>&1; then
errorMessage "could not find \"$i\", DynB depends on it. "
(( failCounter++ ))
((failCounter++))
fi
done
[[ -x $(command -v jq 2> /dev/null) ]] || {
[[ -x $(command -v jq 2>/dev/null) ]] || {
if [[ $DYNB_UPDATE_METHOD != dyndns* ]]; then
echo "This script depends on jq and it is not available." >&2
(( failCounter++ ))
((failCounter++))
fi
}
if [[ failCounter -gt 0 ]]; then
@@ -640,11 +647,11 @@ function doDynDNS2Updates() {
changed=0
if [[ $_is_IPv4_enabled == true ]]; then
ipHasChanged 4
(( changed += $? ))
((changed += $?))
fi
if [[ $_is_IPv6_enabled == true ]]; then
ipHasChanged 6
(( changed += $? ))
((changed += $?))
fi
if [[ $changed -gt 0 ]]; then
if checkStatus; then
@@ -653,7 +660,7 @@ function doDynDNS2Updates() {
debugMessage "DynDNS2 update success"
else
debugMessage "Save new status after dynupdate has failed"
setStatus "$_response" "$(date +%s)" $(( _errorCounter += 1 )) "$DYNB_DYN_DOMAIN" "${DYNB_USERNAME}" "${DYNB_PASSWORD}${DYNB_TOKEN}"
setStatus "$_response" "$(date +%s)" $((_errorCounter += 1)) "$DYNB_DYN_DOMAIN" "${DYNB_USERNAME}" "${DYNB_PASSWORD}${DYNB_TOKEN}"
fi
else
debugMessage "Skip DynDNS2 update, checkStatus fetched previous error."
@@ -677,7 +684,7 @@ function doUpdates() {
## MAIN method ##
#################
function dynb() {
# shellcheck disable=SC1091
# shellcheck disable=SC1091,SC1090
source "$(dirname "$(realpath "$0")")/dynb-parsing.sh"
# shellcheck source=.env
@@ -702,8 +709,7 @@ function dynb() {
checkDependencies
if loopMode; then
while :
do
while :; do
doUpdates
sleep $DYNB_INTERVAL
done
@@ -718,7 +724,7 @@ function dynb() {
## END MAIN section ##
######################
dynb "${@}"
exit $?
dynb "${@}"
exit $?
# ] <-- needed because of Argbash