From b8565eb38f981657988c71dbc5ebb073b7d38756 Mon Sep 17 00:00:00 2001 From: Eduard Veit Date: Sun, 4 Apr 2021 11:19:36 +0200 Subject: [PATCH] :sparkles: add support for deSEC as DynDNS2 provider --- CHANGELOG.md | 2 ++ README.md | 1 + dynb.sh | 68 +++++++++++++++++++++++++++++++++--------------- man/dynb.1 | 2 +- man/man-defs.rst | 2 +- 5 files changed, 52 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbbf629..679d27d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### New +* :sparkles: add support for deSEC as DynDNS2 provider. [Eduard Veit] + * :sparkles: add completion. [Eduard Veit] :sparkles: add man page diff --git a/README.md b/README.md index bf92b07..71d2caa 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ The following update methods are currently implemented: * INWX.com * dynv6.com +* deSEC.io (dedyn.io) ## 📦 Requirements diff --git a/dynb.sh b/dynb.sh index 2c9b698..7e82fd5 100755 --- a/dynb.sh +++ b/dynb.sh @@ -69,7 +69,7 @@ _version=0.0.1 _userAgent="DynB/$_version github.com/EV21/dynb" _configFile=$HOME/.local/share/dynb/.env _statusFile=/tmp/dynb.status -_debug=1 +_debug=0 # Created by argbash-init v2.10.0 # Rearrange the order of options below according to what you would like to see in the help message. @@ -325,7 +325,7 @@ function debugMode() { function debugMessage() { if debugMode; then - echo "Debug: ${1}" + echo "Debug: $*" fi } @@ -429,17 +429,28 @@ function dynupdate() { myipv6_str=myipv6 INWX_DYNDNS_UPDATE_URL="https://dyndns.inwx.com/nic/update?" + DESEC_DYNDNS_UPDATE_URL="https://update.dedyn.io/?" DYNV6_DYNDNS_UPDATE_URL="https://dynv6.com/api/update?zone=$_dyn_domain&token=$_token&" - if [[ $_serviceProvider == "inwx" ]]; then - dyndns_update_url=$INWX_DYNDNS_UPDATE_URL - fi - if [[ $_serviceProvider == "dynv6" ]]; then - dyndns_update_url="${DYNV6_DYNDNS_UPDATE_URL}" - myip_str=ipv4 - myipv6_str=ipv6 - fi + case $_serviceProvider in + inwx | INWX ) + dyndns_update_url=$INWX_DYNDNS_UPDATE_URL + ;; + deSEC | desec* | dedyn* ) + dyndns_update_url="${DESEC_DYNDNS_UPDATE_URL}" + ;; + dynv6 ) + dyndns_update_url="${DYNV6_DYNDNS_UPDATE_URL}" + myip_str=ipv4 + myipv6_str=ipv6 + ;; + * ) + echoerr "$_serviceProvider is not supported" + exit 1 + ;; + esac + # pre encode ip parameters if [[ $_is_IPv4_enabled == true ]] && [[ $_is_IPv6_enabled == true ]]; then dyndns_update_url="${dyndns_update_url}${myip_str}=${_new_IPv4}&${myipv6_str}=${_new_IPv6}" fi @@ -450,19 +461,29 @@ function dynupdate() { dyndns_update_url="${dyndns_update_url}${myipv6_str}=${_new_IPv6}" fi debugMessage "Update URL was: $dyndns_update_url" + ## request ## - if [[ $_serviceProvider == "dynv6" ]]; then - _response=$(curl --silent "$_interface_str" \ - --user-agent "$_userAgent" \ - "${dyndns_update_url}" - ) - fi - if [[ $_serviceProvider == "inwx" ]]; then - _response=$(curl --silent "$_interface_str" \ + case $_serviceProvider in + inwx | INWX ) + _response=$(curl --silent "$_interface_str" \ --user-agent "$_userAgent" \ --user "$_username":"$_password" \ "${dyndns_update_url}" ) - fi + ;; + deSEC | desec* | dedyn* ) + _response=$(curl --silent "$_interface_str" \ + --user-agent "$_userAgent" \ + --header "Authorization: Token $_token" \ + --get --data-urlencode "hostname=$_dyn_domain" \ + "${dyndns_update_url}" ) + ;; + dynv6 ) + _response=$(curl --silent "$_interface_str" \ + --user-agent "$_userAgent" \ + "${dyndns_update_url}" + ) + ;; + esac case $_response in good* ) @@ -653,6 +674,9 @@ function handleParameters() { if [[ $_arg_reset == "on" ]]; then rm --verbose "$_statusFile" exit 0 + fi + if [[ $_arg_debug == "on" ]]; then + _debug=1 fi if [[ $_arg_update_method != "" ]]; then _update_method=$_arg_update_method @@ -792,16 +816,18 @@ function dynb() { fi if [[ $changed -gt 0 ]]; then if checkStatus; then - debugMessage "checkStatus has no errors" + debugMessage "checkStatus has no errors, try update" if dynupdate; then debugMessage "DynDNS2 update success" else debugMessage "Save new status after dynupdate has failed" - setStatus "$_response" "$(date +%s)" $(( _errorCounter += 1 )) "$_dyn_domain" "${_username}${_token}" + setStatus "$_response" "$(date +%s)" $(( _errorCounter += 1 )) "$_dyn_domain" "${_username}" "${_password}${_token}" fi else debugMessage "Skip DynDNS2 update, checkStatus fetched previous error." fi + else + debugMessage "Skip DynDNS2 update, IPs are up to date" fi fi doUnsets diff --git a/man/dynb.1 b/man/dynb.1 index 2747729..f9f5e6c 100644 --- a/man/dynb.1 +++ b/man/dynb.1 @@ -81,7 +81,7 @@ dyndns.example.com .BI \-s \ SERVICE\-PROVIDER\fR,\fB \ \-\-service\-provider \ SERVICE\-PROVIDER set your provider in case you are using DynDNS2. .sp -inwx | dynv6 +inwx | dynv6 | deSEC .TP .BI \-u \ USERNAME\fR,\fB \ \-\-username \ USERNAME depends on your selected update method and your provider. diff --git a/man/man-defs.rst b/man/man-defs.rst index d1f0707..565de07 100644 --- a/man/man-defs.rst +++ b/man/man-defs.rst @@ -22,7 +22,7 @@ .. |OPTION_DOMAIN| replace:: dyndns.example.com -.. |OPTION_SERVICE_PROVIDER| replace:: inwx | dynv6 +.. |OPTION_SERVICE_PROVIDER| replace:: inwx | dynv6 | deSEC .. |OPTION_USERNAME| replace:: e.g. user42