2022-02-15 09:55:45 -05:00
|
|
|
#!/usr/bin/env bash
|
2022-10-11 16:08:48 -04:00
|
|
|
# Set bash options
|
|
|
|
[ -n "$DEBUG" ] && set -x
|
|
|
|
set -o pipefail
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2023-08-10 19:57:13 -04:00
|
|
|
PROXY_HOSTNAME=${PROXY_HOSTNAME:-proxy.casjay.pro}
|
2022-02-16 17:39:19 -05:00
|
|
|
export SQUID_PORT="${SQUID_PORT:-3127}"
|
|
|
|
export E2GUARD_PORT="${E2GUARD_PORT:-3128}"
|
|
|
|
export APACHE2_PORT="${APACHE2_PORT:-8080}"
|
|
|
|
|
|
|
|
export SQUID_USER="${SQUID_USER:-squid}"
|
|
|
|
export APACHE2_USER="${APACHE2_USER:-www-data}"
|
|
|
|
export E2GUARD_USER="${E2GUARD_USER:-e2guardian}"
|
|
|
|
|
|
|
|
export SQUID_LOG_DIR="${SQUID_LOG_DIR:-/data/log/squid}"
|
|
|
|
export SQUID_CACHE_DIR="${SQUID_CACHE_DIR:-/data/cache/squid}"
|
2022-02-16 14:38:33 -05:00
|
|
|
export HOSTNAME="${HOSTNAME:-$(hostname -f)}"
|
|
|
|
|
|
|
|
__init() {
|
|
|
|
mkdir -p "/config" "/data"
|
2022-02-15 09:55:45 -05:00
|
|
|
|
2022-02-17 15:34:54 -05:00
|
|
|
for dir in apache2 e2guardian squid c-icap; do
|
2022-02-17 15:58:12 -05:00
|
|
|
if [ -f "/usr/local/share/squidFiles/config/$dir" ]; then
|
|
|
|
[ -f "/config/$dir" ] || cp -Rf "/usr/local/share/squidFiles/config/$dir" "/config/$dir"
|
|
|
|
elif [ -d "/usr/local/share/squidFiles/config/$dir" ]; then
|
|
|
|
[ -d "/config/$dir" ] || cp -Rf "/usr/local/share/squidFiles/config/$dir/." "/config/$dir/"
|
|
|
|
else
|
|
|
|
[ -e "/config/$dir" ] || cp -Rf "/usr/local/share/squidFiles/config/$dir" "/config/$dir"
|
2022-02-16 14:38:33 -05:00
|
|
|
fi
|
|
|
|
done
|
2022-02-15 09:55:45 -05:00
|
|
|
|
2022-02-17 16:17:23 -05:00
|
|
|
[ -d "/data/htdocs" ] || cp -Rf "/usr/local/share/squidFiles/data/htdocs/." "/data/htdocs/"
|
|
|
|
|
2022-02-17 15:58:12 -05:00
|
|
|
mkdir -p "/data/log/squidguard" "/data/log/e2guardian" "/data/squidguard/db" "/data/log/c-icap"
|
2022-02-16 17:39:19 -05:00
|
|
|
mkdir -p "${SQUID_LOG_DIR}" "${SQUID_CACHE_DIR}" "/data/log/apache2" "/data/htdocs/cgi-bin"
|
2022-02-16 14:38:33 -05:00
|
|
|
chown -Rf ${SQUID_USER}:${SQUID_USER} "/config" "/data"
|
2022-02-16 17:39:19 -05:00
|
|
|
chown -Rf ${E2GUARD_USER}:${E2GUARD_USER} "/data/log/e2guardian" "/config/e2guardian"
|
|
|
|
chown -Rf ${APACHE2_USER}:${APACHE2_USER} "/data/htdocs" "/config/apache2" "/data/log/apache2"
|
2022-02-17 15:58:12 -05:00
|
|
|
chmod -Rf 777 "${SQUID_LOG_DIR}" "${SQUID_CACHE_DIR}" "/data/log/e2guardian" "/data/log/c-icap"
|
2022-02-16 17:39:19 -05:00
|
|
|
|
|
|
|
if [ "${WPAD_IP}" != "" ]; then
|
|
|
|
sed 's/{{WPAD_IP}}/'"${WPAD_IP}"'/' -i "/data/htdocs/www/wpad.dat"
|
|
|
|
sed 's/{{WPAD_NOPROXY_NET}}/'"${WPAD_NOPROXY_NET}"'/' -i "/data/htdocs/www/wpad.dat"
|
|
|
|
sed 's/{{WPAD_NOPROXY_MASK}}/'"${WPAD_NOPROXY_MASK}"'/' -i "/data/htdocs/www/wpad.dat"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "/config/apache2/apache2.conf" ]; then
|
|
|
|
sed -i "s|SERVERNAME|$HOSTNAME|g" "/config/apache2/apache2.conf"
|
|
|
|
sed -i "s|REPLACE_SQUID_USER|$SQUID_USER|g" "/config/apache2/apache2.conf"
|
|
|
|
sed -i "s|REPLACE_HTTP_PORT|$APACHE2_PORT|g" "/config/apache2/apache2.conf"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "/config/e2guardian/e2guardian.conf" ]; then
|
|
|
|
sed -i "s|SQUID_PORT|$SQUID_PORT|g" "/config/e2guardian/e2guardian.conf"
|
|
|
|
sed -i "s|E2GUARD_PORT|$E2GUARD_PORT|g" "/config/e2guardian/e2guardian.conf"
|
|
|
|
sed -i "s|REPLACE_SQUID_USER|$SQUID_USER|g" "/config/e2guardian/e2guardian.conf"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "/config/squid/squid.conf" ]; then
|
|
|
|
sed -i "s|SERVERNAME|$HOSTNAME|g" "/config/squid/squid.conf"
|
|
|
|
sed -i "s|SQUID_PORT|$SQUID_PORT|g" "/config/squid/squid.conf"
|
|
|
|
fi
|
2022-02-16 14:38:33 -05:00
|
|
|
|
2022-02-17 09:44:29 -05:00
|
|
|
if [ -f "/data/htdocs/cgi-bin/e2guardian" ]; then
|
|
|
|
sed -i "s|PROXY_HOSTNAME|$PROXY_HOSTNAME|g" "/data/htdocs/cgi-bin/e2guardian"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "/data/htdocs/cgi-bin/squidguard" ]; then
|
|
|
|
sed -i "s|PROXY_HOSTNAME|$PROXY_HOSTNAME|g" "/data/htdocs/cgi-bin/squidguard"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "/data/htdocs/cgi-bin/cachemgr.cgi" ]; then
|
|
|
|
cp -Rf "/usr/lib/cgi-bin/cachemgr.cgi" "/data/htdocs/cgi-bin/cachemgr.cgi"
|
|
|
|
fi
|
|
|
|
|
2022-02-16 14:38:33 -05:00
|
|
|
cp -Rf "/config/." "/etc/"
|
|
|
|
|
2022-02-16 19:05:31 -05:00
|
|
|
if [ "$(find /data/squidguard/db/* 2>/dev/null | wc -l)" -eq 0 ]; then
|
|
|
|
/usr/local/bin/create-blocklists.sh
|
|
|
|
fi
|
|
|
|
|
2022-02-16 14:38:33 -05:00
|
|
|
if [ "${UPDATE_BLACKLIST_URL}" != "" ]; then
|
|
|
|
sudo wget -O /tmp/backlist.tar.gz ${UPDATE_BLACKLIST_URL} &&
|
|
|
|
tar -xzf /tmp/backlist.tar.gz -C "/data/squidguard/db" &&
|
|
|
|
rm -Rf /tmp/backlist.tar.gz &&
|
|
|
|
chown -Rf ${SQUID_USER}:${SQUID_USER} "/data/squidguard/db"
|
2022-02-15 09:55:45 -05:00
|
|
|
fi
|
|
|
|
|
2022-02-16 14:38:33 -05:00
|
|
|
# allow arguments to be passed to squid
|
|
|
|
if [[ ${1:0:1} = '-' ]]; then
|
2022-02-16 19:05:31 -05:00
|
|
|
EXTRA_ARGS=("$@")
|
2022-02-16 14:38:33 -05:00
|
|
|
set --
|
|
|
|
elif [[ ${1} == squid || ${1} == $(which squid) ]]; then
|
2022-02-16 19:05:31 -05:00
|
|
|
EXTRA_ARGS=("${@:2}")
|
2022-02-16 14:38:33 -05:00
|
|
|
set --
|
|
|
|
fi
|
|
|
|
}
|
2022-02-15 09:55:45 -05:00
|
|
|
|
2022-02-16 14:38:33 -05:00
|
|
|
case "$1" in
|
|
|
|
healthcheck)
|
2022-02-16 17:39:19 -05:00
|
|
|
squidclient -h localhost -p $SQUID_PORT cache_object://localhost/counters
|
2022-02-16 14:38:33 -05:00
|
|
|
exit $?
|
|
|
|
;;
|
2022-02-15 09:55:45 -05:00
|
|
|
|
2022-02-16 14:38:33 -05:00
|
|
|
update)
|
|
|
|
shift 1
|
|
|
|
/usr/local/bin/create-blocklists.sh
|
|
|
|
exit $?
|
|
|
|
;;
|
2022-02-15 09:55:45 -05:00
|
|
|
|
2022-02-16 14:38:33 -05:00
|
|
|
bash | shell | sh)
|
|
|
|
exec /bin/bash -l
|
|
|
|
;;
|
2022-02-15 09:55:45 -05:00
|
|
|
|
2022-02-16 14:38:33 -05:00
|
|
|
*)
|
|
|
|
__init "$@"
|
2022-02-15 09:55:45 -05:00
|
|
|
if [[ ! -d ${SQUID_CACHE_DIR}/00 ]]; then
|
|
|
|
echo "Initializing cache..."
|
2022-02-16 14:38:33 -05:00
|
|
|
$(which squid) -N -f "/config/squid/squid.conf" -z
|
2022-02-15 09:55:45 -05:00
|
|
|
fi
|
2022-02-16 14:38:33 -05:00
|
|
|
|
|
|
|
echo "Starting apache web server..."
|
|
|
|
[ -f "/var/run/apache2.pid" ] && rm -R /var/run/apache2.pid
|
|
|
|
apache2 -D FOREGROUND -f "/config/apache2/apache2.conf" &
|
|
|
|
|
2022-02-17 16:17:23 -05:00
|
|
|
echo "Starting squid..."
|
|
|
|
squid -f "/config/squid/squid.conf" -NYCd 1 ${EXTRA_ARGS} &
|
|
|
|
|
2022-02-16 17:39:19 -05:00
|
|
|
echo "Starting e2guardian..."
|
|
|
|
e2guardian -N -c "/config/e2guardian/e2guardian.conf" &
|
|
|
|
|
2022-02-17 16:17:23 -05:00
|
|
|
sleep 30 && exec tail -f /data/log/*/*
|
2022-02-16 14:38:33 -05:00
|
|
|
;;
|
|
|
|
esac
|