Advertisement
Guest User

ALL-U-NEED AdBlocking By YAQUI for openwrt

a guest
Aug 25th, 2011
1,498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. ## ALL-U-NEED AdBlocking By YAQUI 5/1/09
  2. ## Dnsmasq Ed. v2.92
  3. ##
  4. ## Code optimizations Oct 9 2009
  5. ## idea by ng12345 / implemented by srouquette
  6. ##
  7. ## slightly modified Nov 7 2009 - Groosh
  8. ## 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
  9. ##
  10. ## some modification for working with openwrt backfire
  11. ##
  12.  
  13. sleep 20
  14.  
  15. #!/bin/sh
  16.  
  17. ## EDITABLE VARIABLES
  18. GETS="1 2 3"
  19. S1="http://www.mvps.org/winhelp2002/hosts.txt" # ~612K
  20. S2="http://pgl.yoyo.org/as/serverlist.php?showintro=0;hostformat=hosts" # ~72K
  21. S3="http://someonewhocares.org/hosts/hosts" # ~208K
  22. # Enter sites in format below
  23. WHITE="intel.com"
  24.  
  25. ## DO NOT EDIT BELOW
  26. NIP="0.0.0.0"
  27. GEN="/tmp/gen"
  28. TMP="/tmp/temp"
  29.  
  30. ## FUNCTIONS
  31. CLR ()
  32. {
  33. rm -f $GEN
  34. touch $GEN
  35. logger ADBLOCK Clearing TEMP Files
  36. }
  37.  
  38. FMEM ()
  39. {
  40. /etc/init.d/dnsmasq stop
  41. killall -9 dnsmasq
  42. logger ADBLOCK Unloading Dnsmaq From Memory
  43. }
  44.  
  45. DS ()
  46. {
  47. ##(Inline grep for 127.0.0.1 & Delete DOS Format Returns)
  48. for i in $GETS; do
  49. eval url="\$S$i"
  50. if wget $url -O - | grep 127.0.0.1 | tr -d "\r" >> $GEN; then
  51. logger ADBLOCK Retrieved $url
  52. else
  53. logger ADBLOCK ERROR Retriving $url
  54. fi
  55. done
  56. }
  57.  
  58. CLN ()
  59. {
  60. sed -i -e 's/[[:cntrl:][:blank:]]//g' $GEN
  61. sed -i -e '/\#.*$/ s/\#.*$//' $GEN
  62. sed -i -e '/\[.*\]/ s/\[.*\]//' $GEN
  63. sed -i -e '/^$/d' $GEN
  64. sed -i -e '/127\.0\.0\.1/ s/127\.0\.0\.1//' $GEN
  65. sed -i -e '/^www[0-9]*\./ s/^www[0-9]*\.//' $GEN
  66. sed -i -e '/^[0-9]*www[0-9]*\./ s/^[0-9]*www[0-9]*\.//' $GEN
  67. sed -i -e '/^www\./ s/^www\.//' $GEN
  68. sed -i -e '/</d' $GEN
  69. sed -i -e 's/^[ \t]*//;s/[ \t]*$//' $GEN
  70. cat $GEN | sort -u > $TMP
  71. mv $TMP $GEN
  72. rm -f $TMP
  73. logger ADBLOCK Blacklist Scrubbed
  74. }
  75.  
  76. FDNSM ()
  77. {
  78. sed -i -e 's|$|/'$NIP'|' $GEN
  79. sed -i -e 's|^|address=/|' $GEN
  80. logger ADBLOCK Blacklist Alignment
  81. }
  82.  
  83. LCFG ()
  84. {
  85. cat /etc/dnsmasq.conf >> $GEN
  86. logger ADBLOCK Dnsmasq Config Applied
  87. }
  88.  
  89. LWHT ()
  90. {
  91. for site in $WHITE
  92. do
  93. sed -i -e "/$site/d" $GEN
  94. done
  95. logger ADBLOCK Whitelist Applied
  96. }
  97.  
  98. LBLK ()
  99. {
  100. dnsmasq --conf-file=$GEN
  101. logger ADBLOCK Launching Dnsmasq With Blacklist
  102. sleep 15
  103. FS
  104. }
  105.  
  106. FS ()
  107. {
  108. if ps | grep -E "dnsmasq" | grep -E "nobody"; then
  109. logger ADBLOCK Dnsmasq with Blacklist RUNNING
  110. else
  111. logger ADBLOCK Dnsmasq NOT Running starting Dnsmasq without Blacklist
  112. service dnsmasq stop
  113. killall -9 dnsmasq
  114. dnsmasq
  115. fi
  116. }
  117.  
  118. TST ()
  119. {
  120. if sed -n -e '/^address=\/ad\..*\..*\/0\.0\.0\.0$/p' $GEN; then
  121. TOT=`wc -l $GEN | cut -d" " -f5`
  122. logger ADBLOCK Blacklist Format PASS
  123. logger ADBLOCK Blacklist Contains $TOT Entries
  124. LBLK
  125. else
  126. logger ADBLOCK Blacklist Format ERROR
  127. FS
  128. fi
  129. }
  130.  
  131. AUP ()
  132. {
  133. if [[ "$(cru l | grep AdUpd | cut -d "#" -f2)" != "AdUpd" ]]; then
  134. ## cru (a)dd <name> "min hr day mo wkday <cmd>"
  135. ## min=0-59 hour=0-23 day=1-31 month=1-12 sun=0 *=all
  136. cru a AdUpd "30 3 * * 2 /tmp/script_wanup.sh >/dev/NULL 2>&1"
  137. logger ADBLOCK AutoUpdate added to Cron
  138. fi
  139. }
  140.  
  141. ## Run Functions
  142. CLR
  143. DS
  144. FMEM
  145. CLN
  146. FDNSM
  147. LCFG
  148. LWHT
  149. TST ## Launches LBLK and/OR FS
  150. CLR
  151. #AUP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement