From: Christian Weiske Date: Tue, 5 Feb 2013 21:01:07 +0000 (+0100) Subject: support domain patterns X-Git-Url: https://git.cweiske.de/ssh-dyndns.git/commitdiff_plain/b5769585c05ebced0217f516d92445ccd06f34e4 support domain patterns --- diff --git a/README.rst b/README.rst index 55947a9..4a456e0 100644 --- a/README.rst +++ b/README.rst @@ -64,6 +64,14 @@ The configuration file may define the following variables: DNS entry TTL (time to live) in seconds Default: 300 +``domain_patterns`` + Defines patterns for domains that may be dynamically changed. + If the domain name does not match the pattern, the script aborts. + + You may use several patterns by separating them with a space. + Shell wildcards are supported (``*`` and ``?``). + + Default: ``home.example.org *.home.example.org`` ===== diff --git a/ssh-dyndns b/ssh-dyndns index 903e859..18fc5d9 100755 --- a/ssh-dyndns +++ b/ssh-dyndns @@ -44,22 +44,34 @@ if [ ! -f "$data_dir/Makefile" ]; then exit 6 fi -#FIXME: check allowed domains, allowed suffixes +if [ ! -z "$domain_patterns" ]; then + ok=0 + for single_dp in $domain_patterns; do + case "$domain" in + ($single_dp) ok=1;; + esac + done + if [ $ok -ne 1 ]; then + echo "Domain \"$domain\" does not match \$domain_pattern" + exit 7 + fi +fi + file_pattern="${file_pattern:-data-dyndns-%DOMAIN%}" timeout=${timeout:-300} datafile=${data_dir}`echo $file_pattern | sed "s/%DOMAIN%/$domain/"` -#echo $datafile if [ `echo "$remoteip"| sed "s/://"` != "$remoteip" ]; then echo "IPv6 not supported yet" # we need ipv6 address expansion - exit 7 + exit 8 fi #=cweiske.de:5.35.241.22 djbdnsline="=${domain}:${remoteip}:${timeout}" +#FIXME: do not update if nothing changed echo $djbdnsline > $datafile #compile dns data diff --git a/ssh-dyndns.sh.config-dist b/ssh-dyndns.sh.config-dist index 7dd3fa8..f78934d 100644 --- a/ssh-dyndns.sh.config-dist +++ b/ssh-dyndns.sh.config-dist @@ -7,3 +7,4 @@ data_dir=/tmp/ file_pattern=data-dyndns-%DOMAIN% timeout=300 +domain_patterns="home.example.org *.home.example.org"