2023-07-12 09:10:32 +02:00
|
|
|
#!/usr/bin/env sh
|
2023-07-12 07:53:09 +02:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2023-07-12 09:10:32 +02:00
|
|
|
CONFIG="/etc/tinyproxy/tinyproxy.conf"
|
2023-07-12 07:53:09 +02:00
|
|
|
|
|
|
|
function writeConfig() {
|
|
|
|
cat << EOF >> "$CONFIG"
|
|
|
|
User $TINYPROXY_UID
|
|
|
|
Group $TINYPROXY_GID
|
|
|
|
Port $PORT
|
|
|
|
Timeout $TIMEOUT
|
|
|
|
DefaultErrorFile "/usr/share/tinyproxy/default.html"
|
|
|
|
|
|
|
|
StatHost "tinyproxy.stats"
|
|
|
|
StatFile "/usr/share/tinyproxy/stats.html"
|
|
|
|
|
|
|
|
LogLevel $LOGLEVEL
|
|
|
|
MaxClients $MAXCLIENTS
|
|
|
|
ViaProxyName "tinyproxy"
|
|
|
|
|
|
|
|
Allow 127.0.0.1/8
|
|
|
|
Allow 10.0.0.0/8
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
function addUpstreamConfig() {
|
|
|
|
[ -z "$UPSTREAM_PROXY_FILE" ] || export UPSTREAM_PROXY=$(cat $UPSTREAM_PROXY_FILE)
|
|
|
|
[ -z "$UPSTREAM_PROXY" ] || echo "upstream http $UPSTREAM_PROXY \".\"" >> "$CONFIG"
|
|
|
|
}
|
|
|
|
|
2023-07-12 09:10:32 +02:00
|
|
|
function addFilterConfig() {
|
|
|
|
if [ -f "$FILTER_FILE" ]; then
|
|
|
|
cat << FBLOCK >> "$CONFIG"
|
|
|
|
Filter "$FILTER_FILE"
|
|
|
|
FilterURLs Off
|
|
|
|
FilterCaseSensitive Off
|
|
|
|
FilterDefaultDeny Yes
|
|
|
|
FBLOCK
|
|
|
|
else
|
|
|
|
echo "🦁 FILTER_FILE not found or set."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function showConfig() {
|
|
|
|
echo "🦁 Final Swarmproxy config 🦁"
|
|
|
|
cat "$CONFIG"
|
|
|
|
}
|
|
|
|
|
|
|
|
function execTinyproxy() {
|
|
|
|
echo "🦁 Starting Tinyproxy..."
|
|
|
|
echo "args count: $#"
|
|
|
|
echo "args: $@"
|
|
|
|
exec "/usr/bin/tinyproxy" "$@"
|
|
|
|
}
|
|
|
|
|
2023-07-12 07:53:09 +02:00
|
|
|
function main() {
|
|
|
|
writeConfig
|
|
|
|
addUpstreamConfig
|
2023-07-12 09:10:32 +02:00
|
|
|
addFilterConfig
|
|
|
|
showConfig
|
|
|
|
execTinyproxy $@
|
2023-07-12 07:53:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main $@
|