74 lines
2.4 KiB
Bash
74 lines
2.4 KiB
Bash
|
|
#!/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
|
||
|
|
|
||
|
|
# Test whether necessary applications are installed
|
||
|
|
function testinst {
|
||
|
|
APP=$1
|
||
|
|
if [ $(which $APP | wc -l) != 1 ]; then
|
||
|
|
echo "$APP does not seem to be installed. Aborting."
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
testinst curl
|
||
|
|
|
||
|
|
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
|
||
|
|
|
||
|
|
|