2ea2bc36ce
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.
422 lines
16 KiB
Bash
Executable File
422 lines
16 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
###############################################################################
|
|
# TEST LAUNCHER - Cross-Platform Verification
|
|
# Tests multi-platform reference database building without modifying launcher.sh
|
|
###############################################################################
|
|
|
|
# Get script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
export TOOLKIT_BASE_DIR="$SCRIPT_DIR"
|
|
|
|
# Source libraries
|
|
LIB_DIR="$SCRIPT_DIR/lib"
|
|
source "$LIB_DIR/common-functions.sh"
|
|
source "$LIB_DIR/system-detect.sh"
|
|
source "$LIB_DIR/domain-discovery.sh"
|
|
source "$LIB_DIR/user-manager.sh"
|
|
|
|
# Test database location
|
|
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
|
|
###############################################################################
|
|
|
|
build_domains_cpanel_test() {
|
|
print_info "Using cPanel-optimized domain discovery..."
|
|
|
|
local users=($(list_all_users))
|
|
local current=0
|
|
local total=0
|
|
|
|
# Count domains
|
|
for user in "${users[@]}"; do
|
|
local userdata_dir="${SYS_CPANEL_USERDATA_DIR:-/var/cpanel/userdata}/${user}"
|
|
if [ -d "$userdata_dir" ]; then
|
|
total=$((total + $(find "$userdata_dir" -type f ! -name "*.cache" ! -name "*.yaml" ! -name "*.json" ! -name "main*" ! -name "cache" ! -name "*_SSL" 2>/dev/null | wc -l)))
|
|
fi
|
|
done
|
|
|
|
# Process domains
|
|
declare -A seen_domains
|
|
for user in "${users[@]}"; do
|
|
local userdata_dir="${SYS_CPANEL_USERDATA_DIR:-/var/cpanel/userdata}/${user}"
|
|
|
|
if [ -d "$userdata_dir" ]; then
|
|
for config_file in "$userdata_dir"/*; do
|
|
[ ! -f "$config_file" ] && continue
|
|
local basename=$(basename "$config_file")
|
|
|
|
# Skip cache files
|
|
[[ "$basename" =~ \.cache$|\.yaml$|\.json$|^main|^cache$|_SSL$ ]] && continue
|
|
|
|
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)
|
|
|
|
# Determine if primary domain
|
|
local is_primary="no"
|
|
local primary_domain=$(get_user_domains "$user" | head -1)
|
|
[ "$domain" = "$primary_domain" ] && is_primary="yes"
|
|
|
|
# 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() {
|
|
print_info "Using Plesk-specific domain discovery..."
|
|
|
|
local all_domains=$(list_all_domains)
|
|
local domain_count=$(echo "$all_domains" | wc -w)
|
|
local current=0
|
|
|
|
for domain in $all_domains; do
|
|
[ -z "$domain" ] && continue
|
|
((current++))
|
|
|
|
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")
|
|
local docroot=$(get_domain_docroot "$domain" || echo "")
|
|
local logdir=$(get_domain_logdir "$domain" || echo "")
|
|
local access_log=$(get_domain_access_log "$domain" || echo "")
|
|
|
|
# Try to get PHP version if plesk helper exists
|
|
local php_version=""
|
|
if type plesk_get_php_version >/dev/null 2>&1; then
|
|
php_version=$(plesk_get_php_version "$domain" || echo "")
|
|
fi
|
|
|
|
# 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
|
|
}
|
|
|
|
build_domains_standalone_test() {
|
|
print_info "Using standalone domain discovery..."
|
|
|
|
local all_domains=$(list_all_domains)
|
|
local domain_count=$(echo "$all_domains" | wc -w)
|
|
local current=0
|
|
|
|
if [ -z "$all_domains" ]; then
|
|
print_warning "No domains found via directory scanning"
|
|
return
|
|
fi
|
|
|
|
for domain in $all_domains; do
|
|
[ -z "$domain" ] && continue
|
|
((current++))
|
|
|
|
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 "")
|
|
|
|
# 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
|
|
}
|
|
|
|
###############################################################################
|
|
# MAIN TEST FUNCTION
|
|
###############################################################################
|
|
|
|
test_reference_database() {
|
|
local start_time=$(date +%s)
|
|
|
|
print_header "Cross-Platform Reference Database Test"
|
|
echo ""
|
|
|
|
# Show detected platform
|
|
print_info "Detected Platform: $SYS_CONTROL_PANEL"
|
|
print_info "OS: $SYS_OS_TYPE $SYS_OS_VERSION"
|
|
print_info "Web Server: $SYS_WEB_SERVER $SYS_WEB_SERVER_VERSION"
|
|
print_info "Database: $SYS_DB_TYPE $SYS_DB_VERSION"
|
|
print_info "User Home Base: $SYS_USER_HOME_BASE"
|
|
print_info "Log Directory: $SYS_LOG_DIR"
|
|
echo ""
|
|
|
|
# Initialize test database
|
|
print_info "Building test reference database..."
|
|
echo "# Test System Reference Database" > "$TEST_SYSREF_DB"
|
|
echo "# Platform: $SYS_CONTROL_PANEL" >> "$TEST_SYSREF_DB"
|
|
echo "# Generated: $(date)" >> "$TEST_SYSREF_DB"
|
|
echo "" >> "$TEST_SYSREF_DB"
|
|
|
|
# Test users
|
|
echo "[USERS]" >> "$TEST_SYSREF_DB"
|
|
local users=($(list_all_users))
|
|
print_info "Found ${#users[@]} users"
|
|
for user in "${users[@]}"; do
|
|
echo "USER|$user" >> "$TEST_SYSREF_DB"
|
|
done
|
|
echo "" >> "$TEST_SYSREF_DB"
|
|
|
|
# Test domains - platform-specific
|
|
echo "[DOMAINS]" >> "$TEST_SYSREF_DB"
|
|
case "$SYS_CONTROL_PANEL" in
|
|
cpanel)
|
|
build_domains_cpanel_test
|
|
;;
|
|
plesk)
|
|
build_domains_plesk_test
|
|
;;
|
|
interworx)
|
|
print_warning "InterWorx support not yet implemented in test"
|
|
build_domains_standalone_test
|
|
;;
|
|
*)
|
|
build_domains_standalone_test
|
|
;;
|
|
esac
|
|
echo "" >> "$TEST_SYSREF_DB"
|
|
|
|
# Test databases
|
|
echo "[DATABASES]" >> "$TEST_SYSREF_DB"
|
|
if [ "$SYS_DB_TYPE" != "none" ]; then
|
|
local all_dbs=$(mysql -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$" || true)
|
|
local db_count=$(echo "$all_dbs" | wc -l)
|
|
print_info "Found $db_count databases"
|
|
for db in $all_dbs; do
|
|
local owner=$(get_database_owner "$db" || echo "unknown")
|
|
echo "DB|$db|$owner" >> "$TEST_SYSREF_DB"
|
|
done
|
|
fi
|
|
echo "" >> "$TEST_SYSREF_DB"
|
|
|
|
# Save timestamp
|
|
date +%s > "$TEST_SYSREF_TIMESTAMP"
|
|
|
|
local end_time=$(date +%s)
|
|
local duration=$((end_time - start_time))
|
|
|
|
echo ""
|
|
print_success "Test database built in ${duration}s"
|
|
print_info "Test database location: $TEST_SYSREF_DB"
|
|
echo ""
|
|
|
|
# Show statistics
|
|
local user_count=$(grep -c "^USER|" "$TEST_SYSREF_DB" 2>/dev/null || echo 0)
|
|
local domain_count=$(grep -c "^DOMAIN|" "$TEST_SYSREF_DB" 2>/dev/null || echo 0)
|
|
local db_count=$(grep -c "^DB|" "$TEST_SYSREF_DB" 2>/dev/null || echo 0)
|
|
|
|
print_header "Test Results"
|
|
echo " Users: $user_count"
|
|
echo " Domains: $domain_count"
|
|
echo " Databases: $db_count"
|
|
echo ""
|
|
|
|
# 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 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 " Type: $domain_type"
|
|
echo " Status: HTTP=$http_code HTTPS=$https_code ($status_summary)"
|
|
echo ""
|
|
done
|
|
fi
|
|
|
|
# Compare with production database if it exists
|
|
if [ -f "$TOOLKIT_BASE_DIR/.sysref" ]; then
|
|
echo ""
|
|
print_header "Comparison with Production Database"
|
|
|
|
local prod_users=$(grep -c "^USER|" "$TOOLKIT_BASE_DIR/.sysref" 2>/dev/null || echo 0)
|
|
local prod_domains=$(grep -c "^DOMAIN|" "$TOOLKIT_BASE_DIR/.sysref" 2>/dev/null || echo 0)
|
|
local prod_dbs=$(grep -c "^DB|" "$TOOLKIT_BASE_DIR/.sysref" 2>/dev/null || echo 0)
|
|
|
|
echo " Production: $prod_users users, $prod_domains domains, $prod_dbs databases"
|
|
echo " Test: $user_count users, $domain_count domains, $db_count databases"
|
|
echo ""
|
|
|
|
if [ "$user_count" -eq "$prod_users" ] && [ "$domain_count" -eq "$prod_domains" ]; then
|
|
print_success "✅ Counts match! Test successful."
|
|
else
|
|
print_warning "⚠️ Counts differ - this may be expected for cross-platform changes"
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
print_info "Test database saved to: $TEST_SYSREF_DB"
|
|
print_info "You can inspect it with: cat $TEST_SYSREF_DB"
|
|
}
|
|
|
|
###############################################################################
|
|
# RUN TEST
|
|
###############################################################################
|
|
|
|
# Clear screen and run
|
|
clear
|
|
test_reference_database
|
|
|
|
# Instructions
|
|
echo ""
|
|
print_header "Next Steps"
|
|
echo "1. Review the test database: cat $TEST_SYSREF_DB"
|
|
echo "2. If results look good on this cPanel server, test on Plesk:"
|
|
echo " - git pull on Plesk server"
|
|
echo " - bash test-launcher.sh"
|
|
echo " - Verify domains/users/databases are detected"
|
|
echo "3. If Plesk test succeeds, we can integrate into main launcher"
|
|
echo ""
|