Guide for Ad-Blocking: Removing some domains from list?

Discussion in 'Tomato Firmware' started by Nox997, Dec 29, 2007.

  1. Nox997

    Nox997 LI Guru Member

  2. Slavedriver

    Slavedriver LI Guru Member

    I haven't tested it and it could contain errors (I have no Linux anywhere nearby to test it) but here's a simple script with which you could create a whitelist of domains.

    Step 1
    Create a file with space-separated domains you don't want to block.
    Step 2
    Create the script which will apply the whitelist to your adblock list. The script could be placed either on cifs, jffs or in WAN UP section and it must be run after each adblock list update.
    WHITELIST_INVOCATION=$(cat $WHITELIST | sed "\$s/[[:space:]]/ -v /g")
    cat $1 | $WHITELIST_INVOCATION > $1
    You pass your adblock file as the parameter to the script and it filters out every whitelisted site.

    Please note that whitelist must begin with a space and must not end with it.

    As I said I haven't tested it because I don't have Linux anywhere around but it probably should be fine. Try it on some test files first though.
  3. Nox997

    Nox997 LI Guru Member

    Thank you!

    Let's see if it works...
  4. Slavedriver

    Slavedriver LI Guru Member

    Umm...did it work or have I just bricked someone's router ? :)
  5. Nox997

    Nox997 LI Guru Member

    Sry didn't try it yet...
    but I read some guide in shell scripting and as far as my little knowledge admits me to understand your script, I also think it should work this way :)
  6. crandy2

    crandy2 Network Guru Member

    Couldn't get that to work, but....

    I never could get the code above to work (problems with the sed command) , but did get the grep command to work. Code below:

    logger WAN UP Script Executing
    sleep 5
    test -s /tmp/dlhosts
    if [ $? == 1 ] ; then
       echo -e "\n" > /tmp/whitelist.txt
       echo -e "" >> /tmp/whitelist.txt
       echo -e "" >> /tmp/whitelist.txt
       echo -e "#!/bin/sh\nwget -O - | grep |  sed -e '2,\$s/' -e 's/[[:space:]]*#.*$//' > /tmp/hosts\nlogger DOWNLOADED" > /tmp/dlhosts
       echo -e "cat /tmp/hosts | grep -v -f /tmp/whitelist.txt > /etc/hosts" >> /tmp/dlhosts
       echo -e "killall -1 dnsmasq\nrm /tmp/hosts\nlogger Applied Whitelist" >> /tmp/dlhosts
       chmod 777 /tmp/dlhosts
    cru a Gethosts "45 23 * * 5 /tmp/dlhosts"
    I am sure this could be written many ways. I only have a few sites for my whitelist, so I could just put them directly in the script.

    Maybe someone else can improve this, I am a novice at Linux scripts, but this is working for me.:)
  7. Slavedriver

    Slavedriver LI Guru Member

    Well doh, your way is much easier :)
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice