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

49 Commits

Author SHA1 Message Date
1f31d943ca add DynDNS2 support for noip.com 2021-11-03 23:24:39 +01:00
c712ec5654 minor: 🔃 update .gitchangelog.rc 2021-11-03 18:09:52 +01:00
9cc26d737f feat: validate ip address respons from ip check web service 2021-11-03 18:09:51 +01:00
e6af29dcd4 feat: check internet connection for selected ip versions 2021-11-03 18:09:51 +01:00
b3eb045cc7 doc: 📝 add labels to Dockerfile 2021-11-03 18:09:51 +01:00
4b68ca837d feat: 🎨 colorful info, debug and error messages 2021-11-03 18:09:50 +01:00
eedb0623ac refactor: ♻️ remove unused argbash fragment 2021-11-03 18:09:50 +01:00
b5d300a86e doc: 📝 update CHANGELOG.md 2021-11-03 18:09:50 +01:00
a95effb00d dev: 🔥 remove md-toc from pre-commit 2021-11-03 18:09:49 +01:00
a5dc7ea9b3 doc: 📝 document docker parameters 2021-11-03 18:09:49 +01:00
63cbce3568 feat: enable parameter extensions for docker run --interactive 2021-11-03 18:09:49 +01:00
73d2a7ac44 dev: add pre-commit hooks for markdown 2021-11-03 18:09:49 +01:00
cad6d47cd2 cosmetic: 🎨 lint README.md 2021-11-03 18:09:48 +01:00
06c35d99af doc: 📝 change default dns server setting 2021-11-03 18:09:48 +01:00
9da624b163 dev: 🎨 add shfmt params to pre-commit check 2021-11-03 18:09:47 +01:00
c01bea615e cosmetic: 🎨 fix shell style 2021-11-03 18:09:47 +01:00
046a728f22 change: handle dns server selection 2021-11-03 18:09:47 +01:00
3ded7fc883 refactor: ♻️ seperate parsing logic 2021-11-03 18:09:46 +01:00
f942a4495d dev:️ change git hooks and add shfmt 2021-11-03 18:09:46 +01:00
32404f2957 doc: 📝 update CHANGELOG 2021-11-03 18:09:46 +01:00
3cdcdbc8bf cosmetic: ♻️ normalizing pre-commit configuration to a top-level map 2021-11-03 18:09:45 +01:00
226537b2b0 refactor: ♻️ something 2021-11-03 18:09:45 +01:00
976ea673f8 dev: add pre-commit git hook for shellcheck 2021-11-03 18:09:45 +01:00
9ed30f2bee refactor: ♻️ remove unused help message 2021-11-03 18:09:44 +01:00
3ab88e5993 doc: 📝 update README.md 2021-11-03 18:09:44 +01:00
317abdbcec doc: 📝 document environment variables 2021-11-03 18:09:44 +01:00
4faba4e600 refactor: ♻️ method extractions and other beautifications 2021-11-03 18:09:43 +01:00
84784248c3 fix: 🐛 fix loop and error handling in case of connection issues 2021-11-03 18:09:43 +01:00
b083080c9d doc: 📝 document example of an docker-compose.yml file 2021-11-03 18:09:42 +01:00
48df7c7646 feat: add Dockerfile 2021-11-03 18:09:42 +01:00
b1f6c5a0fd doc: 📝 document loop mode and mention dig as requirement 2021-11-03 18:09:42 +01:00
17e23e7623 feat: add loop mode 2021-11-03 18:09:41 +01:00
bb1e0db9bf doc: 📝 update example of .env in README.md 2021-11-03 18:09:41 +01:00
29c2f62292 change: 🔃 rename environment variables 2021-11-03 18:09:41 +01:00
c85d5eaaee feat: add support for Duck DNS as DynDNS2 provider 2021-11-03 18:09:40 +01:00
3221f29d71 feat: add support for deSEC as DynDNS2 provider 2021-11-03 18:09:40 +01:00
706b6d84c1 feat: add completion
 add man page
