loreal-global-kickoff/server-setup.sh
Vadym Samoilenko 53e9365c01 Add Azure AD SSO, RBAC (admin/user roles), and server-setup improvements
- Enable SSO with Azure AD credentials (tenant + client ID + redirect_uri)
- Add JWTValidator.php: RS256 idToken validation via Azure JWKS with 1h cache
- Add auth.php: POST login handler sets auth cookie, GET logout clears it
- Add UserRoleManager.php: file-based role CRUD in data/user_roles.json
- Add admin.php: admin-only role management panel
- AuthMiddleware: add requireAdmin(), role in user array, fix MSAL redirect
- header.php: hide Activity Logs + Admin Panel tabs for non-admin users
- logs-viewer.php: protect with requireAdmin() instead of requireAuth()
- server-setup.sh: add composer check, data/ dir, PHP extension checks, SSO validation
- .gitignore: add data/ directory

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-02 20:34:50 +00:00

127 lines
4.7 KiB
Bash
Executable file

#!/bin/bash
# Server Setup Script for L'Oréal OMG Assistant Global
echo "========================================="
echo "L'Oréal OMG Assistant - Server Setup"
echo "========================================="
echo ""
# ─── Logs directory ────────────────────────────────────────────────────────────
echo "Creating logs directory..."
mkdir -p logs
chmod 755 logs
touch logs/.gitkeep
echo "✓ logs/ directory created"
# ─── Data directory (roles, JWKS cache) ────────────────────────────────────────
echo ""
echo "Creating data directory..."
mkdir -p data
chmod 755 data
if [ ! -f data/user_roles.json ]; then
echo '{}' > data/user_roles.json
echo "✓ data/user_roles.json initialised"
else
echo "✓ data/user_roles.json already exists"
fi
# ─── File permissions ──────────────────────────────────────────────────────────
echo ""
echo "Setting file permissions..."
chmod -R 755 .
chmod 644 config.php
chmod 600 43984435_77m2ujl3_config.json 2>/dev/null || echo "⚠ Box JWT config not found (will be added separately)"
chmod 755 data
chmod 644 data/user_roles.json 2>/dev/null
echo "✓ Permissions set"
# ─── PHP extensions ────────────────────────────────────────────────────────────
echo ""
echo "Checking PHP extensions..."
MISSING_EXTS=()
for ext in zip curl json mbstring openssl; do
if php -m 2>/dev/null | grep -qi "^${ext}$"; then
echo "${ext} extension installed"
else
echo "${ext} extension MISSING"
MISSING_EXTS+=("php-${ext}")
fi
done
if [ ${#MISSING_EXTS[@]} -gt 0 ]; then
echo ""
echo "To install missing extensions on Ubuntu/Debian:"
echo " sudo apt-get update"
echo " sudo apt-get install ${MISSING_EXTS[*]}"
echo " sudo systemctl restart apache2"
fi
# ─── Composer ─────────────────────────────────────────────────────────────────
echo ""
echo "Checking Composer..."
if command -v composer &>/dev/null; then
echo "✓ Composer found: $(composer --version 2>/dev/null | head -1)"
else
echo "❌ Composer not found in PATH"
echo " Install from https://getcomposer.org or run:"
echo " curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer"
fi
echo ""
echo "Checking vendor directory..."
if [ -d vendor ]; then
echo "✓ vendor/ directory exists"
else
echo "⚠ vendor/ not found — running composer install..."
if command -v composer &>/dev/null; then
composer install --no-interaction --prefer-dist
if [ $? -eq 0 ]; then
echo "✓ composer install completed"
else
echo "❌ composer install failed"
fi
else
echo "❌ Cannot run composer install — Composer not available"
fi
fi
# ─── SSO configuration check ───────────────────────────────────────────────────
echo ""
echo "Checking SSO configuration..."
if php -r "
\$c = require 'config.php';
\$sso = \$c['sso'] ?? [];
if (!empty(\$sso['tenant_id']) && !empty(\$sso['client_id']) && !empty(\$sso['redirect_uri'])) {
echo 'ok';
} else {
echo 'missing';
}
" 2>/dev/null | grep -q "ok"; then
echo "✓ SSO credentials configured"
else
echo "⚠ SSO credentials missing in config.php (tenant_id, client_id, or redirect_uri)"
fi
# ─── ApplicationLogger test ───────────────────────────────────────────────────
echo ""
echo "Testing ApplicationLogger..."
if php -r "require 'vendor/autoload.php'; require 'ApplicationLogger.php'; new ApplicationLogger();" 2>/dev/null; then
echo "✓ ApplicationLogger works"
else
echo "❌ ApplicationLogger failed (run composer install first)"
fi
echo ""
echo "========================================="
echo "Setup Complete!"
echo "========================================="
echo ""
echo "Next steps:"
echo "1. Fix any missing PHP extensions listed above"
echo "2. Ensure composer install has been run"
echo "3. Verify server-check.php shows all green checkmarks"
echo "4. First admin login: add email to config.php roles.admin_emails[]"
echo "5. Test the application!"
echo ""