| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #!/bin/sh
- set -e
- case "$1" in
- configure)
- # ── Create dedicated system user ──────────────────────────────────
- if ! getent passwd squidstats > /dev/null 2>&1; then
- adduser \
- --system \
- --group \
- --no-create-home \
- --home /var/lib/squidstats \
- --shell /usr/sbin/nologin \
- --gecos "SquidStats web application" \
- squidstats
- fi
- # Add to the proxy group so the service can read squid access logs
- if getent group proxy > /dev/null 2>&1; then
- usermod -aG proxy squidstats 2>/dev/null || true
- fi
- # ── Runtime directories ───────────────────────────────────────────
- install -d -m 0750 -o squidstats -g squidstats /var/log/squidstats
- install -d -m 0750 -o squidstats -g squidstats /var/lib/squidstats
- # ── Configuration file ────────────────────────────────────────────
- # On first install the example config is the real config; protect it
- if [ -f /opt/SquidStats/app/.env ]; then
- chown root:squidstats /opt/SquidStats/app/.env
- chmod 0640 /opt/SquidStats/app/.env
- fi
- # ── Create application .env configuration file if missing ───────
- if [ ! -f /opt/SquidStats/app/.env ]; then
- cat > /opt/SquidStats/app/.env <<'EOF'
- VERSION=2.3.2
- SQUID_HOST="127.0.0.1"
- SQUID_PORT=3128
- # Multi-proxy load-balancing (optional): comma-separated host:port list.
- # When set, overrides SQUID_HOST/SQUID_PORT for the active-connections page.
- # Example: SQUID_HOSTS="192.168.0.10:3128,192.168.0.11:3128"
- SQUID_HOSTS=
- FLASK_DEBUG=True
- DATABASE_TYPE="SQLITE"
- SQUID_LOG="/var/log/squid/access.log"
- SQUID_CACHE_LOG="/var/log/squid/cache.log"
- DATABASE_STRING_CONNECTION="./squidstats.db"
- REFRESH_INTERVAL=60
- HTTP_PROXY=""
- HTTPS_PROXY=
- NO_PROXY=
- SQUID_CONFIG_PATH=/etc/squid/squid.conf
- ACL_FILES_DIR=/etc/squid/acl
- LISTEN_HOST="0.0.0.0"
- LISTEN_PORT=5000
- FIRST_PASSWORD="mipasswordsegura"
- JWT_EXPIRY_HOURS=24
- MAX_LOGIN_ATTEMPTS=5
- LOCKOUT_DURATION_MINUTES=15
- EOF
- chown root:squidstats /opt/SquidStats/app/.env
- chmod 0640 /opt/SquidStats/app/.env
- fi
- # ── Create Python virtualenv on the target system ────────────────
- if [ ! -d /opt/SquidStats/venv ]; then
- python3 -m venv /opt/SquidStats/venv
- /opt/SquidStats/venv/bin/python3 -m pip install --upgrade pip setuptools wheel
- /opt/SquidStats/venv/bin/pip install --no-cache-dir -r /opt/SquidStats/app/requirements.txt
- fi
- # ── Application directory ownership ──────────────────────────────
- # The app code is owned by root and group-owned by squidstats so the
- # service user can execute and write only where needed.
- chown -R root:squidstats /opt/SquidStats/
- find /opt/SquidStats/ -type d -exec chmod 2750 {} +
- find /opt/SquidStats/ -type f -exec chmod 0640 {} +
- chmod -R g+rwX /opt/SquidStats/
- # Ensure the runtime logs directory exists and is writable.
- install -d -m 2770 -o squidstats -g squidstats /opt/SquidStats/app/logs
- # Allow the service user to write to the data directory
- chown -R squidstats:squidstats /var/lib/squidstats/
- ;;
- esac
- #DEBHELPER#
- exit 0
|