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.

update.sh 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. ########################################################################
  3. # Copyright (C) 2016 Max Mehl <mail [at] mehl [dot] mx>
  4. ########################################################################
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public
  17. # License along with this program. If not, see
  18. # <http://www.gnu.org/licenses/>.
  19. #
  20. ########################################################################
  21. #
  22. # This file uses the data forwarded by update.php, validates the given
  23. # login data in the user database, and does the API call to the INWX
  24. # API.
  25. #
  26. ########################################################################
  27. cd "$(dirname "$(readlink -f "$0")")"
  28. # Test if config.cfg exists and set needed variables
  29. if [ ! -e config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi
  30. source config.cfg
  31. # Test whether necessary applications are installed
  32. function testinst {
  33. APP=$1
  34. if [ $(which $APP | wc -l) != 1 ]; then
  35. echo "$APP does not seem to be installed. Aborting."
  36. exit 1
  37. fi
  38. }
  39. testinst curl
  40. USERDB=users.db
  41. DOMAIN="$1"
  42. NEWIP="$2"
  43. U_USER="$3"
  44. U_PASS="$4"
  45. E=$(grep "^$DOMAIN;" $USERDB)
  46. if [ "$E" != "" ]; then
  47. DNSID=$(echo $E | cut -d";" -f2)
  48. E_USER=$(echo $E | cut -d";" -f3)
  49. E_PASS=$(echo $E | cut -d";" -f4)
  50. # Check if user as given correct user and password
  51. if [ "$U_USER" == "$E_USER" ] && [ "$U_PASS" == "$E_PASS" ]; then
  52. DATA=$(cat update.api | sed "s/%PASSWD%/$PASSWORD/g;s/%USER%/$USERNAME/g;s/%DNSID%/$DNSID/g;s/%NEWIP%/$NEWIP/g")
  53. curl -X POST -d "$DATA" "$APIHOST" --header "Content-Type:text/xml" --insecure > update.log
  54. echo "" >> update.log
  55. echo "Updated IP address for $DNSID ($DOMAIN) to $NEWIP." >> update.log
  56. echo "Success: Updated $DOMAIN to $NEWIP."
  57. else
  58. echo "Wrong user or password."
  59. fi
  60. else
  61. echo "Domain does not exist in database"
  62. fi