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

feat: make network interface configurable

This commit is contained in:
2021-01-25 13:00:05 +01:00
parent 730858344c
commit 1bb0f44d28
2 changed files with 33 additions and 9 deletions

View File

@@ -5,6 +5,8 @@
### New ### New
* :sparkles: make network interface configurable. [Eduard Veit]
* :sparkles: add DynDNS2 support for dynv6.com. [Eduard Veit] * :sparkles: add DynDNS2 support for dynv6.com. [Eduard Veit]
* :sparkles: add .gitchangelog.rc. [Eduard Veit] * :sparkles: add .gitchangelog.rc. [Eduard Veit]

40
dynb.sh
View File

@@ -28,17 +28,25 @@ _ip_mode=
_username= _username=
_password= _password=
## TTL (time to live) minimum allowed value by inwx is 300 (5 minutes) ## TTL (time to live) for the DNS record
## This setting is only relevant for API based record updates (not DnyDNS2!)
## minimum allowed TTL value by inwx is 300 (5 minutes)
TTL=300 TTL=300
## The IP-Check sites (some sites have different urls for v4 and v6) ## The IP-Check sites (some sites have different urls for v4 and v6)
## pro tip: use your own ip check server for privacy ## Pro tip: use your own ip check server for privacy
## it could be as simple as that... ## it could be as simple as that...
## create an index.php with <?php echo $_SERVER['REMOTE_ADDR']; ?> ## create an index.php with <?php echo $_SERVER['REMOTE_ADDR']; ?>
_ipv4_checker=api64.ipify.org _ipv4_checker=api64.ipify.org
_ipv6_checker=api64.ipify.org _ipv6_checker=api64.ipify.org
_DNS_checkServer=1.1.1.1 _DNS_checkServer=1.1.1.1
## if you are actively using multiple network interfaces you might want to specify this
## normally the default value is okay
#_network_interface=eth0
_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/
@@ -49,6 +57,7 @@ _main_domain=
_has_getopt= _has_getopt=
_is_IPv4_enabled=false _is_IPv4_enabled=false
_is_IPv6_enabled=false _is_IPv6_enabled=false
_interface_str=
[[ -x $(command -v jq 2> /dev/null) ]] || { [[ -x $(command -v jq 2> /dev/null) ]] || {
echo "This script depends on jq and it is not available." >&2 echo "This script depends on jq and it is not available." >&2
@@ -76,6 +85,7 @@ dynb [options]
-d | --domain "dyndns.example.com" set the domain you want to update -d | --domain "dyndns.example.com" set the domain you want to update
-u | --username "user42" depends on your selected update method and your provider -u | --username "user42" depends on your selected update method and your provider
-p | --password "SuperSecretPassword" depends on your selected update method and your provider -p | --password "SuperSecretPassword" depends on your selected update method and your provider
--link links to your script at ~/.local/bin/dynb
##### examples ##### ##### examples #####
dynb --ip-mode dualstack --update-method domrobot --domain dyndns.example.com --username user42 --password SuperSecretPassword dynb --ip-mode dualstack --update-method domrobot --domain dyndns.example.com --username user42 --password SuperSecretPassword
@@ -94,9 +104,10 @@ function getMainDomain() {
) )
response=$(curl --silent \ response=$(curl --silent \
"$_interface_str" \
--request POST $_INWX_JSON_API_URL \ --request POST $_INWX_JSON_API_URL \
--header "Content-Type: application/json" \ --header "Content-Type: application/json" \
--data "$request" | jq ".resData.domains[] | select(inside(.domain=\"$_dyn_domain\"))" --data "$request" | jq ".resData.domains[] | select(inside(.domain=\"$_dyn_domain\"))"
) )
_main_domain=$( echo "$response" | jq --raw-output '.domain' ) _main_domain=$( echo "$response" | jq --raw-output '.domain' )
} }
@@ -111,9 +122,10 @@ function fetchDNSRecords() {
) )
response=$( curl --silent \ response=$( curl --silent \
"$_interface_str" \
--request POST $_INWX_JSON_API_URL \ --request POST $_INWX_JSON_API_URL \
--header "Content-Type: application/json" \ --header "Content-Type: application/json" \
--data "$request" --data "$request"
) )
_dns_records=$( echo "$response" | jq '.resData.record[]' ) _dns_records=$( echo "$response" | jq '.resData.record[]' )
@@ -136,7 +148,7 @@ function getDNSIP() {
# 2. param: IP check server address # 2. param: IP check server address
# result to stdout # result to stdout
function getRemoteIP() { function getRemoteIP() {
curl --silent --ipv"${1}" --dns-servers 1.1.1.1 --location "${2}" curl --silent "$_interface_str" --ipv"${1}" --dns-servers 1.1.1.1 --location "${2}"
} }
# requires parameter # requires parameter
@@ -161,6 +173,7 @@ function updateRecord() {
) )
response=$(curl --silent \ response=$(curl --silent \
"$_interface_str" \
--request POST $_INWX_JSON_API_URL \ --request POST $_INWX_JSON_API_URL \
--header "Content-Type: application/json" \ --header "Content-Type: application/json" \
--data "$request" --data "$request"
@@ -200,11 +213,11 @@ function dynupdate() {
## request ## ## request ##
if [[ $_serviceProvider == "dynv6" ]]; then if [[ $_serviceProvider == "dynv6" ]]; then
response=$(curl --silent "${dyndns_update_url}" ) response=$(curl "$_interface_str" --silent "${dyndns_update_url}" )
#echo $dyndns_update_url #echo $dyndns_update_url
fi fi
if [[ $_serviceProvider == "inwx" ]]; then if [[ $_serviceProvider == "inwx" ]]; then
response=$(curl --silent --user "$_username":"$_password" "${dyndns_update_url}" ) response=$(curl "$_interface_str" --silent --user "$_username":"$_password" "${dyndns_update_url}" )
fi fi
case $response in case $response in
@@ -366,6 +379,8 @@ function checkDependencies() {
## MAIN section ## ## MAIN section ##
################## ##################
## parameters and checks
FILE=$(dirname "$(realpath "$0")")/.env FILE=$(dirname "$(realpath "$0")")/.env
if test -f "$FILE"; then if test -f "$FILE"; then
# shellcheck source=.env # shellcheck source=.env
@@ -379,6 +394,10 @@ fi
checkDependencies checkDependencies
if [[ $_network_interface != "" ]]; then
_interface_str="--interface $_network_interface"
fi
if [[ $_ip_mode == d* ]]; then if [[ $_ip_mode == d* ]]; then
_is_IPv4_enabled=true _is_IPv4_enabled=true
_is_IPv6_enabled=true _is_IPv6_enabled=true
@@ -390,6 +409,8 @@ if [[ $_ip_mode == *6* ]]; then
_is_IPv6_enabled=true _is_IPv6_enabled=true
fi fi
## execute operations
if [[ $_update_method == "domrobot" ]]; then if [[ $_update_method == "domrobot" ]]; then
getMainDomain getMainDomain
fetchDNSRecords fetchDNSRecords
@@ -422,6 +443,7 @@ if [[ $_update_method == "dyndns" ]]; then
fi fi
fi fi
unset _network_interface
unset _DNS_checkServer unset _DNS_checkServer
unset _dns_records unset _dns_records
unset _dyn_domain unset _dyn_domain