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

2 Commits

Author SHA1 Message Date
642e53aadf add support for Duck DNS as DynDNS2 provider 2021-04-04 14:46:54 +02:00
b8565eb38f add support for deSEC as DynDNS2 provider 2021-04-04 11:24:13 +02:00
5 changed files with 67 additions and 28 deletions

View File

@@ -5,6 +5,10 @@
### New
* :sparkles: add support for Duck DNS as DynDNS2 provider. [Eduard Veit]
* :sparkles: add support for deSEC as DynDNS2 provider. [Eduard Veit]
* :sparkles: add completion. [Eduard Veit]
:sparkles: add man page

View File

@@ -25,7 +25,9 @@ The following update methods are currently implemented:
### DynDNS2
* INWX.com
* dynv6.com
* deSEC.io (dedyn.io)
* DuckDNS.org
* dynv6.com
## 📦 Requirements

83
dynb.sh
View File

@@ -12,7 +12,7 @@
_dyn_domain=
## service provider could be inwx
## service provider could be deSEC, duckdns, dynv6, inwx
_serviceProvider=
## update method options: domrobot, dyndns
@@ -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.
@@ -287,6 +287,7 @@ parse_commandline "$@"
### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash
# The generated argbash help message does not look as nice as this:
_help_message="$(cat << 'EOF'
dynb - dynamic DNS update script for bash
@@ -325,7 +326,7 @@ function debugMode() {
function debugMessage() {
if debugMode; then
echo "Debug: ${1}"
echo "Debug: $*"
fi
}
@@ -429,17 +430,34 @@ function dynupdate() {
myipv6_str=myipv6
INWX_DYNDNS_UPDATE_URL="https://dyndns.inwx.com/nic/update?"
DESEC_DYNDNS_UPDATE_URL="https://update.dedyn.io/?"
DUCKDNS_DYNDNS_UPDATE_URL="https://www.duckdns.org/update?domains=$_dyn_domain&token=$_token&"
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
;;
DuckDNS* | duckdns* )
dyndns_update_url="${DUCKDNS_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,22 +468,32 @@ 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* | duckDNS* | duckdns* )
_response=$(curl --silent "$_interface_str" \
--user-agent "$_userAgent" \
"${dyndns_update_url}"
)
;;
esac
case $_response in
good* )
good* | OK* )
if [[ $_response == "good 127.0.0.1" ]]; then
echoerr "Error: $_response: Request ignored."
return 1
@@ -624,10 +652,10 @@ function ipHasChanged() {
if [[ ${1} == 4 ]]; then
_new_IPv4=$remote_ip
#echo "New IPv4: $_new_IPv4 old was: $dns_ip"
debugMessage "New IPv4: $_new_IPv4 old was: $dns_ip"
else
_new_IPv6=$remote_ip
#echo "New IPv6: $_new_IPv6 old was: $dns_ip"
debugMessage "New IPv6: $_new_IPv6 old was: $dns_ip"
fi
if [[ "$remote_ip" == "$dns_ip" ]]; then
@@ -653,6 +681,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 +823,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

View File

@@ -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
deSEC | duckdns | dynv6 | inwx
.TP
.BI \-u \ USERNAME\fR,\fB \ \-\-username \ USERNAME
depends on your selected update method and your provider.

View File

@@ -22,7 +22,7 @@
.. |OPTION_DOMAIN| replace:: dyndns.example.com
.. |OPTION_SERVICE_PROVIDER| replace:: inwx | dynv6
.. |OPTION_SERVICE_PROVIDER| replace:: deSEC | duckdns | dynv6 | inwx
.. |OPTION_USERNAME| replace:: e.g. user42