2021-11-03 18:09:39 +01:00
6d9bf8a2ae feat: 🔃 replace getopt with argbash 2021-11-03 18:09:39 +01:00
6a14d00256 fix: 🐛 fix error handling 2021-11-03 18:09:39 +01:00
dff0c1c178 refactor: ♻️ main code 2021-11-03 18:09:38 +01:00
9bac611ddf feat: add interpretaton of status codes and act accordingly 2021-11-03 18:09:38 +01:00
1bb0f44d28 feat: make network interface configurable 2021-11-03 18:09:38 +01:00
730858344c fix: 🐛 fix sourcing of config file
♻️ do some shellcheck fixes
2021-11-03 18:09:02 +01:00
e3781a87bb feat: add DynDNS2 support for dynv6.com 2021-11-03 17:00:44 +01:00
fa5086f197 doc: 📝 CHANGELOG.md 2021-11-03 17:00:21 +01:00
3fa15b4d9d minor: 📝 .gitchangelog.rc 2021-11-03 16:59:05 +01:00
2c90e74bf5 doc: 📝 add example.env 2021-11-03 16:57:53 +01:00
cddcd9cfca add: 📝 README.md 2021-11-03 16:56:55 +01:00
616c1d47c1 add: dynb.sh 2021-11-03 16:56:39 +01:00
2 changed files with 107 additions and 20 deletions

View File

@@ -82,24 +82,34 @@ ignore_regexps = [
## whenever you are tweaking this variable. ## whenever you are tweaking this variable.
## ##
section_regexps = [ section_regexps = [
('New', [ ('Features', [
r'^:sparkles\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', r'^[fF]eat\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]), ]),
('Changes', [ ('Added', [
r'^:wrench\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', r'^[aA]dd\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Changed', [
r'^[cC]hange\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Deprecated', [
r'^[dD]epricated\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Removed', [
r'^[rR]emove\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]), ]),
('Fix', [ ('Fix', [
r'^:bug\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', r'^[fF]ix\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Security', [
r'^[sS]ec\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]), ]),
('Documentation', [ ('Documentation', [
r'^:memo\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$', r'^[dD]oc\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Remove', [
r'^:fire\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]), ]),
('Other', None ## Match all lines
), #('Other', None ## Match all lines
# ),
] ]

93
dynb.sh
View File

@@ -51,6 +51,7 @@ _network_interface=
###################################################### ######################################################
## You don't need to change the following variables ## ## You don't need to change the following variables ##
_INWX_JSON_API_URL=https://api.domrobot.com/jsonrpc/ _INWX_JSON_API_URL=https://api.domrobot.com/jsonrpc/
_internet_connectivity_test_server=https://www.google.de
_new_IPv4= _new_IPv4=
_new_IPv6= _new_IPv6=
_dns_records= _dns_records=
@@ -65,7 +66,7 @@ _response=
_statusHostname= _statusHostname=
_statusUsername= _statusUsername=
_statusPassword= _statusPassword=
_version=0.1.2 _version=0.3.0
_userAgent="DynB/$_version github.com/EV21/dynb" _userAgent="DynB/$_version github.com/EV21/dynb"
_configFile=$HOME/.local/share/dynb/.env _configFile=$HOME/.local/share/dynb/.env
_statusFile=/tmp/dynb.status _statusFile=/tmp/dynb.status
@@ -81,6 +82,23 @@ red_color_bg="\e[0;101m${expand_bg}"
bold="\e[1m" bold="\e[1m"
reset_color_modification="\e[0m" reset_color_modification="\e[0m"
REGEX_IPv4="^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$"
REGEX_IPv6="^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$"
function is_IPv4_address() {
if [[ $1 =~ $REGEX_IPv4 ]]
then return 0
else return 1
fi
}
function is_IPv6_address() {
if [[ $1 =~ $REGEX_IPv6 ]]
then return 0
else return 1
fi
}
function loopMode() { function loopMode() {
if [[ $_loopMode -eq 1 ]]; then if [[ $_loopMode -eq 1 ]]; then
return 0 return 0
@@ -219,7 +237,7 @@ function updateRecord() {
--request POST $_INWX_JSON_API_URL \ --request POST $_INWX_JSON_API_URL \
--data "$request" --data "$request"
) )
echo -e "$(echo "$_response" | jq --raw-output '.msg')\n Domain: $DYNB_DYN_DOMAIN\n new IPv${1}: $IP" infoMessage "$(echo "$_response" | jq --raw-output '.msg')\n Domain: $DYNB_DYN_DOMAIN\n New IPv${1}: $IP"
fi fi
} }
@@ -233,6 +251,7 @@ function dynupdate() {
DESEC_DYNDNS_UPDATE_URL="https://update.dedyn.io/?" DESEC_DYNDNS_UPDATE_URL="https://update.dedyn.io/?"
DUCKDNS_DYNDNS_UPDATE_URL="https://www.duckdns.org/update?domains=$DYNB_DYN_DOMAIN&token=$DYNB_TOKEN&" DUCKDNS_DYNDNS_UPDATE_URL="https://www.duckdns.org/update?domains=$DYNB_DYN_DOMAIN&token=$DYNB_TOKEN&"
DYNV6_DYNDNS_UPDATE_URL="https://dynv6.com/api/update?zone=$DYNB_DYN_DOMAIN&token=$DYNB_TOKEN&" DYNV6_DYNDNS_UPDATE_URL="https://dynv6.com/api/update?zone=$DYNB_DYN_DOMAIN&token=$DYNB_TOKEN&"
NOIP_DYNDNS_UPDATE_URL="https://dynupdate.no-ip.com/nic/update?hostname=$DYNB_DYN_DOMAIN&"
case $DYNB_SERVICE_PROVIDER in case $DYNB_SERVICE_PROVIDER in
inwx* | INWX*) inwx* | INWX*)
@@ -241,6 +260,9 @@ function dynupdate() {
deSEC* | desec* | dedyn*) deSEC* | desec* | dedyn*)
dyndns_update_url="${DESEC_DYNDNS_UPDATE_URL}" dyndns_update_url="${DESEC_DYNDNS_UPDATE_URL}"
;; ;;
noip* | no-ip*)
dyndns_update_url="$NOIP_DYNDNS_UPDATE_URL"
;;
dynv6*) dynv6*)
dyndns_update_url="${DYNV6_DYNDNS_UPDATE_URL}" dyndns_update_url="${DYNV6_DYNDNS_UPDATE_URL}"
myip_str=ipv4 myip_str=ipv4
@@ -271,7 +293,7 @@ function dynupdate() {
## request ## ## request ##
case $DYNB_SERVICE_PROVIDER in case $DYNB_SERVICE_PROVIDER in
inwx* | INWX*) inwx* | INWX* | noip* | no-ip*)
_response=$(curl --silent "$_interface_str" \ _response=$(curl --silent "$_interface_str" \
--user-agent "$_userAgent" \ --user-agent "$_userAgent" \
--user "$DYNB_USERNAME":"$DYNB_PASSWORD" \ --user "$DYNB_USERNAME":"$DYNB_PASSWORD" \
@@ -293,6 +315,7 @@ function dynupdate() {
;; ;;
esac esac
case $_response in case $_response in
good* | OK* | "addresses updated") good* | OK* | "addresses updated")
if [[ $_response == "good 127.0.0.1" ]]; then if [[ $_response == "good 127.0.0.1" ]]; then
@@ -437,6 +460,11 @@ function ipHasChanged() {
case ${1} in case ${1} in
4) 4)
remote_ip=$(getRemoteIP 4 $_ipv4_checker) remote_ip=$(getRemoteIP 4 $_ipv4_checker)
if ! is_IPv4_address "$remote_ip"
then
errorMessage "The response from the IP check server is not an IPv4 address: $remote_ip"
return 0
fi
if [[ $DYNB_UPDATE_METHOD == domrobot ]]; then if [[ $DYNB_UPDATE_METHOD == domrobot ]]; then
dns_ip=$(getDNSIP A) dns_ip=$(getDNSIP A)
else else
@@ -449,13 +477,20 @@ function ipHasChanged() {
errorMessage "DNS request failed $dig_response" errorMessage "DNS request failed $dig_response"
return 0 return 0
fi fi
dns_ip=$dig_response # If the dns resolver lists multiple records in the answer section we filter the first line
# using short option "-n" and not "--lines" because of alpines limited BusyBox head command
dns_ip=$(echo "$dig_response" | head -n 1)
fi fi
_new_IPv4=$remote_ip _new_IPv4=$remote_ip
debugMessage "New IPv4: $_new_IPv4 old was: $dns_ip" debugMessage "IPv4 from remote IP check server: $_new_IPv4, IPv4 from DNS: $dns_ip"
;; ;;
6) 6)
remote_ip=$(getRemoteIP 6 $_ipv6_checker) remote_ip=$(getRemoteIP 6 $_ipv6_checker)
if ! is_IPv6_address "$remote_ip"
then
errorMessage "The response from the IP check server is not an IPv6 address: $remote_ip"
return 0
fi
if [[ $DYNB_UPDATE_METHOD == domrobot ]]; then if [[ $DYNB_UPDATE_METHOD == domrobot ]]; then
dns_ip=$(getDNSIP AAAA) dns_ip=$(getDNSIP AAAA)
else else
@@ -468,18 +503,22 @@ function ipHasChanged() {
errorMessage "DNS request failed $dig_response" errorMessage "DNS request failed $dig_response"
return 0 return 0
fi fi
dns_ip=$dig_response # If the dns server lists multiple records in the answer section we filter the first line
dns_ip=$(echo "$dig_response" | head -n 1)
fi fi
_new_IPv6=$remote_ip _new_IPv6=$remote_ip
debugMessage "New IPv6: $_new_IPv6 old was: $dns_ip" debugMessage "IPv6 from remote IP check server: $_new_IPv6, IPv4 from DNS: $dns_ip"
;; ;;
*) ;; *) ;;
esac esac
if [[ "$remote_ip" == "$dns_ip" ]]; then if [[ "$remote_ip" == "$dns_ip" ]]; then
return 0 return 0
else else
case ${1} in
4) infoMessage "New IPv4: $_new_IPv4 old was: $dns_ip";;
6) infoMessage "New IPv6: $_new_IPv6 old was: $dns_ip";;
esac
return 1 return 1
fi fi
} }
@@ -690,6 +729,43 @@ function doUpdates() {
fi fi
} }
function ipv6_is_not_working() {
curl --ipv6 --head --silent --max-time 1 "$_internet_connectivity_test_server" > /dev/null
status_code=$?
if [[ $status_code -gt 0 ]]
then return 0
else return 1
fi
}
function ipv4_is_not_working() {
curl --ipv4 --head --silent --max-time 1 "$_internet_connectivity_test_server" > /dev/null
status_code=$?
if [[ $status_code -gt 0 ]]
then return 0
else return 1
fi
}
function check_internet_connection() {
if [[ $_is_IPv4_enabled == true ]]
then
if ipv4_is_not_working
then
_is_IPv4_enabled="false"
errorMessage "Your IPv4 internet connection does not work."
fi
fi
if [[ $_is_IPv6_enabled == true ]]
then
if ipv6_is_not_working
then
_is_IPv6_enabled="false"
errorMessage "Your IPv6 internet connection does not work."
fi
fi
}
################# #################
## MAIN method ## ## MAIN method ##
################# #################
@@ -717,6 +793,7 @@ function dynb() {
## parameters and checks ## parameters and checks
handleParameters handleParameters
checkDependencies checkDependencies
check_internet_connection
if loopMode; then if loopMode; then
while :; do while :; do