#!/bin/sh /etc/rc.common
|
|
# Copyright (C) 2008-2011 OpenWrt.org
|
|
|
|
START=50
|
|
|
|
CFGFILE=/var/etc/tinyproxy.conf
|
|
|
|
section_enabled() {
|
|
local enabled
|
|
config_get_bool enabled "$1" 'enabled' 0
|
|
[ "$enabled" -gt 0 ]
|
|
}
|
|
|
|
start() {
|
|
config_load 'tinyproxy'
|
|
config_foreach start_proxy 'tinyproxy'
|
|
}
|
|
|
|
stop() {
|
|
service_stop /usr/sbin/tinyproxy
|
|
}
|
|
|
|
start_proxy() {
|
|
section_enabled "$1" || return 1
|
|
|
|
mkdir -p /var/etc
|
|
chmod 0755 /var/etc
|
|
{
|
|
echo '### AUTOGENERATED CONFIGURATION'
|
|
echo '### DO NOT EDIT'
|
|
echo '### SEE /etc/config/tinyproxy INSTEAD'
|
|
echo ''
|
|
|
|
proxy_atom "$1" User
|
|
proxy_atom "$1" Group
|
|
proxy_atom "$1" Port 8888
|
|
proxy_atom "$1" Listen
|
|
proxy_atom "$1" Bind
|
|
proxy_atom "$1" Timeout
|
|
|
|
proxy_string "$1" ErrorFile_400 "ErrorFile 400"
|
|
proxy_string "$1" ErrorFile_403 "ErrorFile 403"
|
|
proxy_string "$1" ErrorFile_404 "ErrorFile 404"
|
|
proxy_string "$1" ErrorFile_408 "ErrorFile 408"
|
|
proxy_string "$1" ErrorFile_503 "ErrorFile 503"
|
|
|
|
proxy_string "$1" DefaultErrorFile
|
|
proxy_string "$1" StatHost StatHost 127.0.0.1
|
|
proxy_string "$1" StatFile
|
|
proxy_string "$1" LogFile
|
|
|
|
proxy_flag "$1" Syslog
|
|
|
|
proxy_atom "$1" LogLevel
|
|
|
|
proxy_flag "$1" XTinyproxy
|
|
|
|
proxy_atom "$1" MaxClients
|
|
proxy_atom "$1" MinSpareServers
|
|
proxy_atom "$1" MaxSpareServers
|
|
proxy_atom "$1" StartServers
|
|
proxy_atom "$1" MaxRequestsPerChild
|
|
proxy_list "$1" Allow
|
|
|
|
proxy_string "$1" ViaProxyName
|
|
proxy_string "$1" Filter
|
|
|
|
proxy_flag "$1" FilterURLs
|
|
proxy_flag "$1" FilterExtended
|
|
proxy_flag "$1" FilterCaseSensitive
|
|
proxy_flag "$1" FilterDefaultDeny Yes No
|
|
|
|
proxy_list "$1" Anonymous '"'
|
|
proxy_list "$1" ConnectPort
|
|
|
|
config_foreach write_upstream upstream
|
|
} > "$CFGFILE"
|
|
|
|
service_start /usr/sbin/tinyproxy -c "$CFGFILE"
|
|
}
|
|
|
|
write_upstream() {
|
|
local type
|
|
local via
|
|
local target
|
|
|
|
config_get "type" "$1" "type"
|
|
config_get via "$1" via
|
|
config_get target "$1" target
|
|
[ -n "$target" ] && target=' "'"$target"'"'
|
|
|
|
[ "$type" = "proxy" ] && [ -n "$via" ] && \
|
|
echo "upstream $via$target"
|
|
|
|
[ "$type" = "reject" ] && [ -n "$target" ] && \
|
|
echo "no upstream$target"
|
|
}
|
|
|
|
proxy_atom() {
|
|
local SECTION=$1
|
|
local OPTION=$2
|
|
local DEFAULT=$3
|
|
|
|
config_get _value "$SECTION" "$OPTION"
|
|
[ -z "$_value" ] && _value="$DEFAULT"
|
|
[ -n "$_value" ] && echo "$OPTION $_value"
|
|
}
|
|
|
|
proxy_string() {
|
|
local SECTION=$1
|
|
local OPTION=$2
|
|
local ALIAS=$3
|
|
local DEFAULT=$4
|
|
|
|
config_get _value "$SECTION" "$OPTION"
|
|
[ -z "$_value" ] && _value="$DEFAULT"
|
|
[ -n "$_value" ] && echo "${ALIAS:-${OPTION}} "'"'"$_value"'"'
|
|
[ -n "$_value" ] && [ "$OPTION" = "LogFile" ] && {
|
|
touch "$_value"
|
|
chmod 666 "$_value"
|
|
}
|
|
}
|
|
|
|
proxy_flag() {
|
|
local SECTION=$1
|
|
local OPTION=$2
|
|
local TRUE="${3:-On}"
|
|
local FALSE="${4:-Off}"
|
|
|
|
config_get_bool _value "$SECTION" "$OPTION" 0
|
|
[ "$_value" -eq "1" ] && _value="$TRUE" || _value="$FALSE"
|
|
echo "$OPTION $_value"
|
|
}
|
|
|
|
proxy_list() {
|
|
local SECTION=$1
|
|
local OPTION=$2
|
|
local ENCLOSE=$3
|
|
|
|
config_get _value "$SECTION" "$OPTION"
|
|
[ -n "$_value" ] && {
|
|
for entry in $_value; do
|
|
echo "$OPTION ${ENCLOSE}${entry}${ENCLOSE}"
|
|
done
|
|
}
|
|
}
|