add update_dyndns.sh for authelia-managment

This commit is contained in:
2026-01-31 19:29:00 +01:00
parent e4b4718dc7
commit 18557c66dc
5 changed files with 124 additions and 10 deletions

View File

@@ -76,6 +76,8 @@ The tool automatically detects your system language.
- **English**: Default.
- **German**: Available if system locale is set to German.
sudo crontab -e
@reboot /opt/containers/authelia-watcher/update_dyndns.sh > /dev/null 2>&1 &
## Disclaimer
Use without warranty! This tool is provided as-is to help manage Docker environments.

View File

@@ -18,7 +18,7 @@ export TEXTDOMAIN=clidmanager
export TEXTDOMAINDIR="/usr/share/locale"
# Translations for header variables
version_num="v. 2.01.3026"
version_num="v. 2.01.3126"
version=$(printf "${GREEN}%s${LBLUE}" "$version_num")
cmname=$(printf "${YELLOW}%s${LBLUE}" "containermanager")
info=$(echo -e "${GREEN}$(gettext "Enter 'dw' in terminal to go directly")")
@@ -191,6 +191,25 @@ watcher_management() {
return
fi
ENV_PATH="/opt/containers/authelia-watcher/config/.env"
# Initial .env is not exist
if [ ! -f "$ENV_PATH" ]; then
{
echo "MY_DOMAIN=\"\""
echo "CHECK_INTERVAL=300"
echo "SEND_WELCOME_NOTIFICATION=1"
echo "SEND_WATCHER_START_NOTIFICATION=1"
} > "$ENV_PATH"
else
# Ensure rows before write
for var in MY_DOMAIN CHECK_INTERVAL SEND_WELCOME_NOTIFICATION SEND_WATCHER_START_NOTIFICATION; do
grep -q "^$var=" "$ENV_PATH" || echo "$var=" >> "$ENV_PATH"
done
# Set standard value when empty
sed -i 's/^CHECK_INTERVAL=$/CHECK_INTERVAL=300/' "$ENV_PATH"
fi
while true; do
clear
echo -e "${LBLUE}--- Authelia Watcher: Management & Config ---${NORMAL}"
@@ -200,8 +219,9 @@ watcher_management() {
echo -e "[$two] $(gettext "Manually unban an IP")"
echo -e "[$three] $(gettext "Whitelist Management (DynDNS/Static)")"
echo -e "[$four] $(gettext "Edit JSON Configuration")"
echo -e "[$five] $(gettext "View Watcher Logs")"
echo -e "[$six] $(gettext "Back to Main Menu")"
echo -e "[$five] $(gettext "DynDNS & Notification Settings")"
echo -e "[$six] $(gettext "View Watcher Logs")"
echo -e "[$seven] $(gettext "Back to Main Menu")"
echo "======================================================"
read -n 1 -s -r -p "$(gettext "Select an option: ")" wopt
@@ -267,10 +287,34 @@ watcher_management() {
nano /opt/containers/authelia-watcher/config/watcher-config.json
docker restart "$REAL_CONTAINER_NAME"
;;
5)
5)
echo -e "\n\n--- $(gettext "DynDNS & Notification Settings") ---"
echo -e "$(gettext "Current Domain:") ${GREEN}${MY_DOMAIN:-N/A}${NORMAL}"
echo -e "$(gettext "Current Interval:") ${GREEN}${CHECK_INTERVAL}${NORMAL}s"
read -p "$(gettext "New Domain (Leave empty to skip): ")" NEW_DOM
read -p "$(gettext "New Interval (seconds, default 300): ")" NEW_INT
read -p "$(gettext "Send Welcome Notification? (1=Yes, 0=No): ")" NEW_WELCOME
read -p "$(gettext "Send Container Start Notification? (1=Yes, 0=No): ")" NEW_START
# Domain Update
[ -n "$NEW_DOM" ] && sed -i "s|^MY_DOMAIN=.*|MY_DOMAIN=\"$NEW_DOM\"|" "$ENV_PATH"
# Interval Update
[ -n "$NEW_INT" ] && sed -i "s/^CHECK_INTERVAL=.*/CHECK_INTERVAL=$NEW_INT/" "$ENV_PATH"
# Welcome Notification Update
[ -n "$NEW_WELCOME" ] && sed -i "s/^SEND_WELCOME_NOTIFICATION=.*/SEND_WELCOME_NOTIFICATION=$NEW_WELCOME/" "$ENV_PATH"
# Watcher Start Notification Update
[ -n "$NEW_START" ] && sed -i "s/^SEND_WATCHER_START_NOTIFICATION=.*/SEND_WATCHER_START_NOTIFICATION=$NEW_START/" "$ENV_PATH"
echo -e "${GREEN}$(gettext "Settings saved.")${NORMAL}"
sleep 2 ;;
6)
docker logs -f --tail 50 "$REAL_CONTAINER_NAME"
;;
6)
7)
sudo clidmanager # Back to main menu
;;
esac

View File

