traefik_v2x/config/ipv64-dns-challenge.sh

83 lines
3.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env sh
#################################################################################################################
# DNS challenge Script für ipv64.net
# Das Script soll genutzt werden um die DNS-01 Challenge per EXEC Methode über
# den "Lets Encrypt client and ACME library written in Go" (LEGO) und die API von ipv64.net
# LEGO Dokumentation: https://go-acme.github.io/lego/dns/exec/
# API Dokumentation: https://ipv64.net/dyndns_updater_api.php
# Mit dem Nginx Proxy Manager ist das Skript nicht kompatibel, da der NPM die EXEC Methode nicht unterstützt.
# Daher wurde das Skript für die Nutzung mit Traefik umgesetzt.
# Traefik Dokumentation: https://doc.traefik.io/traefik/https/acme/#providers
# Getestet wurde es mit Traefik 2.9 aber auch 1.7 sollte es laut Dokumentation unterstützen:
# https://doc.traefik.io/traefik/v1.7/configuration/acme/#provider
#################################################################################################################
# Alle Konfigurationsparameter werden aus der config.env Datei gelesen
#############################################
apk add -U curl
configfile="/etc/traefik/config.env"
if [ ! -r "$configfile" ]; then
echo "Configfile: $configfile does not exist or isn't readable"
exit 1
fi
apitoken=$(grep ^"apitoken=" "$configfile" | sed -e "s/apitoken=//")
if [ -z "$apitoken" ]; then
echo "apitoken is not defined in $configfile"
exit 1
fi
set -e
case "$1" in
"present")
echo "Present"
full_domain=${2%"."}
domain=$(echo $full_domain | rev | cut -d . -f -3 | rev)
praefix=${full_domain%"$domain"}
praefix=${praefix%"."}
auth_h="Authorization: Bearer $apitoken"
domain_pl="add_record=$domain"
praefix_pl="praefix=$praefix"
type_pl="type=TXT"
content_pl="content=$3"
echo "fd=$full_domain, domain=$domain, praefix=$praefix, $content_pl"
curl -s -X POST -d "$domain_pl" -d "$praefix_pl" -d "$type_pl" -d "$content_pl" -H "$auth_h" https://ipv64.net/api
;;
"cleanup")
full_domain=${2%"."}
domain=$(echo $full_domain | rev | cut -d . -f -3 | rev)
praefix=${full_domain%"$domain"}
praefix=${praefix%"."}
auth_h="Authorization: Bearer $apitoken"
domain_pl="del_record=$domain"
praefix_pl="praefix=$praefix"
type_pl="type=TXT"
content_pl="content=$3"
echo "fd=$full_domain, domain= $domain, praefix=$praefix, $content_pl"
curl -s -X DELETE -d "$domain_pl" -d "$praefix_pl" -d "$type_pl" -d "$content_pl" -H "$auth_h" https://ipv64.net/api
;;
"debug")
echo "Debug"
full_domain=${2%"."}
domain=$(echo $full_domain | rev | cut -d . -f -3 | rev)
praefix=${full_domain%"$domain"}
praefix=${praefix%"."}
auth_h="Authorization: Bearer $apitoken"
domain_pl="add_record=$domain"
praefix_pl="praefix=$praefix"
type_pl="type=TXT"
content_pl="content=$3"
echo "fd=$full_domain, domain=$domain, praefix=$praefix, $content_pl $auth_h"
curl -s -X POST -d "$domain_pl" -d "$praefix_pl" -d "$type_pl" -d "$content_pl" -H "$auth_h" https://ipv64.net/api
;;
*)
echo "OOPS"
;;
esac