#!/bin/bash ################################################################################ # InterWorx Validation Script # Purpose: Verify all assumptions about InterWorx file system, commands, and paths # Run this on a real InterWorx server to validate our refactoring ################################################################################ set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" RESULTS_FILE="/tmp/interworx-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 "INTERWORX VALIDATION SCRIPT" echo "=======================================================================" echo "This script will verify all assumptions about InterWorx" echo "Results will be saved to: $RESULTS_FILE" echo "" echo "Started: $(date)" echo "=======================================================================" echo "" # Initialize results file cat > "$RESULTS_FILE" <> "$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/interworx" ]; then test_pass "InterWorx installation directory exists: /usr/local/interworx" else test_fail "InterWorx installation directory NOT found: /usr/local/interworx" fi if [ -f "/usr/local/interworx/iworx.ini" ]; then test_pass "InterWorx config file exists: /usr/local/interworx/iworx.ini" IW_VERSION=$(grep -i "^version" /usr/local/interworx/iworx.ini 2>/dev/null | cut -d'=' -f2 | tr -d ' ') test_info "InterWorx version: $IW_VERSION" else test_fail "InterWorx config file NOT found" fi ################################################################################ # TEST 2: File System Structure ################################################################################ section_header "TEST 2: File System Structure" # Find a test user (first user in /home with a domain structure) TEST_USER="" TEST_DOMAIN="" for user_dir in /home/*; do if [ -d "$user_dir" ]; then username=$(basename "$user_dir") # Skip system accounts if [[ "$username" != "lost+found" ]] && [[ "$username" != "aquota.user" ]]; then # Look for domain structure domain_dir=$(find "$user_dir" -maxdepth 1 -type d -name "*.com" 2>/dev/null | head -1) if [ -n "$domain_dir" ]; then TEST_USER="$username" TEST_DOMAIN=$(basename "$domain_dir") break fi fi fi done if [ -n "$TEST_USER" ] && [ -n "$TEST_DOMAIN" ]; then test_pass "Found test user: $TEST_USER with domain: $TEST_DOMAIN" # Test document root path EXPECTED_DOCROOT="/home/$TEST_USER/$TEST_DOMAIN/html" if [ -d "$EXPECTED_DOCROOT" ]; then test_pass "Document root exists: $EXPECTED_DOCROOT" else test_fail "Document root NOT found: $EXPECTED_DOCROOT" fi # Test log directory EXPECTED_LOG_DIR="/home/$TEST_USER/var/$TEST_DOMAIN/logs" if [ -d "$EXPECTED_LOG_DIR" ]; then test_pass "Log directory exists: $EXPECTED_LOG_DIR" # Check for specific log files if [ -f "$EXPECTED_LOG_DIR/access_log" ]; then test_pass "Access log exists: $EXPECTED_LOG_DIR/access_log" else test_warn "Access log NOT found (may not have traffic yet)" fi if [ -f "$EXPECTED_LOG_DIR/error_log" ]; then test_pass "Error log exists: $EXPECTED_LOG_DIR/error_log" else test_warn "Error log NOT found (may not have errors yet)" fi # List all log files found test_info "Log files in directory:" ls -lh "$EXPECTED_LOG_DIR" >> "$RESULTS_FILE" 2>&1 else test_fail "Log directory NOT found: $EXPECTED_LOG_DIR" fi # Test var directory structure if [ -d "/home/$TEST_USER/var" ]; then test_pass "User var directory exists: /home/$TEST_USER/var" test_info "Domains under var directory:" ls -d "/home/$TEST_USER/var"/*/ 2>/dev/null >> "$RESULTS_FILE" else test_fail "User var directory NOT found: /home/$TEST_USER/var" fi else test_warn "No test user/domain found - cannot test file structure" test_info "Available users in /home:" ls -d /home/*/ 2>/dev/null >> "$RESULTS_FILE" fi ################################################################################ # TEST 3: Virtual Host Configuration ################################################################################ section_header "TEST 3: Virtual Host Configuration" if [ -d "/etc/httpd/conf.d" ]; then test_pass "Apache conf.d directory exists: /etc/httpd/conf.d" # Find vhost configs VHOST_CONFIGS=$(find /etc/httpd/conf.d -name "vhost_*.conf" 2>/dev/null) if [ -n "$VHOST_CONFIGS" ]; then VHOST_COUNT=$(echo "$VHOST_CONFIGS" | wc -l) test_pass "Found $VHOST_COUNT vhost config files" # Test first vhost config structure FIRST_VHOST=$(echo "$VHOST_CONFIGS" | head -1) test_info "Testing vhost config: $FIRST_VHOST" if grep -q "ServerName" "$FIRST_VHOST"; then test_pass "ServerName directive found in vhost config" else test_fail "ServerName directive NOT found in vhost config" fi if grep -q "SuexecUserGroup" "$FIRST_VHOST"; then test_pass "SuexecUserGroup directive found in vhost config" else test_fail "SuexecUserGroup directive NOT found in vhost config" fi else test_fail "No vhost_*.conf files found in /etc/httpd/conf.d" fi else test_fail "Apache conf.d directory NOT found: /etc/httpd/conf.d" fi ################################################################################ # TEST 4: Domain → User Mapping ################################################################################ section_header "TEST 4: Domain → User Mapping" if [ -n "$TEST_DOMAIN" ]; then test_info "Testing domain→user lookup for: $TEST_DOMAIN" # Method: grep vhost configs for ServerName, then extract SuexecUserGroup FOUND_USER=$(grep -l "ServerName $TEST_DOMAIN" /etc/httpd/conf.d/vhost_*.conf 2>/dev/null | \ xargs grep "SuexecUserGroup" 2>/dev/null | head -1 | awk '{print $2}') if [ -n "$FOUND_USER" ]; then test_pass "Domain→User lookup successful: $TEST_DOMAIN → $FOUND_USER" if [ "$FOUND_USER" = "$TEST_USER" ]; then test_pass "Lookup returned correct user (matches expected: $TEST_USER)" else test_fail "Lookup returned wrong user: got $FOUND_USER, expected $TEST_USER" fi else test_fail "Domain→User lookup failed for: $TEST_DOMAIN" fi else test_warn "No test domain available for lookup test" fi ################################################################################ # TEST 5: User → Domains Mapping ################################################################################ section_header "TEST 5: User → Domains Mapping" if [ -n "$TEST_USER" ]; then test_info "Testing user→domains lookup for: $TEST_USER" # Method 1: From vhost configs USER_DOMAINS_VHOST=$(grep "SuexecUserGroup $TEST_USER" /etc/httpd/conf.d/vhost_*.conf 2>/dev/null -l | \ xargs grep "ServerName" 2>/dev/null | awk '{print $2}' | sort -u) if [ -n "$USER_DOMAINS_VHOST" ]; then DOMAIN_COUNT=$(echo "$USER_DOMAINS_VHOST" | wc -l) test_pass "Method 1 (vhost configs): Found $DOMAIN_COUNT domain(s) for user $TEST_USER" test_info "Domains from vhost configs:" echo "$USER_DOMAINS_VHOST" >> "$RESULTS_FILE" else test_fail "Method 1 (vhost configs): No domains found" fi # Method 2: From filesystem USER_DOMAINS_FS=$(find "/home/$TEST_USER" -maxdepth 1 -type d -name "*.com" -o -name "*.net" -o -name "*.org" 2>/dev/null | \ xargs -n1 basename 2>/dev/null | sort -u) if [ -n "$USER_DOMAINS_FS" ]; then DOMAIN_COUNT_FS=$(echo "$USER_DOMAINS_FS" | wc -l) test_pass "Method 2 (filesystem): Found $DOMAIN_COUNT_FS domain(s) for user $TEST_USER" test_info "Domains from filesystem:" echo "$USER_DOMAINS_FS" >> "$RESULTS_FILE" else test_fail "Method 2 (filesystem): No domains found" fi # Compare methods if [ "$USER_DOMAINS_VHOST" = "$USER_DOMAINS_FS" ]; then test_pass "Both methods return identical domain lists" else test_warn "Methods return different domain lists (may be normal)" fi else test_warn "No test user available for user→domains test" fi ################################################################################ # TEST 6: Database Prefix Pattern ################################################################################ section_header "TEST 6: Database Prefix Pattern" test_info "Checking database naming conventions..." # Try to connect to MySQL/MariaDB if command -v mysql &> /dev/null; then # Get database list DB_LIST=$(mysql -e "SHOW DATABASES;" 2>/dev/null | grep -v "Database\|information_schema\|performance_schema\|mysql") if [ -n "$DB_LIST" ]; then test_pass "Successfully connected to database and retrieved database list" test_info "Sample databases:" echo "$DB_LIST" | head -10 >> "$RESULTS_FILE" # Check for username_ prefix pattern if [ -n "$TEST_USER" ]; then USER_DBS=$(echo "$DB_LIST" | grep "^${TEST_USER}_") if [ -n "$USER_DBS" ]; then DB_COUNT=$(echo "$USER_DBS" | wc -l) test_pass "VERIFIED: Found $DB_COUNT database(s) with username_ prefix pattern: ${TEST_USER}_*" test_info "Databases for user $TEST_USER:" echo "$USER_DBS" >> "$RESULTS_FILE" test_pass "DATABASE PREFIX PATTERN CONFIRMED: username_dbname (same as cPanel)" else test_warn "No databases found with ${TEST_USER}_ prefix" fi fi # Check if any databases DON'T follow username_ pattern NO_PREFIX_DBS=$(echo "$DB_LIST" | grep -v "_" | grep -v "test") if [ -n "$NO_PREFIX_DBS" ]; then test_warn "Found databases without underscore (may not follow username_ pattern):" echo "$NO_PREFIX_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 7: Cron System ################################################################################ section_header "TEST 7: Cron System" if command -v crontab &> /dev/null; then test_pass "crontab command available" if [ -n "$TEST_USER" ]; then # Try to list user crontab if crontab -u "$TEST_USER" -l &> /dev/null; then test_pass "Can read crontab for user: $TEST_USER" test_info "User crontab entries:" crontab -u "$TEST_USER" -l 2>/dev/null | head -20 >> "$RESULTS_FILE" else test_warn "No crontab for user $TEST_USER (or permission denied)" fi fi # Check cron directory if [ -d "/var/spool/cron" ]; then test_pass "Standard cron spool directory exists: /var/spool/cron" else test_warn "Standard cron spool directory not found" fi else test_fail "crontab command not available" fi ################################################################################ # TEST 8: PHP Configuration ################################################################################ section_header "TEST 8: PHP Configuration" # Check PHP versions test_info "Checking available PHP versions:" PHP_BINS=$(find /usr/bin /opt -name "php*" -type f 2>/dev/null | grep -E "php[0-9]" | head -10) if [ -n "$PHP_BINS" ]; then echo "$PHP_BINS" >> "$RESULTS_FILE" fi # Check for 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)" else test_warn "PHP-FPM pool directory not found: /etc/php-fpm.d" fi # Check vhost for PHP handler configuration if [ -n "$FIRST_VHOST" ]; then if grep -qi "php" "$FIRST_VHOST"; then test_info "PHP configuration found in vhost config" grep -i "php" "$FIRST_VHOST" | head -5 >> "$RESULTS_FILE" else test_warn "No PHP configuration visible in vhost config" fi fi ################################################################################ # TEST 9: WordPress Detection ################################################################################ section_header "TEST 9: WordPress Detection" test_info "Searching for WordPress installations..." WP_SITES=$(find /home -maxdepth 4 -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: /home/USER/DOMAIN/html/wp-config.php if echo "$FIRST_WP" | grep -qE "^/home/[^/]+/[^/]+/html/wp-config.php$"; then test_pass "WordPress path matches expected pattern: /home/USER/DOMAIN/html/wp-config.php" else test_warn "WordPress path doesn't match expected pattern" fi # Extract user and domain from path WP_USER=$(echo "$FIRST_WP" | cut -d'/' -f3) WP_DOMAIN=$(echo "$FIRST_WP" | cut -d'/' -f4) test_info "Extracted from path - User: $WP_USER, Domain: $WP_DOMAIN" else test_warn "No WordPress installations found (this is OK if none installed)" fi ################################################################################ # TEST 10: InterWorx CLI Tools ################################################################################ section_header "TEST 10: InterWorx CLI Tools" if [ -d "/usr/local/interworx/bin" ]; then test_pass "InterWorx bin directory exists: /usr/local/interworx/bin" test_info "Available InterWorx commands:" ls /usr/local/interworx/bin | head -20 >> "$RESULTS_FILE" else test_warn "InterWorx bin directory not found" fi # Check for nodeworx CLI if command -v nodeworx &> /dev/null; then test_pass "nodeworx command available" else test_warn "nodeworx command not found" fi if command -v siteworx &> /dev/null; then test_pass "siteworx command available" else test_warn "siteworx command not found" 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" <> "$RESULTS_FILE" echo "" echo "InterWorx 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 "=======================================================================" exit 0