Advertisement
Guest User

Untitled

a guest
Jul 13th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Copyright (c) 2014, Peder O. Klingenberg
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. #
  10. # 1. Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # 2. Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in
  14. # the documentation and/or other materials provided with the
  15. # distribution.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  21. # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  27. # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. # POSSIBILITY OF SUCH DAMAGE.
  29. ##########
  30.  
  31. # This is a script to allow direct use of nsupdate to update a dynamic
  32. # DNS zone from Synology DSM. Not supported or endorsed by Synology
  33. # Inc. Developed on DSM 5.0, no guarantees on earlier or later
  34. # versions. IPv4 only, because that's all I use.
  35.  
  36. # Instructions for use:
  37. #
  38. # Prerequisites:
  39. # 1) Set up ssh access as root to your DiskStation.
  40. # 2) Install the DNS Server package. This provides the necessary
  41. # nsupdate binary and a convenient way to store keys. You don't
  42. # need to set up any zones, and unless importing new keys, the
  43. # DNS server doesn't need to run.
  44. #
  45. # Setup (this is the tricky bit, requiring shell use and file
  46. # editing):
  47. # 1) Drop this script somewhere convenient on the DS, for instance
  48. # /volume1/DS-hacks/ddns_nsupdate.sh, and make sure it's executable.
  49. # 2) Log on to the DS as root, and append the following to two files,
  50. # which should already exist:
  51. # /etc.default/ddns_provider.conf and
  52. # /etc/ddns_provider.conf
  53. # (It doesn't seem like the latter matters, but it seems they are
  54. # equal originally, so I kept them equal). Anyway, append this,
  55. # adjusting path as necessary:
  56. # [Direct NSUpdate]
  57. # modulepath=/volume1/DS-hacks/ddns_nsupdate.sh
  58. # queryurl=Direct_NSupdate
  59. #
  60. # Use:
  61. # 1) Import the key to use for updates to the Synology DNS Server
  62. # using the DNS Server GUI, tab "Keys", button "create" ->
  63. # "import". This will give you a key of the same name as your
  64. # dynamic domain, with a trailing dot.
  65. # 2) Go to Control Panel - section "External Access", tab "DDNS".
  66. # Click "Add".
  67. # 3) "Direct NSUpdate" should now be a choice of service provider.
  68. # Choose it.
  69. # 4) "Hostname" is your desired name in the dynamic zone. Not a FQDN.
  70. # 5) "Username/Email". We repurpose this field for the name of the
  71. # dynamic zone. So enter your zone here, no trailing dot.
  72. # 6) Enter whatever. We ignore it.
  73. # 7) "External address" is fairly self-explanatory, and pre-filled in
  74. # my GUI.
  75. # 8) Click "Test Connection" or "OK". Status should flip to "Normal"
  76. # after a while, and your DNS server should now answer requests for
  77. # <yourhost>.<dynamic-domain>. You're done. If it says something
  78. # else, check your upstream logs and start debugging.
  79.  
  80. ##########
  81. ## Code follows
  82.  
  83. # Arguments as specified in /etc.default/ddns_provider.conf:
  84.  
  85. username=$1
  86. password=$2 # We ignore this.
  87. hostname=$3
  88. ip=$4
  89.  
  90. # But we instead use
  91. domain=$username
  92.  
  93. keyfile=/volume1/@appstore/DNSServer/named/etc/key/$domain.
  94.  
  95. if [ ! -r $keyfile ]; then
  96. echo badauth
  97. exit 1
  98. fi
  99.  
  100. /volume1/@appstore/DNSServer/bin/nsupdate -k $keyfile <<EOF
  101. zone $domain
  102. update delete ${hostname}.${domain}. A
  103. update add ${hostname}.${domain}. 600 A $ip
  104. send
  105. EOF
  106.  
  107. rc=$?
  108.  
  109. if [ $rc != 0 ]; then
  110. echo 911
  111. exit 2
  112. fi
  113.  
  114. echo good
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement