mirror of
https://github.com/EV21/dynb.git
synced 2025-12-26 16:39:32 +01:00
Compare commits
3 Commits
1dcb743f50
...
4e82eab9f4
| Author | SHA1 | Date | |
|---|---|---|---|
|
4e82eab9f4
|
|||
|
ca2a5a0d62
|
|||
|
06de559607
|
86
dynb.sh
86
dynb.sh
@@ -51,7 +51,6 @@ _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=
|
||||||
@@ -66,7 +65,7 @@ _response=
|
|||||||
_statusHostname=
|
_statusHostname=
|
||||||
_statusUsername=
|
_statusUsername=
|
||||||
_statusPassword=
|
_statusPassword=
|
||||||
_version=0.3.0
|
_version=0.1.2
|
||||||
_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
|
||||||
@@ -82,23 +81,6 @@ 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
|
||||||
@@ -237,7 +219,7 @@ function updateRecord() {
|
|||||||
--request POST $_INWX_JSON_API_URL \
|
--request POST $_INWX_JSON_API_URL \
|
||||||
--data "$request"
|
--data "$request"
|
||||||
)
|
)
|
||||||
infoMessage "$(echo "$_response" | jq --raw-output '.msg')\n Domain: $DYNB_DYN_DOMAIN\n New IPv${1}: $IP"
|
echo -e "$(echo "$_response" | jq --raw-output '.msg')\n Domain: $DYNB_DYN_DOMAIN\n new IPv${1}: $IP"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,11 +437,6 @@ 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
|
||||||
@@ -472,20 +449,13 @@ function ipHasChanged() {
|
|||||||
errorMessage "DNS request failed $dig_response"
|
errorMessage "DNS request failed $dig_response"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
# If the dns resolver lists multiple records in the answer section we filter the first line
|
dns_ip=$dig_response
|
||||||
# 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 "IPv4 from remote IP check server: $_new_IPv4, IPv4 from DNS: $dns_ip"
|
debugMessage "New IPv4: $_new_IPv4 old was: $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
|
||||||
@@ -498,22 +468,18 @@ function ipHasChanged() {
|
|||||||
errorMessage "DNS request failed $dig_response"
|
errorMessage "DNS request failed $dig_response"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
# If the dns server lists multiple records in the answer section we filter the first line
|
dns_ip=$dig_response
|
||||||
dns_ip=$(echo "$dig_response" | head -n 1)
|
|
||||||
fi
|
fi
|
||||||
_new_IPv6=$remote_ip
|
_new_IPv6=$remote_ip
|
||||||
debugMessage "IPv6 from remote IP check server: $_new_IPv6, IPv4 from DNS: $dns_ip"
|
debugMessage "New IPv6: $_new_IPv6 old was: $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
|
||||||
}
|
}
|
||||||
@@ -724,43 +690,6 @@ 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 ##
|
||||||
#################
|
#################
|
||||||
@@ -788,7 +717,6 @@ 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
|
||||||
|
|||||||
Reference in New Issue
Block a user