polipo.init 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2008-2011 OpenWrt.org
  3. START=99
  4. CFGFILE=/var/etc/polipo.conf
  5. start() {
  6. config_load 'polipo'
  7. config_get_bool enabled "general" 'enabled' '0'
  8. [ $enabled -gt 0 ] || return 1
  9. mkdir -m 0755 -p /var/etc/
  10. echo '### AUTOGENERATED CONFIGURATION' > $CFGFILE
  11. echo '### DO NOT EDIT' >> $CFGFILE
  12. echo '### SEE /etc/config/polipo INSTEAD' >> $CFGFILE
  13. echo '' >> $CFGFILE
  14. config_foreach polipo_config 'polipo'
  15. # handle values that are disabled when not defined or empty
  16. echo "### VALUES THAT ARE DISABLED WHEN EMPTY" >> $CFGFILE
  17. polipo_atom "cache" "diskCacheRoot" '"' "1" >> $CFGFILE
  18. polipo_atom "general" "logFile" '"' "1" >> $CFGFILE
  19. polipo_atom "general" "localDocumentRoot" '"' "1" >> $CFGFILE
  20. service_start /usr/sbin/polipo -c "$CFGFILE"
  21. }
  22. stop() {
  23. service_stop /usr/sbin/polipo -c "$CFGFILE"
  24. }
  25. polipo_config() {
  26. echo "### SECTION $1" >> $CFGFILE
  27. string_options='authCredentials authRealm dnsNameServer forbiddenFile
  28. forbiddenUrl logFacility pidFile parentAuthCredentials parentProxy
  29. proxyAddress proxyName redirector socksParentProxy socksProxyType
  30. socksUserName uncachableFile'
  31. number_options='bigBufferSize chunkCriticalMark chunkHighMark chunkLowMark
  32. diskCacheDirectoryPermissions diskCacheFilePermissions
  33. diskCacheTruncateSize diskCacheWriteoutOnClose forbiddenRedirectCode
  34. logFilePermissions logLevel maxDiskCacheEntrySize maxDiskEntries
  35. maxObjectsWhenIdle maxPipelineTrain maxSideBuffering maxWriteoutWhenIdle
  36. objectHashTableSize objectHighMark pmmFirstSize pmmSize proxyPort
  37. publicObjectLowMark redirectorRedirectCode replyUnpipelineSize
  38. serverMaxSlots serverSlots serverSlots1 maxAgeFraction'
  39. time_options='clientTimeout diskCacheTruncateTime diskCacheUnlinkTime
  40. dnsGethostbynameTtl dnsMaxTimeout dnsNegativeTtl idleTime maxAge
  41. maxConnectionAge maxConnectionRequests maxExpiresAge maxNoModifiedAge
  42. replyUnpipelineTime serverExpireTime serverIdleTimeout serverTimeout
  43. smallRequestTime'
  44. multistate_options='censorReferer dnsQueryIPv6 dnsUseGethostbyname
  45. dontTrustVaryETag expectContinue pipelineAdditionalRequests
  46. useTemporarySourceAddress relaxTransparency'
  47. boolean_options='cacheIsShared daemonise disableConfiguration disableIndexing
  48. disableLocalInterface disableProxy disableServersList disableVia
  49. dontCacheCookies dontCacheRedirects logSyslog mindlesslyCacheVary
  50. preciseExpiry proxyOffline scrubLogs laxHttpParser'
  51. string_list_options='allowedClients censoredHeaders'
  52. number_list_options='allowedPorts tunnelAllowedPorts'
  53. for option in $string_options; do
  54. polipo_atom "$1" "$option" '"' >> $CFGFILE
  55. done
  56. for option in $number_options; do
  57. polipo_atom "$1" "$option" >> $CFGFILE
  58. done
  59. for option in $time_options; do
  60. polipo_atom "$1" "$option" >> $CFGFILE
  61. done
  62. for option in $multistate_options; do
  63. polipo_atom "$1" "$option" >> $CFGFILE
  64. done
  65. for option in $boolean_options; do
  66. polipo_boolean "$1" "$option" >> $CFGFILE
  67. done
  68. for option in $string_list_options; do
  69. polipo_list "$1" "$option" '"' >> $CFGFILE
  70. done
  71. for option in $number_list_options; do
  72. polipo_list "$1" "$option" >> $CFGFILE
  73. done
  74. }
  75. polipo_atom() {
  76. local SECTION=$1
  77. local OPTION=$2
  78. local QUOTE=$3
  79. local EMPTY_DISABLED=${4:-0}
  80. config_get _value "$SECTION" "$OPTION"
  81. [ -n "$_value" -o "$EMPTY_DISABLED" -eq "1" ] && {
  82. echo "$OPTION = ${QUOTE}${_value}${QUOTE}"
  83. }
  84. }
  85. polipo_boolean() {
  86. local SECTION=$1
  87. local OPTION=$2
  88. config_get_bool _value "$SECTION" "$OPTION"
  89. [ -n "$_value" ] && {
  90. [ "$_value" -eq "1" ] && _value="true" || _value="false"
  91. echo "$OPTION = $_value"
  92. }
  93. }
  94. polipo_list() {
  95. local SECTION=$1
  96. local OPTION=$2
  97. local QUOTE=$3
  98. config_get _value "$SECTION" "$OPTION"
  99. [ "$SECTION" = general ] && [ "$OPTION" = allowedClients ] && {
  100. case "$_value" in
  101. *127.0.0.1*) : ;;
  102. *) _value="127.0.0.1 $_value" ;;
  103. esac
  104. }
  105. [ -n "$_value" ] && {
  106. echo -n "$OPTION = "
  107. local FIRST=1
  108. for entry in $_value; do
  109. [ "$FIRST" -ne "1" ] && echo -n ", " || FIRST=0
  110. echo -n "${QUOTE}${entry}${QUOTE}"
  111. done
  112. echo ''
  113. }
  114. }