Snap DynDNS Server enables you to set up your own easy and simple Dynamic DNS service.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

80 lines
2.6 KiB

#!/bin/bash
########################################################################
# Copyright (C) 2016 Max Mehl <mail [at] mehl [dot] mx>
########################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
########################################################################
#
# This file uses the data forwarded by update.php, validates the given
# login data in the user database, and does the API call to the INWX
# API.
#
########################################################################
cd "$(dirname "$(readlink -f "$0")")"
# Test if config.cfg exists and set needed variables
if [ ! -e config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi
source config.cfg
# Check dependencies
deperrors=''
for depend in curl; do
if ! command -v "$depend" >/dev/null 2>&1; then
deperrors="$depend $deperrors"
fi
done
if [ -n "$deperrors" ]; then
cat <<-EOF
This program depends on some other programs to function.
Not all of those programs could be located on your system.
Please use your package manager to install the following programs:
EOF
echo "$deperrors"
exit 1
fi
USERDB=users.db
DOMAIN="$1"
NEWIP="$2"
U_USER="$3"
U_PASS="$4"
E=$(grep "^$DOMAIN;" $USERDB)
if [ "$E" != "" ]; then
DNSID=$(echo $E | cut -d";" -f2)
E_USER=$(echo $E | cut -d";" -f3)
E_PASS=$(echo $E | cut -d";" -f4)
# Check if user as given correct user and password
if [ "$U_USER" == "$E_USER" ] && [ "$U_PASS" == "$E_PASS" ]; then
DATA=$(cat update.api | sed "s/%PASSWD%/$PASSWORD/g;s/%USER%/$USERNAME/g;s/%DNSID%/$DNSID/g;s/%NEWIP%/$NEWIP/g")
curl -X POST -d "$DATA" "$APIHOST" --header "Content-Type:text/xml" --insecure > update.log
echo "" >> update.log
echo "Updated IP address for $DNSID ($DOMAIN) to $NEWIP." >> update.log
echo "Success: Updated $DOMAIN to $NEWIP."
else
echo "Wrong user or password."
fi
else
echo "Domain does not exist in database"
fi