Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## ALL-U-NEED AdBlocking By YAQUI 5/1/09
- ## Dnsmasq Ed. v2.92
- ##
- ## Code optimizations Oct 9 2009
- ## idea by ng12345 / implemented by srouquette
- ##
- ## slightly modified Nov 7 2009 - Groosh
- ## autoupdate on, intel.com added to whitelist, s3 added, s4 removed, pdl.yoyo.org url chng, ADBLOCK.sh removed, single cln, added more logging, chng function flow, temp file removed from clr
- ##
- ## some modification for working with openwrt backfire
- ##
- sleep 20
- #!/bin/sh
- ## EDITABLE VARIABLES
- GETS="1 2 3"
- S1="http://www.mvps.org/winhelp2002/hosts.txt" # ~612K
- S2="http://pgl.yoyo.org/as/serverlist.php?showintro=0;hostformat=hosts" # ~72K
- S3="http://someonewhocares.org/hosts/hosts" # ~208K
- # Enter sites in format below
- WHITE="intel.com"
- ## DO NOT EDIT BELOW
- NIP="0.0.0.0"
- GEN="/tmp/gen"
- TMP="/tmp/temp"
- ## FUNCTIONS
- CLR ()
- {
- rm -f $GEN
- touch $GEN
- logger ADBLOCK Clearing TEMP Files
- }
- FMEM ()
- {
- /etc/init.d/dnsmasq stop
- killall -9 dnsmasq
- logger ADBLOCK Unloading Dnsmaq From Memory
- }
- DS ()
- {
- ##(Inline grep for 127.0.0.1 & Delete DOS Format Returns)
- for i in $GETS; do
- eval url="\$S$i"
- if wget $url -O - | grep 127.0.0.1 | tr -d "\r" >> $GEN; then
- logger ADBLOCK Retrieved $url
- else
- logger ADBLOCK ERROR Retriving $url
- fi
- done
- }
- CLN ()
- {
- sed -i -e 's/[[:cntrl:][:blank:]]//g' $GEN
- sed -i -e '/\#.*$/ s/\#.*$//' $GEN
- sed -i -e '/\[.*\]/ s/\[.*\]//' $GEN
- sed -i -e '/^$/d' $GEN
- sed -i -e '/127\.0\.0\.1/ s/127\.0\.0\.1//' $GEN
- sed -i -e '/^www[0-9]*\./ s/^www[0-9]*\.//' $GEN
- sed -i -e '/^[0-9]*www[0-9]*\./ s/^[0-9]*www[0-9]*\.//' $GEN
- sed -i -e '/^www\./ s/^www\.//' $GEN
- sed -i -e '/</d' $GEN
- sed -i -e 's/^[ \t]*//;s/[ \t]*$//' $GEN
- cat $GEN | sort -u > $TMP
- mv $TMP $GEN
- rm -f $TMP
- logger ADBLOCK Blacklist Scrubbed
- }
- FDNSM ()
- {
- sed -i -e 's|$|/'$NIP'|' $GEN
- sed -i -e 's|^|address=/|' $GEN
- logger ADBLOCK Blacklist Alignment
- }
- LCFG ()
- {
- cat /etc/dnsmasq.conf >> $GEN
- logger ADBLOCK Dnsmasq Config Applied
- }
- LWHT ()
- {
- for site in $WHITE
- do
- sed -i -e "/$site/d" $GEN
- done
- logger ADBLOCK Whitelist Applied
- }
- LBLK ()
- {
- dnsmasq --conf-file=$GEN
- logger ADBLOCK Launching Dnsmasq With Blacklist
- sleep 15
- FS
- }
- FS ()
- {
- if ps | grep -E "dnsmasq" | grep -E "nobody"; then
- logger ADBLOCK Dnsmasq with Blacklist RUNNING
- else
- logger ADBLOCK Dnsmasq NOT Running starting Dnsmasq without Blacklist
- service dnsmasq stop
- killall -9 dnsmasq
- dnsmasq
- fi
- }
- TST ()
- {
- if sed -n -e '/^address=\/ad\..*\..*\/0\.0\.0\.0$/p' $GEN; then
- TOT=`wc -l $GEN | cut -d" " -f5`
- logger ADBLOCK Blacklist Format PASS
- logger ADBLOCK Blacklist Contains $TOT Entries
- LBLK
- else
- logger ADBLOCK Blacklist Format ERROR
- FS
- fi
- }
- AUP ()
- {
- if [[ "$(cru l | grep AdUpd | cut -d "#" -f2)" != "AdUpd" ]]; then
- ## cru (a)dd <name> "min hr day mo wkday <cmd>"
- ## min=0-59 hour=0-23 day=1-31 month=1-12 sun=0 *=all
- cru a AdUpd "30 3 * * 2 /tmp/script_wanup.sh >/dev/NULL 2>&1"
- logger ADBLOCK AutoUpdate added to Cron
- fi
- }
- ## Run Functions
- CLR
- DS
- FMEM
- CLN
- FDNSM
- LCFG
- LWHT
- TST ## Launches LBLK and/OR FS
- CLR
- #AUP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement