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.

212 lines
8.3 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/e2guardian
  7. CONFIGFILE="/tmp/e2guardian/e2guardian.conf"
  8. LOGFILE="/tmp/e2guardian/access.log"
  9. GROUPCONFIG="/tmp/e2guardian/e2guardianf1.conf"
  10. validate_e2guardian_section() {
  11. uci_validate_section e2guardian e2guardian "${1}" \
  12. 'accessdeniedaddress:string' \
  13. 'bannediplist:string' \
  14. 'contentscanexceptions:string' \
  15. 'contentscanner:string' \
  16. 'contentscannertimeout:uinteger' \
  17. 'createlistcachefiles:string' \
  18. 'custombannedflashfile:string' \
  19. 'custombannedimagefile:string' \
  20. 'deletedownloadedtempfiles:string' \
  21. 'downloadmanager:string' \
  22. 'exceptioniplist:string' \
  23. 'filecachedir:string' \
  24. 'filtergroups:uinteger' \
  25. 'filtergroupslist:string' \
  26. 'filterip:ipaddr' \
  27. 'filterports:port:8080' \
  28. 'forcequicksearch:string' \
  29. 'forwardedfor:string' \
  30. 'hexdecodecontent:string' \
  31. 'initialtrickledelay:uinteger' \
  32. 'ipcfilename:string' \
  33. 'ipipcfilename:string' \
  34. 'languagedir:string' \
  35. 'language:string' \
  36. 'logadblocks:string' \
  37. 'logchildprocesshandling:string' \
  38. 'logclienthostnames:string' \
  39. 'logconnectionhandlingerrors:string' \
  40. 'logexceptionhits:range(0,2)' \
  41. 'logfileformat:range(1,6)' \
  42. 'loglevel:range(0,3)' \
  43. 'loglocation:string' \
  44. 'loguseragent:string' \
  45. 'maxagechildren:uinteger' \
  46. 'maxchildren:uinteger' \
  47. 'maxcontentfilecachescansize:uinteger' \
  48. 'maxcontentfiltersize:uinteger' \
  49. 'maxcontentramcachescansize:uinteger' \
  50. 'maxips:uinteger' \
  51. 'maxsparechildren:uinteger' \
  52. 'maxuploadsize:integer' \
  53. 'minchildren:uinteger' \
  54. 'minsparechildren:uinteger' \
  55. 'nodaemon:string' \
  56. 'nologger:string' \
  57. 'pcontimeout:range(5,300)' \
  58. 'perroomdirectory:string' \
  59. 'phrasefiltermode:range(0,3)' \
  60. 'prefercachedlists:string' \
  61. 'preforkchildren:uinteger' \
  62. 'preservecase:range(0,2)' \
  63. 'proxyexchange:range(20,300)' \
  64. 'proxyip:ipaddr' \
  65. 'proxyport:port:3128' \
  66. 'proxytimeout:range(5,100)' \
  67. 'recheckreplacedurls:string' \
  68. 'reverseaddresslookups:string' \
  69. 'reverseclientiplookups:string' \
  70. 'scancleancache:string' \
  71. 'showweightedfound:string' \
  72. 'softrestart:string' \
  73. 'trickledelay:uinteger' \
  74. 'urlcacheage:uinteger' \
  75. 'urlcachenumber:uinteger' \
  76. 'urlipcfilename:string' \
  77. 'usecustombannedflash:string' \
  78. 'usecustombannedimage:string' \
  79. 'usexforwardedfor:string' \
  80. 'weightedphrasemode:range(0,2)'
  81. }
  82. start_service() {
  83. local accessdeniedaddress bannediplist contentscanexceptions contentscanner contentscannertimeout \
  84. createlistcachefiles custombannedflashfile custombannedimagefile deletedownloadedtempfiles \
  85. downloadmanager exceptioniplist filecachedir loglocation \
  86. filtergroups filtergroupslist filterip filterports forcequicksearch forwardedfor hexdecodecontent \
  87. initialtrickledelay ipcfilename ipipcfilename language languagedir logadblocks logchildprocesshandling \
  88. logclienthostnames logconnectionhandlingerrors logexceptionhits logfileformat loglevel loguseragent \
  89. maxagechildren maxchildren maxcontentfilecachescansize maxcontentfiltersize maxcontentramcachescansize \
  90. maxips maxsparechildren maxuploadsize minchildren minsparechildren nodaemon nologger \
  91. pcontimeout perroomdirectory phrasefiltermode prefercachedlists preforkchildren preservecase proxyexchange \
  92. proxyip proxyport proxytimeout recheckreplacedurls reverseaddresslookups reverseclientiplookups scancleancache \
  93. showweightedfound softrestart trickledelay urlcacheage urlcachenumber urlipcfilename usecustombannedflash \
  94. usecustombannedimage usexforwardedfor weightedphrasemode
  95. validate_e2guardian_section e2guardian || {
  96. echo "validation failed"
  97. return 1
  98. }
  99. mkdir -p $(dirname $CONFIGFILE)
  100. chown -R nobody:nogroup $(dirname $CONFIGFILE)
  101. mkdir -p $(dirname $loglocation)
  102. chown -R nobody:nogroup $(dirname $loglocation)
  103. touch $loglocation
  104. chown nobody:nogroup $loglocation
  105. ln -sf $loglocation $(dirname $LOGFILE)
  106. ln -sf /etc/e2guardian/e2guardian.conf $CONFIGFILE
  107. ln -sf /etc/e2guardian/e2guardianf1.conf $GROUPCONFIG
  108. echo "accessdeniedaddress = " $accessdeniedaddress > $CONFIGFILE
  109. echo "bannediplist = " $bannediplist >> $CONFIGFILE
  110. if [ "$contentscanner" != "" ]
  111. then
  112. echo "contentscanner = " $contentscanner >> $CONFIGFILE
  113. fi
  114. echo "contentscanexceptions = " $contentscanexceptions >> $CONFIGFILE
  115. echo "contentscannertimeout = " $contentscannertimeout >> $CONFIGFILE
  116. echo "createlistcachefiles = " $createlistcachefiles >> $CONFIGFILE
  117. echo "custombannedflashfile = " $custombannedflashfile >> $CONFIGFILE
  118. echo "custombannedimagefile = " $custombannedimagefile >> $CONFIGFILE
  119. echo "deletedownloadedtempfiles = " $deletedownloadedtempfiles >> $CONFIGFILE
  120. echo "downloadmanager = " $downloadmanager >> $CONFIGFILE
  121. echo "exceptioniplist = " $exceptioniplist >> $CONFIGFILE
  122. echo "filecachedir = " $filecachedir >> $CONFIGFILE
  123. echo "filtergroups = " $filtergroups >> $CONFIGFILE
  124. echo "filtergroupslist = " $filtergroupslist >> $CONFIGFILE
  125. echo "filterip = " $filterip >> $CONFIGFILE
  126. echo "filterports = " $filterports >> $CONFIGFILE
  127. echo "forcequicksearch = " $forcequicksearch >> $CONFIGFILE
  128. echo "forwardedfor = " $forwardedfor >> $CONFIGFILE
  129. echo "hexdecodecontent = " $hexdecodecontent >> $CONFIGFILE
  130. echo "initialtrickledelay = " $initialtrickledelay >> $CONFIGFILE
  131. echo "ipcfilename = " $ipcfilename >> $CONFIGFILE
  132. echo "ipipcfilename = " $ipipcfilename >> $CONFIGFILE
  133. echo "language = " $language >> $CONFIGFILE
  134. echo "languagedir = " $languagedir >> $CONFIGFILE
  135. echo "logadblocks = " $logadblocks >> $CONFIGFILE
  136. echo "logchildprocesshandling = " $logchildprocesshandling >> $CONFIGFILE
  137. echo "logclienthostnames = " $logclienthostnames >> $CONFIGFILE
  138. echo "logconnectionhandlingerrors = " $logconnectionhandlingerrors >> $CONFIGFILE
  139. echo "logexceptionhits = " $logexceptionhits >> $CONFIGFILE
  140. echo "logfileformat = " $logfileformat >> $CONFIGFILE
  141. echo "loglevel = " $loglevel >> $CONFIGFILE
  142. echo "loglocation = " $loglocation >> $CONFIGFILE
  143. echo "loguseragent = " $loguseragent >> $CONFIGFILE
  144. echo "maxagechildren = " $maxagechildren >> $CONFIGFILE
  145. echo "maxchildren = " $maxchildren >> $CONFIGFILE
  146. echo "maxcontentfilecachescansize = " $maxcontentfilecachescansize >> $CONFIGFILE
  147. echo "maxcontentfiltersize = " $maxcontentfiltersize >> $CONFIGFILE
  148. echo "maxcontentramcachescansize = " $maxcontentramcachescansize >> $CONFIGFILE
  149. echo "maxips = " $maxips >> $CONFIGFILE
  150. echo "maxsparechildren = " $maxsparechildren >> $CONFIGFILE
  151. echo "maxuploadsize = " $maxuploadsize >> $CONFIGFILE
  152. echo "minchildren = " $minchildren >> $CONFIGFILE
  153. echo "minsparechildren = " $minsparechildren >> $CONFIGFILE
  154. echo "nodaemon = " $nodaemon >> $CONFIGFILE
  155. echo "nologger = " $nologger >> $CONFIGFILE
  156. echo "pcontimeout = " $pcontimeout >> $CONFIGFILE
  157. echo "perroomdirectory = " $perroomdirectory >> $CONFIGFILE
  158. echo "phrasefiltermode = " $phrasefiltermode >> $CONFIGFILE
  159. echo "prefercachedlists = " $prefercachedlists >> $CONFIGFILE
  160. echo "preforkchildren = " $preforkchildren >> $CONFIGFILE
  161. echo "preservecase = " $preservecase >> $CONFIGFILE
  162. echo "proxyexchange = " $proxyexchange >> $CONFIGFILE
  163. echo "proxyip = " $proxyip >> $CONFIGFILE
  164. echo "proxyport = " $proxyport >> $CONFIGFILE
  165. echo "proxytimeout = " $proxytimeout >> $CONFIGFILE
  166. echo "recheckreplacedurls = " $recheckreplacedurls >> $CONFIGFILE
  167. echo "reverseaddresslookups = " $reverseaddresslookups >> $CONFIGFILE
  168. echo "reverseclientiplookups = " $reverseclientiplookups >> $CONFIGFILE
  169. echo "scancleancache = " $scancleancache >> $CONFIGFILE
  170. echo "showweightedfound = " $showweightedfound >> $CONFIGFILE
  171. echo "softrestart = " $softrestart >> $CONFIGFILE
  172. echo "trickledelay = " $trickledelay >> $CONFIGFILE
  173. echo "urlcacheage = " $urlcacheage >> $CONFIGFILE
  174. echo "urlcachenumber = " $urlcachenumber >> $CONFIGFILE
  175. echo "urlipcfilename = " $urlipcfilename >> $CONFIGFILE
  176. echo "usecustombannedflash = " $usecustombannedflash >> $CONFIGFILE
  177. echo "usecustombannedimage = " $usecustombannedimage >> $CONFIGFILE
  178. echo "usexforwardedfor = " $usexforwardedfor >> $CONFIGFILE
  179. echo "weightedphrasemode = " $weightedphrasemode >> $CONFIGFILE
  180. procd_open_instance
  181. procd_set_param command $PROG -c $CONFIGFILE
  182. procd_set_param file $CONFIGFILE
  183. procd_close_instance
  184. }
  185. stop_service()
  186. {
  187. PID=`cat /tmp/e2guardian/e2guardian.pid`
  188. kill $PID
  189. rm -f /tmp/e2guardian/e2guardian.pid
  190. }
  191. service_triggers()
  192. {
  193. procd_add_reload_trigger "e2guardian"
  194. procd_add_validation validate_e2guardian_section
  195. }