@@ -53,7 +53,9 @@ install() {
exit 0
else
sudo cp -f clidmanager docker_work /usr/local/bin/ && sudo mv no_pwd_clidmanager /etc/sudoers.d/
sudo chmod +x /usr/local/bin/update_dyndns.sh
sudo chmod +x /usr/local/bin/clidmanager
sudo chmod +x /usr/local/bin/docker_work
# Install translation file
sudo mkdir -p /usr/share/locale/de/LC_MESSAGES/
@@ -68,7 +70,7 @@ install() {
sleep 0.8
echo "$(gettext "docker_work installed...") $Bar2%"
sleep 0.8
echo "$(gettext "clidmanager installed... 90%")"
echo "$(gettext "clidmanager and update_dyndns.sh installed... 90%")"
sleep 0.8
echo
echo "$(gettext "Update installed. 100%")"
@@ -81,11 +83,15 @@ install() {
sleep 0.8
echo "$(gettext "docker_work installed...") $Bar2%"
sleep 0.8
echo "$(gettext "clidmanager installed... 90%")"
echo "$(gettext "clidmanager and update_dyndns.sh installed... 90%")"
sleep 0.8
sudo usermod -aG docker $USER >/dev/null 2>&1
sleep 0.8
echo "$(gettext "User added to Docker group... 100%")"
# Create cronjob
CRON_ENTRY="@reboot /usr/local/bin/update_dyndns.sh > /dev/null 2>&1 &"
(crontab -l 2>/dev/null | grep -Fq "$CRON_ENTRY") || ( (crontab -l 2>/dev/null; echo "$CRON_ENTRY") | crontab - )
echo "$(gettext "Cronjob for DynDNS protection created.")"
echo
echo "$(gettext "At the next login you can call clidmanager")"
echo
@@ -99,8 +105,10 @@ install() {
remove() {
sudo rm -f /usr/local/bin/clidmanager /usr/local/bin/docker_work && sudo rm /etc/sudoers.d/no_pwd_clidmanager
sudo rm -f /usr/local/bin/clidmanager /usr/local/bin/docker_work \
/usr/local/bin/update_dyndns.sh && sudo rm /etc/sudoers.d/no_pwd_clidmanager
sudo rm -f /usr/share/locale/de/LC_MESSAGES/clidmanager.mo
if [ $? -ne 0 ]
then
exit 0
@@ -120,9 +128,11 @@ remove() {
sed -i -e /"alias dw='source docker_work'"/d ~/.bashrc
echo "$(gettext "Alias dw removed.... 90%")"
sleep 0.5
echo "$(gettext "clidmanager completely removed.... 100%")"
echo "$(gettext "clidmanager and update_dyndns.sh completely removed.... 100%")"
sleep 0.5
echo
crontab -l 2>/dev/null | grep -v "update_dyndns.sh" | crontab -
echo "$(gettext "Cronjob removed.")"
read -p "$(gettext "Press Enter to exit...")"
fi
}

Binary file not shown.

58
update_dyndns.sh Normal file
View File

@@ -0,0 +1,58 @@
#!/bin/bash
# Give the system time to establish network
sleep 30
BASE_DIR="/opt/containers/authelia-watcher"
ENV_FILE="$BASE_DIR/config/.env"
CONFIG_FILE="$BASE_DIR/config/watcher-config.json"
WHITELIST_FILE="$BASE_DIR/config/whitelist.txt"
CACHE_FILE="/tmp/last_known_dyndns_ip.txt"
FIRST_RUN=true
while true; do
if [ -f "$ENV_FILE" ]; then
source "$ENV_FILE"
# Check if domain is set and interval is at least 60s
INTERVAL=${CHECK_INTERVAL:-300}
if [ -n "$MY_DOMAIN" ] && [ "$MY_DOMAIN" != "\"\"" ]; then
GOTIFY_URL=$(jq -r '.gotify_url // empty' "$CONFIG_FILE")
CURRENT_IP=$(dig +short "$MY_DOMAIN" | tail -n1)
if [ -n "$CURRENT_IP" ]; then
# 1. Welcome Notification on First Success
if [ "$FIRST_RUN" = true ] && [ "$SEND_WELCOME_NOTIFICATION" = "1" ]; then
if [ -n "$GOTIFY_URL" ]; then
MSG="DynDNS protection active for $MY_DOMAIN. Your IP $CURRENT_IP is now automatically whitelisted."
curl -s -o /dev/null -H "Content-Type: application/json" -X POST "$GOTIFY_URL" \
-d "{\"title\": \"DynDNS Manager\", \"message\": \"$MSG\", \"priority\": 2}"
fi
FIRST_RUN=false
fi
# 2. Regular IP Check & Update
LAST_IP=$(cat "$CACHE_FILE" 2>/dev/null)
if [ "$CURRENT_IP" != "$LAST_IP" ]; then
[ -n "$LAST_IP" ] && sed -i "/^$LAST_IP$/d" "$WHITELIST_FILE"
grep -Fxq "$CURRENT_IP" "$WHITELIST_FILE" || echo "$CURRENT_IP" >> "$WHITELIST_FILE"
# Clean host iptables
while iptables -L INPUT -n | grep -q "$CURRENT_IP"; do
iptables -D INPUT -s "$CURRENT_IP" -j DROP 2>/dev/null
done
echo "$CURRENT_IP" > "$CACHE_FILE"
if [ "$FIRST_RUN" = false ] && [ -n "$GOTIFY_URL" ]; then
curl -s -o /dev/null -H "Content-Type: application/json" -X POST "$GOTIFY_URL" \
-d "{\"title\": \"DynDNS Update\", \"message\": \"New IP $CURRENT_IP whitelisted.\", \"priority\": 2}"
fi
fi
fi
fi
fi
sleep "$INTERVAL"
done