You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

488 lines
14 KiB

  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2021 Gregory L. Dietsche <Gregory.Dietsche@cuw.edu>
  4. # This is free software, licensed under the MIT License
  5. #
  6. HasIpAddressChanged() {
  7. # Create a sorted, unique list of addresses using DNS
  8. HOST_LIVE=$(nslookup "$1" | grep "Address\ [0-9]\+:" | sed -r 's/^Address [0-9]+: //' | sort | uniq -i)
  9. # Create a sorted, unique list of addresess currently in use
  10. HOST_SAFE=$(grep -i "^[:0-9a-f]" "$2" | sed 's/ .*//' | sort | uniq -i)
  11. # dns resolution errors / not being connected to the internet can cause this.
  12. if [ -z "$HOST_LIVE" ]; then
  13. return 1
  14. fi
  15. #If the lists do not match, then we want to update to match the DNS records.
  16. if [ "$HOST_LIVE" = "$HOST_SAFE" ]; then
  17. return 1 # IP has NOT changed
  18. fi
  19. return 0 # IP has changed
  20. }
  21. StartIpAddressUpdate(){
  22. echo Updating "$1"
  23. RELOAD_DNSMASQ=1
  24. #Create the new hosts file...
  25. cat >"$1"<<EOL
  26. ##########################################################################
  27. # **** IMPORTANT **** #
  28. # Do not make changes to this file instead please execute: #
  29. # /usr/sbin/safe-search-maintenance #
  30. # If this file is not working, please ensure dnsmasq is able to READ it! #
  31. ##########################################################################
  32. # Last Updated On: $(date)
  33. EOL
  34. }
  35. MakeHost(){
  36. for ipAddr in $HOST_LIVE
  37. do
  38. echo "$ipAddr $1"
  39. done
  40. }
  41. #################################################
  42. ### strict.bing.com ###
  43. #################################################
  44. HOST_FILE=/etc/safe-search/available/bing.default
  45. if HasIpAddressChanged strict.bing.com $HOST_FILE; then
  46. StartIpAddressUpdate $HOST_FILE
  47. MakeHost "bing.com www.bing.com">>$HOST_FILE
  48. fi
  49. #################################################
  50. ### safe.duckduckgo.com ###
  51. #################################################
  52. HOST_FILE=/etc/safe-search/available/duckduckgo.default
  53. if HasIpAddressChanged safe.duckduckgo.com $HOST_FILE; then
  54. StartIpAddressUpdate $HOST_FILE
  55. MakeHost "duckduckgo.com">>$HOST_FILE
  56. fi
  57. #################################################
  58. ### restrict.youtube.com ###
  59. #################################################
  60. HOST_FILE=/etc/safe-search/available/youtube.restrict
  61. if HasIpAddressChanged restrict.youtube.com $HOST_FILE; then
  62. StartIpAddressUpdate $HOST_FILE
  63. MakeHost "www.youtube.com m.youtube.com youtubei.googleapis.com youtube.googleapis.com www.youtube-nocookie.com">>$HOST_FILE
  64. fi
  65. #################################################
  66. ### restrictmoderate.youtube.com ###
  67. #################################################
  68. HOST_FILE=/etc/safe-search/available/youtube.restrictmoderate
  69. if HasIpAddressChanged restrictmoderate.youtube.com $HOST_FILE; then
  70. StartIpAddressUpdate $HOST_FILE
  71. MakeHost "www.youtube.com m.youtube.com youtubei.googleapis.com youtube.googleapis.com www.youtube-nocookie.com">>$HOST_FILE
  72. fi
  73. #################################################
  74. ### forcesafesearch.google.com ###
  75. ### https://www.google.com/supported_domains ###
  76. #################################################
  77. HOST_FILE=/etc/safe-search/available/google.default
  78. if HasIpAddressChanged forcesafesearch.google.com $HOST_FILE; then
  79. StartIpAddressUpdate $HOST_FILE
  80. cat >>"$HOST_FILE"<<EOL
  81. $(MakeHost "google.com")
  82. $(MakeHost "google.ad")
  83. $(MakeHost "google.ae")
  84. $(MakeHost "google.com.af")
  85. $(MakeHost "google.com.ag")
  86. $(MakeHost "google.com.ai")
  87. $(MakeHost "google.al")
  88. $(MakeHost "google.am")
  89. $(MakeHost "google.co.ao")
  90. $(MakeHost "google.com.ar")
  91. $(MakeHost "google.as")
  92. $(MakeHost "google.at")
  93. $(MakeHost "google.com.au")
  94. $(MakeHost "google.az")
  95. $(MakeHost "google.ba")
  96. $(MakeHost "google.com.bd")
  97. $(MakeHost "google.be")
  98. $(MakeHost "google.bf")
  99. $(MakeHost "google.bg")
  100. $(MakeHost "google.com.bh")
  101. $(MakeHost "google.bi")
  102. $(MakeHost "google.bj")
  103. $(MakeHost "google.com.bn")
  104. $(MakeHost "google.com.bo")
  105. $(MakeHost "google.com.br")
  106. $(MakeHost "google.bs")
  107. $(MakeHost "google.bt")
  108. $(MakeHost "google.co.bw")
  109. $(MakeHost "google.by")
  110. $(MakeHost "google.com.bz")
  111. $(MakeHost "google.ca")
  112. $(MakeHost "google.cd")
  113. $(MakeHost "google.cf")
  114. $(MakeHost "google.cg")
  115. $(MakeHost "google.ch")
  116. $(MakeHost "google.ci")
  117. $(MakeHost "google.co.ck")
  118. $(MakeHost "google.cl")
  119. $(MakeHost "google.cm")
  120. $(MakeHost "google.cn")
  121. $(MakeHost "google.com.co")
  122. $(MakeHost "google.co.cr")
  123. $(MakeHost "google.com.cu")
  124. $(MakeHost "google.cv")
  125. $(MakeHost "google.com.cy")
  126. $(MakeHost "google.cz")
  127. $(MakeHost "google.de")
  128. $(MakeHost "google.dj")
  129. $(MakeHost "google.dk")
  130. $(MakeHost "google.dm")
  131. $(MakeHost "google.com.do")
  132. $(MakeHost "google.dz")
  133. $(MakeHost "google.com.ec")
  134. $(MakeHost "google.ee")
  135. $(MakeHost "google.com.eg")
  136. $(MakeHost "google.es")
  137. $(MakeHost "google.com.et")
  138. $(MakeHost "google.fi")
  139. $(MakeHost "google.com.fj")
  140. $(MakeHost "google.fm")
  141. $(MakeHost "google.fr")
  142. $(MakeHost "google.ga")
  143. $(MakeHost "google.ge")
  144. $(MakeHost "google.gg")
  145. $(MakeHost "google.com.gh")
  146. $(MakeHost "google.com.gi")
  147. $(MakeHost "google.gl")
  148. $(MakeHost "google.gm")
  149. $(MakeHost "google.gp")
  150. $(MakeHost "google.gr")
  151. $(MakeHost "google.com.gt")
  152. $(MakeHost "google.gy")
  153. $(MakeHost "google.com.hk")
  154. $(MakeHost "google.hn")
  155. $(MakeHost "google.hr")
  156. $(MakeHost "google.ht")
  157. $(MakeHost "google.hu")
  158. $(MakeHost "google.co.id")
  159. $(MakeHost "google.ie")
  160. $(MakeHost "google.co.il")
  161. $(MakeHost "google.im")
  162. $(MakeHost "google.co.in")
  163. $(MakeHost "google.iq")
  164. $(MakeHost "google.is")
  165. $(MakeHost "google.it")
  166. $(MakeHost "google.je")
  167. $(MakeHost "google.com.jm")
  168. $(MakeHost "google.jo")
  169. $(MakeHost "google.co.jp")
  170. $(MakeHost "google.co.ke")
  171. $(MakeHost "google.com.kh")
  172. $(MakeHost "google.ki")
  173. $(MakeHost "google.kg")
  174. $(MakeHost "google.co.kr")
  175. $(MakeHost "google.com.kw")
  176. $(MakeHost "google.kz")
  177. $(MakeHost "google.la")
  178. $(MakeHost "google.com.lb")
  179. $(MakeHost "google.li")
  180. $(MakeHost "google.lk")
  181. $(MakeHost "google.co.ls")
  182. $(MakeHost "google.lt")
  183. $(MakeHost "google.lu")
  184. $(MakeHost "google.lv")
  185. $(MakeHost "google.com.ly")
  186. $(MakeHost "google.co.ma")
  187. $(MakeHost "google.md")
  188. $(MakeHost "google.me")
  189. $(MakeHost "google.mg")
  190. $(MakeHost "google.mk")
  191. $(MakeHost "google.ml")
  192. $(MakeHost "google.com.mm")
  193. $(MakeHost "google.mn")
  194. $(MakeHost "google.ms")
  195. $(MakeHost "google.com.mt")
  196. $(MakeHost "google.mu")
  197. $(MakeHost "google.mv")
  198. $(MakeHost "google.mw")
  199. $(MakeHost "google.com.mx")
  200. $(MakeHost "google.com.my")
  201. $(MakeHost "google.co.mz")
  202. $(MakeHost "google.com.na")
  203. $(MakeHost "google.com.nf")
  204. $(MakeHost "google.com.ng")
  205. $(MakeHost "google.com.ni")
  206. $(MakeHost "google.ne")
  207. $(MakeHost "google.nl")
  208. $(MakeHost "google.no")
  209. $(MakeHost "google.com.np")
  210. $(MakeHost "google.nr")
  211. $(MakeHost "google.nu")
  212. $(MakeHost "google.co.nz")
  213. $(MakeHost "google.com.om")
  214. $(MakeHost "google.com.pa")
  215. $(MakeHost "google.com.pe")
  216. $(MakeHost "google.com.pg")
  217. $(MakeHost "google.com.ph")
  218. $(MakeHost "google.com.pk")
  219. $(MakeHost "google.pl")
  220. $(MakeHost "google.pn")
  221. $(MakeHost "google.com.pr")
  222. $(MakeHost "google.ps")
  223. $(MakeHost "google.pt")
  224. $(MakeHost "google.com.py")
  225. $(MakeHost "google.com.qa")
  226. $(MakeHost "google.ro")
  227. $(MakeHost "google.ru")
  228. $(MakeHost "google.rw")
  229. $(MakeHost "google.com.sa")
  230. $(MakeHost "google.com.sb")
  231. $(MakeHost "google.sc")
  232. $(MakeHost "google.se")
  233. $(MakeHost "google.com.sg")
  234. $(MakeHost "google.sh")
  235. $(MakeHost "google.si")
  236. $(MakeHost "google.sk")
  237. $(MakeHost "google.com.sl")
  238. $(MakeHost "google.sn")
  239. $(MakeHost "google.so")
  240. $(MakeHost "google.sm")
  241. $(MakeHost "google.sr")
  242. $(MakeHost "google.st")
  243. $(MakeHost "google.com.sv")
  244. $(MakeHost "google.td")
  245. $(MakeHost "google.tg")
  246. $(MakeHost "google.co.th")
  247. $(MakeHost "google.com.tj")
  248. $(MakeHost "google.tk")
  249. $(MakeHost "google.tl")
  250. $(MakeHost "google.tm")
  251. $(MakeHost "google.tn")
  252. $(MakeHost "google.to")
  253. $(MakeHost "google.com.tr")
  254. $(MakeHost "google.tt")
  255. $(MakeHost "google.com.tw")
  256. $(MakeHost "google.co.tz")
  257. $(MakeHost "google.com.ua")
  258. $(MakeHost "google.co.ug")
  259. $(MakeHost "google.co.uk")
  260. $(MakeHost "google.com.uy")
  261. $(MakeHost "google.co.uz")
  262. $(MakeHost "google.com.vc")
  263. $(MakeHost "google.co.ve")
  264. $(MakeHost "google.vg")
  265. $(MakeHost "google.co.vi")
  266. $(MakeHost "google.com.vn")
  267. $(MakeHost "google.vu")
  268. $(MakeHost "google.ws")
  269. $(MakeHost "google.rs")
  270. $(MakeHost "google.co.za")
  271. $(MakeHost "google.co.zm")
  272. $(MakeHost "google.co.zw")
  273. $(MakeHost "google.cat")
  274. $(MakeHost "www.google.com")
  275. $(MakeHost "www.google.ad")
  276. $(MakeHost "www.google.ae")
  277. $(MakeHost "www.google.com.af")
  278. $(MakeHost "www.google.com.ag")
  279. $(MakeHost "www.google.com.ai")
  280. $(MakeHost "www.google.al")
  281. $(MakeHost "www.google.am")
  282. $(MakeHost "www.google.co.ao")
  283. $(MakeHost "www.google.com.ar")
  284. $(MakeHost "www.google.as")
  285. $(MakeHost "www.google.at")
  286. $(MakeHost "www.google.com.au")
  287. $(MakeHost "www.google.az")
  288. $(MakeHost "www.google.ba")
  289. $(MakeHost "www.google.com.bd")
  290. $(MakeHost "www.google.be")
  291. $(MakeHost "www.google.bf")
  292. $(MakeHost "www.google.bg")
  293. $(MakeHost "www.google.com.bh")
  294. $(MakeHost "www.google.bi")
  295. $(MakeHost "www.google.bj")
  296. $(MakeHost "www.google.com.bn")
  297. $(MakeHost "www.google.com.bo")
  298. $(MakeHost "www.google.com.br")
  299. $(MakeHost "www.google.bs")
  300. $(MakeHost "www.google.bt")
  301. $(MakeHost "www.google.co.bw")
  302. $(MakeHost "www.google.by")
  303. $(MakeHost "www.google.com.bz")
  304. $(MakeHost "www.google.ca")
  305. $(MakeHost "www.google.cd")
  306. $(MakeHost "www.google.cf")
  307. $(MakeHost "www.google.cg")
  308. $(MakeHost "www.google.ch")
  309. $(MakeHost "www.google.ci")
  310. $(MakeHost "www.google.co.ck")
  311. $(MakeHost "www.google.cl")
  312. $(MakeHost "www.google.cm")
  313. $(MakeHost "www.google.cn")
  314. $(MakeHost "www.google.com.co")
  315. $(MakeHost "www.google.co.cr")
  316. $(MakeHost "www.google.com.cu")
  317. $(MakeHost "www.google.cv")
  318. $(MakeHost "www.google.com.cy")
  319. $(MakeHost "www.google.cz")
  320. $(MakeHost "www.google.de")
  321. $(MakeHost "www.google.dj")
  322. $(MakeHost "www.google.dk")
  323. $(MakeHost "www.google.dm")
  324. $(MakeHost "www.google.com.do")
  325. $(MakeHost "www.google.dz")
  326. $(MakeHost "www.google.com.ec")
  327. $(MakeHost "www.google.ee")
  328. $(MakeHost "www.google.com.eg")
  329. $(MakeHost "www.google.es")
  330. $(MakeHost "www.google.com.et")
  331. $(MakeHost "www.google.fi")
  332. $(MakeHost "www.google.com.fj")
  333. $(MakeHost "www.google.fm")
  334. $(MakeHost "www.google.fr")
  335. $(MakeHost "www.google.ga")
  336. $(MakeHost "www.google.ge")
  337. $(MakeHost "www.google.gg")
  338. $(MakeHost "www.google.com.gh")
  339. $(MakeHost "www.google.com.gi")
  340. $(MakeHost "www.google.gl")
  341. $(MakeHost "www.google.gm")
  342. $(MakeHost "www.google.gp")
  343. $(MakeHost "www.google.gr")
  344. $(MakeHost "www.google.com.gt")
  345. $(MakeHost "www.google.gy")
  346. $(MakeHost "www.google.com.hk")
  347. $(MakeHost "www.google.hn")
  348. $(MakeHost "www.google.hr")
  349. $(MakeHost "www.google.ht")
  350. $(MakeHost "www.google.hu")
  351. $(MakeHost "www.google.co.id")
  352. $(MakeHost "www.google.ie")
  353. $(MakeHost "www.google.co.il")
  354. $(MakeHost "www.google.im")
  355. $(MakeHost "www.google.co.in")
  356. $(MakeHost "www.google.iq")
  357. $(MakeHost "www.google.is")
  358. $(MakeHost "www.google.it")
  359. $(MakeHost "www.google.je")
  360. $(MakeHost "www.google.com.jm")
  361. $(MakeHost "www.google.jo")
  362. $(MakeHost "www.google.co.jp")
  363. $(MakeHost "www.google.co.ke")
  364. $(MakeHost "www.google.com.kh")
  365. $(MakeHost "www.google.ki")
  366. $(MakeHost "www.google.kg")
  367. $(MakeHost "www.google.co.kr")
  368. $(MakeHost "www.google.com.kw")
  369. $(MakeHost "www.google.kz")
  370. $(MakeHost "www.google.la")
  371. $(MakeHost "www.google.com.lb")
  372. $(MakeHost "www.google.li")
  373. $(MakeHost "www.google.lk")
  374. $(MakeHost "www.google.co.ls")
  375. $(MakeHost "www.google.lt")
  376. $(MakeHost "www.google.lu")
  377. $(MakeHost "www.google.lv")
  378. $(MakeHost "www.google.com.ly")
  379. $(MakeHost "www.google.co.ma")
  380. $(MakeHost "www.google.md")
  381. $(MakeHost "www.google.me")
  382. $(MakeHost "www.google.mg")
  383. $(MakeHost "www.google.mk")
  384. $(MakeHost "www.google.ml")
  385. $(MakeHost "www.google.com.mm")
  386. $(MakeHost "www.google.mn")
  387. $(MakeHost "www.google.ms")
  388. $(MakeHost "www.google.com.mt")
  389. $(MakeHost "www.google.mu")
  390. $(MakeHost "www.google.mv")
  391. $(MakeHost "www.google.mw")
  392. $(MakeHost "www.google.com.mx")
  393. $(MakeHost "www.google.com.my")
  394. $(MakeHost "www.google.co.mz")
  395. $(MakeHost "www.google.com.na")
  396. $(MakeHost "www.google.com.nf")
  397. $(MakeHost "www.google.com.ng")
  398. $(MakeHost "www.google.com.ni")
  399. $(MakeHost "www.google.ne")
  400. $(MakeHost "www.google.nl")
  401. $(MakeHost "www.google.no")
  402. $(MakeHost "www.google.com.np")
  403. $(MakeHost "www.google.nr")
  404. $(MakeHost "www.google.nu")
  405. $(MakeHost "www.google.co.nz")
  406. $(MakeHost "www.google.com.om")
  407. $(MakeHost "www.google.com.pa")
  408. $(MakeHost "www.google.com.pe")
  409. $(MakeHost "www.google.com.pg")
  410. $(MakeHost "www.google.com.ph")
  411. $(MakeHost "www.google.com.pk")
  412. $(MakeHost "www.google.pl")
  413. $(MakeHost "www.google.pn")
  414. $(MakeHost "www.google.com.pr")
  415. $(MakeHost "www.google.ps")
  416. $(MakeHost "www.google.pt")
  417. $(MakeHost "www.google.com.py")
  418. $(MakeHost "www.google.com.qa")
  419. $(MakeHost "www.google.ro")
  420. $(MakeHost "www.google.ru")
  421. $(MakeHost "www.google.rw")
  422. $(MakeHost "www.google.com.sa")
  423. $(MakeHost "www.google.com.sb")
  424. $(MakeHost "www.google.sc")
  425. $(MakeHost "www.google.se")
  426. $(MakeHost "www.google.com.sg")
  427. $(MakeHost "www.google.sh")
  428. $(MakeHost "www.google.si")
  429. $(MakeHost "www.google.sk")
  430. $(MakeHost "www.google.com.sl")
  431. $(MakeHost "www.google.sn")
  432. $(MakeHost "www.google.so")
  433. $(MakeHost "www.google.sm")
  434. $(MakeHost "www.google.sr")
  435. $(MakeHost "www.google.st")
  436. $(MakeHost "www.google.com.sv")
  437. $(MakeHost "www.google.td")
  438. $(MakeHost "www.google.tg")
  439. $(MakeHost "www.google.co.th")
  440. $(MakeHost "www.google.com.tj")
  441. $(MakeHost "www.google.tk")
  442. $(MakeHost "www.google.tl")
  443. $(MakeHost "www.google.tm")
  444. $(MakeHost "www.google.tn")
  445. $(MakeHost "www.google.to")
  446. $(MakeHost "www.google.com.tr")
  447. $(MakeHost "www.google.tt")
  448. $(MakeHost "www.google.com.tw")
  449. $(MakeHost "www.google.co.tz")
  450. $(MakeHost "www.google.com.ua")
  451. $(MakeHost "www.google.co.ug")
  452. $(MakeHost "www.google.co.uk")
  453. $(MakeHost "www.google.com.uy")
  454. $(MakeHost "www.google.co.uz")
  455. $(MakeHost "www.google.com.vc")
  456. $(MakeHost "www.google.co.ve")
  457. $(MakeHost "www.google.vg")
  458. $(MakeHost "www.google.co.vi")
  459. $(MakeHost "www.google.com.vn")
  460. $(MakeHost "www.google.vu")
  461. $(MakeHost "www.google.ws")
  462. $(MakeHost "www.google.rs")
  463. $(MakeHost "www.google.co.za")
  464. $(MakeHost "www.google.co.zm")
  465. $(MakeHost "www.google.co.zw")
  466. $(MakeHost "www.google.cat")
  467. EOL
  468. fi
  469. if [ "$RELOAD_DNSMASQ" = "1" ]; then
  470. echo restarting dnsmasq to activate new IP addresses.
  471. /etc/init.d/dnsmasq restart
  472. fi