prepared update URL functionality (implemented new parameters)

This commit is contained in:
Daniel Steglich 2015-03-02 23:39:28 +01:00
parent 7e218b06ed
commit a2e8a0ec8a
3 changed files with 149 additions and 53 deletions

View File

@ -33,7 +33,7 @@ doGetOpt()
basicauth=0 basicauth=0
ignoreCertError=0 ignoreCertError=0
while getopts ":s:d:u:p:I:" opt; do while getopts ":s:d:u:p:I:U:c:b:" opt; do
case $opt in case $opt in
s) s)
server=$OPTARG server=$OPTARG
@ -141,19 +141,71 @@ doReadCFG()
if [ ! -z $file ];then if [ ! -z $file ];then
host=`cat $file 2> /dev/null |grep host |cut -d = -f 2` host=`cat $file 2> /dev/null |grep host |cut -d = -f 2`
server=`cat $file 2> /dev/null |grep server |cut -d = -f 2` server=`cat $file 2> /dev/null |grep server |cut -d = -f 2 |grep -v ^\'\'`
user=`cat $file 2> /dev/null |grep user |cut -d = -f 2 |cut -d : -f 1` user=`cat $file 2> /dev/null |grep user |cut -d = -f 2 |cut -d : -f 1 `
pass=`cat $file 2> /dev/null |grep user |cut -d = -f 2 |cut -d : -f 2` pass=`cat $file 2> /dev/null |grep user |cut -d = -f 2 |cut -d : -f 2`
fi fi
if [ ! -z $HELPERCFG ];then if [ ! -z $HELPERCFG ];then
ipurl=`cat $HELPERCFG 2> /dev/null |grep ^URL |awk '{print $2}'` ipurl=`cat $HELPERCFG 2> /dev/null |grep ^IPURL |awk '{print $2}' |grep -v ^\'\'`
updateurl=`cat $HELPERCFG 2> /dev/null |grep POSTURL |awk '{print $2}'` updateurl=`cat $HELPERCFG 2> /dev/null |grep POSTURL |awk '{print $2}' |grep -v ^\'\'`
basicauth=`cat $HELPERCFG 2> /dev/null |grep POSTAUTH |awk '{print $2}'` basicauth=`cat $HELPERCFG 2> /dev/null |grep POSTAUTH |awk '{print $2}' |grep -v ^\'\'`
ignoreCertError=`cat $HELPERCFG 2> /dev/null |grep POSTSSLIGNORE |awk '{print $2}'` ignoreCertError=`cat $HELPERCFG 2> /dev/null |grep POSTSSLIGNORE |awk '{print $2}' |grep -v ^\'\'`
fi fi
} }
doStatus()
{
PROC=`pgrep ${TOOLNAME}`
if [ -f $CRONJOB ];then
echo enabled
elif [ ! -z $PROC ];then
echo enabled
else
echo disabled
fi
if [ ! -z $server ];then
echo $server
else
echo disabled
fi
if [ ! -z $host ];then
echo $host
else
echo disabled
fi
if [ ! -z $user ];then
echo $user
else
echo disabled
fi
if [ ! -z $pass ];then
echo $pass
else
echo disabled
fi
if [ ! -z $ipurl ];then
echo $ipurl
else
echo disabled
fi
if [ ! -z $updateurl ];then
echo $updateurl
else
echo disabled
fi
if [ ! -z $basicauth ];then
echo $basicauth
else
echo disabled
fi
if [ ! -z $ignoreCertError ];then
echo $ignoreCertError
else
echo disabled
fi
}
doGetWANIP() doGetWANIP()
{ {
if [ ! -z $ipurl ];then if [ ! -z $ipurl ];then
@ -161,6 +213,7 @@ doGetWANIP()
$WGET $WGETOPTIONS -O $outfile $ipurl $WGET $WGETOPTIONS -O $outfile $ipurl
wanip=`cat $outfile` wanip=`cat $outfile`
rm $outfile rm $outfile
[ -z $wanip ] && wanip=${NOIP}
else else
#no WAN IP found because of missing check URL #no WAN IP found because of missing check URL
wanip=${NOIP} wanip=${NOIP}
@ -187,8 +240,14 @@ case $cmd in
;; ;;
start) start)
if [ "$(cat $HELPERCFG |grep ^NAT | awk '{print $2}')" = "no" ];then if [ "$(cat $HELPERCFG |grep ^NAT | awk '{print $2}')" = "no" ];then
mv $CFG_disabled $CFG if [ -f $CFG -a ! -z $(cat $file 2> /dev/null |grep server |cut -d = -f 2 |grep -v ^\'\')];then
/etc/init.d/${TOOLNAME} start mv $CFG_disabled $CFG
/etc/init.d/${TOOLNAME} start
fi
if [ ! -z $(cat $HELPERCFG |grep ^POSTURL | awk '{print $2}') ];then
echo "*/${UPDATEMINUTES} * * * * root $0 update" > $CRONJOB
$0 update
fi
else else
echo "*/${UPDATEMINUTES} * * * * root $0 update" > $CRONJOB echo "*/${UPDATEMINUTES} * * * * root $0 update" > $CRONJOB
$0 update $0 update
@ -257,28 +316,14 @@ case $cmd in
;; ;;
status) status)
doReadCFG doReadCFG
PROC=`pgrep ${TOOLNAME}` doStatus
if [ -f $CRONJOB ];then
echo enabled
elif [ ! -z $PROC ];then
echo enabled
else
echo disabled
fi
echo $server
echo $host
echo $user
echo $pass
echo $ipurl
echo $updateurl
echo $basicauth
echo $ignoreCertError
;; ;;
get-timer) get-timer)
echo $UPDATEMINUTES echo $UPDATEMINUTES
;; ;;
clean) clean)
rm ${CFGDIR}/* rm ${CFGDIR}/*
rm $CRONJOB
;; ;;
*) *)
echo "usage: status|configure <options>|start|stop|update|get-nat|clean|success [updated IP]|failed" echo "usage: status|configure <options>|start|stop|update|get-nat|clean|success [updated IP]|failed"

View File

@ -83,10 +83,11 @@ class ConfigureForm(forms.Form):
('2', 'noip.com'), ('2', 'noip.com'),
('3', 'selfhost.bz'), ('3', 'selfhost.bz'),
('4', 'other Update URL')), ('4', 'other Update URL')),
widget=forms.Select(attrs={"onChange":'mod_form()'})) widget=forms.Select(attrs={'onChange':'dropdown()'}))
dynamicdns_server = TrimmedCharField( dynamicdns_server = TrimmedCharField(
label=_('GnudIP Server Address'), label=_('GnudIP Server Address'),
required=False,
help_text=_('Example: gnudip.provider.org'), help_text=_('Example: gnudip.provider.org'),
validators=[ validators=[
validators.RegexValidator(r'^[\w-]{1,63}(\.[\w-]{1,63})*$', validators.RegexValidator(r'^[\w-]{1,63}(\.[\w-]{1,63})*$',
@ -97,9 +98,7 @@ class ConfigureForm(forms.Form):
required=False, required=False,
help_text=_('The Variables $User, $Pass, $IP, $Domain may be used \ help_text=_('The Variables $User, $Pass, $IP, $Domain may be used \
within this URL.</br> Example URL: </br> \ within this URL.</br> Example URL: </br> \
https://some.tld/up.php?us=$User&pw=$Pass&ip=$IP&dom=$Domain'), https://some.tld/up.php?us=$User&pw=$Pass&ip=$IP&dom=$Domain'))
validators=[
validators.URLValidator(schemes=['http', 'https'])])
disable_SSL_cert_check = forms.BooleanField( disable_SSL_cert_check = forms.BooleanField(
label=_('accept all SSL certificates'), label=_('accept all SSL certificates'),
@ -149,11 +148,11 @@ class ConfigureForm(forms.Form):
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')
old_dynamicdns_secret = self.initial['dynamicdns_secret'] old_dynamicdns_secret = self.initial['dynamicdns_secret']
if not dynamicdns_secret and not old_dynamicdns_secret: if not dynamicdns_secret and not old_dynamicdns_secret:
raise forms.ValidationError("please give a password") raise forms.ValidationError('please give a password')
@login_required @login_required
@ -211,50 +210,71 @@ def get_status():
output = actions.run('dynamicdns', 'status') output = actions.run('dynamicdns', 'status')
details = output.split() details = output.split()
status['enabled'] = (output.split()[0] == 'enabled') status['enabled'] = (output.split()[0] == 'enabled')
if len(details) > 1: if len(details) > 1:
status['dynamicdns_server'] = details[1] if details[1] == 'disabled':
status['dynamicdns_server'] = ''
else:
status['dynamicdns_server'] = details[1]
else: else:
status['dynamicdns_server'] = '' status['dynamicdns_server'] = ''
if len(details) > 2: if len(details) > 2:
status['dynamicdns_domain'] = details[2] if details[2] == 'disabled':
status['dynamicdns_domain'] = ''
else:
status['dynamicdns_domain'] = details[2]
else: else:
status['dynamicdns_domain'] = '' status['dynamicdns_domain'] = ''
if len(details) > 3: if len(details) > 3:
status['dynamicdns_user'] = details[3] if details[3] == 'disabled':
status['dynamicdns_user'] = ''
else:
status['dynamicdns_user'] = details[3]
else: else:
status['dynamicdns_user'] = '' status['dynamicdns_user'] = ''
if len(details) > 4: if len(details) > 4:
status['dynamicdns_secret'] = details[4] if details[4] == 'disabled':
status['dynamicdns_secret'] = ''
else:
status['dynamicdns_secret'] = details[4]
else: else:
status['dynamicdns_secret'] = '' status['dynamicdns_secret'] = ''
if len(details) > 5: if len(details) > 5:
status['dynamicdns_ipurl'] = details[5] if details[5] == 'disabled':
status['dynamicdns_ipurl'] = ''
else:
status['dynamicdns_ipurl'] = details[5]
else: else:
status['dynamicdns_ipurl'] = '' status['dynamicdns_ipurl'] = ''
if len(details) > 6: if len(details) > 6:
status['dynamicdns_update_url'] = details[6] if details[6] == 'disabled':
status['dynamicdns_update_url'] = ''
else:
status['dynamicdns_update_url'] = details[6]
else: else:
status['dynamicdns_update_url'] = '' status['dynamicdns_update_url'] = ''
if len(details) > 7: if len(details) > 7:
status['disable_SSL_cert_check'] = details[7] status['disable_SSL_cert_check'] = (output.split()[7] == 'enabled')
else: else:
status['disable_SSL_cert_check'] = '' status['disable_SSL_cert_check'] = False
if len(details) > 8: if len(details) > 8:
status['use_http_basic_auth'] = details[8] status['use_http_basic_auth'] = (output.split()[8] == 'enabled')
else: else:
status['use_http_basic_auth'] = '' status['use_http_basic_auth'] = False
if status['dynamicdns_server'] is not '': if not status['dynamicdns_server'] and not status['dynamicdns_update_url']:
status['dynamicdns_service'] = '1' status['dynamicdns_service'] = '1'
elif not status['dynamicdns_server'] and status['dynamicdns_update_url']:
status['dynamicdns_service'] = '4'
else: else:
status['dynamicdns_service'] = '4' status['dynamicdns_service'] = '1'
return status return status
@ -289,14 +309,23 @@ def _apply_changes(request, old_status, new_status):
old_status['enabled'] != \ old_status['enabled'] != \
new_status['enabled']: new_status['enabled']:
disable_ssl_check="disabled"
use_http_basic_auth="disabled"
if new_status['disable_SSL_cert_check']:
disable_ssl_check = "enabled"
if new_status['use_http_basic_auth']:
use_http_basic_auth = "enabled"
_run(['configure', '-s', new_status['dynamicdns_server'], _run(['configure', '-s', new_status['dynamicdns_server'],
'-d', new_status['dynamicdns_domain'], '-d', new_status['dynamicdns_domain'],
'-u', new_status['dynamicdns_user'], '-u', new_status['dynamicdns_user'],
'-p', new_status['dynamicdns_secret'], '-p', new_status['dynamicdns_secret'],
'-I', new_status['dynamicdns_ipurl'], '-I', new_status['dynamicdns_ipurl'],
'-U', new_status['dynamicdns_update_url'], '-U', new_status['dynamicdns_update_url'],
'-c', new_status['disable_SSL_cert_check'], '-c', disable_ssl_check,
'-b', new_status['use_http_basic_auth']]) '-b', use_http_basic_auth])
if old_status['enabled']: if old_status['enabled']:
_run(['stop']) _run(['stop'])

View File

@ -76,6 +76,35 @@
document.getElementById('id_dynamicdns-dynamicdns_secret').type='password'; document.getElementById('id_dynamicdns-dynamicdns_secret').type='password';
} }
function dropdown()
{
var dropdown = document.getElementById('id_dynamicdns-dynamicdns_service');
var service_type = dropdown.options[dropdown.selectedIndex].value;
if (service_type == 1){
document.getElementById('div-dynamicdns-updateurl').style.display = 'none';
document.getElementById('div-dynamicdns-gnudip').style.display = 'block';
document.getElementById('id_dynamicdns-dynamicdns_update_url').value='';
}
if (service_type == 2){
document.getElementById('div-dynamicdns-gnudip').style.display = 'none';
document.getElementById('div-dynamicdns-updateurl').style.display = 'block';
document.getElementById('id_dynamicdns-dynamicdns_update_url').value='noip';
document.getElementById('id_dynamicdns-dynamicdns_server').value='';
}
if (service_type == 3){
document.getElementById('div-dynamicdns-gnudip').style.display = 'none';
document.getElementById('div-dynamicdns-updateurl').style.display = 'block';
document.getElementById('id_dynamicdns-dynamicdns_update_url').value='selfhost';
document.getElementById('id_dynamicdns-dynamicdns_server').value='';
}
if (service_type == 4){
document.getElementById('div-dynamicdns-gnudip').style.display = 'none';
document.getElementById('div-dynamicdns-updateurl').style.display = 'block';
document.getElementById('id_dynamicdns-dynamicdns_update_url').value='';
document.getElementById('id_dynamicdns-dynamicdns_server').value='';
}
}
function mod_form() function mod_form()
{ {
document.getElementById('dynamicdns-no-js').style.display = 'none'; document.getElementById('dynamicdns-no-js').style.display = 'none';
@ -88,25 +117,18 @@
if (service_type == 1){ if (service_type == 1){
document.getElementById('div-dynamicdns-updateurl').style.display = 'none'; document.getElementById('div-dynamicdns-updateurl').style.display = 'none';
document.getElementById('div-dynamicdns-gnudip').style.display = 'block'; document.getElementById('div-dynamicdns-gnudip').style.display = 'block';
document.getElementById('id_dynamicdns-dynamicdns_update_url').value='';
} }
if (service_type == 2){ if (service_type == 2){
document.getElementById('div-dynamicdns-gnudip').style.display = 'none'; document.getElementById('div-dynamicdns-gnudip').style.display = 'none';
document.getElementById('div-dynamicdns-updateurl').style.display = 'block'; document.getElementById('div-dynamicdns-updateurl').style.display = 'block';
document.getElementById('id_dynamicdns-dynamicdns_update_url').value='noip';
document.getElementById('id_dynamicdns-dynamicdns_server').value='';
} }
if (service_type == 3){ if (service_type == 3){
document.getElementById('div-dynamicdns-gnudip').style.display = 'none'; document.getElementById('div-dynamicdns-gnudip').style.display = 'none';
document.getElementById('div-dynamicdns-updateurl').style.display = 'block'; document.getElementById('div-dynamicdns-updateurl').style.display = 'block';
document.getElementById('id_dynamicdns-dynamicdns_update_url').value='selfhost';
document.getElementById('id_dynamicdns-dynamicdns_server').value='';
} }
if (service_type == 4){ if (service_type == 4){
document.getElementById('div-dynamicdns-gnudip').style.display = 'none'; document.getElementById('div-dynamicdns-gnudip').style.display = 'none';
document.getElementById('div-dynamicdns-updateurl').style.display = 'block'; document.getElementById('div-dynamicdns-updateurl').style.display = 'block';
document.getElementById('id_dynamicdns-dynamicdns_update_url').value='';
document.getElementById('id_dynamicdns-dynamicdns_server').value='';
} }
}else{ }else{
document.getElementById('dynamicdns-post-enabled-form').style.display = 'none'; document.getElementById('dynamicdns-post-enabled-form').style.display = 'none';