Files
Linux-Server-Management-Too…/testing/validate-plesk.sh
T
cschantz 20a3615242 TESTING PHASE: Add comprehensive validation scripts for InterWorx and Plesk
Created automated validation framework to test multi-panel refactoring on real servers.

NEW FILES:
- testing/validate-interworx.sh (650+ lines)
  - 10 comprehensive tests validating all InterWorx assumptions
  - File system structure, logs, domain lookups, database prefix
  - WordPress detection, cron system, PHP config, CLI tools
  - Color-coded output + detailed results file

- testing/validate-plesk.sh (750+ lines)
  - 12 comprehensive tests validating all Plesk assumptions
  - File system structure, logs, plesk bin commands
  - Domain/user lookups, database prefix, system user detection
  - WordPress detection, cron system, PHP config
  - Critical: Determines system user for cron jobs

- testing/README.md
  - Complete testing guide and documentation
  - Quick start instructions for both panels
  - What gets validated and why
  - 4-phase testing priority plan
  - Known issues and next steps

UPDATED:
- REFDB_FORMAT.txt
  - Added TESTING & VALIDATION PHASE section
  - Documented validation scripts and their coverage
  - Listed testing priority and next actions
  - Updated last modified date

VALIDATION COVERAGE:
InterWorx (10 tests):
   All file paths (verified from official docs)
   Database prefix: username_ (verified)
   Domain→User lookup (needs real server)
   User→Domains lookup (needs real server)
   WordPress detection (needs real server)

Plesk (12 tests):
   File paths (assumed correct)
   Database prefix (appears to be no prefix)
   System user for cron (critical for wordpress-cron-manager!)
   Cron system (standard vs plesk bin cron)
   All lookup methods (need real server)

READY FOR: Testing on real InterWorx and Plesk servers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 00:29:29 -05:00

605 lines
21 KiB
Bash
Executable File

