From 2ea2bc36cef14ce67c3aaa69b7089f9876dce590 Mon Sep 17 00:00:00 2001 From: cschantz Date: Wed, 24 Dec 2025 15:17:02 -0500 Subject: [PATCH] Fix test-launcher.sh to match production logic exactly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added missing production features to test-launcher.sh: 1. Domain Status Checking: - Added check_domain_status() function (HTTP/HTTPS curl requests) - cPanel: Status checks for primary/addon domains only - Plesk: Status checks for all domains - Standalone: Status checks for all domains - Uses 3-second timeouts per request 2. cPanel Additional Domain Sources: - Added /etc/localdomains check (local domains not in userdata) - Added /etc/remotedomains check (remote MX domains) - Wrapped in SYS_CONTROL_PANEL=cpanel conditional 3. Domain Type Detection: - primary: User's main domain - addon: Additional domains - subdomain: Subdomain of primary - alias: Server alias / www variant - local: From /etc/localdomains - remote: From /etc/remotedomains 4. Output Format Matching: - Changed from 7 fields to 12 fields to match production - Format: DOMAIN|domain|owner|docroot|logdir|php|is_primary|type|aliases|http|https|status - Updated sample display to show type and status codes 5. Server Aliases: - Extract serveralias from cPanel userdata - Add aliases as separate DOMAIN entries - Mark as type=alias with parent reference Testing Results: ✅ cPanel: 1 users, 4 domains, 1 databases (matches production) ✅ Completed in 7s (includes HTTP/HTTPS checks for 4 domains) ✅ Found all domains: pickledperil.com, www, 67-227-141-132.cprapid.com, cloudvpstemplate ✅ Status codes working: 200_OK, TIMEOUT detected correctly Ready for Plesk server testing. --- test-launcher.sh | 164 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 155 insertions(+), 9 deletions(-) diff --git a/test-launcher.sh b/test-launcher.sh index d4e821e..f4402fa 100755 --- a/test-launcher.sh +++ b/test-launcher.sh @@ -20,6 +20,67 @@ source "$LIB_DIR/user-manager.sh" TEST_SYSREF_DB="${TOOLKIT_BASE_DIR}/.sysref-test" TEST_SYSREF_TIMESTAMP="${TOOLKIT_BASE_DIR}/.sysref-test.timestamp" +############################################################################### +# DOMAIN STATUS CHECKING (from reference-db.sh) +############################################################################### + +# Returns: http_code|https_code|status_summary +check_domain_status() { + local domain="$1" + local http_code="000" + local https_code="000" + local status_summary="unchecked" + + # Skip if curl not available + if ! command -v curl &>/dev/null; then + echo "000|000|no_curl" + return 0 + fi + + # Skip obviously invalid domains + if [ -z "$domain" ] || [[ ! "$domain" =~ \. ]]; then + echo "000|000|invalid_domain" + return 0 + fi + + # Try HTTP (timeout 3 seconds, max 2 redirects, check for valid response) + http_code=$(timeout 3 curl -s -o /dev/null -w "%{http_code}" --max-redirs 2 -m 3 "http://$domain" 2>/dev/null) + if [ $? -ne 0 ] || [ -z "$http_code" ]; then + http_code="timeout" + fi + + # Try HTTPS (timeout 3 seconds, max 2 redirects, ignore cert errors) + https_code=$(timeout 3 curl -s -o /dev/null -w "%{http_code}" --max-redirs 2 -m 3 -k "https://$domain" 2>/dev/null) + if [ $? -ne 0 ] || [ -z "$https_code" ]; then + https_code="timeout" + fi + + # Determine overall status + if [ "$http_code" = "200" ] || [ "$https_code" = "200" ]; then + status_summary="200_OK" + elif [ "$http_code" = "403" ] || [ "$https_code" = "403" ]; then + status_summary="403_FORBIDDEN" + elif [ "$http_code" = "404" ] || [ "$https_code" = "404" ]; then + status_summary="404_NOT_FOUND" + elif [ "$http_code" = "500" ] || [ "$https_code" = "500" ]; then + status_summary="500_ERROR" + elif [ "$http_code" = "502" ] || [ "$https_code" = "502" ]; then + status_summary="502_BAD_GATEWAY" + elif [ "$http_code" = "503" ] || [ "$https_code" = "503" ]; then + status_summary="503_UNAVAILABLE" + elif [[ "$http_code" =~ ^30[0-9]$ ]] || [[ "$https_code" =~ ^30[0-9]$ ]]; then + status_summary="REDIRECT" + elif [ "$http_code" = "timeout" ] && [ "$https_code" = "timeout" ]; then + status_summary="TIMEOUT" + elif [ "$http_code" = "000" ] && [ "$https_code" = "000" ]; then + status_summary="UNREACHABLE" + else + status_summary="OTHER" + fi + + echo "${http_code}|${https_code}|${status_summary}" +} + ############################################################################### # PLATFORM-SPECIFIC DOMAIN BUILDERS ############################################################################### @@ -55,18 +116,92 @@ build_domains_cpanel_test() { local domain="$basename" local doc_root=$(grep "^documentroot:" "$config_file" | awk '{print $2}' || true) local log_path=$(grep "target:.*domlogs" "$config_file" | head -1 | awk '{print $2}' || true) + local server_alias=$(grep "^serveralias:" "$config_file" | awk '{print $2}' || true) local php_version=$(grep "^phpversion:" "$config_file" | awk '{print $2}' || true) - current=$((current + 1)) - show_progress $current $total "Processing cPanel domains..." + # Determine if primary domain + local is_primary="no" + local primary_domain=$(get_user_domains "$user" | head -1) + [ "$domain" = "$primary_domain" ] && is_primary="yes" - echo "DOMAIN|$domain|$user|$doc_root|$log_path|$php_version|cpanel" >> "$TEST_SYSREF_DB" + # Determine domain type (addon, parked, subdomain, primary) + local domain_type="addon" + if [ "$is_primary" = "yes" ]; then + domain_type="primary" + elif [[ "$domain" =~ \. ]] && [[ "$domain" =~ ^[^.]+\. ]]; then + # Check if it's a subdomain of the primary + local base_domain=$(echo "$domain" | rev | cut -d. -f1-2 | rev) + if [ "$base_domain" = "$primary_domain" ]; then + domain_type="subdomain" + fi + fi + + # Check HTTP/HTTPS status codes (only for primary and addon domains) + current=$((current + 1)) + local http_code="000" + local https_code="000" + local status_summary="skipped" + + if [ "$domain_type" = "primary" ] || [ "$domain_type" = "addon" ]; then + show_progress $current $total "Checking domain status codes..." + local status_result=$(check_domain_status "$domain") + IFS='|' read -r http_code https_code status_summary <<< "$status_result" + fi + + # Format: DOMAIN|domain|owner|doc_root|log_path|php_version|is_primary|type|aliases|http_code|https_code|status_summary + echo "DOMAIN|$domain|$user|$doc_root|$log_path|$php_version|$is_primary|$domain_type|$server_alias|$http_code|$https_code|$status_summary" >> "$TEST_SYSREF_DB" seen_domains["$domain"]=1 + + # Also add aliases as separate entries + if [ -n "$server_alias" ]; then + for alias in $server_alias; do + [ -z "$alias" ] && continue + [ -n "${seen_domains[$alias]:-}" ] && continue + + # Alias points to same document root and logs (inherit status from parent) + echo "DOMAIN|$alias|$user|$doc_root|$log_path|$php_version|no|alias|$domain|$http_code|$https_code|alias_of_$status_summary" >> "$TEST_SYSREF_DB" + seen_domains["$alias"]=1 + done + fi done fi done finish_progress + + # Check /etc/localdomains (cPanel local domains not yet added) + if [ "$SYS_CONTROL_PANEL" = "cpanel" ] && [ -f "/etc/localdomains" ]; then + while read -r domain; do + [ -z "$domain" ] && continue + [ -n "${seen_domains[$domain]:-}" ] && continue + + local owner=$(grep "^${domain}:" /etc/trueuserdomains 2>/dev/null | cut -d: -f2 | xargs || true) + [ -z "$owner" ] && owner="unknown" + + local log_path="${SYS_LOG_DIR}/${domain}" + + # Check status + local status_result=$(check_domain_status "$domain") + IFS='|' read -r http_code https_code status_summary <<< "$status_result" + + echo "DOMAIN|$domain|$owner||$log_path||unknown|local||$http_code|$https_code|$status_summary" >> "$TEST_SYSREF_DB" + seen_domains["$domain"]=1 + done < /etc/localdomains + fi + + # Check /etc/remotedomains (cPanel remote MX domains) + if [ "$SYS_CONTROL_PANEL" = "cpanel" ] && [ -f "/etc/remotedomains" ]; then + while read -r domain; do + [ -z "$domain" ] && continue + [ -n "${seen_domains[$domain]:-}" ] && continue + + local owner=$(grep "^${domain}:" /etc/trueuserdomains 2>/dev/null | cut -d: -f2 | xargs || true) + [ -z "$owner" ] && owner="unknown" + + echo "DOMAIN|$domain|$owner||||unknown|remote||000|000|remote_mx" >> "$TEST_SYSREF_DB" + seen_domains["$domain"]=1 + done < /etc/remotedomains + fi } build_domains_plesk_test() { @@ -80,7 +215,7 @@ build_domains_plesk_test() { [ -z "$domain" ] && continue ((current++)) - show_progress $current $domain_count "Processing Plesk domains..." + show_progress $current $domain_count "Checking domain status codes..." # Use panel-agnostic functions that call Plesk helpers local owner=$(get_domain_owner "$domain" || echo "unknown") @@ -94,7 +229,12 @@ build_domains_plesk_test() { php_version=$(plesk_get_php_version "$domain" || echo "") fi - echo "DOMAIN|$domain|$owner|$docroot|$logdir|$access_log|$php_version|plesk" >> "$TEST_SYSREF_DB" + # Check domain status + local status_result=$(check_domain_status "$domain") + IFS='|' read -r http_code https_code status_summary <<< "$status_result" + + # Format to match production + echo "DOMAIN|$domain|$owner|$docroot|$logdir|$php_version|unknown|local||$http_code|$https_code|$status_summary" >> "$TEST_SYSREF_DB" done finish_progress @@ -116,14 +256,19 @@ build_domains_standalone_test() { [ -z "$domain" ] && continue ((current++)) - show_progress $current $domain_count "Processing standalone domains..." + show_progress $current $domain_count "Checking domain status codes..." local docroot=$(get_domain_docroot "$domain" || echo "") local owner=$(get_domain_owner "$domain" || echo "unknown") local logdir=$(get_domain_logdir "$domain" || echo "") local access_log=$(get_domain_access_log "$domain" || echo "") - echo "DOMAIN|$domain|$owner|$docroot|$logdir|$access_log||standalone" >> "$TEST_SYSREF_DB" + # Check domain status + local status_result=$(check_domain_status "$domain") + IFS='|' read -r http_code https_code status_summary <<< "$status_result" + + # Format to match production + echo "DOMAIN|$domain|$owner|$docroot|$logdir||unknown|local||$http_code|$https_code|$status_summary" >> "$TEST_SYSREF_DB" done finish_progress @@ -221,11 +366,12 @@ test_reference_database() { # Show sample domains if [ "$domain_count" -gt 0 ]; then print_header "Sample Domain Entries (first 5)" - grep "^DOMAIN|" "$TEST_SYSREF_DB" | head -5 | while IFS='|' read -r type domain owner docroot logdir access_log php platform; do + grep "^DOMAIN|" "$TEST_SYSREF_DB" | head -5 | while IFS='|' read -r type domain owner docroot logdir php_version is_primary domain_type server_alias http_code https_code status_summary; do echo " Domain: $domain" echo " Owner: $owner" echo " Docroot: $docroot" - echo " Platform: $platform" + echo " Type: $domain_type" + echo " Status: HTTP=$http_code HTTPS=$https_code ($status_summary)" echo "" done fi