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
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
s)
server=$OPTARG
@ -141,19 +141,71 @@ doReadCFG()
if [ ! -z $file ];then
host=`cat $file 2> /dev/null |grep host |cut -d = -f 2`
server=`cat $file 2> /dev/null |grep server |cut -d = -f 2`
user=`cat $file 2> /dev/null |grep user |cut -d = -f 2 |cut -d : -f 1`
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 `
pass=`cat $file 2> /dev/null |grep user |cut -d = -f 2 |cut -d : -f 2`
fi
if [ ! -z $HELPERCFG ];then
ipurl=`cat $HELPERCFG 2> /dev/null |grep ^URL |awk '{print $2}'`
updateurl=`cat $HELPERCFG 2> /dev/null |grep POSTURL |awk '{print $2}'`
basicauth=`cat $HELPERCFG 2> /dev/null |grep POSTAUTH |awk '{print $2}'`
ignoreCertError=`cat $HELPERCFG 2> /dev/null |grep POSTSSLIGNORE |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}' |grep -v ^\'\'`
basicauth=`cat $HELPERCFG 2> /dev/null |grep POSTAUTH |awk '{print $2}' |grep -v ^\'\'`
ignoreCertError=`cat $HELPERCFG 2> /dev/null |grep POSTSSLIGNORE |awk '{print $2}' |grep -v ^\'\'`
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()
{
if [ ! -z $ipurl ];then
@ -161,6 +213,7 @@ doGetWANIP()
$WGET $WGETOPTIONS -O $outfile $ipurl
wanip=`cat $outfile`
rm $outfile
[ -z $wanip ] && wanip=${NOIP}
else
#no WAN IP found because of missing check URL
wanip=${NOIP}
@ -187,8 +240,14 @@ case $cmd in
;;
start)
if [ "$(cat $HELPERCFG |grep ^NAT | awk '{print $2}')" = "no" ];then
mv $CFG_disabled $CFG
/etc/init.d/${TOOLNAME} start
if [ -f $CFG -a ! -z $(cat $file 2> /dev/null |grep server |cut -d = -f 2 |grep -v ^\'\')];then
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
echo "*/${UPDATEMINUTES} * * * * root $0 update" > $CRONJOB
$0 update
@ -257,28 +316,14 @@ case $cmd in
;;
status)
doReadCFG
PROC=`pgrep ${TOOLNAME}`
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
doStatus
;;
get-timer)
echo $UPDATEMINUTES
;;
clean)
rm ${CFGDIR}/*
rm $CRONJOB
;;
*)
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'),
('3', 'selfhost.bz'),
('4', 'other Update URL')),
widget=forms.Select(attrs={"onChange":'mod_form()'}))
widget=forms.Select(attrs={'onChange':'dropdown()'}))
dynamicdns_server = TrimmedCharField(
label=_('GnudIP Server Address'),
required=False,
help_text=_('Example: gnudip.provider.org'),
validators=[
validators.RegexValidator(r'^[\w-]{1,63}(\.[\w-]{1,63})*$',
@ -97,9 +98,7 @@ class ConfigureForm(forms.Form):
required=False,
help_text=_('The Variables $User, $Pass, $IP, $Domain may be used \
within this URL.</br> Example URL: </br> \
https://some.tld/up.php?us=$User&pw=$Pass&ip=$IP&dom=$Domain'),
validators=[
validators.URLValidator(schemes=['http', 'https'])])
https://some.tld/up.php?us=$User&pw=$Pass&ip=$IP&dom=$Domain'))
disable_SSL_cert_check = forms.BooleanField(
label=_('accept all SSL certificates'),
@ -149,11 +148,11 @@ class ConfigureForm(forms.Form):
def clean(self):
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']
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
@ -211,50 +210,71 @@ def get_status():
output = actions.run('dynamicdns', 'status')
details = output.split()
status['enabled'] = (output.split()[0] == 'enabled')
if len(details) > 1:
status['dynamicdns_server'] = details[1]
if details[1] == 'disabled':
status['dynamicdns_server'] = ''
else:
status['dynamicdns_server'] = details[1]
else:
status['dynamicdns_server'] = ''
if len(details) > 2:
status['dynamicdns_domain'] = details[2]
if details[2] == 'disabled':
status['dynamicdns_domain'] = ''
else:
status['dynamicdns_domain'] = details[2]
else:
status['dynamicdns_domain'] = ''
if len(details) > 3:
status['dynamicdns_user'] = details[3]
if details[3] == 'disabled':
status['dynamicdns_user'] = ''
else:
status['dynamicdns_user'] = details[3]
else:
status['dynamicdns_user'] = ''
if len(details) > 4:
status['dynamicdns_secret'] = details[4]
if details[4] == 'disabled':
status['dynamicdns_secret'] = ''
else:
status['dynamicdns_secret'] = details[4]
else:
status['dynamicdns_secret'] = ''
if len(details) > 5:
status['dynamicdns_ipurl'] = details[5]
if details[5] == 'disabled':
status['dynamicdns_ipurl'] = ''
else:
status['dynamicdns_ipurl'] = details[5]
else:
status['dynamicdns_ipurl'] = ''
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:
status['dynamicdns_update_url'] = ''
if len(details) > 7:
status['disable_SSL_cert_check'] = details[7]
status['disable_SSL_cert_check'] = (output.split()[7] == 'enabled')
else:
status['disable_SSL_cert_check'] = ''
status['disable_SSL_cert_check'] = False
if len(details) > 8:
status['use_http_basic_auth'] = details[8]
status['use_http_basic_auth'] = (output.split()[8] == 'enabled')
else:
status['use_http_basic_auth'] = ''
status['use_http_basic_auth'] = False
if status['dynamicdns_server'] is not '':
status['dynamicdns_service'] = '1'
if not status['dynamicdns_server'] and not status['dynamicdns_update_url']:
status['dynamicdns_service'] = '1'
elif not status['dynamicdns_server'] and status['dynamicdns_update_url']:
status['dynamicdns_service'] = '4'
else:
status['dynamicdns_service'] = '4'
status['dynamicdns_service'] = '1'
return status
@ -289,14 +309,23 @@ def _apply_changes(request, old_status, new_status):
old_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'],
'-d', new_status['dynamicdns_domain'],
'-u', new_status['dynamicdns_user'],
'-p', new_status['dynamicdns_secret'],
'-I', new_status['dynamicdns_ipurl'],
'-U', new_status['dynamicdns_update_url'],
'-c', new_status['disable_SSL_cert_check'],
'-b', new_status['use_http_basic_auth']])
'-c', disable_ssl_check,
'-b', use_http_basic_auth])
if old_status['enabled']:
_run(['stop'])

View File

@ -76,6 +76,35 @@
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()
{
document.getElementById('dynamicdns-no-js').style.display = 'none';
@ -88,25 +117,18 @@
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='';
}
}else{
document.getElementById('dynamicdns-post-enabled-form').style.display = 'none';