Enable dynamicdns module to handle IPv6

Signed-off-by: Matthias Dellweg <2500@gmx.de>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Matthias Dellweg 2020-11-08 16:02:23 +01:00 committed by James Valleroy
parent 451856999f
commit 4b4f8187ef
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
5 changed files with 53 additions and 9 deletions

View File

@ -22,7 +22,7 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# static values # static values
WGET=$(which wget) WGET=$(which wget)
WGETOPTIONS="-4 -o /dev/null -t 3 -T 3" WGETOPTIONS="-o /dev/null -t 3 -T 3"
EMPTYSTRING="none" EMPTYSTRING="none"
NOIP="0.0.0.0" NOIP="0.0.0.0"
# how often do we poll for IP changes if we are behind a NAT? # how often do we poll for IP changes if we are behind a NAT?
@ -51,8 +51,9 @@ doGetOpt()
{ {
basicauth=0 basicauth=0
ignoreCertError=0 ignoreCertError=0
useIPv6=0
while getopts ":s:d:u:P:I:U:c:b:p" opt; do while getopts ":s:d:u:P:I:U:c:b:6:p" opt; do
case ${opt} in case ${opt} in
s) s)
if [ "${OPTARG}" != "${EMPTYSTRING}" ];then if [ "${OPTARG}" != "${EMPTYSTRING}" ];then
@ -95,6 +96,9 @@ doGetOpt()
c) c)
ignoreCertError=${OPTARG} ignoreCertError=${OPTARG}
;; ;;
6)
useIPv6=${OPTARG}
;;
\?) \?)
echo "Invalid option: -${OPTARG}" >&2 echo "Invalid option: -${OPTARG}" >&2
exit 1 exit 1
@ -137,6 +141,7 @@ doWriteCFG()
echo "POSTURL ${updateurl}" echo "POSTURL ${updateurl}"
echo "POSTAUTH ${basicauth}" echo "POSTAUTH ${basicauth}"
echo "POSTSSLIGNORE ${ignoreCertError}" echo "POSTSSLIGNORE ${ignoreCertError}"
echo "POSTUSEIPV6 ${useIPv6}"
} > ${HELPERCFG} } > ${HELPERCFG}
# check if we are behind a NAT Router # check if we are behind a NAT Router
@ -187,6 +192,7 @@ doReadCFG()
updateurl=$(grep POSTURL "${HELPERCFG}" 2> /dev/null |awk '{print $2}' |grep -v ^\'\') updateurl=$(grep POSTURL "${HELPERCFG}" 2> /dev/null |awk '{print $2}' |grep -v ^\'\')
basicauth=$(grep POSTAUTH "${HELPERCFG}" 2> /dev/null |awk '{print $2}' |grep -v ^\'\') basicauth=$(grep POSTAUTH "${HELPERCFG}" 2> /dev/null |awk '{print $2}' |grep -v ^\'\')
ignoreCertError=$(grep POSTSSLIGNORE "${HELPERCFG}" 2> /dev/null |awk '{print $2}' |grep -v ^\'\') ignoreCertError=$(grep POSTSSLIGNORE "${HELPERCFG}" 2> /dev/null |awk '{print $2}' |grep -v ^\'\')
useIPv6=$(grep POSTUSEIPV6 "${HELPERCFG}" 2> /dev/null |awk '{print $2}' |grep -v ^\'\')
fi fi
} }
@ -259,6 +265,11 @@ doStatus()
else else
echo "${DISABLED_STRING}" echo "${DISABLED_STRING}"
fi fi
if [ ! -z "${useIPv6}" ];then
echo "${useIPv6}"
else
echo "${DISABLED_STRING}"
fi
} }
# ask a public WEB Server for the WAN IP we are comming from # ask a public WEB Server for the WAN IP we are comming from
@ -266,11 +277,18 @@ doStatus()
doGetWANIP() doGetWANIP()
{ {
if [ ! -z "${ipurl}" ];then if [ ! -z "${ipurl}" ];then
outfile=$(mktemp) local wgetoptions="${WGETOPTIONS}"
local cmd="${WGET} ${WGETOPTIONS} -O ${outfile} ${ipurl}" if [ "${useIPv6}" = "enabled" ];then
$cmd wgetoptions="${wgetoptions} -6"
wanip=$(sed s/[^0-9.]//g "${outfile}") else
rm "${outfile}" wgetoptions="${wgetoptions} -4"
fi
local cmd="${WGET} ${wgetoptions} -O - ${ipurl}"
if [ "${useIPv6}" = "enabled" ];then
wanip=$($cmd | tr A-F a-f | sed s/[^0-9a-f:]//g)
else
wanip=$($cmd | sed s/[^0-9.]//g)
fi
[ -z "${wanip}" ] && wanip=${NOIP} [ -z "${wanip}" ] && wanip=${NOIP}
else else
# no WAN IP found because of missing check URL # no WAN IP found because of missing check URL
@ -282,7 +300,11 @@ doGetWANIP()
# this function is called via cronjob # this function is called via cronjob
doUpdate() doUpdate()
{ {
local dnsentry=$(nslookup "${host}"|tail -n2|grep A|sed s/[^0-9.]//g) if [ "${useIPv6}" = "enabled" ];then
local dnsentry="$(host -t AAAA "${host}" | sed 's/.*address\s*//')"
else
local dnsentry="$(host -t A "${host}" | sed 's/.*address\s*//')"
fi
if [ "${dnsentry}" = "${wanip}" ];then if [ "${dnsentry}" = "${wanip}" ];then
return return
fi fi
@ -297,6 +319,11 @@ doUpdate()
if [ "${ignoreCertError}" = "enabled" ];then if [ "${ignoreCertError}" = "enabled" ];then
WGETOPTIONS="${WGETOPTIONS} --no-check-certificate " WGETOPTIONS="${WGETOPTIONS} --no-check-certificate "
fi fi
if [ "${useIPv6}" = "enabled" ];then
WGETOPTIONS="${WGETOPTIONS} -6"
else
WGETOPTIONS="${WGETOPTIONS} -4"
fi
local cmd="${WGET} -O /dev/null ${WGETOPTIONS} ${updateurl}" local cmd="${WGET} -O /dev/null ${WGETOPTIONS} ${updateurl}"
$cmd $cmd
# ToDo: check the returning text from WEB Server. User need to give expected string. # ToDo: check the returning text from WEB Server. User need to give expected string.
@ -431,6 +458,7 @@ case ${cmd} in
echo "-U <update URL> The update URL (a HTTP GET on this URL will be done)" echo "-U <update URL> The update URL (a HTTP GET on this URL will be done)"
echo "-c <1|0> disable SSL check on Update URL" echo "-c <1|0> disable SSL check on Update URL"
echo "-b <1|0> use HTTP basic auth on Update URL" echo "-b <1|0> use HTTP basic auth on Update URL"
echo "-6 use IPv6 type address"
echo "" echo ""
echo "update do a one time update" echo "update do a one time update"
echo "clean delete configuration" echo "clean delete configuration"

View File

@ -157,6 +157,11 @@ def get_status():
else: else:
status['use_http_basic_auth'] = False status['use_http_basic_auth'] = False
if len(details) > 9:
status['use_ipv6'] = (output.split()[9] == 'enabled')
else:
status['use_ipv6'] = False
if not status['dynamicdns_server'] and not status['dynamicdns_update_url']: if not status['dynamicdns_server'] and not status['dynamicdns_update_url']:
status['service_type'] = 'GnuDIP' status['service_type'] = 'GnuDIP'
elif not status['dynamicdns_server'] and status['dynamicdns_update_url']: elif not status['dynamicdns_server'] and status['dynamicdns_update_url']:

View File

@ -115,6 +115,10 @@ class ConfigureForm(forms.Form):
help_text=help_ip_url, help_text=help_ip_url,
validators=[validators.URLValidator(schemes=['http', 'https', 'ftp'])]) validators=[validators.URLValidator(schemes=['http', 'https', 'ftp'])])
use_ipv6 = forms.BooleanField(
label=ugettext_lazy('Use IPv6 instead of IPv4'),
required=False)
def clean(self): def clean(self):
cleaned_data = super(ConfigureForm, self).clean() cleaned_data = super(ConfigureForm, self).clean()
dynamicdns_secret = cleaned_data.get('dynamicdns_secret') dynamicdns_secret = cleaned_data.get('dynamicdns_secret')

View File

@ -116,6 +116,7 @@
$('#id_dynamicdns_update_url').closest('.form-group').hide(); $('#id_dynamicdns_update_url').closest('.form-group').hide();
$('#id_disable_SSL_cert_check').closest('.form-group').hide(); $('#id_disable_SSL_cert_check').closest('.form-group').hide();
$('#id_use_http_basic_auth').closest('.form-group').hide(); $('#id_use_http_basic_auth').closest('.form-group').hide();
$('#id_use_ipv6').closest('.form-group').hide();
$('#id_dynamicdns_server').closest('.form-group').show(); $('#id_dynamicdns_server').closest('.form-group').show();
} }
@ -123,6 +124,7 @@
$('#id_dynamicdns_update_url').closest('.form-group').show(); $('#id_dynamicdns_update_url').closest('.form-group').show();
$('#id_disable_SSL_cert_check').closest('.form-group').show(); $('#id_disable_SSL_cert_check').closest('.form-group').show();
$('#id_use_http_basic_auth').closest('.form-group').show(); $('#id_use_http_basic_auth').closest('.form-group').show();
$('#id_use_ipv6').closest('.form-group').show();
$('#id_dynamicdns_server').closest('.form-group').hide(); $('#id_dynamicdns_server').closest('.form-group').hide();
} }
@ -138,5 +140,6 @@
$('#id_dynamicdns_secret').closest('.form-group').show(); $('#id_dynamicdns_secret').closest('.form-group').show();
$('#id_showpw').closest('.form-group').show(); $('#id_showpw').closest('.form-group').show();
$('#id_dynamicdns_ipurl').closest('.form-group').show(); $('#id_dynamicdns_ipurl').closest('.form-group').show();
$('#id_use_ipv6').closest('.form-group').show();
} }
})(jQuery); })(jQuery);

View File

@ -118,6 +118,7 @@ def _apply_changes(request, old_status, new_status):
if old_status != new_status: if old_status != new_status:
disable_ssl_check = "disabled" disable_ssl_check = "disabled"
use_http_basic_auth = "disabled" use_http_basic_auth = "disabled"
use_ipv6 = "disabled"
if new_status['disable_SSL_cert_check']: if new_status['disable_SSL_cert_check']:
disable_ssl_check = "enabled" disable_ssl_check = "enabled"
@ -125,13 +126,16 @@ def _apply_changes(request, old_status, new_status):
if new_status['use_http_basic_auth']: if new_status['use_http_basic_auth']:
use_http_basic_auth = "enabled" use_http_basic_auth = "enabled"
if new_status.get('use_ipv6'):
use_ipv6 = "enabled"
_run([ _run([
'configure', '-s', new_status['dynamicdns_server'], '-d', 'configure', '-s', new_status['dynamicdns_server'], '-d',
new_status['dynamicdns_domain'], '-u', new_status['dynamicdns_domain'], '-u',
new_status['dynamicdns_user'], '-p', '-I', new_status['dynamicdns_user'], '-p', '-I',
new_status['dynamicdns_ipurl'], '-U', new_status['dynamicdns_ipurl'], '-U',
new_status['dynamicdns_update_url'], '-c', disable_ssl_check, '-b', new_status['dynamicdns_update_url'], '-c', disable_ssl_check, '-b',
use_http_basic_auth use_http_basic_auth, '-6', use_ipv6,
], input=new_status['dynamicdns_secret'].encode()) ], input=new_status['dynamicdns_secret'].encode())
if old_status['enabled']: if old_status['enabled']: