lede-packages-rs

git clone git://archive.git.mtrnord.blog/MTRNord/lede-packages-rs.git
Log | Files | Refs | README | LICENSE

update_nsupdate.sh (1720B)


      1 #
      2 #.Distributed under the terms of the GNU General Public License (GPL) version 2.0
      3 #
      4 # The script directly updates a PowerDNS (or maybe bind server) via nsupdate from bind-client package.
      5 #.based on github request #957 by Jan Riechers <de at r-jan dot de>
      6 #.2015 Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
      7 #
      8 # This script is parsed by dynamic_dns_functions.sh inside send_update() function
      9 #
     10 # using following options from /etc/config/ddns
     11 # option username   - keyname 
     12 # option password   - shared secret (base64 encoded)
     13 # option domain     - full qualified domain to update
     14 # option dns_server - DNS server to update
     15 #
     16 # variable __IP already defined with the ip-address to use for update
     17 #
     18 local __TTL=600		#.preset DNS TTL (in seconds)
     19 local __RRTYPE __PW __TCP
     20 local __PROG=$(which nsupdate)			# BIND nsupdate ?
     21 [ -z "$__PROG" ] && __PROG=$(which knsupdate)	# Knot nsupdate ?
     22 
     23 [ -z "$__PROG" ]     && write_log 14 "'nsupdate' or 'knsupdate' not installed !"
     24 [ -z "$username" ]   && write_log 14 "Service section not configured correctly! Missing 'username'"
     25 [ -z "$password" ]   && write_log 14 "Service section not configured correctly! Missing 'password'"
     26 [ -z "$dns_server" ] && write_log 14 "Service section not configured correctly! Missing 'dns_server'"
     27 
     28 [ $use_ipv6 -ne 0 ] && __RRTYPE="AAAA" || __RRTYPE="A"
     29 [ $force_dnstcp -ne 0 ] && __TCP="-v" || __TCP=""
     30 
     31 # create command file
     32 cat >$DATFILE <<-EOF
     33 server $dns_server
     34 key $username $password
     35 update del $domain $__RRTYPE
     36 update add $domain $__TTL $__RRTYPE $__IP
     37 show
     38 send
     39 answer
     40 quit
     41 EOF
     42 
     43 $__PROG -d $__TCP $DATFILE >$ERRFILE 2>&1
     44 
     45 # nsupdate always return success
     46 write_log 7 "(k)nsupdate reports:\n$(cat $ERRFILE)"
     47 
     48 return 0