Skip to content

Commit

Permalink
Merge pull request #73 from linuxserver/add-address-echo
Browse files Browse the repository at this point in the history
Added IP logging
  • Loading branch information
homerr authored Apr 6, 2024
2 parents 3f63491 + fb299eb commit eb17b8c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
12 changes: 6 additions & 6 deletions readme-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ param_net: "host"
param_net_desc: "Use host networking for IPv6 detection"
param_usage_include_env: true
param_env_vars:
- { env_var: "TZ", env_value: "Europe/London", desc: "Specify a timezone to use EG Europe/London"}
- { env_var: "SUBDOMAINS", env_value: "subdomain1,subdomain2", desc: "multiple subdomains allowed, comma separated, no spaces, if your domain is user.duckdns.org you put user, not a sub-subdomain"}
- { env_var: "TOKEN", env_value: "token", desc: "DuckDNS token"}
param_usage_include_vols: false
Expand All @@ -43,7 +42,7 @@ opt_param_env_vars:
- { env_var: "LOG_FILE", env_value: "false", desc: "Set to `true` to log to file (also need to map /config).", env_options: ["false", "true"] }
opt_param_usage_include_vols: true
opt_param_volumes:
- { vol_path: "/config", vol_host_path: "/path/to/{{ project_name }}/config", desc: "Persistent config files" }
- { vol_path: "/config", vol_host_path: "/path/to/{{ project_name }}/config", desc: "Persistent config files. Also set `LOG_FILE=true` to keep address history." }
opt_param_usage_include_ports: false
opt_param_ports: ""
opt_param_device_map: false
Expand All @@ -58,9 +57,9 @@ optional_block_1_items: ""
# application setup block
app_setup_block_enabled: true
app_setup_block: |
- Go to the [duckdns website]({{project_url}}), register your subdomain(s) and retrieve your token
- Create a container with your subdomain(s) and token. If you own user.duckdns.org, you put `SUBDOMAINS=user` you would NOT put a sub subdomain like overseerr from overseerr.user.ducksdns.org
- It will update your IP with the DuckDNS service every 5 minutes (with a random jitter)
- Go to the [duckdns website]({{project_url}}), register your subdomain(s) and retrieve your token.
- Create a container with your subdomain(s) and token. If you own `user.duckdns.org`, you set `SUBDOMAINS=user`. You would NOT set a sub subdomain like `overseerr` from `overseerr.user.ducksdns.org`.
- It will update your IP with the DuckDNS service every 5 minutes (with a random jitter).
## Notice regarding automatic detection
Expand All @@ -71,7 +70,8 @@ app_setup_block: |
# changelog
changelogs:
- { date: "23.12.23:", desc: "Rebase to Alpine 3.19."}
- { date: "30.03.24:", desc: "Added IP address to logging output when IP changes." }
- { date: "23.12.23:", desc: "Rebase to Alpine 3.19." }
- { date: "14.10.23:", desc: "Rework shell script for case insensitivity and update readme to be more clear." }
- { date: "13.10.23:", desc: "Add support for public IPv6 address update using Cloudflare." }
- { date: "25.05.23:", desc: "Rebase to Alpine 3.18, deprecate armhf." }
Expand Down
40 changes: 29 additions & 11 deletions root/app/duck.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

if [ "${LOG_FILE,,}" = "true" ]; then
if [[ "${LOG_FILE,,}" = "true" ]]; then
DUCK_LOG="/config/duck.log"
touch "${DUCK_LOG}"
touch /config/logrotate.status
Expand All @@ -12,28 +12,46 @@ fi

{
# Use cloudflare to autodetect IP if UPDATE_IP is set
if [ "${UPDATE_IP}" = "ipv4" ]; then
if [[ "${UPDATE_IP}" = "ipv4" ]]; then
echo "Detecting IPv4 via CloudFlare"
IPV4=$(dig +short ch txt whoami.cloudflare -4 @1.1.1.1 | sed 's/"//g')
RESPONSE=$(curl -sS --max-time 60 "https://www.duckdns.org/update?domains=${SUBDOMAINS}&token=${TOKEN}&ip=${IPV4}")
elif [ "${UPDATE_IP}" = "ipv6" ]; then
DRESPONSE=$(curl -sS --max-time 60 "https://www.duckdns.org/update?domains=${SUBDOMAINS}&token=${TOKEN}&ip=${IPV4}&verbose=true")
RESPONSE=$(echo "${DRESPONSE}" | awk 'NR==1')
IPCHANGE=$(echo "${DRESPONSE}" | awk 'NR==4')
elif [[ "${UPDATE_IP}" = "ipv6" ]]; then
echo "Detecting IPv6 via CloudFlare"
IPV6=$(dig +short ch txt whoami.cloudflare -6 @2606:4700:4700::1111 | sed 's/"//g')
RESPONSE=$(curl -sS --max-time 60 "https://www.duckdns.org/update?domains=${SUBDOMAINS}&token=${TOKEN}&ipv6=${IPV6}")
elif [ "${UPDATE_IP}" = "both" ]; then
DRESPONSE=$(curl -sS --max-time 60 "https://www.duckdns.org/update?domains=${SUBDOMAINS}&token=${TOKEN}&ipv6=${IPV6}&verbose=true")
RESPONSE=$(echo "${DRESPONSE}" | awk 'NR==1')
IPCHANGE=$(echo "${DRESPONSE}" | awk 'NR==4')
elif [[ "${UPDATE_IP}" = "both" ]]; then
echo "Detecting IPv4 and IPv6 via CloudFlare"
IPV4=$(dig +short ch txt whoami.cloudflare -4 @1.1.1.1 | sed 's/"//g')
IPV6=$(dig +short ch txt whoami.cloudflare -6 @2606:4700:4700::1111 | sed 's/"//g')
RESPONSE=$(curl -sS --max-time 60 "https://www.duckdns.org/update?domains=${SUBDOMAINS}&token=${TOKEN}&ip=${IPV4}&ipv6=${IPV6}")
DRESPONSE=$(curl -sS --max-time 60 "https://www.duckdns.org/update?domains=${SUBDOMAINS}&token=${TOKEN}&ip=${IPV4}&ipv6=${IPV6}&verbose=true")
RESPONSE=$(echo "${DRESPONSE}" | awk 'NR==1')
IPCHANGE=$(echo "${DRESPONSE}" | awk 'NR==4')
else
# Use DuckDns to autodetect IPv4 (default behaviour)
echo "Detecting IPv4 via DuckDNS"
RESPONSE=$(curl -sS --max-time 60 "https://www.duckdns.org/update?domains=${SUBDOMAINS}&token=${TOKEN}&ip=")
DRESPONSE=$(curl -sS --max-time 60 "https://www.duckdns.org/update?domains=${SUBDOMAINS}&token=${TOKEN}&ip=&verbose=true")
IPV4=$(echo "${DRESPONSE}" | awk 'NR==2')
IPV6=$(echo "${DRESPONSE}" | awk 'NR==3')
RESPONSE=$(echo "${DRESPONSE}" | awk 'NR==1')
IPCHANGE=$(echo "${DRESPONSE}" | awk 'NR==4')
fi

if [ "${RESPONSE}" = "OK" ]; then
echo "Your IP was updated at $(date)"
if [[ "${RESPONSE}" = "OK" ]] && [[ "${IPCHANGE}" = "UPDATED" ]]; then
if [[ "${IPV4}" != "" ]] && [[ "${IPV6}" == "" ]]; then
echo "Your IP was updated at $(date) to IPv4: ${IPV4}"
elif [[ "${IPV4}" == "" ]] && [[ "${IPV6}" != "" ]]; then
echo "Your IP was updated at $(date) to IPv6: ${IPV6}"
else
echo "Your IP was updated at $(date) to IPv4: ${IPV4} & IPv6 to: {$IPV6}"
fi
elif [[ "${RESPONSE}" = "OK" ]] && [[ "${IPCHANGE}" = "NOCHANGE" ]]; then
echo "DuckDNS request at $(date) successful. IP(s) unchanged."
else
echo -e "Something went wrong, please check your settings $(date)\nThe response returned was:\n${RESPONSE}"
echo -e "Something went wrong, please check your settings $(date)\nThe response returned was:\n${DRESPONSE}\n"
fi
} | tee -a "${DUCK_LOG}"

0 comments on commit eb17b8c

Please sign in to comment.