Skip to content

Commit

Permalink
Check if IP parameter is set and a valid IPv4 address
Browse files Browse the repository at this point in the history
Added command output to webhook response
  • Loading branch information
maxkratz committed Apr 13, 2021
1 parent 563b16a commit 3d52c44
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions config/dynamic/webhook.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
{
"id": "update",
"execute-command": "/app/dyn.sh",
"include-command-output-in-response": true,
"pass-arguments-to-command":
[
{
"source": "query",
"name": "ip"
}
],
"response-message": "Success"
]
}
]
23 changes: 20 additions & 3 deletions scripts/dyn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@

set -e

# Get ip from parameter
# Get IP from parameter
IP=$1
echo "Update ip to $IP."

# Replace old ip from zonefile by new ip, use tee instead of sed -i
# Check if provided parameter was empty
if [ -z "$IP" ]
then
echo "=> No IP provided. Aborting." >&2
exit 1;
fi

# Check if IP is valid
IP_REGEX="^((25[0-5]|2[0-4][0-9]|[1]?[1-9][0-9]?).){3}(25[0-5]|2[0-4][0-9]|[1]?[1-9]?[0-9])$"
VALID=$(echo $IP | grep -oE "$IP_REGEX" || true)
if [ -z "$VALID" ]
then
echo "=> Provided IP is not a valid IPv4 address. Aborting." >&2
exit 2;
else
echo "=> Update ip to $IP."
fi

# Replace old IP from zonefile by new IP, use tee instead of sed -i
# because Docker does not permit the overwriting of inodes.
sed "s/@ IN A .*/@ IN A $IP/" /zonefile | tee /zonefile.tmp >/dev/null

Expand Down

0 comments on commit 3d52c44

Please sign in to comment.