What's new

ddns ip whitelist with little script.

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

topmusic

Occasional Visitor
Oke my situation.
I have a mailserver running, and to get access for all users i have created a little scripts that resolves from a no-ip dynamic host to ip.
Then the ip-address is always add to the whitelist (running a cron every hour) so the users will always get access to read there email.

Now i want to adjust the script that it first check in the whitelist if its there, if so then end the script and update the log.
If its not there, then add it and write to the log also

the first little script.
Code:
#!/bin/sh
VER="v1.01a"

# - Cron job or in init-start
# - /usr/sbin/cru a IPUPDATE   "0 * * * * /jffs/scripts/update-ip.sh"    #Every hour

# - Check ip firewall - /jffs/scripts/firewall stats search ip 82.75.62.105 10
# - Check ip ipset - /usr/sbin/ipset list Skynet-Whitelist |grep -c 82.75.62.105

log_file="/tmp/mnt/RT-AX86U/log/emailname.log"
SCRIPT_PATH="/jffs/scripts/firewall"
now=$(date +%d-%m-%Y/%H:%M)

# User = emailname
IP=$(kdig +short ddnsname.hopto.org @resolver1.opendns.com)
echo " -> RT-AX86U-Pro ip-update"
echo "[$now]=[$IP]" >> ${log_file}

    (exec "$SCRIPT_PATH" whitelist ip $IP)


Finally i have something like this, but ill get an error when running.
Code:
#!/bin/sh
VER="v1.01a"

# - Cron job or in init-start
# - /usr/sbin/cru a IPUPDATE   "0 * * * * /jffs/scripts/update-ip.sh"    #Every hour

# - Check ip firewall - /jffs/scripts/firewall stats search ip 82.75.62.105 10
# - Check ip ipset - /usr/sbin/ipset list Skynet-Whitelist |grep -c 82.75.62.105

log_file="/tmp/mnt/RT-AX86U/log/emailname.log"
SCRIPT_PATH="/jffs/scripts/firewall"
now=$(date +%d-%m-%Y/%H:%M)

# User = emailname
IP=$(kdig +short ddnsname.hopto.org @resolver1.opendns.com)

echo " -> RT-AX86U-Pro ip-update"

if [ "$(/jffs/scripts/firewall whitelist view | grep -c "$IP")" = 0 ] ; then
   echo "ERROR - $IP is NOT in Whitelist"
  (exec "$SCRIPT_PATH" whitelist ip $IP)
   echo "$IP is Added to the Whitelist"
   echo "[$now]=[$IP]" >> ${log_file}
   fi
 
if [ "$IP" -eq = "1" ] ; then
    echo "NEW $IP is already in the whitelist]"
    echo "[$now]=[$IP]" >> ${log_file}
   fi

The error ill get is ;
root# /jffs/scripts/test-update.sh
-> RT-AX86U-Pro ip-update
[: bad number


Can someone help me with that tot get it running correctly ?


Regards
 
This is error row.
echo "NEW $IP is already in the whitelist]"
Sorry, realized that is a echo command and not the problem.
 
Last edited:
Warning, newb advice incoming

Run your script with the code below to see everything it is processing.
Code:
sh -x /jffs/scripts/test-update.sh

Code:
if [ "$IP" -eq = "1" ] ; then
This is causing the bad number error '-eq =' , but if $IP is an actual IP it will never equal 1

Code:
#!/bin/sh
VER="v1.01a"

log_file="/tmp/mnt/RT-AX86U/log/emailname.log"
SCRIPT_PATH="/jffs/scripts/firewall"
now=$(date +%d-%m-%Y/%H:%M)
IP=$(kdig +short ddnsname.hopto.org @resolver1.opendns.com)
FW_CHECK=$(/jffs/scripts/firewall whitelist view | grep -c "$IP")

echo " -> RT-AX86U-Pro ip-update"

if [ "$FW_CHECK" -eq 0 ] ; then
    echo "ERROR - $IP is NOT in Whitelist"
    sh "$SCRIPT_PATH" whitelist ip $IP
    echo "$IP is Added to the Whitelist"
    echo "[${now}]=[${IP}]" >> ${log_file}
else
    echo "NEW $IP is already in the whitelist]"
    echo "[${now}]=[${IP}]" >> ${log_file}
fi
 
Last edited:
Thx for the modifications, it's working like it should :)
 
I forgot something to ask, i have over 150 users, all with there own ddns name, must i use a sql database to read-out the users and how create i for all the users a separate log file.
 
I forgot something to ask, i have over 150 users, all with there own ddns name, must i use a sql database to read-out the users and how create i for all the users a separate log file.
If it were me Id create a file listing out all the ddns names then create a while loop containing the above script to iterate through the list
Code:
while read -r ddnsuser ; do
    log_file="/tmp/mnt/RT-AX86U/log/${ddnsuser}.log"
    ....
done < /jffs/scripts/ddnslist.txt
 
oke im almost there, created a csv file with number, noip address and logfilename also with a loop but the checking is one time.
when its running the else command ip stay empty.

Code:
#!/bin/sh
VER="v1.02a"

SCRIPT_PATH="/jffs/scripts/firewall"
now=$(date +%d-%m-%Y/%H:%M)

while read LINE; # by line from a list
do

  num=$(echo "${LINE}" | cut -d "," -f 1)
  noip=$(echo "${LINE}" | cut -d "," -f 2)
  logname=$(echo "${LINE}" | cut -d "," -f 3)
 
  echo "${num},${noip},${logname}"
 
done < /jffs/scripts/update-ip.csv

log_file="/tmp/mnt/RT-AX86U/log/$logname.log"
IP=$(kdig +short "$noip" @resolver1.opendns.com)
IPVAR=$("$IP" "$num")
FW_CHECK=$(/jffs/scripts/firewall whitelist view | grep -c "$IP")

echo " -> RT-AX86U-Pro ip-update"

if [ "$FW_CHECK" -eq 0 ] ; then
    echo "ERROR - $IPVAR is NOT in Whitelist"
    sh "$SCRIPT_PATH" whitelist ip $IPVAR
    echo "$IPVAR is Added to the Whitelist"
    echo "[${now}]=[${IPVAR}]" >> ${log_file}
else
    echo "NEW $IPVAR is already in the whitelist"
    echo "[${now}]=[${IPVAR}]" >> ${log_file}
fi
 
it must add a number to the $IP(number) , that is what i have in my old script.
every ddns has it's own number.

Example:

Code:
#!/bin/sh
VER="v1.02a"

log_file1="/tmp/mnt/RT-AX86U/log/emailname1.log"
log_file2="/tmp/mnt/RT-AX86U/log/emailname2.log"
log_file3="/tmp/mnt/RT-AX86U/log/emailname3.log"

SCRIPT_PATH="/jffs/scripts/firewall"
now=$(date +%d-%m-%Y/%H:%M)

IP1=$(kdig +short ddns1.hopto.org @resolver1.opendns.com)
echo " -> emailname1 ip-update"
echo "[$now]=[$IP1]" >> ${log_file}
  (exec "$SCRIPT_PATH" whitelist ip $IP1)
 
IP2=$(kdig +short ddns2.hopto.org @resolver1.opendns.com)
echo " -> emailname2 ip-update"
echo "[$now]=[$IP2]" >> ${log_file}
  (exec "$SCRIPT_PATH" whitelist ip $IP2)
 
IP3=$(kdig +short ddns3.hopto.org @resolver1.opendns.com)
echo " -> emailname3 ip-update"
echo "[$now]=[$IP3]" >> ${log_file}
  (exec "$SCRIPT_PATH" whitelist ip $IP3)
 
oke im almost there, created a csv file with number, noip address and logfilename also with a loop but the checking is one time.
when its running the else command ip stay empty.

Code:
#!/bin/sh
VER="v1.02a"

SCRIPT_PATH="/jffs/scripts/firewall"
now=$(date +%d-%m-%Y/%H:%M)

while read LINE; # by line from a list
do

  num=$(echo "${LINE}" | cut -d "," -f 1)
  noip=$(echo "${LINE}" | cut -d "," -f 2)
  logname=$(echo "${LINE}" | cut -d "," -f 3)
 
  echo "${num},${noip},${logname}"
 
done < /jffs/scripts/update-ip.csv

log_file="/tmp/mnt/RT-AX86U/log/$logname.log"
IP=$(kdig +short "$noip" @resolver1.opendns.com)
IPVAR=$("$IP" "$num")
FW_CHECK=$(/jffs/scripts/firewall whitelist view | grep -c "$IP")

echo " -> RT-AX86U-Pro ip-update"

if [ "$FW_CHECK" -eq 0 ] ; then
    echo "ERROR - $IPVAR is NOT in Whitelist"
    sh "$SCRIPT_PATH" whitelist ip $IPVAR
    echo "$IPVAR is Added to the Whitelist"
    echo "[${now}]=[${IPVAR}]" >> ${log_file}
else
    echo "NEW $IPVAR is already in the whitelist"
    echo "[${now}]=[${IPVAR}]" >> ${log_file}
fi
Everything needs to be inside while loop, move 'done < /jffs/scripts/update-ip.csv' to the bottom of the file
 
thnx @Maverickcdn that did it, its running oke now. You helped me allot to fix this.👍
 
Similar threads
Thread starter Title Forum Replies Date
J DDNS does not update dyndns.org when WAN IP changes Asuswrt-Merlin AddOns 11

Similar threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top