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.
 
 
 

81 lines
2.6 KiB

  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. # Check dependencies
  32. deperrors=''
  33. for depend in curl; do
  34. if ! command -v "$depend" >/dev/null 2>&1; then
  35. deperrors="$depend $deperrors"
  36. fi
  37. done
  38. if [ -n "$deperrors" ]; then
  39. cat <<-EOF
  40. This program depends on some other programs to function.
  41. Not all of those programs could be located on your system.
  42. Please use your package manager to install the following programs:
  43. EOF
  44. echo "$deperrors"
  45. exit 1
  46. fi
  47. USERDB=users.db
  48. DOMAIN="$1"
  49. NEWIP="$2"
  50. U_USER="$3"
  51. U_PASS="$4"
  52. E=$(grep "^$DOMAIN;" $USERDB)
  53. if [ "$E" != "" ]; then
  54. DNSID=$(echo $E | cut -d";" -f2)
  55. E_USER=$(echo $E | cut -d";" -f3)
  56. E_PASS=$(echo $E | cut -d";" -f4)
  57. # Check if user as given correct user and password
  58. if [ "$U_USER" == "$E_USER" ] && [ "$U_PASS" == "$E_PASS" ]; then
  59. DATA=$(cat update.api | sed "s/%PASSWD%/$PASSWORD/g;s/%USER%/$USERNAME/g;s/%DNSID%/$DNSID/g;s/%NEWIP%/$NEWIP/g")
  60. curl -X POST -d "$DATA" "$APIHOST" --header "Content-Type:text/xml" --insecure > update.log
  61. echo "" >> update.log
  62. echo "Updated IP address for $DNSID ($DOMAIN) to $NEWIP." >> update.log
  63. echo "Success: Updated $DOMAIN to $NEWIP."
  64. else
  65. echo "Wrong user or password."
  66. fi
  67. else
  68. echo "Domain does not exist in database"
  69. fi