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.

190 lines
7.9 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2015 OpenWrt.org
  3. START=90
  4. STOP=10
  5. USE_PROCD=1
  6. PROG=/usr/sbin/dansguardian
  7. CONFIGFILE="/tmp/dansguardian/dansguardian.conf"
  8. validate_dansguardian_section() {
  9. uci_validate_section dansguardian dansguardian "${1}" \
  10. 'config_file:string' \
  11. 'accessdeniedaddress:string' \
  12. 'bannediplist:string' \
  13. 'contentscanexceptions:string' \
  14. 'contentscannertimeout:uinteger' \
  15. 'createlistcachefiles:string' \
  16. 'custombannedflashfile:string' \
  17. 'custombannedimagefile:string' \
  18. 'deletedownloadedtempfiles:string' \
  19. 'downloadmanager:string' \
  20. 'exceptioniplist:string' \
  21. 'filecachedir:string' \
  22. 'filtergroups:uinteger' \
  23. 'filtergroupslist:string' \
  24. 'filterip:ipaddr' \
  25. 'filterports:port:8080' \
  26. 'forcequicksearch:string' \
  27. 'forwardedfor:string' \
  28. 'hexdecodecontent:string' \
  29. 'initialtrickledelay:uinteger' \
  30. 'ipcfilename:string' \
  31. 'ipipcfilename:string' \
  32. 'languagedir:string' \
  33. 'language:string' \
  34. 'logadblocks:string' \
  35. 'logchildprocesshandling:string' \
  36. 'logclienthostnames:string' \
  37. 'logconnectionhandlingerrors:string' \
  38. 'logexceptionhits:range(0,2)' \
  39. 'logfileformat:range(1,4)' \
  40. 'loglevel:range(0,3)' \
  41. 'loglocation:string' \
  42. 'loguseragent:string' \
  43. 'maxagechildren:uinteger' \
  44. 'maxchildren:uinteger' \
  45. 'maxcontentfilecachescansize:uinteger' \
  46. 'maxcontentfiltersize:uinteger' \
  47. 'maxcontentramcachescansize:uinteger' \
  48. 'maxips:uinteger' \
  49. 'maxsparechildren:uinteger' \
  50. 'maxuploadsize:integer' \
  51. 'minchildren:uinteger' \
  52. 'minsparechildren:uinteger' \
  53. 'nodaemon:string' \
  54. 'nologger:string' \
  55. 'nonstandarddelimiter:string' \
  56. 'perroomblockingdirectory:string' \
  57. 'phrasefiltermode:range(0,3)' \
  58. 'prefercachedlists:string' \
  59. 'preforkchildren:uinteger' \
  60. 'preservecase:range(0,2)' \
  61. 'proxyip:ipaddr' \
  62. 'proxyport:port:3128' \
  63. 'proxytimeout:range(20,30)' \
  64. 'recheckreplacedurls:string' \
  65. 'reportinglevel:range(-1,3)' \
  66. 'reverseaddresslookups:string' \
  67. 'reverseclientiplookups:string' \
  68. 'scancleancache:string' \
  69. 'showweightedfound:string' \
  70. 'softrestart:string' \
  71. 'trickledelay:uinteger' \
  72. 'urlcacheage:uinteger' \
  73. 'urlcachenumber:uinteger' \
  74. 'urlipcfilename:string' \
  75. 'usecustombannedflash:string' \
  76. 'usecustombannedimage:string' \
  77. 'usexforwardedfor:string' \
  78. 'weightedphrasemode:range(0,2)'
  79. }
  80. start_service() {
  81. local config_file accessdeniedaddress bannediplist contentscanexceptions contentscannertimeout \
  82. createlistcachefiles custombannedflashfile custombannedimagefile deletedownloadedtempfiles \
  83. downloadmanager exceptioniplist filecachedir filtergroups filtergroupslist filterip filterports \
  84. forcequicksearch forwardedfor hexdecodecontent initialtrickledelay ipcfilename ipipcfilename \
  85. language languagedir logadblocks logchildprocesshandling logclienthostnames logconnectionhandlingerrors \
  86. logexceptionhits logfileformat loglevel loguseragent maxagechildren maxchildren maxcontentfilecachescansize \
  87. maxcontentfiltersize maxcontentramcachescansize maxips maxsparechildren maxuploadsize minchildren minsparechildren \
  88. nodaemon nologger nonstandarddelimiter perroomblockingdirectory phrasefiltermode prefercachedlists preforkchildren \
  89. preservecase proxyip proxyport proxytimeout recheckreplacedurls reportinglevel reverseaddresslookups \
  90. reverseclientiplookups scancleancache showweightedfound softrestart trickledelay urlcacheage urlcachenumber \
  91. urlipcfilename usecustombannedflash usecustombannedimage usexforwardedfor weightedphrasemode
  92. validate_dansguardian_section dansguardian || {
  93. echo "validation failed"
  94. return 1
  95. }
  96. mkdir -p $(dirname $CONFIGFILE)
  97. ln -sf $config_file $(dirname $CONFIGFILE)
  98. echo "accessdeniedaddress = " $accessdeniedaddress > $CONFIGFILE
  99. echo "bannediplist = " $bannediplist >> $CONFIGFILE
  100. echo "contentscanexceptions = " $contentscanexceptions >> $CONFIGFILE
  101. echo "contentscannertimeout = " $contentscannertimeout >> $CONFIGFILE
  102. echo "createlistcachefiles = " $createlistcachefiles >> $CONFIGFILE
  103. echo "custombannedflashfile = " $custombannedflashfile >> $CONFIGFILE
  104. echo "custombannedimagefile = " $custombannedimagefile >> $CONFIGFILE
  105. echo "deletedownloadedtempfiles = " $deletedownloadedtempfiles >> $CONFIGFILE
  106. echo "downloadmanager = " $downloadmanager >> $CONFIGFILE
  107. echo "exceptioniplist = " $exceptioniplist >> $CONFIGFILE
  108. echo "filecachedir = " $filecachedir >> $CONFIGFILE
  109. echo "filtergroups = " $filtergroups >> $CONFIGFILE
  110. echo "filtergroupslist = " $filtergroupslist >> $CONFIGFILE
  111. echo "filterip = " $filterip >> $CONFIGFILE
  112. echo "filterports = " $filterports >> $CONFIGFILE
  113. echo "forcequicksearch = " $forcequicksearch >> $CONFIGFILE
  114. echo "forwardedfor = " $forwardedfor >> $CONFIGFILE
  115. echo "hexdecodecontent = " $hexdecodecontent >> $CONFIGFILE
  116. echo "initialtrickledelay = " $initialtrickledelay >> $CONFIGFILE
  117. echo "ipcfilename = " $ipcfilename >> $CONFIGFILE
  118. echo "ipipcfilename = " $ipipcfilename >> $CONFIGFILE
  119. echo "language = " $language >> $CONFIGFILE
  120. echo "languagedir = " $languagedir >> $CONFIGFILE
  121. echo "logadblocks = " $logadblocks >> $CONFIGFILE
  122. echo "logchildprocesshandling = " $logchildprocesshandling >> $CONFIGFILE
  123. echo "logclienthostnames = " $logclienthostnames >> $CONFIGFILE
  124. echo "logconnectionhandlingerrors = " $logconnectionhandlingerrors >> $CONFIGFILE
  125. echo "logexceptionhits = " $logexceptionhits >> $CONFIGFILE
  126. echo "logfileformat = " $logfileformat >> $CONFIGFILE
  127. echo "loglevel = " $loglevel >> $CONFIGFILE
  128. echo "loglocation = " $loglocation >> $CONFIGFILE
  129. echo "loguseragent = " $loguseragent >> $CONFIGFILE
  130. echo "maxagechildren = " $maxagechildren >> $CONFIGFILE
  131. echo "maxchildren = " $maxchildren >> $CONFIGFILE
  132. echo "maxcontentfilecachescansize = " $maxcontentfilecachescansize >> $CONFIGFILE
  133. echo "maxcontentfiltersize = " $maxcontentfiltersize >> $CONFIGFILE
  134. echo "maxcontentramcachescansize = " $maxcontentramcachescansize >> $CONFIGFILE
  135. echo "maxips = " $maxips >> $CONFIGFILE
  136. echo "maxsparechildren = " $maxsparechildren >> $CONFIGFILE
  137. echo "maxuploadsize = " $maxuploadsize >> $CONFIGFILE
  138. echo "minchildren = " $minchildren >> $CONFIGFILE
  139. echo "minsparechildren = " $minsparechildren >> $CONFIGFILE
  140. echo "nodaemon = " $nodaemon >> $CONFIGFILE
  141. echo "nologger = " $nologger >> $CONFIGFILE
  142. echo "nonstandarddelimiter = " $nonstandarddelimiter >> $CONFIGFILE
  143. echo "perroomblockingdirectory = " $perroomblockingdirectory >> $CONFIGFILE
  144. echo "phrasefiltermode = " $phrasefiltermode >> $CONFIGFILE
  145. echo "prefercachedlists = " $prefercachedlists >> $CONFIGFILE
  146. echo "preforkchildren = " $preforkchildren >> $CONFIGFILE
  147. echo "preservecase = " $preservecase >> $CONFIGFILE
  148. echo "proxyip = " $proxyip >> $CONFIGFILE
  149. echo "proxyport = " $proxyport >> $CONFIGFILE
  150. echo "proxytimeout = " $proxytimeout >> $CONFIGFILE
  151. echo "recheckreplacedurls = " $recheckreplacedurls >> $CONFIGFILE
  152. echo "reportinglevel = " $reportinglevel >> $CONFIGFILE
  153. echo "reverseaddresslookups = " $reverseaddresslookups >> $CONFIGFILE
  154. echo "reverseclientiplookups = " $reverseclientiplookups >> $CONFIGFILE
  155. echo "scancleancache = " $scancleancache >> $CONFIGFILE
  156. echo "showweightedfound = " $showweightedfound >> $CONFIGFILE
  157. echo "softrestart = " $softrestart >> $CONFIGFILE
  158. echo "trickledelay = " $trickledelay >> $CONFIGFILE
  159. echo "urlcacheage = " $urlcacheage >> $CONFIGFILE
  160. echo "urlcachenumber = " $urlcachenumber >> $CONFIGFILE
  161. echo "urlipcfilename = " $urlipcfilename >> $CONFIGFILE
  162. echo "usecustombannedflash = " $usecustombannedflash >> $CONFIGFILE
  163. echo "usecustombannedimage = " $usecustombannedimage >> $CONFIGFILE
  164. echo "usexforwardedfor = " $usexforwardedfor >> $CONFIGFILE
  165. echo "weightedphrasemode = " $weightedphrasemode >> $CONFIGFILE
  166. procd_open_instance
  167. procd_set_param command $PROG -N -c "$CONFIGFILE"
  168. procd_set_param file $CONFIGFILE
  169. procd_set_param respawn
  170. procd_close_instance
  171. }
  172. stop_service()
  173. {
  174. dansguardian -s | awk -F':' '{ print $2}' | xargs kill -9
  175. }
  176. service_triggers()
  177. {
  178. procd_add_reload_trigger "dansguardian"
  179. procd_add_validation validate_dansguardian_section
  180. }