diff --git a/UI/.htaccess b/UI/.htaccess new file mode 100644 index 0000000..bb04789 --- /dev/null +++ b/UI/.htaccess @@ -0,0 +1,73 @@ +# ZitiNexus Router Enrollment UI - Apache Configuration +# This file helps serve assets correctly when document root is not set to /public/ + +# Redirect to public directory for main pages +RewriteEngine On + +# Serve assets directly from assets directory +RewriteRule ^assets/(.*)$ assets/$1 [L] + +# Redirect main pages to public directory +RewriteRule ^$ public/index.php [L] +RewriteRule ^index\.php$ public/index.php [L] +RewriteRule ^dashboard\.php$ public/dashboard.php [L] + +# Handle other requests +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ public/$1 [L] + +# Security: Deny access to sensitive directories + + + Require all granted + + + + + Require all denied + + + + Require all denied + + + + Require all denied + + +# Set proper MIME types for assets + + AddType text/css .css + AddType application/javascript .js + AddType image/png .png + AddType image/jpeg .jpg .jpeg + AddType image/gif .gif + AddType image/svg+xml .svg + AddType image/x-icon .ico + + +# Enable compression for text files + + AddOutputFilterByType DEFLATE text/plain + AddOutputFilterByType DEFLATE text/html + AddOutputFilterByType DEFLATE text/xml + AddOutputFilterByType DEFLATE text/css + AddOutputFilterByType DEFLATE application/xml + AddOutputFilterByType DEFLATE application/xhtml+xml + AddOutputFilterByType DEFLATE application/rss+xml + AddOutputFilterByType DEFLATE application/javascript + AddOutputFilterByType DEFLATE application/x-javascript + + +# Set cache headers for static assets + + ExpiresActive On + ExpiresByType text/css "access plus 1 month" + ExpiresByType application/javascript "access plus 1 month" + ExpiresByType image/png "access plus 1 month" + ExpiresByType image/jpeg "access plus 1 month" + ExpiresByType image/gif "access plus 1 month" + ExpiresByType image/svg+xml "access plus 1 month" + ExpiresByType image/x-icon "access plus 1 year" + diff --git a/UI/includes/config.php b/UI/includes/config.php index ce4dbb4..b7533b1 100644 --- a/UI/includes/config.php +++ b/UI/includes/config.php @@ -144,4 +144,38 @@ function executeCommand($command, &$output = null, &$returnCode = null) { return false; } + +/** + * Get the correct asset path based on current directory structure + */ +function getAssetPath($asset) { + // Determine if we're in the public directory or main directory + $currentDir = dirname($_SERVER['SCRIPT_FILENAME']); + $publicDir = realpath(__DIR__ . '/../public'); + + if ($currentDir === $publicDir) { + // We're in the public directory, use relative paths + return '../assets/' . ltrim($asset, '/'); + } else { + // We're in the main directory, use direct paths + return 'assets/' . ltrim($asset, '/'); + } +} + +/** + * Get base URL for the application + */ +function getBaseUrl() { + $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; + $host = $_SERVER['HTTP_HOST']; + $scriptName = $_SERVER['SCRIPT_NAME']; + + // Remove the script filename to get the base path + $basePath = dirname($scriptName); + if ($basePath === '/') { + $basePath = ''; + } + + return $protocol . '://' . $host . $basePath; +} ?> diff --git a/UI/install.sh b/UI/install.sh index 293fd00..f2024b4 100644 --- a/UI/install.sh +++ b/UI/install.sh @@ -16,6 +16,7 @@ NC='\033[0m' # No Color WEB_DIR="/var/www/ziti-enrollment" DOMAIN="ziti-enrollment.local" WEB_USER="www-data" +PHP_VERSION="" # Logging function log() { @@ -56,6 +57,59 @@ check_root() { fi } +# Detect available PHP version +detect_php_version() { + log "INFO" "Detecting available PHP version..." + + # Update package cache first + apt update >/dev/null 2>&1 + + # Check for available PHP versions in order of preference + for version in "8.3" "8.2" "8.1" "8.0"; do + log "INFO" "Checking for PHP $version..." + + # Check multiple ways to ensure package availability + if apt-cache show "php${version}" >/dev/null 2>&1 || \ + apt-cache show "php${version}-cli" >/dev/null 2>&1 || \ + apt list "php${version}" 2>/dev/null | grep -q "php${version}"; then + + # Double-check that the FPM package exists for Nginx + if apt-cache show "php${version}-fpm" >/dev/null 2>&1 || \ + apt list "php${version}-fpm" 2>/dev/null | grep -q "php${version}-fpm"; then + PHP_VERSION="$version" + log "SUCCESS" "Found PHP $PHP_VERSION with FPM support" + break + else + log "WARNING" "PHP $version found but FPM package not available" + fi + else + log "INFO" "PHP $version not available" + fi + done + + if [[ -z "$PHP_VERSION" ]]; then + log "ERROR" "No compatible PHP version found. Available packages:" + apt list --installed | grep php 2>/dev/null || echo "No PHP packages found" + log "INFO" "Trying to install default PHP..." + + # Fallback: try to install default php package + if apt-cache show "php" >/dev/null 2>&1; then + log "INFO" "Found default PHP package, will use system default" + # Get the default PHP version + PHP_VERSION=$(apt-cache show php | grep "^Depends:" | grep -o "php[0-9]\+\.[0-9]\+" | head -1 | sed 's/php//') + if [[ -n "$PHP_VERSION" ]]; then + log "SUCCESS" "Will use system default PHP $PHP_VERSION" + else + error_exit "Could not determine PHP version from default package" + fi + else + error_exit "No PHP packages available. Please install PHP manually first." + fi + fi + + log "SUCCESS" "Selected PHP version: $PHP_VERSION" +} + # Detect web server preference detect_web_server() { echo @@ -82,30 +136,30 @@ detect_web_server() { # Install web server and PHP install_web_server() { - log "INFO" "Installing web server and PHP..." + log "INFO" "Installing web server and PHP $PHP_VERSION..." # Update package list apt update || error_exit "Failed to update package list" if [[ "$WEB_SERVER" == "apache" ]]; then # Install Apache and PHP - apt install -y apache2 php8.1 php8.1-curl php8.1-json libapache2-mod-php8.1 || error_exit "Failed to install Apache and PHP" + apt install -y apache2 php${PHP_VERSION} php${PHP_VERSION}-curl php${PHP_VERSION}-json libapache2-mod-php${PHP_VERSION} || error_exit "Failed to install Apache and PHP" # Enable and start Apache systemctl enable apache2 || error_exit "Failed to enable Apache" systemctl start apache2 || error_exit "Failed to start Apache" - log "SUCCESS" "Apache and PHP installed successfully" + log "SUCCESS" "Apache and PHP $PHP_VERSION installed successfully" elif [[ "$WEB_SERVER" == "nginx" ]]; then # Install Nginx and PHP-FPM - apt install -y nginx php8.1-fpm php8.1-curl php8.1-json || error_exit "Failed to install Nginx and PHP" + apt install -y nginx php${PHP_VERSION}-fpm php${PHP_VERSION}-curl php${PHP_VERSION}-json || error_exit "Failed to install Nginx and PHP" # Enable and start services - systemctl enable nginx php8.1-fpm || error_exit "Failed to enable Nginx and PHP-FPM" - systemctl start nginx php8.1-fpm || error_exit "Failed to start Nginx and PHP-FPM" + systemctl enable nginx php${PHP_VERSION}-fpm || error_exit "Failed to enable Nginx and PHP-FPM" + systemctl start nginx php${PHP_VERSION}-fpm || error_exit "Failed to start Nginx and PHP-FPM" - log "SUCCESS" "Nginx and PHP-FPM installed successfully" + log "SUCCESS" "Nginx and PHP $PHP_VERSION installed successfully" fi } @@ -182,7 +236,7 @@ server { } location ~ \.php$ { - fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; + fastcgi_pass unix:/var/run/php/php${PHP_VERSION}-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME \$realpath_root\$fastcgi_script_name; include fastcgi_params; @@ -213,9 +267,9 @@ configure_php() { # Find PHP configuration file if [[ "$WEB_SERVER" == "apache" ]]; then - PHP_INI="/etc/php/8.1/apache2/php.ini" + PHP_INI="/etc/php/${PHP_VERSION}/apache2/php.ini" else - PHP_INI="/etc/php/8.1/fpm/php.ini" + PHP_INI="/etc/php/${PHP_VERSION}/fpm/php.ini" fi # Check if exec functions are disabled @@ -228,7 +282,7 @@ configure_php() { if [[ "$WEB_SERVER" == "apache" ]]; then systemctl restart apache2 || error_exit "Failed to restart Apache" else - systemctl restart php8.1-fpm || error_exit "Failed to restart PHP-FPM" + systemctl restart php${PHP_VERSION}-fpm || error_exit "Failed to restart PHP-FPM" fi log "SUCCESS" "PHP configured successfully" @@ -288,7 +342,7 @@ test_installation() { log "ERROR" "Apache is not running" fi else - if systemctl is-active --quiet nginx && systemctl is-active --quiet php8.1-fpm; then + if systemctl is-active --quiet nginx && systemctl is-active --quiet php${PHP_VERSION}-fpm; then log "SUCCESS" "Nginx and PHP-FPM are running" else log "ERROR" "Nginx or PHP-FPM is not running" @@ -346,7 +400,7 @@ show_final_info() { echo " Check status: systemctl status apache2" echo " View logs: tail -f /var/log/apache2/ziti-enrollment_error.log" else - echo " Check status: systemctl status nginx php8.1-fpm" + echo " Check status: systemctl status nginx php${PHP_VERSION}-fpm" echo " View logs: tail -f /var/log/nginx/error.log" fi echo " Test sudo: sudo -u www-data sudo -l" @@ -363,6 +417,9 @@ main() { # Check if running as root check_root + # Detect available PHP version + detect_php_version + # Detect web server preference detect_web_server diff --git a/UI/public/dashboard.php b/UI/public/dashboard.php index 60bf09c..1c11c35 100644 --- a/UI/public/dashboard.php +++ b/UI/public/dashboard.php @@ -60,8 +60,8 @@ $systemStatus = $enrollmentManager->getSystemStatus(); <?php echo APP_NAME; ?> - Dashboard - - + +
@@ -305,6 +305,6 @@ $systemStatus = $enrollmentManager->getSystemStatus();
- + diff --git a/UI/public/index.php b/UI/public/index.php index 983e876..bf4cd61 100644 --- a/UI/public/index.php +++ b/UI/public/index.php @@ -48,8 +48,8 @@ if (isset($loginError)) { <?php echo APP_NAME; ?> - Login - - + +
diff --git a/UI/test-php-detection.sh b/UI/test-php-detection.sh new file mode 100644 index 0000000..0e4f883 --- /dev/null +++ b/UI/test-php-detection.sh @@ -0,0 +1,151 @@ +#!/bin/bash + +# Quick test script to verify PHP version detection +# Run this to see what PHP versions are available on your system + +set -euo pipefail + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +log() { + local level=$1 + shift + local message="$*" + + case $level in + "ERROR") + echo -e "${RED}[ERROR]${NC} $message" >&2 + ;; + "SUCCESS") + echo -e "${GREEN}[SUCCESS]${NC} $message" + ;; + "WARNING") + echo -e "${YELLOW}[WARNING]${NC} $message" + ;; + "INFO") + echo -e "${BLUE}[INFO]${NC} $message" + ;; + *) + echo "$message" + ;; + esac +} + +echo "==============================================" +echo " PHP Version Detection Test" +echo "==============================================" +echo + +# Update package cache +log "INFO" "Updating package cache..." +apt update >/dev/null 2>&1 + +echo +log "INFO" "Checking available PHP packages..." +echo + +# Check what PHP packages are available +for version in "8.3" "8.2" "8.1" "8.0"; do + echo "--- Checking PHP $version ---" + + # Check main package + if apt-cache show "php${version}" >/dev/null 2>&1; then + log "SUCCESS" "php${version} is available" + else + log "ERROR" "php${version} is NOT available" + fi + + # Check CLI package + if apt-cache show "php${version}-cli" >/dev/null 2>&1; then + log "SUCCESS" "php${version}-cli is available" + else + log "ERROR" "php${version}-cli is NOT available" + fi + + # Check FPM package + if apt-cache show "php${version}-fpm" >/dev/null 2>&1; then + log "SUCCESS" "php${version}-fpm is available" + else + log "ERROR" "php${version}-fpm is NOT available" + fi + + # Check curl extension + if apt-cache show "php${version}-curl" >/dev/null 2>&1; then + log "SUCCESS" "php${version}-curl is available" + else + log "ERROR" "php${version}-curl is NOT available" + fi + + # Check json extension + if apt-cache show "php${version}-json" >/dev/null 2>&1; then + log "SUCCESS" "php${version}-json is available" + else + log "ERROR" "php${version}-json is NOT available" + fi + + echo +done + +echo "==============================================" +echo " System Information" +echo "==============================================" +echo + +# Show OS version +log "INFO" "Operating System:" +lsb_release -a 2>/dev/null || cat /etc/os-release + +echo +log "INFO" "Available PHP packages (using apt list):" +apt list 2>/dev/null | grep "^php[0-9]" | head -20 + +echo +log "INFO" "Currently installed PHP packages:" +dpkg -l | grep php | head -10 + +echo +if command -v php >/dev/null 2>&1; then + CURRENT_PHP=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;") + log "SUCCESS" "Currently active PHP version: $CURRENT_PHP" + php --version | head -1 +else + log "WARNING" "No PHP currently installed or in PATH" +fi + +echo +echo "==============================================" +echo " Recommended Action" +echo "==============================================" +echo + +# Determine best PHP version +PHP_VERSION="" +for version in "8.3" "8.2" "8.1" "8.0"; do + if apt-cache show "php${version}" >/dev/null 2>&1 && \ + apt-cache show "php${version}-fpm" >/dev/null 2>&1 && \ + apt-cache show "php${version}-curl" >/dev/null 2>&1; then + PHP_VERSION="$version" + break + fi +done + +if [[ -n "$PHP_VERSION" ]]; then + log "SUCCESS" "Recommended PHP version for installation: $PHP_VERSION" + echo + echo "To install manually:" + echo " sudo apt install -y php${PHP_VERSION} php${PHP_VERSION}-fpm php${PHP_VERSION}-curl php${PHP_VERSION}-json" +else + log "ERROR" "No suitable PHP version found!" + echo + echo "You may need to add a PHP repository:" + echo " sudo apt install -y software-properties-common" + echo " sudo add-apt-repository ppa:ondrej/php" + echo " sudo apt update" +fi + +echo diff --git a/UI/troubleshoot.sh b/UI/troubleshoot.sh new file mode 100644 index 0000000..01ba6c9 --- /dev/null +++ b/UI/troubleshoot.sh @@ -0,0 +1,358 @@ +#!/bin/bash + +# ZitiNexus Router Enrollment UI Troubleshooting Script +# This script helps diagnose common issues with the UI installation + +set -euo pipefail + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Configuration +WEB_DIR="/var/www/ziti-enrollment" +DOMAIN="ziti-enrollment.local" + +# Logging function +log() { + local level=$1 + shift + local message="$*" + + case $level in + "ERROR") + echo -e "${RED}[ERROR]${NC} $message" >&2 + ;; + "SUCCESS") + echo -e "${GREEN}[SUCCESS]${NC} $message" + ;; + "WARNING") + echo -e "${YELLOW}[WARNING]${NC} $message" + ;; + "INFO") + echo -e "${BLUE}[INFO]${NC} $message" + ;; + *) + echo "$message" + ;; + esac +} + +# Check web server status +check_web_server() { + log "INFO" "Checking web server status..." + + if systemctl is-active --quiet apache2; then + log "SUCCESS" "Apache is running" + WEB_SERVER="apache" + elif systemctl is-active --quiet nginx; then + log "SUCCESS" "Nginx is running" + WEB_SERVER="nginx" + else + log "ERROR" "No web server is running" + return 1 + fi +} + +# Check PHP status +check_php() { + log "INFO" "Checking PHP status..." + + if command -v php >/dev/null 2>&1; then + PHP_VERSION=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;") + log "SUCCESS" "PHP $PHP_VERSION is installed" + + # Check if PHP-FPM is running (for Nginx) + if [[ "$WEB_SERVER" == "nginx" ]]; then + if systemctl is-active --quiet php${PHP_VERSION}-fpm; then + log "SUCCESS" "PHP-FPM is running" + else + log "ERROR" "PHP-FPM is not running" + log "INFO" "Try: sudo systemctl start php${PHP_VERSION}-fpm" + fi + fi + else + log "ERROR" "PHP is not installed or not in PATH" + return 1 + fi +} + +# Check file permissions +check_permissions() { + log "INFO" "Checking file permissions..." + + if [[ -d "$WEB_DIR" ]]; then + log "SUCCESS" "Web directory exists: $WEB_DIR" + + # Check ownership + OWNER=$(stat -c '%U:%G' "$WEB_DIR") + if [[ "$OWNER" == "www-data:www-data" ]]; then + log "SUCCESS" "Correct ownership: $OWNER" + else + log "WARNING" "Incorrect ownership: $OWNER (should be www-data:www-data)" + fi + + # Check key files + local files=("public/index.php" "public/dashboard.php" "assets/css/style.css" "assets/js/app.js") + for file in "${files[@]}"; do + if [[ -f "$WEB_DIR/$file" ]]; then + log "SUCCESS" "File exists: $file" + else + log "ERROR" "File missing: $file" + fi + done + + # Check log directories + if [[ -d "$WEB_DIR/logs" && -w "$WEB_DIR/logs" ]]; then + log "SUCCESS" "Log directory is writable" + else + log "ERROR" "Log directory is not writable" + fi + + else + log "ERROR" "Web directory does not exist: $WEB_DIR" + return 1 + fi +} + +# Check web server configuration +check_web_config() { + log "INFO" "Checking web server configuration..." + + if [[ "$WEB_SERVER" == "apache" ]]; then + # Check Apache configuration + if [[ -f "/etc/apache2/sites-available/ziti-enrollment.conf" ]]; then + log "SUCCESS" "Apache site configuration exists" + + if a2ensite -q ziti-enrollment 2>/dev/null; then + log "SUCCESS" "Apache site is enabled" + else + log "ERROR" "Apache site is not enabled" + fi + else + log "ERROR" "Apache site configuration missing" + fi + + # Check if rewrite module is enabled + if a2enmod -q rewrite 2>/dev/null; then + log "SUCCESS" "Apache rewrite module is enabled" + else + log "WARNING" "Apache rewrite module is not enabled" + fi + + elif [[ "$WEB_SERVER" == "nginx" ]]; then + # Check Nginx configuration + if [[ -f "/etc/nginx/sites-available/ziti-enrollment" ]]; then + log "SUCCESS" "Nginx site configuration exists" + + if [[ -L "/etc/nginx/sites-enabled/ziti-enrollment" ]]; then + log "SUCCESS" "Nginx site is enabled" + else + log "ERROR" "Nginx site is not enabled" + fi + else + log "ERROR" "Nginx site configuration missing" + fi + + # Test Nginx configuration + if nginx -t >/dev/null 2>&1; then + log "SUCCESS" "Nginx configuration is valid" + else + log "ERROR" "Nginx configuration has errors" + fi + fi +} + +# Check PHP configuration +check_php_config() { + log "INFO" "Checking PHP configuration..." + + # Check for required extensions + local extensions=("curl" "json") + for ext in "${extensions[@]}"; do + if php -m | grep -q "^$ext$"; then + log "SUCCESS" "PHP extension loaded: $ext" + else + log "ERROR" "PHP extension missing: $ext" + fi + done + + # Check if exec functions are enabled + DISABLED_FUNCTIONS=$(php -r "echo ini_get('disable_functions');") + if [[ -n "$DISABLED_FUNCTIONS" ]]; then + if echo "$DISABLED_FUNCTIONS" | grep -q -E "(exec|shell_exec|proc_open)"; then + log "ERROR" "Required PHP functions are disabled: $DISABLED_FUNCTIONS" + else + log "SUCCESS" "Required PHP functions are enabled" + fi + else + log "SUCCESS" "No PHP functions are disabled" + fi +} + +# Check sudo access +check_sudo() { + log "INFO" "Checking sudo access..." + + if [[ -f "/etc/sudoers.d/ziti-enrollment" ]]; then + log "SUCCESS" "Sudoers file exists" + + # Test sudo access + if sudo -u www-data sudo -n systemctl --version >/dev/null 2>&1; then + log "SUCCESS" "Sudo access is working" + else + log "ERROR" "Sudo access is not working" + fi + else + log "ERROR" "Sudoers file missing: /etc/sudoers.d/ziti-enrollment" + fi +} + +# Check network connectivity +check_network() { + log "INFO" "Checking network connectivity..." + + # Test DNS resolution + if nslookup google.com >/dev/null 2>&1; then + log "SUCCESS" "DNS resolution is working" + else + log "ERROR" "DNS resolution failed" + fi + + # Test HTTPS connectivity + if curl -s --connect-timeout 5 https://google.com >/dev/null 2>&1; then + log "SUCCESS" "HTTPS connectivity is working" + else + log "ERROR" "HTTPS connectivity failed" + fi +} + +# Check system resources +check_resources() { + log "INFO" "Checking system resources..." + + # Check disk space + DISK_USAGE=$(df / | awk 'NR==2 {print $5}' | sed 's/%//') + if [[ $DISK_USAGE -lt 90 ]]; then + log "SUCCESS" "Disk usage is acceptable: ${DISK_USAGE}%" + else + log "WARNING" "Disk usage is high: ${DISK_USAGE}%" + fi + + # Check memory + MEMORY_USAGE=$(free | awk 'NR==2{printf "%.0f", $3*100/$2}') + if [[ $MEMORY_USAGE -lt 90 ]]; then + log "SUCCESS" "Memory usage is acceptable: ${MEMORY_USAGE}%" + else + log "WARNING" "Memory usage is high: ${MEMORY_USAGE}%" + fi +} + +# Test web access +test_web_access() { + log "INFO" "Testing web access..." + + # Test local access + if curl -s -o /dev/null -w "%{http_code}" "http://localhost" | grep -q "200\|302\|301"; then + log "SUCCESS" "Local web access is working" + else + log "ERROR" "Local web access failed" + fi + + # Test domain access + if curl -s -o /dev/null -w "%{http_code}" "http://$DOMAIN" | grep -q "200\|302\|301"; then + log "SUCCESS" "Domain access is working" + else + log "WARNING" "Domain access failed (check hosts file)" + fi +} + +# Show log files +show_logs() { + log "INFO" "Recent log entries..." + + echo + echo "=== Web Server Error Logs ===" + if [[ "$WEB_SERVER" == "apache" ]]; then + if [[ -f "/var/log/apache2/ziti-enrollment_error.log" ]]; then + tail -n 10 /var/log/apache2/ziti-enrollment_error.log + else + tail -n 10 /var/log/apache2/error.log 2>/dev/null || echo "No Apache error logs found" + fi + elif [[ "$WEB_SERVER" == "nginx" ]]; then + tail -n 10 /var/log/nginx/error.log 2>/dev/null || echo "No Nginx error logs found" + fi + + echo + echo "=== PHP Error Logs ===" + if [[ -f "/var/log/php_errors.log" ]]; then + tail -n 10 /var/log/php_errors.log + else + echo "No PHP error logs found" + fi + + echo + echo "=== UI Logs ===" + if [[ -f "$WEB_DIR/logs/ui-enrollment.log" ]]; then + tail -n 10 "$WEB_DIR/logs/ui-enrollment.log" + else + echo "No UI logs found" + fi +} + +# Main troubleshooting function +main() { + echo "==============================================" + echo " ZitiNexus Router Enrollment UI Troubleshoot" + echo "==============================================" + echo + + # Run all checks + check_web_server || exit 1 + check_php || exit 1 + check_permissions + check_web_config + check_php_config + check_sudo + check_network + check_resources + test_web_access + + echo + log "INFO" "Troubleshooting complete!" + echo + + # Show logs + show_logs + + echo + echo "==============================================" + echo " Common Solutions" + echo "==============================================" + echo + echo "1. Fix file permissions:" + echo " sudo chown -R www-data:www-data $WEB_DIR" + echo " sudo chmod -R 755 $WEB_DIR" + echo " sudo chmod -R 777 $WEB_DIR/logs $WEB_DIR/temp" + echo + echo "2. Restart web services:" + if [[ "$WEB_SERVER" == "apache" ]]; then + echo " sudo systemctl restart apache2" + else + echo " sudo systemctl restart nginx php${PHP_VERSION}-fpm" + fi + echo + echo "3. Check configuration files:" + echo " sudo nano $WEB_DIR/includes/config.php" + echo + echo "4. View detailed logs:" + echo " sudo tail -f /var/log/apache2/error.log" # or nginx + echo " sudo tail -f $WEB_DIR/logs/ui-enrollment.log" + echo +} + +# Run main function +main "$@"