#!/bin/bash
################################################################################
# Plesk Validation Script
# Purpose: Verify all assumptions about Plesk file system, commands, and paths
# Run this on a real Plesk server to validate our refactoring
################################################################################
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
RESULTS_FILE="/tmp/plesk-validation-results.txt"
# Color output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Counters
PASS=0
FAIL=0
WARN=0
echo "======================================================================="
echo "PLESK VALIDATION SCRIPT"
echo "======================================================================="
echo "This script will verify all assumptions about Plesk"
echo "Results will be saved to: $RESULTS_FILE"
echo ""
echo "Started: $(date)"
echo "======================================================================="
echo ""
# Initialize results file
cat > "$RESULTS_FILE" <<EOF
Plesk Validation Results
Generated: $(date)
Hostname: $(hostname)
EOF
################################################################################
# Helper Functions
################################################################################
test_pass() {
echo -e "${GREEN}[PASS]${NC} $1"
echo "[PASS] $1" >> "$RESULTS_FILE"
((PASS++))
}
test_fail() {
echo -e "${RED}[FAIL]${NC} $1"
echo "[FAIL] $1" >> "$RESULTS_FILE"
((FAIL++))
}
test_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
echo "[WARN] $1" >> "$RESULTS_FILE"
((WARN++))
}
test_info() {
echo -e "${BLUE}[INFO]${NC} $1"
echo "[INFO] $1" >> "$RESULTS_FILE"
}
section_header() {
echo ""
echo "======================================================================="
echo "$1"
echo "======================================================================="
echo "" >> "$RESULTS_FILE"
echo "=======================================================================" >> "$RESULTS_FILE"
echo "$1" >> "$RESULTS_FILE"
echo "=======================================================================" >> "$RESULTS_FILE"
}
################################################################################
# TEST 1: Control Panel Detection
################################################################################
section_header "TEST 1: Control Panel Detection"
if [ -d "/usr/local/psa" ]; then
test_pass "Plesk installation directory exists: /usr/local/psa"
else
test_fail "Plesk installation directory NOT found: /usr/local/psa"
fi
if command -v plesk &> /dev/null; then
test_pass "plesk command available"
# Get Plesk version
PLESK_VERSION=$(plesk version 2>/dev/null | head -1)
test_info "Plesk version: $PLESK_VERSION"
else
test_fail "plesk command not available"
fi
################################################################################
# TEST 2: File System Structure
################################################################################
section_header "TEST 2: File System Structure"
# Check main vhosts directory
if [ -d "/var/www/vhosts" ]; then
test_pass "Main vhosts directory exists: /var/www/vhosts"
# Find a test domain
TEST_DOMAIN=""
for domain_dir in /var/www/vhosts/*; do
domain=$(basename "$domain_dir")
# Skip system directories
if [[ "$domain" != "system" ]] && [[ "$domain" != "default" ]] && [[ "$domain" != "chroot" ]] && [[ -d "$domain_dir/httpdocs" ]]; then
TEST_DOMAIN="$domain"
break
fi
done
if [ -n "$TEST_DOMAIN" ]; then
test_pass "Found test domain: $TEST_DOMAIN"
# Test document root path
EXPECTED_DOCROOT="/var/www/vhosts/$TEST_DOMAIN/httpdocs"
if [ -d "$EXPECTED_DOCROOT" ]; then
test_pass "Document root exists: $EXPECTED_DOCROOT"
test_pass "VERIFIED: Document root pattern is /var/www/vhosts/DOMAIN/httpdocs"
else
test_fail "Document root NOT found: $EXPECTED_DOCROOT"
fi
# Test domain root structure
test_info "Domain root structure for $TEST_DOMAIN:"
ls -la "/var/www/vhosts/$TEST_DOMAIN" | head -20 >> "$RESULTS_FILE" 2>&1
else
test_warn "No test domain found in /var/www/vhosts"
test_info "Available directories:"
ls -d /var/www/vhosts/*/ 2>/dev/null | head -10 >> "$RESULTS_FILE"
fi
else
test_fail "Main vhosts directory NOT found: /var/www/vhosts"
fi
################################################################################
# TEST 3: Log File Locations
################################################################################
section_header "TEST 3: Log File Locations"
if [ -d "/var/www/vhosts/system" ]; then
test_pass "System logs directory exists: /var/www/vhosts/system"
if [ -n "$TEST_DOMAIN" ]; then
# Test access log path
EXPECTED_ACCESS_LOG="/var/www/vhosts/system/$TEST_DOMAIN/logs/access_log"
if [ -f "$EXPECTED_ACCESS_LOG" ]; then
test_pass "Access log exists: $EXPECTED_ACCESS_LOG"
test_pass "VERIFIED: Access log pattern is /var/www/vhosts/system/DOMAIN/logs/access_log"
else
test_warn "Access log NOT found: $EXPECTED_ACCESS_LOG (may not have traffic yet)"
fi
# Test SSL access log path
EXPECTED_SSL_LOG="/var/www/vhosts/system/$TEST_DOMAIN/logs/access_ssl_log"
if [ -f "$EXPECTED_SSL_LOG" ]; then
test_pass "SSL access log exists: $EXPECTED_SSL_LOG"
else
test_warn "SSL access log NOT found (may not have SSL traffic)"
fi
# Test error log path
EXPECTED_ERROR_LOG="/var/www/vhosts/system/$TEST_DOMAIN/logs/error_log"
if [ -f "$EXPECTED_ERROR_LOG" ]; then
test_pass "Error log exists: $EXPECTED_ERROR_LOG"
test_pass "VERIFIED: Error log pattern is /var/www/vhosts/system/DOMAIN/logs/error_log"
else
test_warn "Error log NOT found: $EXPECTED_ERROR_LOG (may not have errors yet)"
fi
# List all log files
LOG_DIR="/var/www/vhosts/system/$TEST_DOMAIN/logs"
if [ -d "$LOG_DIR" ]; then
test_info "Log files found:"
ls -lh "$LOG_DIR" >> "$RESULTS_FILE" 2>&1
fi
fi
else
test_fail "System logs directory NOT found: /var/www/vhosts/system"
fi
# Check for domain-level error logs (PHP errors)
if [ -n "$TEST_DOMAIN" ]; then
PHP_ERROR_LOG="/var/www/vhosts/$TEST_DOMAIN/httpdocs/error_log"
if [ -f "$PHP_ERROR_LOG" ]; then
test_pass "PHP error log exists in httpdocs: $PHP_ERROR_LOG"
else
test_warn "PHP error log not found in httpdocs (may not have PHP errors)"
fi
fi
################################################################################
# TEST 4: Plesk bin Commands
################################################################################
section_header "TEST 4: Plesk bin Commands"
if [ -d "/usr/local/psa/bin" ]; then
test_pass "Plesk bin directory exists: /usr/local/psa/bin"
test_info "Available Plesk bin commands:"
ls /usr/local/psa/bin | head -20 >> "$RESULTS_FILE"
else
test_fail "Plesk bin directory NOT found"
fi
# Test subscription command
if command -v plesk &> /dev/null; then
if plesk bin subscription --help &> /dev/null; then
test_pass "plesk bin subscription command available"
else
test_fail "plesk bin subscription command not working"
fi
fi
################################################################################
# TEST 5: Domain → User Mapping
################################################################################
section_header "TEST 5: Domain → User Mapping (Owner Lookup)"
if [ -n "$TEST_DOMAIN" ]; then
test_info "Testing domain→user lookup for: $TEST_DOMAIN"
# Method: plesk bin subscription --info DOMAIN
SUBSCRIPTION_INFO=$(plesk bin subscription --info "$TEST_DOMAIN" 2>/dev/null)
if [ -n "$SUBSCRIPTION_INFO" ]; then
test_pass "Successfully retrieved subscription info for $TEST_DOMAIN"
# Look for Owner field
OWNER=$(echo "$SUBSCRIPTION_INFO" | grep -i "^Owner:" | awk '{print $2}')
if [ -n "$OWNER" ]; then
test_pass "Found Owner field: $OWNER"
test_pass "VERIFIED: Domain→User lookup works via: plesk bin subscription --info DOMAIN | grep Owner"
TEST_OWNER="$OWNER"
else
# Try Login field as alternative
OWNER=$(echo "$SUBSCRIPTION_INFO" | grep -i "^Login:" | awk '{print $2}')
if [ -n "$OWNER" ]; then
test_pass "Found Login field: $OWNER (alternative to Owner)"
TEST_OWNER="$OWNER"
else
test_fail "Could not find Owner or Login field in subscription info"
fi
fi
# Show sample output
test_info "Sample subscription info output:"
echo "$SUBSCRIPTION_INFO" | head -15 >> "$RESULTS_FILE"
else
test_fail "Could not retrieve subscription info for: $TEST_DOMAIN"
fi
else
test_warn "No test domain available for lookup test"
fi
################################################################################
# TEST 6: User → Domains Mapping
################################################################################
section_header "TEST 6: User → Domains Mapping (List User's Domains)"
if [ -n "$TEST_OWNER" ]; then
test_info "Testing user→domains lookup for owner: $TEST_OWNER"
# Method 1: plesk bin subscription --list -owner USERNAME
USER_DOMAINS=$(plesk bin subscription --list -owner "$TEST_OWNER" 2>/dev/null)
if [ -n "$USER_DOMAINS" ]; then
DOMAIN_COUNT=$(echo "$USER_DOMAINS" | wc -l)
test_pass "Method 1: plesk bin subscription --list -owner found $DOMAIN_COUNT domain(s)"
test_pass "VERIFIED: User→Domains lookup works via: plesk bin subscription --list -owner USERNAME"
test_info "Domains for owner $TEST_OWNER:"
echo "$USER_DOMAINS" >> "$RESULTS_FILE"
else
test_warn "Method 1: No domains found for owner $TEST_OWNER"
fi
# Method 2: From filesystem (alternative)
FS_DOMAINS=$(find /var/www/vhosts -maxdepth 1 -type d ! -name "system" ! -name "default" ! -name "chroot" ! -name "vhosts" 2>/dev/null | xargs -n1 basename | sort)
if [ -n "$FS_DOMAINS" ]; then
FS_COUNT=$(echo "$FS_DOMAINS" | wc -l)
test_info "Method 2: Found $FS_COUNT total domain(s) in filesystem (all users)"
test_info "All domains in /var/www/vhosts:"
echo "$FS_DOMAINS" | head -10 >> "$RESULTS_FILE"
fi
else
test_warn "No test owner available - skipping user→domains test"
fi
################################################################################
# TEST 7: Database Prefix Pattern
################################################################################
section_header "TEST 7: Database Prefix Pattern"
test_info "Checking database naming conventions..."
# Try to connect to MySQL/MariaDB
if command -v mysql &> /dev/null; then
# Try to get database list
DB_LIST=$(mysql -e "SHOW DATABASES;" 2>/dev/null | grep -v "Database\|information_schema\|performance_schema\|mysql\|sys")
if [ -n "$DB_LIST" ]; then
test_pass "Successfully connected to database and retrieved database list"
test_info "Sample databases:"
echo "$DB_LIST" | head -15 >> "$RESULTS_FILE"
# Check for prefix patterns
HAS_UNDERSCORES=$(echo "$DB_LIST" | grep "_" | wc -l)
NO_UNDERSCORES=$(echo "$DB_LIST" | grep -v "_" | wc -l)
test_info "Databases with underscores: $HAS_UNDERSCORES"
test_info "Databases without underscores: $NO_UNDERSCORES"
# Check if databases follow username_ pattern or no prefix
if [ $NO_UNDERSCORES -gt 0 ]; then
test_info "Found databases without underscores (suggests NO PREFIX pattern)"
test_info "Sample databases without prefix:"
echo "$DB_LIST" | grep -v "_" | grep -v "test" | head -5 >> "$RESULTS_FILE"
test_pass "DATABASE PREFIX PATTERN: Appears to use NO PREFIX (bare database names)"
else
test_warn "All databases have underscores - cannot determine prefix pattern"
fi
# Look for WordPress database pattern
WP_DBS=$(echo "$DB_LIST" | grep -E "wp_|wordpress|_wp")
if [ -n "$WP_DBS" ]; then
test_info "Found WordPress-like databases:"
echo "$WP_DBS" | head -5 >> "$RESULTS_FILE"
fi
else
test_warn "Could not retrieve database list (may need credentials)"
fi
else
test_warn "mysql command not found - cannot test database prefix"
fi
################################################################################
# TEST 8: System User for Web Processes
################################################################################
section_header "TEST 8: System User for Web Processes"
test_info "Checking what user runs web/PHP processes..."
# Check PHP-FPM processes
PHP_FPM_USERS=$(ps aux | grep "php-fpm" | grep -v "grep" | awk '{print $1}' | sort -u)
if [ -n "$PHP_FPM_USERS" ]; then
test_pass "Found PHP-FPM processes running as:"
echo "$PHP_FPM_USERS" >> "$RESULTS_FILE"
if echo "$PHP_FPM_USERS" | grep -q "www-data"; then
test_info "PHP-FPM uses www-data (Debian/Ubuntu pattern)"
elif echo "$PHP_FPM_USERS" | grep -q "apache"; then
test_info "PHP-FPM uses apache (RHEL/CentOS pattern)"
else
test_info "PHP-FPM uses custom user(s)"
fi
else
test_warn "No PHP-FPM processes found"
fi
# Check Apache processes
APACHE_USERS=$(ps aux | grep -E "httpd|apache2" | grep -v "grep\|root" | awk '{print $1}' | sort -u | head -5)
if [ -n "$APACHE_USERS" ]; then
test_pass "Found Apache processes running as:"
echo "$APACHE_USERS" >> "$RESULTS_FILE"
else
test_warn "No Apache processes found"
fi
################################################################################
# TEST 9: Cron System
################################################################################
section_header "TEST 9: Cron System"
if command -v crontab &> /dev/null; then
test_pass "crontab command available"
# Check for plesk bin cron command
if plesk bin cron --help &> /dev/null 2>&1; then
test_pass "plesk bin cron command available (Plesk custom cron management)"
test_warn "IMPORTANT: Plesk may use its own cron system - verify which to use"
else
test_info "plesk bin cron not available - using standard cron"
fi
# Check standard cron directory
if [ -d "/var/spool/cron" ]; then
test_pass "Standard cron spool directory exists: /var/spool/cron"
elif [ -d "/var/spool/cron/crontabs" ]; then
test_pass "Standard cron spool directory exists: /var/spool/cron/crontabs"
else
test_warn "Standard cron spool directory not found"
fi
# Try to read a cron for test owner
if [ -n "$TEST_OWNER" ]; then
if crontab -u "$TEST_OWNER" -l &> /dev/null; then
test_pass "Can read standard crontab for user: $TEST_OWNER"
test_info "Crontab entries:"
crontab -u "$TEST_OWNER" -l 2>/dev/null | head -10 >> "$RESULTS_FILE"
else
test_warn "No standard crontab for user $TEST_OWNER"
fi
fi
else
test_fail "crontab command not available"
fi
################################################################################
# TEST 10: PHP Configuration
################################################################################
section_header "TEST 10: PHP Configuration"
# Check PHP versions
test_info "Checking available PHP versions:"
# Plesk-specific PHP locations
if [ -d "/opt/plesk/php" ]; then
test_pass "Plesk PHP directory exists: /opt/plesk/php"
test_info "Plesk PHP versions:"
ls -d /opt/plesk/php/*/ 2>/dev/null >> "$RESULTS_FILE"
fi
# System PHP versions
PHP_BINS=$(find /usr/bin /opt -name "php" -o -name "php[0-9]*" 2>/dev/null | grep -E "php[0-9]|php$" | head -10)
if [ -n "$PHP_BINS" ]; then
test_info "Available PHP binaries:"
echo "$PHP_BINS" >> "$RESULTS_FILE"
fi
# Check PHP-FPM pools
if [ -d "/etc/php-fpm.d" ]; then
test_pass "PHP-FPM pool directory exists: /etc/php-fpm.d"
POOL_COUNT=$(ls /etc/php-fpm.d/*.conf 2>/dev/null | wc -l)
test_info "Found $POOL_COUNT PHP-FPM pool config(s)"
elif [ -d "/etc/php/*/fpm/pool.d" ]; then
test_pass "PHP-FPM pool directory exists (Debian/Ubuntu pattern)"
fi
# Check how domain selects PHP version
if [ -n "$TEST_DOMAIN" ]; then
test_info "Checking PHP handler for $TEST_DOMAIN:"
# Try plesk bin command
PHP_HANDLER=$(plesk bin site -i "$TEST_DOMAIN" 2>/dev/null | grep -i "php")
if [ -n "$PHP_HANDLER" ]; then
test_pass "Retrieved PHP handler info via plesk bin site"
echo "$PHP_HANDLER" >> "$RESULTS_FILE"
else
test_warn "Could not retrieve PHP handler info"
fi
fi
################################################################################
# TEST 11: WordPress Detection
################################################################################
section_header "TEST 11: WordPress Detection"
test_info "Searching for WordPress installations..."
WP_SITES=$(find /var/www/vhosts -maxdepth 3 -name "wp-config.php" -type f 2>/dev/null | head -10)
if [ -n "$WP_SITES" ]; then
WP_COUNT=$(echo "$WP_SITES" | wc -l)
test_pass "Found $WP_COUNT WordPress installation(s)"
# Test path pattern
FIRST_WP=$(echo "$WP_SITES" | head -1)
test_info "Sample WordPress path: $FIRST_WP"
# Verify it matches expected pattern: /var/www/vhosts/DOMAIN/httpdocs/wp-config.php
if echo "$FIRST_WP" | grep -qE "^/var/www/vhosts/[^/]+/httpdocs/wp-config.php$"; then
test_pass "WordPress path matches expected pattern: /var/www/vhosts/DOMAIN/httpdocs/wp-config.php"
test_pass "VERIFIED: WordPress detection pattern works"
else
test_warn "WordPress path doesn't match expected pattern (may be in subdirectory)"
test_info "Actual pattern found: $FIRST_WP"
fi
# Extract domain from path
WP_DOMAIN=$(echo "$FIRST_WP" | grep -oE '/vhosts/[^/]+' | sed 's|/vhosts/||')
test_info "Extracted domain from path: $WP_DOMAIN"
# Try to lookup owner
WP_OWNER=$(plesk bin subscription --info "$WP_DOMAIN" 2>/dev/null | grep -i "^Owner:" | awk '{print $2}')
if [ -n "$WP_OWNER" ]; then
test_info "WordPress site owner: $WP_OWNER"
fi
else
test_warn "No WordPress installations found (this is OK if none installed)"
fi
################################################################################
# TEST 12: Apache/Web Server Configuration
################################################################################
section_header "TEST 12: Apache/Web Server Configuration"
# Check Apache/httpd config
if [ -d "/etc/httpd/conf.d" ]; then
test_pass "Apache conf.d directory exists: /etc/httpd/conf.d"
elif [ -d "/etc/apache2/sites-enabled" ]; then
test_pass "Apache sites-enabled directory exists: /etc/apache2/sites-enabled"
fi
# Check for Plesk Apache configs
if [ -d "/usr/local/psa/admin/conf" ]; then
test_pass "Plesk admin conf directory exists"
fi
# Check if Apache or nginx
if ps aux | grep -v grep | grep -q "nginx"; then
test_info "System is using nginx"
if ps aux | grep -v grep | grep -q "httpd\|apache"; then
test_info "System is using nginx + Apache (Plesk typical setup)"
fi
elif ps aux | grep -v grep | grep -q "httpd\|apache"; then
test_info "System is using Apache only"
fi
################################################################################
# SUMMARY
################################################################################
section_header "VALIDATION SUMMARY"
TOTAL=$((PASS + FAIL + WARN))
echo ""
echo "======================================================================="
echo "RESULTS SUMMARY"
echo "======================================================================="
echo -e "${GREEN}PASS: $PASS${NC}"
echo -e "${RED}FAIL: $FAIL${NC}"
echo -e "${YELLOW}WARN: $WARN${NC}"
echo "TOTAL TESTS: $TOTAL"
echo ""
cat >> "$RESULTS_FILE" <<EOF
======================================================================
RESULTS SUMMARY
======================================================================
PASS: $PASS
FAIL: $FAIL
WARN: $WARN
TOTAL TESTS: $TOTAL
Completed: $(date)
EOF
if [ $FAIL -eq 0 ]; then
echo -e "${GREEN}✓ ALL CRITICAL TESTS PASSED${NC}"
echo "✓ ALL CRITICAL TESTS PASSED" >> "$RESULTS_FILE"
echo ""
echo "Plesk appears to match all our assumptions!"
else
echo -e "${RED}✗ SOME TESTS FAILED - REVIEW RESULTS${NC}"
echo "✗ SOME TESTS FAILED - REVIEW RESULTS" >> "$RESULTS_FILE"
fi
echo ""
echo "Full results saved to: $RESULTS_FILE"
echo ""
echo "======================================================================="
echo "CRITICAL ITEMS TO VERIFY:"
echo "======================================================================="
echo "1. Database prefix pattern (appears to be NO PREFIX)"
echo "2. System user for cron jobs (check PHP-FPM user vs www-data)"
echo "3. Cron system (standard vs plesk bin cron)"
echo "4. PHP handler configuration per domain"
echo "======================================================================="
exit 0