From 48c935d283216bb96ded78c453186f6ab22ee201 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Tue, 3 May 2022 20:03:36 +0200 Subject: Init Netcup IP failover script Signed-off-by: Georg Pfuetzenreuter --- scripts/sh/netcup_failover.sh | 105 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 scripts/sh/netcup_failover.sh (limited to 'scripts/sh') diff --git a/scripts/sh/netcup_failover.sh b/scripts/sh/netcup_failover.sh new file mode 100755 index 0000000..fbd5dbd --- /dev/null +++ b/scripts/sh/netcup_failover.sh @@ -0,0 +1,105 @@ +#!/bin/sh +# Floating IP switching script utilizing the Netcup API + +SCP_USER="12345" +SCP_PASS="xxx" +SCP_SERVER="v6789" +MAC="xx:xx:xx:xx:xx:xx" +IP_v4="192.0.2.10/32" +IP_v6="not:tested::/64" + +URL="https://www.servercontrolpanel.de/WSEndUser?xsd=1" ### ?xsd=1 ?wsdl + +usage () { + echo "$0 [--ipv4 | --ipv6 | --all] [--debug]" + exit 2 +} + +init () { + construct "$1" + run + parse +} + +construct () { + if [ "$1" = "ip4" ]; + then + local IP="$IP_v4" + fi + if [ "$1" = "ip6" ]; + then + local IP="$IP_v6" + fi + local CIDR="${IP#*/}" + local IP="`echo $IP | sed "s?/$CIDR??"`" + if [ "$DEBUG" = "true" ]; + then + echo "[DEBUG] Initiating: $1" + echo "[DEBUG] IP Address: $IP" + echo "[DEBUG] CIDR Mask: $CIDR" + fi + XML_BODY="$SCP_USER$SCP_PASS$IP$CIDR$SCP_SERVER$MAC" + if [ "$DEBUG" = "true" ]; + then + echo "[DEBUG] Payload: $XML_BODY" + fi +} + +request () { + curl -s -H 'Content-Type: text/xml' -H 'SOAPAction:' -d "$XML_BODY" -X POST "$URL" +} + +run () { + RESPONSE=`request` + if [ "$DEBUG" = "true" ]; + then + echo "[DEBUG] Response: $RESPONSE" + fi + +} + +parse () { + local IFS='&' + local check_invalid="validation error&IP already assigned&true" + for check in $check_invalid; + do + if [ "$DEBUG" = "true" ]; + then + echo "[DEBUG] Parsing: $check" + fi + if [ "${RESPONSE#*$check}" = "$RESPONSE" ]; + then + result="Not found" + fi + if [ "${RESPONSE#*$check}" != "$RESPONSE" ]; + then + result="Found" + fi + echo "Check for \"$check\": $result" + done +} + +MODE="$1" + +if [ "$2" = "--debug" ]; +then + DEBUG="true" + echo "[DEBUG] Script invoked at `date`" +fi + +case "$MODE" in + "--ipv4" ) + init ip4 + ;; + "--ipv6" ) + init ip6 + ;; + "--all" ) + init ip6 + init ip4 + ;; + * ) + usage + ;; +esac + -- cgit v1.2.3