OpenWrt Forum Archive

Topic: ALL-U-NEED Ad Blocking by YAQUI - Does it work with OpenWRT

The content of this topic has been archived between 22 Apr 2018 and 30 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

drwxr-xr-x    2 root     root             0 Jun 28 21:48 dns

rgranados80:
run the set command with no parameters to see the busybox envirionment.  Here is what mine looks like:

root@OpenWrt:/etc# set
HOME='/root'
IFS='
'
LOGNAME='root'
OLDPWD='/sbin'
OPTIND='1'
PATH='/bin:/sbin:/usr/bin:/usr/sbin'
PPID='4301'
PS1='\u@\h:\w\$ '
PS2='> '
PS4='+ '
PWD='/etc'
SHELL='/bin/ash'
SSH_CONNECTION='192.168.68.144 1052 192.168.68.1 22'
SSH_TTY='/dev/pts/0'
TERM='xterm'
USER='root'
_='-l'

There appears to be only one difference at the very end and it is for a variable I'm not familiar with at all.

root@OpenWrt:/etc# set
HOME='/root'
IFS='     
'
LOGNAME='root'
OLDPWD='/root'
OPTIND='1'
PATH='/bin:/sbin:/usr/bin:/usr/sbin'
PPID='1988'
PS1='\u@\h:\w\$ '
PS2='> '
PS4='+ '
PWD='/etc'
SHELL='/bin/ash'
SSH_CONNECTION='206.54.145.254 26179 67.190.222.79 443'
SSH_TTY='/dev/pts/0'
TERM='xterm'
USER='root'
_='clear'
root@OpenWrt:/etc#

The only other thing that I can think of is that there was corruption of the disable_adds.sh file that was put on the router.  How did you transfer it to the router?  I used winScp.  If some how the file gets corrupted so that un-printable characters were inserted, then that could cause all symptoms.  If the shell cannot read/interperet (correctly) the "#!/bin/sh" it will not execute the file and issue a "not found" error message.  I think we need to verify the state of the script file.

KingJL wrote:

The only other thing that I can think of is that there was corruption of the disable_adds.sh file that was put on the router.  How did you transfer it to the router?  I used winScp.  If some how the file gets corrupted so that un-printable characters were inserted, then that could cause all symptoms.  If the shell cannot read/interperet (correctly) the "#!/bin/sh" it will not execute the file and issue a "not found" error message.  I think we need to verify the state of the script file.

Sorry for the delayed response KingJL. The file was transferred using scp command from a terminal. I don't have the commands but the responses of those commands appeared to indicate a successful transmission of the file. I was doing this remotely though as opposed to locally on the network. (Not sure if that really makes a difference)

Since the files really don't change -- I'll re-upload them now and report back what happens.

So here's the situation now... smile

I took what KingJL said into consideration regarding the file being corrupt and re-uploaded the file. The same result occurred when I tried to run the script so I opted to try and see if I could find anything about the "exact" message it was returning when I did run the script.

I was led to a "How-To-Geek" post regarding the very same thing I'm trying to execute to now.

This user had the same error I was experiencing. Link Here

This user brought up "EXACTLY" how I had transferred the file (scp) and how that will mess with the file. So he indicated it was best to paste the script into the SSH session while working within vi. Link Here

I managed to get that completed and re-applied the the permissions and attributes the script and pixelserv files.

Viola! The script ran!

It came back with errors though. sad (and some bad consequences)

root@OpenWrt:/etc/dns# ./disable_add.sh 
ad_blocker_script: ###########Ads blocker ed###########
ad_blocker_script: Sleeping for 30 secs to give time for router boot
ad_blocker_script: New IP and ports setup
ad_blocker_script: Adding a refresh cycle by puting the script in cron if it isnt there yet
ad_blocker_script: The script is already in cron
ad_blocker_script: Redirect setup & Appending to the FW script
ad_blocker_script: did NOT find an active redirect rule with the iptable command, injecting it now.
ad_blocker_script: Starting or ReSpawning pixelsrv
ad_blocker_script: it seems that the pixelserv isnt up. starting it now
pixelserv[4430]: /etc/dns/pixelserv V22 compiled: Dec  8 2010 14:58:16 from pixelserv22.c
ad_blocker_script: Get the online lists
date: can't stat '/etc/dns/dlhosts': No such file or directory
date: can't stat '/etc/dns/adblock.conf': No such file or directory
expr: syntax error
expr: syntax error
sh: -o: bad number
ad_blocker_script: The lists are less then 3 days old, saving on flash erosion and NOT refreshing them
ad_blocker_script: Removing whitelist from the personal file
ad_blocker_script: Refreshing DNS settings

