afwall.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. #!/bin/bash
  2. ## [afwall_easy] Simple script for generating ASN Block lists and DNS Server entry for Android AFWall.
  3. # < https://notabug.org/angrytux/afwall_easy >
  4. # This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as
  5. # published by the Free Software Foundation, either version 3 of the License, or any later version.
  6. # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. # See the GNU General Public License for more details < https://www.gnu.org/licenses >
  9. setdns=1
  10. clear
  11. echo "=================================================="
  12. echo -e "\033[3;34m BLOCK ASNs SCRIPT AND SET DNS FOR ANDROID AFWALL\033[0m"
  13. echo "=================================================="
  14. echo
  15. echo
  16. echo "--------------------------------------------------"
  17. echo "Thx ukanth for the great AFWall app!"
  18. echo
  19. echo "Visit https://github.com/ukanth/afwall"
  20. echo
  21. echo
  22. echo "Script is based on infos and python scripts from Mike Kuketz,"
  23. echo "https://www.kuketz-blog.de/"
  24. echo
  25. echo "and was further enhanced by maloe"
  26. echo "https://notabug.org/maloe/ASN_IPFire_Script"
  27. echo
  28. echo
  29. echo "Great job guys!"
  30. echo
  31. echo "--------------------------------------------------"
  32. echo
  33. echo
  34. read -n 1 -s -p "Press any key to continue"
  35. clear
  36. ####make ASN fetching script executable####
  37. chmod +x asn_ipfire.sh
  38. ####delete and create folder to reset process####
  39. rm -f copy_paste.txt
  40. rm -R -f afwscripts
  41. mkdir afwscripts
  42. ####copy common rules####
  43. echo "Which Android version do you use?"
  44. echo
  45. echo "[1] Android 8 and higher"
  46. echo
  47. echo "[2] Android 7 or older"
  48. echo
  49. echo -n ":"
  50. while read version
  51. do
  52. case $version in
  53. 1)
  54. cp default.8 ./afwscripts/aafwall_on.sh
  55. cp iptables_off.a8 ./afwscripts/iptables_off.sh
  56. break
  57. ;;
  58. 2)
  59. cp default ./afwscripts/aafwall_on.sh
  60. cp iptables_off.a7 ./afwscripts/iptables_off.sh
  61. break
  62. ;;
  63. esac
  64. done
  65. clear
  66. echo "Set DNS Server? Press key [1-4]"
  67. echo
  68. echo "(You´ll be asked for seperate Wifi dns exception later)"
  69. echo
  70. echo
  71. echo
  72. echo "[1] Don't set custom DNS server (choose this for TLS over DNS)"
  73. echo "[2] 194.150.168.169 AS250 (germany, ad-blocking)"
  74. echo "[3] 91.239.100.100 Censurfridns Denmark"
  75. echo "[4] 80.241.218.68 Dismail (germany)"
  76. echo "[5] 46.182.19.48 Digitalcourage (germany)"
  77. echo "[6] Set own DNS server (ipfire wiki list)"
  78. echo
  79. echo "See https://wiki.ipfire.org/dns/public-servers"
  80. echo "It´s only an overview, not all listed servers are censorship-free!"
  81. echo "At least you should prefer dnssec validating servers."
  82. echo
  83. echo "--------------------------------------------------"
  84. echo -e "\e[3;91mImportant!!!!!"
  85. echo
  86. echo "If you chose a custom dns server set the DNS proxy to -Disable DNS via netd- (preferences->Binaries->DNS proxy)"
  87. echo "For TLS over DNS set DNS proxy enabled."
  88. echo
  89. echo "You must allow (Android 5+) -[0] (root) - Apps running as root- in afwall else dns resolving won´t work!"
  90. echo "--------------------------------------------------"
  91. echo -e "\e[0m"
  92. echo -n ":"
  93. while read Option
  94. do
  95. case $Option in
  96. 1)
  97. setdns=0
  98. break
  99. ;;
  100. 2)
  101. # AS250.net
  102. dns_ip=194.150.168.169:53
  103. break
  104. ;;
  105. 3)
  106. # Censurfridns Denmark
  107. dns_ip=91.239.100.100:53
  108. break
  109. ;;
  110. 4)
  111. # Dismail
  112. dns_ip=80.241.218.68:53
  113. break
  114. ;;
  115. 5)
  116. # Digitalcourage
  117. dns_ip=46.182.19.48:53
  118. break
  119. ;;
  120. 6)
  121. echo "Please enter IPv4:"
  122. echo "e.g. 194.150.168.169"
  123. read ip
  124. echo
  125. echo $ip "will be set for dns"
  126. echo
  127. echo
  128. read -n 1 -s -p "Press any key to continue"
  129. dns_ip=$ip
  130. setdns=1
  131. break
  132. esac
  133. done
  134. clear
  135. if [ $setdns == 1 ]; then
  136. echo "Should another DNS server be used for your private Wifi?"
  137. echo "(Set a specific dns server for all networks except home WiFi)"
  138. echo
  139. echo "[1] No, use same dns for mobile and wifi (not set if chosen not to change)"
  140. echo
  141. echo "[2] Yes, use routers dns server(s) for my own Wifi"
  142. echo
  143. echo -n ":"
  144. while read wifi_dns
  145. do
  146. case $wifi_dns in
  147. 1)
  148. echo "# DNS Server generated from the script" >> ./afwscripts/aafwall_on.sh
  149. echo "$""IPTABLES -t nat -I OUTPUT -p tcp --dport 53 -j DNAT --to-destination $dns_ip" >> ./afwscripts/aafwall_on.sh
  150. break
  151. ;;
  152. 2)
  153. while
  154. echo "You have to enter your subnet now."
  155. echo "E.g. If your routers IP is 192.168.178.1 then enter 192.168.178.0/24"
  156. echo "If it´s 192.168.1.1 enter 192.168.1.0/24"
  157. echo
  158. read -p 'subnet:' subnet
  159. echo "Used subnet: $subnet"
  160. read -p "Is this correct? [y/n] " yn
  161. case $yn in
  162. [Yy]* ) false;;
  163. * ) true;;
  164. esac
  165. do
  166. :
  167. done
  168. echo -e "# Set a specific DNS server for all networks except home WiFi\n""$""IPTABLES -t nat -I OUTPUT ! -s $subnet -p tcp --dport 53 -j DNAT --to-destination $dns_ip\n""$""IPTABLES -t nat -I OUTPUT ! -s $subnet -p udp --dport 53 -j DNAT --to-destination $dns_ip" >> ./afwscripts/aafwall_on.sh
  169. break
  170. ;;
  171. esac
  172. done
  173. fi
  174. clear
  175. echo "Should the captive portal check be disabled?"
  176. echo
  177. echo "[1] No. Keep captive portal check [default android] !"
  178. echo
  179. echo "[2] Yes. Disable captive portal check!"
  180. echo
  181. echo -n ":"
  182. while read cportal
  183. do
  184. case $cportal in
  185. 1)
  186. break
  187. ;;
  188. 2)
  189. echo -e "\n#Disable captive portal check\npm disable com.android.captiveportallogin \nsettings put global captive_portal_detection_enabled 0\nsettings put global captive_portal_server localhost\nsettings put global captive_portal_mode 0\n" >> ./afwscripts/aafwall_on.sh
  190. if [ $version == 2 ]; then
  191. sed -i '/android.captiveportallogin/d' ./afwscripts/aafwall_on.sh
  192. fi
  193. break
  194. ;;
  195. esac
  196. done
  197. clear
  198. path=/data/local
  199. echo "Now we need to set the Path to your internal storage"
  200. echo "Default used: /data/local"
  201. echo
  202. echo "Please check yourself what´s the right path for your device!"
  203. echo
  204. echo "[1] Keep default path /data/local"
  205. echo "[2] Set different path"
  206. echo -n ":"
  207. while read Option2
  208. do
  209. case $Option2 in
  210. 1)
  211. echo
  212. echo
  213. path=/data/local
  214. echo "$path/afwscripts will be used"
  215. echo
  216. echo
  217. read -n 1 -s -p "Press any key to continue"
  218. break
  219. ;;
  220. 2)
  221. clear
  222. while
  223. echo "Please enter your path like /data/local"
  224. echo
  225. read -p 'New path:' pathinput
  226. path=$(echo "/"$pathinput | sed 's/^[/]\+/\//; s/[/]\+$//')
  227. echo "Used path: $path/afwscripts"
  228. read -p "Is this correct? [y/n] " yn
  229. case $yn in
  230. [Yy]* ) false;;
  231. * ) true;;
  232. esac
  233. do
  234. :
  235. done
  236. break
  237. esac
  238. done
  239. clear
  240. echo "Now choose the companies you want to be blocked! (Seperate them by comma without space)"
  241. echo "e.g. Google,Facebook,Samsung ..."
  242. echo
  243. echo "Just press enter if you don´t want to block any companies"
  244. echo
  245. echo
  246. read companies
  247. echo
  248. echo $companies "will be blocked"
  249. echo
  250. echo
  251. read -n 1 -s -p "Press any key to continue"
  252. echo
  253. ####start fetching ASNs####
  254. ./asn_ipfire.sh --afwall "$companies"
  255. mv afwall_rules.txt ./afwscripts/afwall_rules
  256. #### split rules at 100 lines. Else afwall could fail on some devices####
  257. split -l 100 ./afwscripts/afwall_rules ./afwscripts/afwall_rules_
  258. rm ./afwscripts/afwall_rules
  259. ls -d ./afwscripts/* | xargs -n1 basename > ./afwscripts/cp.txt
  260. nl -s ". $path/afwscripts/" ./afwscripts/cp.txt | cut -c7- > copy_paste.txt
  261. rm ./afwscripts/cp.txt
  262. clear
  263. echo "End of script..."
  264. echo
  265. echo "In Afwall app:"
  266. echo "If you dont't want to use DNS over TLS set the DNS proxy to -Disable DNS via netd- (preferences->Binaries->DNS proxy)"
  267. echo "You must allow (Android 5+) -0 - Apps running as root- in afwall else dns resolving won´t work!"
  268. echo
  269. echo "Now copy the whole afwscripts folder to $path on your device."
  270. echo "Additionally transfer copy_paste.txt onto the device."
  271. echo
  272. echo "Device: Open copy_paste.txt and copy all to the clipboard."
  273. echo
  274. echo "Open AFWall and press the three dots in the top right corner and select"
  275. echo "<Set custom script>. Paste the contents of the clipboard to user defined script."
  276. echo
  277. echo
  278. echo "Set the shutdown script path (user defined shutdown script)."
  279. echo
  280. echo "Enter this: . $path/afwscripts/iptables_off.sh"
  281. echo
  282. echo -e "\e[3;91mIMPORTANT: Don't forget the ". /" point-space-slash!!"
  283. echo -e "\e[0m"
  284. echo
  285. echo "Hint: See attached screenshot how it should look like!"
  286. echo
  287. echo "Afterwards press OK and wait until AFWall applied the rules!"
  288. echo
  289. echo
  290. read -n 1 -s -p "Press any key to continue"
  291. clear
  292. echo
  293. echo
  294. echo "The afwall.sh script sets IPv6 to drop!"
  295. echo
  296. echo "Done!"
  297. echo
  298. echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
  299. echo
  300. echo "Have fun and enjoy a bit more privacy!"
  301. echo
  302. echo ""
  303. echo "https://github.com/ukanth/afwall"
  304. echo "https://www.kuketz-blog.de"
  305. echo "https://notabug.org/maloe/ASN_IPFire_Script"
  306. echo
  307. echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
  308. echo