1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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.
    I.e.
    Code:
     google.com yahoo.com msn.com
    
    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.
    Code:
    #!/bin/sh
    WHITELIST_FILE_PATH="/cifs1/whitelist.txt"
    WHITELIST=$(cat $WHITELIST_FILE_PATH)
    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 LI 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:

    Code:
    logger WAN UP Script Executing
    sleep 5
    test -s /tmp/dlhosts
    if [ $? == 1 ] ; then
       echo -e " www.googleadservices.com\n partner.googleadservices.com" > /tmp/whitelist.txt
       echo -e " ad.doubleclick.net" >> /tmp/whitelist.txt
       echo -e " ad.yieldmanager.com" >> /tmp/whitelist.txt
       echo -e "#!/bin/sh\nwget -O - http://www.mvps.org/winhelp2002/hosts.txt | grep 127.0.0.1 |  sed -e '2,\$s/127.0.0.1/0.0.0.0/g' -e 's/[[:space:]]*#.*$//' > /tmp/hosts\nlogger DOWNLOADED http://www.mvps.org/winhelp2002/hosts.txt" > /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
       /tmp/dlhosts   
    fi
    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 :)
     

Share This Page