dnsmasq: cannot read /etc/dns/adblock.conf: No such file or directory
ad_blocker_script: ##########The Ads blocker script has finished its run and you should up and running##########
root@OpenWrt:/etc/dns# ls
disable_add.sh          personal-ads-list.conf  pixelserv               whitelist
root@OpenWrt:/etc/dns#

As can be seen from the "ls" command at the end -- some of the files were created as the script indicated it would -- but not all of them.

I figured "no harm" -- just reboot the router and all will be fine. Well it appears that the script makes some changes to the overall router and some settings stuck and are currently not allowing me access to the internet from my router. sad (using my Droid X right now as a wireless access point) tongue

From my computer that is wired to the router -- I have no internet but I can ping google.com and other sites.

From my laptop that is wireless to the router -- I cannot even establish a connection.

I am maintaining a positive attitude though... because that's all part of learning right? smile

My theory for my wired connection regarding the script is that it makes some "iptable" changes that effects the firewall, but I am definitely not versed in making those kinds of commands yet since I do almost all of my changes within Luci. I'm assuming there is something that the script didn't get to complete and packets are just falling off somewhere.

What I can't explain is why my laptop cannot get an address wirelessly on the router though?

Again -- any and all help will be appreciated.

Thanks in advance. smile

rgranados80 wrote:

From my computer that is wired to the router -- I have no internet but I can ping google.com and other sites.

That wasn't entirely true.

From my PC I am unable to access the internet OR ping any outside DNS.

From an SSH connection to my router -- I CAN ping any outside DNS.

Pardon my mistake there.

There is always 'failsafe' that will let you telnet into the router at the default ip address.  Once in in failsafe, you can run 'firstboot' to restore all settings to the installed default.  After running 'firstboot' wait unti the router reboots or 15 minutes to be safe.  On reboot telnet in and set passwd (all steps you originally took). 

I have modified the script to take care of the errors that occurred because the files that bdid not exist and gave the 'stat' errors that in turn resulted in the 'expr' errors (I had original files already in place, just out of date).  When these errors occurred, the conditional block was never executed to create the 2 main adblock files.  Not sure what happened to cause you not to be able to get in.  Did you ensure that the correct interface was br-lan?

New script:

#!/bin/sh
########Debug commands for terminal############
#echo "alias mem='cat /proc/meminfo'" >>/tmp/root/.profile
#echo "alias ll='ls -lash --color=auto'" >>/tmp/root/.profile
#echo "alias ls='ls --color=auto'" >>/tmp/root/.profile
#echo "alias tlog='tail -f /var/log/messages'" >>/tmp/root/.profile
#echo "alias clog='cat /var/log/messages | grep local0.notice'" >>/tmp/root/.profile
########Functions setup#########################
logger_ads()
{
logger -s -p local0.notice -t ad_blocker_script $1
}
 
##################################################

logger_ads "###########Ads blocker ed###########"

if [[ -z "$1" ]]; then
    logger_ads "Sleeping for 30 secs to give time for router boot"
    sleep 30
else
    logger_ads "override switch given"
    [[ $1 = "-h" || $1 = "/?" ]] && echo "use -m to override the 30 seconds delay and -f to force a list refresh" && exit 0    
    [ $1 = "-f" ] && rm /etc/dns/adblock.conf && rm /etc/dns/dlhosts
fi

# while ! ping www.google.com -c 1 > /dev/null ; do
# use wget for thos instances where the host network prevents pings
while ! wget http://www.google.com -O /dev/null 2>/dev/null ; do
    logger_ads "waiting for the internet connection to come up"
    sleep 5
done
 
logger_ads "New IP and ports setup"
pixel="`ifconfig br-lan | grep inet | awk '{ print $3 }' | awk -F ":" '{ print $2 }' | cut -d . -f 1,2,3`.254"
/sbin/ifconfig br-lan:1 $pixel
#/sbin/ifconfig br-lan:1 $pixel netmask "`ifconfig br-lan | grep inet | awk '{ print $4 }' | awk -F ":" '{ print $2 }'`" broadcast "`ifconfig br-lan | grep inet | awk '{ print $3 }' | awk -F ":" '{ print $2 }'`" up
 
logger_ads "Adding a refresh cycle by puting the script in cron if it isnt there yet"
if [[ -z "`cat /etc/crontabs/root | grep "/etc/dns/disable_adds.sh"`" ]] ; then
    echo '0 0 * * * \t/etc/dns/disable_adds.sh -m' >> /etc/crontabs/root
    /etc/init.d/cron restart && logger_ads "restarted the cron service"
else
    logger_ads "The script is already in cron"
fi

logger_ads "Redirect setup & Appending to the FW script"
#[[ -z "`iptables -L -n -t nat | grep ${pixel} | grep 88`" ]] && logger_ads "did NOT find an active redirect rule with the iptable command, injecting it now." && /usr/sbin/iptables -t nat -I PREROUTING -p tcp -d ${pixel} --dport 80 -j REDIRECT --to-ports 88
[[ -z "`iptables -L -n -t nat | grep ${pixel} | grep 88`" ]] && logger_ads "did NOT find an active redirect rule with the iptable command, injecting it now." && /usr/sbin/iptables -t nat -I PREROUTING 1 -d ${pixel} -p tcp --dport 80 -j DNAT --to ${pixel}:88

 
logger_ads "Starting or ReSpawning pixelsrv"
if [[ -n "`ps | grep -v grep | grep /etc/dns/pixelserv`" ]]
then
logger_ads "the pixelserv is already up"
else
logger_ads "it seems that the pixelserv isnt up. starting it now"
/etc/dns/pixelserv $pixel -p 88
fi

logger_ads "Get the online lists"
tdhl=0
tadblk=0
tnow=`date +%s`
[ -e /etc/dns/dlhosts ] && tdlh=`date +%s -r /etc/dns/dlhosts`
[ -e /etc/dns/adblock.conf ] && tadblk=`date +%s -r /etc/dns/adblock.conf`
tdlh=`expr $tdlh + 86400`
tadblk=`expr $tadblk + 86400`

[ ! -e /etc/dns/whitelist ] && echo google-analytics > /etc/dns/whitelist && echo googleadservices >> /etc/dns/whitelist
if [[ $tnow -ge $tdlh || $tnow -ge $tadblk || ! -e /etc/dns/dlhosts || ! -e /etc/dns/adblock.conf ]]; then
    logger_ads "The lists are NOT setup at all yet, or more then 3 days old. will now retrieve them from the web"
    logger_ads "Retrieving the MVPS hosts list"
    wget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep "^127.0.0.1" | grep -v localhost | tr -d '\015' >/tmp/dlhosts.tmp
    logger_ads "adjusting the MVPS hosts list for our use"
    cat /etc/dns/whitelist | while read line; do sed -i /${line}/d /tmp/dlhosts.tmp ; done
    sed -i s/127.0.0.1/$pixel/g /tmp/dlhosts.tmp
    logger_ads "done adjusting the MVPS hosts list use"
    logger_ads "retrieving the Yoyo domain list"
    wget -q "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mimetype=plaintext" -O /tmp/adblock.tmp
    logger_ads "adjusting the Yoyo domain list for our use"
    cat /etc/dns/whitelist | while read line; do sed -i /${line}/d /tmp/adblock.tmp ; done
    sed -i s/127.0.0.1/$pixel/g /tmp/adblock.tmp
    logger_ads "Moving the Yoyo list to etc"
    mv /tmp/adblock.tmp /etc/dns/adblock.conf
    logger_ads "Moving the MVPS hosts list to etc"
    mv /tmp/dlhosts.tmp /etc/dns/dlhosts

else
    logger_ads "The lists are less then 3 days old, saving on flash erosion and NOT refreshing them"
fi
 
logger_ads "Removing whitelist from the personal file"
[ ! -e /etc/dns/personal-ads-list.conf ] && touch /etc/dns/personal-ads-list.conf
cat /etc/dns/whitelist | while read line; do sed -i /${line}/d /etc/dns/personal-ads-list.conf ; done

# Replace the adblock stuff in the "dnsmasq.conf" file.
sed  -i "/^#BEGIN--adblock-custom/,/^#END--adblock-custom/d" /etc/dnsmasq.conf
echo "#BEGIN--adblock-custom" >>/etc/dnsmasq.conf
echo "conf-file=/etc/dns/adblock.conf" >>/etc/dnsmasq.conf
echo "addn-hosts=/etc/dns/dlhosts" >>/etc/dnsmasq.conf
echo "conf-file=/etc/dns/personal-ads-list.conf" >> /etc/dnsmasq.conf
echo "#END--adblock-custom" >>/etc/dnsmasq.conf

logger_ads "Refreshing DNS settings"
/etc/init.d/dnsmasq restart && logger_ads "restarted the dnsmasq service"

logger_ads "##########The Ads blocker script has finished its run and you should up and running##########"
rgranados80 wrote:
rgranados80 wrote:

From my computer that is wired to the router -- I have no internet but I can ping google.com and other sites.

That wasn't entirely true.

From my PC I am unable to access the internet OR ping any outside DNS.

From an SSH connection to my router -- I CAN ping any outside DNS.

Pardon my mistake there.

get in with ssh.
use vi to edit the dnsmasq.conf
delete the lines:

#BEGIN--adblock-custom
conf-file=/etc/dns/adblock.conf
addn-hosts=/etc/dns/dlhosts
conf-file=/etc/dns/personal-ads-list.conf
#END--adblock-custom

save and exit the file
use vi to edit the /etc/crontabs/root file
delete the line:
0 0 * * *       /etc/dns/disable_adds.sh -m
save and exit the file

in the /etc/dns directory delete the adblock.conf, dlhosts, personal-ads-list.conf, whitelist

reboot and see if you can get in... you should be back to pre script configuration.

Note: Using WinSCP, I have never had a corrupted file transfer.  With the corruption that occurred with the script would make me wonder the condition of the binary.

KingJL wrote:

There is always 'failsafe' that will let you telnet into the router at the default ip address.  Once in in failsafe, you can run 'firstboot' to restore all settings to the installed default.  After running 'firstboot' wait unti the router reboots or 15 minutes to be safe.  On reboot telnet in and set passwd (all steps you originally took).

I can get into the router still via SSH. I've noticed that DHCP wasn't working correctly but with a static IP address I am able to communicate with the router. If I take the route of initiating the "firstboot" command -- will I lose all of my configurations and installed modules? 


KingJL wrote:

I have modified the script to take care of the errors that occurred because the files that bdid not exist and gave the 'stat' errors that in turn resulted in the 'expr' errors (I had original files already in place, just out of date).  When these errors occurred, the conditional block was never executed to create the 2 main adblock files.  Not sure what happened to cause you not to be able to get in.

Does this mean I should make dummy files within the directory so that the script sees something at least? Or has the script changed in a way that it creates dummies in advance and then inserts information into them?

Also -- I want to confirm before doing anything "firstboot" commands -- that when you say, "cause you not to be able to get in." -- that you mean not at all? I am still able to SSH into the router and once logged into it, I can ping out to google.com and other websites. Functional... just seems that DNSMASQ has seen better days! tongue

KingJL wrote:

Did you ensure that the correct interface was br-lan?

Yep -- I made sure of that when I first started reading the beginning of the script and the interface is called exactly the same as the script needs.



KingJL wrote:

logger_ads "Adding a refresh cycle by puting the script in cron if it isnt there yet"
if [[ -z "`cat /etc/crontabs/root | grep "/etc/dns/disable_adds.sh"`" ]] ; then
    echo '0 0 * * * \t/etc/dns/disable_adds.sh -m' >> /etc/crontabs/root
    /etc/init.d/cron restart && logger_ads "restarted the cron service"
else
    logger_ads "The script is already in cron"
fi

This information below is what I had in your original e-mail to me and I wanted to make sure that the script above was correct or if there was a typo?

logger_ads "Adding a refresh cycle by puting the script in cron if it isnt there yet"
if [[ -z "`cat /etc/crontabs/root | grep "/etc/dns/disable_adds.sh"`" ]] ; then
    echo '0 0 * * * root /etc/dns/disable_adds.sh -m' >> /etc/crontabs/root
    /etc/init.d/cron restart && logger_ads "restarted the cron service"
else
    logger_ads "The script is already in cron"
fi



KingJL wrote:

logger_ads "Redirect setup & Appending to the FW script"
#[[ -z "`iptables -L -n -t nat | grep ${pixel} | grep 88`" ]] && logger_ads "did NOT find an active redirect rule with the iptable command, injecting it now." && /usr/sbin/iptables -t nat -I PREROUTING -p tcp -d ${pixel} --dport 80 -j REDIRECT --to-ports 88
[[ -z "`iptables -L -n -t nat | grep ${pixel} | grep 88`" ]] && logger_ads "did NOT find an active redirect rule with the iptable command, injecting it now." && /usr/sbin/iptables -t nat -I PREROUTING 1 -d ${pixel} -p tcp --dport 80 -j DNAT --to ${pixel}:88

Was the syntax wrong? Curious because I'm trying to learn all the different parts of the script and what it does.


KingJL wrote:

logger_ads "Get the online lists"
tdhl=0
tadblk=0
tnow=`date +%s`
[ -e /etc/dns/dlhosts ] && tdlh=`date +%s -r /etc/dns/dlhosts`
[ -e /etc/dns/adblock.conf ] && tadblk=`date +%s -r /etc/dns/adblock.conf`
tdlh=`expr $tdlh + 86400`
tadblk=`expr $tadblk + 86400`

Curious if this is possibly the dummy file creation if the /etc/dns/ path doesn't have the dlhost & adblock.conf files. Below is the original.


logger_ads "Get the online lists"
tnow=`date +%s`
tdlh=`date +%s -r /etc/dns/dlhosts`
tadblk=`date +%s -r /etc/dns/adblock.conf`
tdlh=`expr $tdlh + 86400`
tadblk=`expr $tadblk + 86400`



I'd really hate to lose what I've gotten configured -- but I will if I have to. I'm curious if there is any way to recover the DNSMASQ or other daemon service configurations to allow for the router to work again and just rerun the script with your changes?


I'll start working on whatever fix once I've confirmed I'm not assuming anything. smile

Thanks again KingJL!

rgranados80 wrote:
KingJL wrote:

There is always 'failsafe' that will let you telnet into the router at the default ip address.  Once in in failsafe, you can run 'firstboot' to restore all settings to the installed default.  After running 'firstboot' wait unti the router reboots or 15 minutes to be safe.  On reboot telnet in and set passwd (all steps you originally took).

I can get into the router still via SSH. I've noticed that DHCP wasn't working correctly but with a static IP address I am able to communicate with the router. If I take the route of initiating the "firstboot" command -- will I lose all of my configurations and installed modules?

Probably.  firstboot restore to the original installed image.

KingJL wrote:

I have modified the script to take care of the errors that occurred because the files that bdid not exist and gave the 'stat' errors that in turn resulted in the 'expr' errors (I had original files already in place, just out of date).  When these errors occurred, the conditional block was never executed to create the 2 main adblock files.  Not sure what happened to cause you not to be able to get in.

Does this mean I should make dummy files within the directory so that the script sees something at least? Or has the script changed in a way that it creates dummies in advance and then inserts information into them?

No need the modified script now allows for the non-existence of these files

Also -- I want to confirm before doing anything "firstboot" commands -- that when you say, "cause you not to be able to get in." -- that you mean not at all? I am still able to SSH into the router and once logged into it, I can ping out to google.com and other websites. Functional... just seems that DNSMASQ has seen better days! tongue

KingJL wrote:

Did you ensure that the correct interface was br-lan?

Yep -- I made sure of that when I first started reading the beginning of the script and the interface is called exactly the same as the script needs.



KingJL wrote:

logger_ads "Adding a refresh cycle by puting the script in cron if it isnt there yet"
if [[ -z "`cat /etc/crontabs/root | grep "/etc/dns/disable_adds.sh"`" ]] ; then
    echo '0 0 * * * \t/etc/dns/disable_adds.sh -m' >> /etc/crontabs/root
    /etc/init.d/cron restart && logger_ads "restarted the cron service"
else
    logger_ads "The script is already in cron"
fi

This information below is what I had in your original e-mail to me and I wanted to make sure that the script above was correct or if there was a typo?

logger_ads "Adding a refresh cycle by puting the script in cron if it isnt there yet"
if [[ -z "`cat /etc/crontabs/root | grep "/etc/dns/disable_adds.sh"`" ]] ; then
    echo '0 0 * * * root /etc/dns/disable_adds.sh -m' >> /etc/crontabs/root
    /etc/init.d/cron restart && logger_ads "restarted the cron service"
else
    logger_ads "The script is already in cron"
fi

take the actions in my oteher post concering dnsmasq.conf and crontabs/root

KingJL wrote:

logger_ads "Redirect setup & Appending to the FW script"
#[[ -z "`iptables -L -n -t nat | grep ${pixel} | grep 88`" ]] && logger_ads "did NOT find an active redirect rule with the iptable command, injecting it now." && /usr/sbin/iptables -t nat -I PREROUTING -p tcp -d ${pixel} --dport 80 -j REDIRECT --to-ports 88
[[ -z "`iptables -L -n -t nat | grep ${pixel} | grep 88`" ]] && logger_ads "did NOT find an active redirect rule with the iptable command, injecting it now." && /usr/sbin/iptables -t nat -I PREROUTING 1 -d ${pixel} -p tcp --dport 80 -j DNAT --to ${pixel}:88

Was the syntax wrong? Curious because I'm trying to learn all the different parts of the script and what it does.

Syntax here was correct.  On reboot the iptables entry should be gone until the script is run again.  The problem now is mainly with the dnsmasq.conf which should be straightened out with the edits I described in the other post.  What happened was that the dnsmasq.conf was referencing some non-existant files and was probably erroring thus disableing routing and dhcp.

KingJL wrote:

logger_ads "Get the online lists"
tdhl=0
tadblk=0
tnow=`date +%s`
[ -e /etc/dns/dlhosts ] && tdlh=`date +%s -r /etc/dns/dlhosts`
[ -e /etc/dns/adblock.conf ] && tadblk=`date +%s -r /etc/dns/adblock.conf`
tdlh=`expr $tdlh + 86400`
tadblk=`expr $tadblk + 86400`

Curious if this is possibly the dummy file creation if the /etc/dns/ path doesn't have the dlhost & adblock.conf files. Below is the original.

No this is now a test for the existence before trying to get the creation date (previous failing code did not check for existence, thus failing when trying to get the creation date of a non-existing file


logger_ads "Get the online lists"
tnow=`date +%s`
tdlh=`date +%s -r /etc/dns/dlhosts`
tadblk=`date +%s -r /etc/dns/adblock.conf`
tdlh=`expr $tdlh + 86400`
tadblk=`expr $tadblk + 86400`



I'd really hate to lose what I've gotten configured -- but I will if I have to. I'm curious if there is any way to recover the DNSMASQ or other daemon service configurations to allow for the router to work again and just rerun the script with your changes?


I'll start working on whatever fix once I've confirmed I'm not assuming anything. smile

Thanks again KingJL!

If after taking the steps to edit the dnsmasq .conf file and rebooting, dnsmasq still not working, you can copy /rom/etc/dnsmasq.conf to /etc/dnsmasq.conf for the original file.  Then go into LuCi and make sure that dhcp is enabled for the lan.

KingJL wrote:

reboot and see if you can get in... you should be back to pre script configuration.

You are the man King! I have read your other posts but have been on my slow connection with my laptop using my cell phone. I have tested my wireless and DHCP and DNS are back up and running on both my computer and on my laptop!! big_smile

KingJL wrote:

With the corruption that occurred with the script would make me wonder the condition of the binary

I'm not sure what you mean by binary here? Do you mean the build of my router firmware or something wrong with the script file itself when it transferred? If your concern is over the script -- I'm currently using vi and pasting the script in now and modifying the file to be executable. If you mean something else -- could you explain?

So I've taken the script with the edits you've created and attempted to run it again and came up with less errors but the same situation of being unable to surf the web.

root@OpenWrt:/etc/dns# ./disable_add.sh 
./disable_add.sh: line 1: nds: not found
ad_blocker_script: ###########Ads blocker ed###########
ad_blocker_script: Sleeping for 30 secs to give time for router boot
ad_blocker_script: New IP and ports setup
ad_blocker_script: Adding a refresh cycle by puting the script in cron if it isnt there yet
ad_blocker_script: restarted the cron service
ad_blocker_script: Redirect setup & Appending to the FW script
ad_blocker_script: did NOT find an active redirect rule with the iptable command, injecting it now.
ad_blocker_script: Starting or ReSpawning pixelsrv
ad_blocker_script: it seems that the pixelserv isnt up. starting it now
pixelserv[2061]: /etc/dns/pixelserv V22 compiled: Dec  8 2010 14:58:16 from pixelserv22.c
ad_blocker_script: Get the online lists
expr: syntax error
sh: -o: bad number
ad_blocker_script: The lists are less then 3 days old, saving on flash erosion and NOT refreshing them
ad_blocker_script: Removing whitelist from the personal file
ad_blocker_script: Refreshing DNS settings

dnsmasq: cannot read /etc/dns/adblock.conf: No such file or directory
ad_blocker_script: ##########The Ads blocker script has finished its run and you should up and running##########
root@OpenWrt:/etc/dns#

I'm posting immediately to you now because I'm using your fixes to the dnsmasq.conf and cron right after I ran the script. I should be able to make responses quicker now because of that. smile

KIngJL, this time I got your update. Thanks.

rgranados80 wrote:
KingJL wrote:

With the corruption that occurred with the script would make me wonder the condition of the binary

I'm not sure what you mean by binary here? Do you mean the build of my router firmware or something wrong with the script file itself when it transferred? If your concern is over the script -- I'm currently using vi and pasting the script in now and modifying the file to be executable. If you mean something else -- could you explain?

I was referring to the 'pixelserv' binary.

So I've taken the script with the edits you've created and attempted to run it again and came up with less errors but the same situation of being unable to surf the web.

root@OpenWrt:/etc/dns# ./disable_add.sh 
./disable_add.sh: line 1: nds: not found
ad_blocker_script: ###########Ads blocker ed###########
ad_blocker_script: Sleeping for 30 secs to give time for router boot
ad_blocker_script: New IP and ports setup
ad_blocker_script: Adding a refresh cycle by puting the script in cron if it isnt there yet
ad_blocker_script: restarted the cron service
ad_blocker_script: Redirect setup & Appending to the FW script
ad_blocker_script: did NOT find an active redirect rule with the iptable command, injecting it now.
ad_blocker_script: Starting or ReSpawning pixelsrv
ad_blocker_script: it seems that the pixelserv isnt up. starting it now
pixelserv[2061]: /etc/dns/pixelserv V22 compiled: Dec  8 2010 14:58:16 from pixelserv22.c
ad_blocker_script: Get the online lists
expr: syntax error
sh: -o: bad number
ad_blocker_script: The lists are less then 3 days old, saving on flash erosion and NOT refreshing them
ad_blocker_script: Removing whitelist from the personal file
ad_blocker_script: Refreshing DNS settings

dnsmasq: cannot read /etc/dns/adblock.conf: No such file or directory
ad_blocker_script: ##########The Ads blocker script has finished its run and you should up and running##########
root@OpenWrt:/etc/dns#

I'm posting immediately to you now because I'm using your fixes to the dnsmasq.conf and cron right after I ran the script. I should be able to make responses quicker now because of that. smile

There is still something amiss in the script causing the error at line 1, the expr error, and the sh -o bad number error.
You need to carefully compare your script (on the router) with the one I corrected in a previous post ( https://forum.openwrt.org/viewtopic.php … 95#p138695 ).

Line 1: should be only '#!/bin/sh' (there is no 'nds' on line 1).

KingJL wrote:

There is still something amiss in the script causing the error at line 1, the expr error, and the sh -o bad number error.

I think I found the cause of the expr error.
Change:

tdhl=0

to

tdlh=0

I'll post results a little later today -- I don't want to run the script remotely and be unable to get back into the router if something goes awry. Should be 3-5 hours for next post.

KingJL wrote:

There is still something amiss in the script causing the error at line 1, the expr error, and the sh -o bad number error.
You need to carefully compare your script (on the router) with the one I corrected in a previous post ( https://forum.openwrt.org/viewtopic.php … 95#p138695 ).

Line 1: should be only '#!/bin/sh' (there is no 'nds' on line 1).

Okay, I THINK I know what happened to cause the error "nds not found" at line 1.  You said that you used copy/paste while you were using vi to create disable_adds.sh.  I think that you were not in "INSERT" mode when you did the paste.  That would cause all characters of the paste to be ignored as illegal commands until the 'a' in "commands" on line 2.  At that point vi was put in "APPEND" mode and from that point forward everything pasted sucessfully.  Resulting in line 1 becomming:

nds for terminal############

resuting in the "./disable_add.sh: line 1: nds: not found".  I think that if you use vi and restore the first 2 lines and apply the edit of the tdhl to tdlh variable, then everything shoiuld be fine for the disable_adds.sh.

KingJL

ALL IS WORKING!!!

After following your last post -- the script is fully functional! big_smile You hit the nail on the head regarding VI and my pasting into the terminal window. I looked at the script file and it started incorrectly because it didn't go into "insert" mode until it hit an "i" in the script. <dumb mistake> I also made the modification of the script for the one line indicating "tdhl=0" to "tdlh=0" and there were no errors. smile

This is by far the best modification I've made on a router before as it will benefit everyone on the network. I've only ever done port forwarding to get access to things on another computer, so this is the most advanced thing I've ever implemented.

Thank you so much for sticking it out with me on this thread and dealing with my lack of scripting knowledge and basic router troubleshoot. I really appreciate everything I've learned and I'm making sure to remember the more common files that were worked with on this to try and help others on the forum.

Would you be interested at all in doing a how to?

rgranados80 wrote:

KingJL

ALL IS WORKING!!!

Great! The only other recommendation I would give would be to add an entry into the /etc/hosts file of "xxx.xxx.xxx.254 local_ad_blocker" (replace the xxx.xxx.xxx with your domain address).  That way when someone does a ping -a or a nslookup that resoves to your pixelserv, it shows a name that you will recognize rather than what ever host is the first one listed in the /etc/dns/dlhosts file.

(Last edited by KingJL on 12 Jul 2011, 01:15)

pixelserv[2061]: /etc/dns/pixelserv V22 compiled: Dec  8 2010 14:58:16 from pixelserv22.c

There was an 'enhanced version' of the little c program a few days later, trying to workaround ad hosts that load javascript or other non image requests

http://www.linksysinfo.org/forums/showp … tcount=154

hasn't been updated since - I know of one bug - pixelserv should be killed and restarted if the interface (ie lan bridge) is reconfigured - else it can sit forever attached to some no-longer-existent handle.

Would probably be preferable to re-build using the appropriate toolchains - this version used the tomatousb Broadcom mips toolchain (which is OpenWRT derived) .

Anyone give advice howto package as the smallest optware contribution?

Great thread and good work.  Here's a lightweight version that doesn't require a third party program.

1) Create a document root with a blank gif file

mkdir /www2
wget –O /www2/Blank.gif http://upload.wikimedia.org/wikipedia/commons/c/c0/Blank.gif

2) Append the following to /etc/config/uhttpd to start a new web server on port 88 that returns the blank gif file for any URL

config uhttpd pixelserv
    list listen_http    0.0.0.0:88
    option home    /www2
    option error_page    /Blank.gif
    option index_page    Blank.gif

The rest of a solution could use the prior script mentioned previously (which uses dnsmasq to point ad domains to the pixelserv).  Alternatively a lightweight version of the script could be something like:

3) Create a new executable file /etc/init.d/adblock

#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=59
start() {
        pixel="`ifconfig br-lan | grep inet | awk '{ print $3 }' | awk -F ":" '{ print $2 }' | cut -d . -f 1,2,3`.254"
        /sbin/ifconfig br-lan:1 $pixel
        /usr/sbin/iptables -t nat -I PREROUTING 1 -d ${pixel} -p tcp --dport 80 -j DNAT --to ${pixel}:88
        wget -O - "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" | sed "s/127\.0\.0\.1/$pixel/" > /var/hosts.yoyo
        wget -O - "http://www.mvps.org/winhelp2002/hosts.txt" | tr -d '\015\032' | sed "s/127\.0\.0\.1/$pixel/" > /var/hosts.mvps
}

4) Enable the adblock script to start on boot (right before dnsmasq)

/etc/init.d/adblock enable

5) Append to /etc/config/dhcp (ignoring the "config 'dnsmasq'")

config 'dnsmasq'
        list 'addnhosts' '/var/hosts.mvps'
        list 'addnhosts' '/var/hosts.yoyo'

6) Reboot

(Last edited by languagegame on 26 Jul 2011, 07:42)

You cannot use the built-in web-server in Tomato/dd-wrt etc because they are heavily customized for web gui/control script type functions - so this is a big plus for OpenWRT - but presumably can also do similar with OpenWRT/Tomato when using Optware.  Can you also filter the reply based on request?  Many links to adhosts are now to javascript snippets, and IE at least tries to execute the null gif string and reports script error.

I prefer dnsmasq's domain blocking config should be fewer entries than specific hosts? - the pgl list is downloadable in suitable form for use, others can be transformed - the Tomato based scripts merge, sort and remove duplicates.  If the resulting dnsmasq config is invalid it will error and exit - hence there are are also checks and default configs for unattended operation.

You will also likely need a Whitelist file to over-ride the download, I use this bash snip to do this

CNF=/jffs/adblock.conf
WHL=/jffs/whitelist
ADS="http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mimetype=plaintext"
AIP="192.168.0.1" # changes 127.0.0.1 to this globally
wget -O - "$ADS"|sed "s/127.0.0.1/$AIP/" | grep -Fvf $WHL >$CNF

Agree the javascript functionality is preferred for the web server.  The built-in server on OpenWRT runs relatively fast for sending blank image files, but it does not address the IE script error for javascript snippets.

I suppose this gets us back to your original request. What's the best way to get a package for the latest pixelserv executable and related scripts?

(Last edited by languagegame on 27 Jul 2011, 04:48)