postinst 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/sh
  2. set -e
  3. case "$1" in
  4. configure)
  5. # ── Create dedicated system user ──────────────────────────────────
  6. if ! getent passwd squidstats > /dev/null 2>&1; then
  7. adduser \
  8. --system \
  9. --group \
  10. --no-create-home \
  11. --home /var/lib/squidstats \
  12. --shell /usr/sbin/nologin \
  13. --gecos "SquidStats web application" \
  14. squidstats
  15. fi
  16. # Add to the proxy group so the service can read squid access logs
  17. if getent group proxy > /dev/null 2>&1; then
  18. usermod -aG proxy squidstats 2>/dev/null || true
  19. fi
  20. # ── Runtime directories ───────────────────────────────────────────
  21. install -d -m 0750 -o squidstats -g squidstats /var/log/squidstats
  22. install -d -m 0750 -o squidstats -g squidstats /var/lib/squidstats
  23. # ── Configuration file ────────────────────────────────────────────
  24. # On first install the example config is the real config; protect it
  25. if [ -f /etc/squidstats/squidstats.env ]; then
  26. chown root:squidstats /etc/squidstats/squidstats.env
  27. chmod 0640 /etc/squidstats/squidstats.env
  28. fi
  29. # ── Create application .env configuration file if missing ───────
  30. if [ ! -f /opt/SquidStats/app/.env ]; then
  31. cat > /opt/SquidStats/app/.env <<'EOF'
  32. VERSION=2.3.2
  33. SQUID_HOST="127.0.0.1"
  34. SQUID_PORT=3128
  35. # Multi-proxy load-balancing (optional): comma-separated host:port list.
  36. # When set, overrides SQUID_HOST/SQUID_PORT for the active-connections page.
  37. # Example: SQUID_HOSTS="192.168.0.10:3128,192.168.0.11:3128"
  38. SQUID_HOSTS=
  39. FLASK_DEBUG=True
  40. DATABASE_TYPE="SQLITE"
  41. SQUID_LOG="/var/log/squid/access.log"
  42. SQUID_CACHE_LOG="/var/log/squid/cache.log"
  43. DATABASE_STRING_CONNECTION="./squidstats.db"
  44. REFRESH_INTERVAL=60
  45. HTTP_PROXY=""
  46. HTTPS_PROXY=
  47. NO_PROXY=
  48. SQUID_CONFIG_PATH=/etc/squid/squid.conf
  49. ACL_FILES_DIR=/etc/squid/acl
  50. LISTEN_HOST="0.0.0.0"
  51. LISTEN_PORT=5000
  52. FIRST_PASSWORD="mipasswordsegura"
  53. JWT_EXPIRY_HOURS=24
  54. MAX_LOGIN_ATTEMPTS=5
  55. LOCKOUT_DURATION_MINUTES=15
  56. EOF
  57. chown root:squidstats /opt/SquidStats/app/.env
  58. chmod 0640 /opt/SquidStats/app/.env
  59. fi
  60. # ── Create Python virtualenv on the target system ────────────────
  61. if [ ! -d /opt/SquidStats/venv ]; then
  62. python3 -m venv /opt/SquidStats/venv
  63. /opt/SquidStats/venv/bin/python3 -m pip install --upgrade pip setuptools wheel
  64. /opt/SquidStats/venv/bin/pip install --no-cache-dir -r /opt/SquidStats/app/requirements.txt
  65. fi
  66. # ── Application directory ownership ──────────────────────────────
  67. # The app code is owned by root and group-owned by squidstats so the
  68. # service user can execute and write only where needed.
  69. chown -R root:squidstats /opt/SquidStats/
  70. find /opt/SquidStats/ -type d -exec chmod 2750 {} +
  71. find /opt/SquidStats/ -type f -exec chmod 0640 {} +
  72. chmod -R g+rwX /opt/SquidStats/
  73. # Ensure the runtime logs directory exists and is writable.
  74. install -d -m 2770 -o squidstats -g squidstats /opt/SquidStats/app/logs
  75. # Allow the service user to write to the data directory
  76. chown -R squidstats:squidstats /var/lib/squidstats/
  77. ;;
  78. esac
  79. #DEBHELPER#
  80. exit 0