postinst 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. LOG_FORMAT=DETAILED
  40. FLASK_DEBUG=True
  41. DATABASE_TYPE="SQLITE"
  42. SQUID_LOG="/var/log/squid/access.log"
  43. SQUID_CACHE_LOG="/var/log/squid/cache.log"
  44. DATABASE_STRING_CONNECTION="./squidstats.db"
  45. REFRESH_INTERVAL=60
  46. HTTP_PROXY=""
  47. HTTPS_PROXY=
  48. NO_PROXY=
  49. SQUID_CONFIG_PATH=/etc/squid/squid.conf
  50. ACL_FILES_DIR=/etc/squid/acl
  51. LISTEN_HOST="0.0.0.0"
  52. LISTEN_PORT=8080
  53. FIRST_PASSWORD="mipasswordsegura"
  54. JWT_EXPIRY_HOURS=24
  55. MAX_LOGIN_ATTEMPTS=5
  56. LOCKOUT_DURATION_MINUTES=15
  57. EOF
  58. chown root:squidstats /opt/SquidStats/app/.env
  59. chmod 0640 /opt/SquidStats/app/.env
  60. fi
  61. # ── Create Python virtualenv on the target system ────────────────
  62. if [ ! -d /opt/SquidStats/venv ]; then
  63. python3 -m venv /opt/SquidStats/venv
  64. /opt/SquidStats/venv/bin/python3 -m pip install --upgrade pip setuptools wheel
  65. /opt/SquidStats/venv/bin/pip install --no-cache-dir -r /opt/SquidStats/app/requirements.txt
  66. fi
  67. # ── Application directory ownership ──────────────────────────────
  68. # The app code is owned by root and group-owned by squidstats so the
  69. # service user can execute and write only where needed.
  70. chown -R root:squidstats /opt/SquidStats/
  71. find /opt/SquidStats/ -type d -exec chmod 2750 {} +
  72. find /opt/SquidStats/ -type f -exec chmod 0640 {} +
  73. chmod -R g+rwX /opt/SquidStats/
  74. # Ensure the runtime logs directory exists and is writable.
  75. install -d -m 2770 -o squidstats -g squidstats /opt/SquidStats/app/logs
  76. # Allow the service user to write to the data directory
  77. chown -R squidstats:squidstats /var/lib/squidstats/
  78. ;;
  79. esac
  80. #DEBHELPER#
  81. exit 0