From 2a030f91fec7e18820b500ba65b708e0576f8065 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 1 Feb 2016 10:53:26 +0530 Subject: [PATCH 1/5] dynamicdns: Fix reading configuration file - The current code to parse the configuration file does not work proper if there is an '=' in the password. Fix it. - Also if predesignated keyword like 'server' occurs in the password, configuration can't be read properly. Fix it. --- actions/dynamicdns | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/actions/dynamicdns b/actions/dynamicdns index b9b145412..4b45a8c37 100755 --- a/actions/dynamicdns +++ b/actions/dynamicdns @@ -189,10 +189,10 @@ doReadCFG() ipurl="" if [ ! -z "${cfgfile}" ];then - host=$(grep host "${cfgfile}" 2> /dev/null |cut -d = -f 2) - server=$(grep server "${cfgfile}" 2> /dev/null |cut -d = -f 2 |grep -v ^\'\') - user=$(grep user "${cfgfile}" 2> /dev/null |cut -d = -f 2 |cut -d : -f 1 ) - pass=$(grep user "${cfgfile}" 2> /dev/null |cut -d = -f 2 |cut -d : -f 2) + host=$(grep ^host= "${cfgfile}" 2> /dev/null | cut -d = -f 2-) + server=$(grep ^server= "${cfgfile}" 2> /dev/null | cut -d = -f 2- | grep -v ^\'\') + user=$(grep ^user= "${cfgfile}" 2> /dev/null | cut -d = -f 2- | cut -d : -f 1 ) + pass=$(grep ^user= "${cfgfile}" 2> /dev/null | cut -d = -f 2- | cut -d : -f 2-) fi if [ ! -z ${HELPERCFG} ];then @@ -338,7 +338,7 @@ case ${cmd} in doGetWANIP if [ "$(grep ^NAT ${HELPERCFG} | awk '{print $2}')" = "no" ];then #if we are not behind a NAT device and we use gnudip, start the daemon tool - local gnudipServer=$(grep server ${cfgfile} 2> /dev/null |cut -d = -f 2 |grep -v ^\'\') + local gnudipServer=$(grep ^server= ${cfgfile} 2> /dev/null | cut -d = -f 2- |grep -v ^\'\') if [ -f ${CFG} -a ! -z "${gnudipServer}" ];then mv ${CFG_disabled} ${CFG} /etc/init.d/${TOOLNAME} start From aa5efd498489bc966282ae99a19f3a5ca39891f0 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 1 Feb 2016 10:57:33 +0530 Subject: [PATCH 2/5] dynamicdns: Fix computing update times Currenly uptime is being taken as measure to decide whether update must run. Uptime is the number of seconds since machine has booted. If a machine has run for 30 hours, and rebooted, then update will not be done until the machine has run for 30 hours + desinated time. Using seconds since epoch fixes this. --- actions/dynamicdns | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/actions/dynamicdns b/actions/dynamicdns index 4b45a8c37..3968d744f 100755 --- a/actions/dynamicdns +++ b/actions/dynamicdns @@ -374,10 +374,10 @@ case ${cmd} in fi # if we don't know our WAN IP do a blind update once a hour if [ "${wanip}" = ${NOIP} ];then - uptime=$(cut -d . -f 1 /proc/uptime) + currenttime=$(date +%s) LAST=0 [ -f ${LASTUPDATE} ] && LAST=$(cat ${LASTUPDATE}) - diff=$((uptime - LAST)) + diff=$((currenttime - LAST)) if [ ${diff} -gt ${UPDATEMINUTESUNKNOWN} ];then doUpdate fi @@ -392,7 +392,7 @@ case ${cmd} in success) date=$(date) echo "last update done (${date})" > ${STATUSFILE} - awk '{print $1}' /proc/uptime |cut -d . -f 1 > ${LASTUPDATE} + date +%s > ${LASTUPDATE} # if called from cronjob, the current IP is given as parameter if [ $# -eq 1 ];then echo "${1}" > ${IPFILE} From ea1e9b6e2a1b57737ffad962a15ba3528eff9b22 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 1 Feb 2016 11:00:46 +0530 Subject: [PATCH 3/5] dynamicdns: Fix writing configuration for no NAT - When writing the configuration file for no NAT case, append then last part of the file instead of overwriting. - Also 'echo' statements are missing leading to attempt to execute the config options instead of writing them to a file. --- actions/dynamicdns | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/actions/dynamicdns b/actions/dynamicdns index 3968d744f..aae9b9992 100755 --- a/actions/dynamicdns +++ b/actions/dynamicdns @@ -167,11 +167,11 @@ doWriteCFG() echo "NAT no" >> ${HELPERCFG} # if this file is added ez-ipupdate will take ip form this interface { - "interface=${default_interface}" + echo "interface=${default_interface}" # if this line is added to config file, ez-ipupdate will be launched on startup via init.d - "daemon" - "execute=${0} success" - } > ${out_file} + echo "daemon" + echo "execute=${0} success" + } >> ${out_file} fi fi } From 51dd1bb0007802a4b7b186bc6c569dcf82bc5e0d Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 1 Feb 2016 11:02:43 +0530 Subject: [PATCH 4/5] dynamicdns: Fix an invalid syntax 'local' keyword can't be used outside a method. --- actions/dynamicdns | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/dynamicdns b/actions/dynamicdns index aae9b9992..f437e657a 100755 --- a/actions/dynamicdns +++ b/actions/dynamicdns @@ -338,7 +338,7 @@ case ${cmd} in doGetWANIP if [ "$(grep ^NAT ${HELPERCFG} | awk '{print $2}')" = "no" ];then #if we are not behind a NAT device and we use gnudip, start the daemon tool - local gnudipServer=$(grep ^server= ${cfgfile} 2> /dev/null | cut -d = -f 2- |grep -v ^\'\') + gnudipServer=$(grep ^server= ${cfgfile} 2> /dev/null | cut -d = -f 2- |grep -v ^\'\') if [ -f ${CFG} -a ! -z "${gnudipServer}" ];then mv ${CFG_disabled} ${CFG} /etc/init.d/${TOOLNAME} start From 83ec57414ce1d2b2025a240f6055dcfa862a51ad Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 1 Feb 2016 11:03:54 +0530 Subject: [PATCH 5/5] dynamicdns: Fix starting daemon for no NAT Incase the machine is not behind NAT, fix the logic that decides to start the daemon. --- actions/dynamicdns | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/dynamicdns b/actions/dynamicdns index f437e657a..34aca8d87 100755 --- a/actions/dynamicdns +++ b/actions/dynamicdns @@ -339,7 +339,7 @@ case ${cmd} in if [ "$(grep ^NAT ${HELPERCFG} | awk '{print $2}')" = "no" ];then #if we are not behind a NAT device and we use gnudip, start the daemon tool gnudipServer=$(grep ^server= ${cfgfile} 2> /dev/null | cut -d = -f 2- |grep -v ^\'\') - if [ -f ${CFG} -a ! -z "${gnudipServer}" ];then + if [ ! -f ${CFG} -a ! -z "${gnudipServer}" ];then mv ${CFG_disabled} ${CFG} /etc/init.d/${TOOLNAME} start fi