#!/bin/sh /etc/rc.common
-# Copyright (C) 2007 OpenWrt.org
-
+# Copyright (C) 2008 OpenWrt.org
START=99
-NAME=polipo
-BIN_F=/usr/sbin/$NAME
-SSD=start-stop-daemon
+DAEMON=/usr/sbin/polipo
+CFGFILE=/var/etc/polipo.conf
-is_enabled() {
- local cfg="$1"
+start() {
+ config_load polipo
- config_get_bool enabled "$cfg" enabled '1'
- [ $enabled -ne 0 ] || {
- echo "$initscript: not enabled"
- return 1
+ config_get_bool enabled "general" enabled
+ [ "$enabled" -ne "1" ] && {
+ echo 'Polipo is disabled.'
+ return 0
}
+
+ echo '### AUTOGENERATED CONFIGURATION' > $CFGFILE
+ echo '### DO NOT EDIT' >> $CFGFILE
+ echo '### SEE /etc/config/polipo INSTEAD' >> $CFGFILE
+ echo '' >> $CFGFILE
+
+ config_foreach polipo_config polipo
+
+ # handle values that are disabled when not defiend or empty
+ echo "### VALUES THAT ARE DISABLED WHEN EMPTY" >> $CFGFILE
+ polipo_atom "cache" "diskCacheRoot" '"' "1" >> $CFGFILE
+ polipo_atom "general" "logFile" '"' "1" >> $CFGFILE
+ polipo_atom "general" "localDocumentRoot" '"' "1" >> $CFGFILE
+
+ echo 'Polipo is starting...'
+ start-stop-daemon -S -q -x "$DAEMON" -- -c "$CFGFILE"
}
-get_pid_file() {
- local cfg="$1"
-
- config_get pid_file "$cfg" pid-file
- [ -n "$pid_file" ] || pid_file="/var/run/$NAME.pid"
+stop() {
+ echo 'Polipo is stopping...'
+ start-stop-daemon -K -q -x "$DAEMON"
+ rm -f $CFGFILE
}
-get_options() {
- local cfg="$1"
-
- config_get options "$cfg" options
-
- config_get config_file "$cfg" config_file
- [ -n "$config_script" ] && append options "-c $config_file"
+restart() {
+ stop
+ sleep 2
+ start
}
-start_service() {
- local cfg="$1"
-
- is_enabled "$cfg" || return
- get_pid_file "$cfg"
- get_options "$cfg"
-
- $SSD -S -p $pid_file -b -m -x $BIN_F -- $options &>/dev/null
+polipo_config() {
+ echo "### SECTION $1" >> $CFGFILE
+
+ string_options='authCredentials authRealm dnsNameServer forbiddenFile
+ forbiddenUrl logFacility pidFile parentAuthCredentials parentProxy
+ proxyAddress proxyName redirector socksParentProxy socksProxyType
+ socksUserName uncachableFile'
+
+ number_options='bigBufferSize chunkCriticalMark chunkHighMark chunkLowMark
+ diskCacheDirectoryPermissions diskCacheFilePermissions
+ diskCacheTruncateSize diskCacheWriteoutOnClose forbiddenRedirectCode
+ logFilePermissions logLevel maxDiskCacheEntrySize maxDiskEntries
+ maxObjectsWhenIdle maxPipelineTrain maxSideBuffering maxWriteoutWhenIdle
+ objectHashTableSize objectHighMark pmmFirstSize pmmSize proxyPort
+ publicObjectLowMark redirectorRedirectCode replyUnpipelineSize
+ serverMaxSlots serverSlots serverSlots1 maxAgeFraction'
+
+ time_options='clientTimeout diskCacheTruncateTime diskCacheUnlinkTime
+ dnsGethostbynameTtl dnsMaxTimeout dnsNegativeTtl idleTime maxAge
+ maxConnectionAge maxConnectionRequests maxExpiresAge maxNoModifiedAge
+ replyUnpipelineTime serverExpireTime serverIdleTimeout serverTimeout
+ smallRequestTime'
+
+ multistate_options='censorReferer dnsQueryIPv6 dnsUseGethostbyname
+ dontTrustVaryETag expectContinue pipelineAdditionalRequests
+ useTemporarySourceAddress'
+
+ boolean_options='cacheIsShared daemonise disableConfiguration disableIndexing
+ disableLocalInterface disableProxy disableServersList disableVia
+ dontCacheCookies dontCacheRedirects logSyslog mindlesslyCacheVary
+ preciseExpiry proxyOffline scrubLogs laxHttpParser'
+
+ string_list_options='allowedClients censoredHeaders'
+
+ number_list_options='allowedPorts tunnelAllowedPorts'
+
+ for option in $string_options; do
+ polipo_atom "$1" "$option" '"' >> $CFGFILE
+ done
+
+ for option in $number_options; do
+ polipo_atom "$1" "$option" >> $CFGFILE
+ done
+
+ for option in $time_options; do
+ polipo_atom "$1" "$option" >> $CFGFILE
+ done
+
+ for option in $multistate_options; do
+ polipo_atom "$1" "$option" >> $CFGFILE
+ done
+
+ for option in $boolean_options; do
+ polipo_boolean "$1" "$option" >> $CFGFILE
+ done
+
+ for option in $string_list_options; do
+ polipo_list "$1" "$option" '"' >> $CFGFILE
+ done
+
+ for option in $number_list_options; do
+ polipo_list "$1" "$option" >> $CFGFILE
+ done
}
-stop_service() {
- local cfg="$1"
+polipo_atom() {
+ local SECTION=$1
+ local OPTION=$2
+ local QUOTE=$3
+ local EMPTY_DISABLED=$4
- is_enabled "$cfg" || return
- get_pid_file "$cfg"
-
- $SSD -K -p $pid_file &>/dev/null
+ config_get _value "$SECTION" "$OPTION"
+ [ -n "$_value" -o "$EMPTY_DISABLED" -eq "1" ] && {
+ echo "$OPTION = ${QUOTE}${_value}${QUOTE}"
+ }
}
-start() {
- config_load $NAME
- config_foreach start_service $NAME
+polipo_boolean() {
+ local SECTION=$1
+ local OPTION=$2
+
+ config_get_bool _value "$SECTION" "$OPTION"
+ [ -n "$_value" ] && {
+ [ "$_value" -eq "1" ] && _value="true" || _value="false"
+ echo "$OPTION = $_value"
+ }
}
-stop() {
- config_load $NAME
- config_foreach stop_service $NAME
+polipo_list() {
+ local SECTION=$1
+ local OPTION=$2
+ local QUOTE=$3
+
+ config_get _value "$SECTION" "$OPTION"
+ [ -n "$_value" ] && {
+ echo -n "$OPTION = "
+
+ local FIRST=1
+ for entry in $_value; do
+ [ "$FIRST" -ne "1" ] && echo -n ", " || FIRST=0
+
+ echo -n "${QUOTE}${entry}${QUOTE}"
+ done
+
+ echo ''
+ }
}