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

7 Commits

3 changed files with 129 additions and 26 deletions

View File

@@ -82,24 +82,34 @@ ignore_regexps = [
## whenever you are tweaking this variable.
##
section_regexps = [
('New', [
r'^:sparkles\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
('Features', [
r'^[fF]eat\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Changes', [
r'^:wrench\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
('Added', [
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', [
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', [
r'^:memo\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]*)$',
]),
r'^[dD]oc\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Other', None ## Match all lines
),
#('Other', None ## Match all lines
# ),
]

View File

@@ -1,4 +1,5 @@
FROM alpine:latest
RUN \
apk update \
&& \
@@ -7,6 +8,13 @@ bash \
curl \
jq \
bind-tools
WORKDIR /usr/src/app
COPY . .
ENTRYPOINT ["/bin/bash", "/usr/src/app/dynb.sh"]
ENTRYPOINT ["/bin/bash", "/usr/src/app/dynb.sh"]
LABEL org.opencontainers.image.source="https://github.com/EV21/dynb"
LABEL org.opencontainers.image.description="DynB - dynamic DNS update client."
LABEL org.opencontainers.image.licenses="MIT"

111
dynb.sh
View File

@@ -51,6 +51,7 @@ _network_interface=
######################################################
## You don't need to change the following variables ##
_INWX_JSON_API_URL=https://api.domrobot.com/jsonrpc/
_internet_connectivity_test_server=https://www.google.de
_new_IPv4=
_new_IPv6=
_dns_records=
@@ -65,7 +66,7 @@ _response=
_statusHostname=
_statusUsername=
_statusPassword=
_version=0.1.2
_version=0.3.0
_userAgent="DynB/$_version github.com/EV21/dynb"
_configFile=$HOME/.local/share/dynb/.env
_statusFile=/tmp/dynb.status
@@ -73,6 +74,31 @@ _debug=0
_minimum_looptime=60
_loopMode=0
# Ansi color code variables
yellow_color="\e[0;33m"
green_color="\e[0;92m"
expand_bg="\e[K"
red_color_bg="\e[0;101m${expand_bg}"
bold="\e[1m"
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() {
if [[ $_loopMode -eq 1 ]]; then
return 0
@@ -90,16 +116,18 @@ function debugMode() {
}
function infoMessage() {
echo "$(logtime) INFO: $*"
echo -e "${green_color}$(logtime) INFO: $*${reset_color_modification}"
}
function debugMessage() {
if debugMode; then
echo "$(logtime) DEBUG: $*"
echo -e "${yellow_color}$(logtime) DEBUG: ${*}${reset_color_modification}"
fi
}
function errorMessage() { printf "$(logtime) ERROR: %s\n" "$*" >&2; }
function errorMessage() {
echo -e "${red_color_bg}${bold}$(logtime) ERROR: $*${reset_color_modification}" >&2
}
function logtime() {
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
@@ -209,7 +237,7 @@ function updateRecord() {
--request POST $_INWX_JSON_API_URL \
--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
}
@@ -223,6 +251,7 @@ function dynupdate() {
DESEC_DYNDNS_UPDATE_URL="https://update.dedyn.io/?"
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&"
NOIP_DYNDNS_UPDATE_URL="https://dynupdate.no-ip.com/nic/update?hostname=$DYNB_DYN_DOMAIN&"
case $DYNB_SERVICE_PROVIDER in
inwx* | INWX*)
@@ -231,6 +260,9 @@ function dynupdate() {
deSEC* | desec* | dedyn*)
dyndns_update_url="${DESEC_DYNDNS_UPDATE_URL}"
;;
noip* | no-ip*)
dyndns_update_url="$NOIP_DYNDNS_UPDATE_URL"
;;
dynv6*)
dyndns_update_url="${DYNV6_DYNDNS_UPDATE_URL}"
myip_str=ipv4
@@ -261,7 +293,7 @@ function dynupdate() {
## request ##
case $DYNB_SERVICE_PROVIDER in
inwx* | INWX*)
inwx* | INWX* | noip* | no-ip*)
_response=$(curl --silent "$_interface_str" \
--user-agent "$_userAgent" \
--user "$DYNB_USERNAME":"$DYNB_PASSWORD" \
@@ -283,6 +315,7 @@ function dynupdate() {
;;
esac
case $_response in
good* | OK* | "addresses updated")
if [[ $_response == "good 127.0.0.1" ]]; then
@@ -427,6 +460,11 @@ function ipHasChanged() {
case ${1} in
4)
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
dns_ip=$(getDNSIP A)
else
@@ -439,13 +477,20 @@ function ipHasChanged() {
errorMessage "DNS request failed $dig_response"
return 0
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
_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)
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
dns_ip=$(getDNSIP AAAA)
else
@@ -458,18 +503,22 @@ function ipHasChanged() {
errorMessage "DNS request failed $dig_response"
return 0
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
_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
if [[ "$remote_ip" == "$dns_ip" ]]; then
return 0
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
fi
}
@@ -680,6 +729,43 @@ function doUpdates() {
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 ##
#################
@@ -707,6 +793,7 @@ function dynb() {
## parameters and checks
handleParameters
checkDependencies
check_internet_connection
if loopMode; then
while :; do
@@ -726,5 +813,3 @@ function dynb() {
dynb "${@}"
exit $?
# ] <-- needed because of Argbash