Revert "Fix WordPress path parsing for multi-panel support in reference-db.sh"

This reverts commit c9e70a35c3.
This commit is contained in:
cschantz
2025-12-23 21:22:38 -05:00
parent 65c523f005
commit 316a35f93c
2 changed files with 160 additions and 81 deletions
-27
View File
@@ -1,27 +0,0 @@
build_domains_section() {
echo "[DOMAINS]" >> "$SYSREF_DB"
# Use unified 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 "Processing domains..."
# Get domain information using unified functions
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 "")
# Simple domain entry - Format: DOMAIN|domain|owner|docroot|logdir|access_log
echo "DOMAIN|$domain|$owner|$docroot|$logdir|$access_log" >> "$SYSREF_DB"
done
finish_progress
echo "" >> "$SYSREF_DB"
}
Regular → Executable
+148 -42
View File
@@ -11,7 +11,6 @@ if [ -z "$TOOLKIT_BASE_DIR" ]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/common-functions.sh" source "$SCRIPT_DIR/common-functions.sh"
source "$SCRIPT_DIR/system-detect.sh" source "$SCRIPT_DIR/system-detect.sh"
source "$SCRIPT_DIR/domain-discovery.sh"
source "$SCRIPT_DIR/user-manager.sh" source "$SCRIPT_DIR/user-manager.sh"
fi fi
@@ -245,28 +244,157 @@ check_domain_status() {
build_domains_section() { build_domains_section() {
echo "[DOMAINS]" >> "$SYSREF_DB" echo "[DOMAINS]" >> "$SYSREF_DB"
# Use unified domain discovery # Track domains we've already added
local all_domains=$(list_all_domains) declare -A seen_domains
local domain_count=$(echo "$all_domains" | wc -w)
local current=0 local users=($(list_all_users))
# Count total domains for progress
local total_domains=0
for user in "${users[@]}"; do
local userdata_dir="${SYS_CPANEL_USERDATA_DIR:-/var/cpanel/userdata}/${user}"
if [ -d "$userdata_dir" ]; then
total_domains=$((total_domains + $(find "$userdata_dir" -type f ! -name "*.cache" ! -name "*.yaml" ! -name "*.json" ! -name "main*" ! -name "cache" ! -name "*_SSL" 2>/dev/null | wc -l)))
fi
done
local current_domain=0
# Get detailed domain information from cPanel userdata (if available)
for user in "${users[@]}"; do
local userdata_dir="${SYS_CPANEL_USERDATA_DIR:-/var/cpanel/userdata}/${user}"
if [ -d "$userdata_dir" ]; then
# Parse each domain configuration file in userdata
for config_file in "$userdata_dir"/*; do
[ ! -f "$config_file" ] && continue
local basename=$(basename "$config_file")
# Skip cache files and special files
[[ "$basename" =~ \.cache$ ]] && continue
[[ "$basename" =~ \.yaml$ ]] && continue
[[ "$basename" =~ \.json$ ]] && continue
[[ "$basename" =~ ^main ]] && continue
[[ "$basename" =~ ^cache$ ]] && continue
[[ "$basename" =~ _SSL$ ]] && continue
# Extract domain info from config
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, skip aliases/subdomains)
current_domain=$((current_domain + 1))
local http_code="000"
local https_code="000"
local status_summary="skipped"
if [ "$domain_type" = "primary" ] || [ "$domain_type" = "addon" ]; then
show_progress $current_domain $total_domains "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" >> "$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" >> "$SYSREF_DB"
seen_domains["$alias"]=1
done
fi
done
else
# Fallback for non-cPanel or if userdata not available
local primary_domain=$(get_user_domains "$user" | head -1)
local all_domains=$(get_user_domains "$user")
for domain in $all_domains; do for domain in $all_domains; do
[ -z "$domain" ] && continue [ -z "$domain" ] && continue
((current++)) [ -n "${seen_domains[$domain]:-}" ] && continue
show_progress $current $domain_count "Processing domains..." local is_primary="no"
[ "$domain" = "$primary_domain" ] && is_primary="yes"
# Get domain information using unified functions # Find log path
local owner=$(get_domain_owner "$domain" || echo "unknown") local log_path="${SYS_LOG_DIR}/${domain}"
local docroot=$(get_domain_docroot "$domain" || echo "") [ ! -f "$log_path" ] && log_path="${SYS_LOG_DIR}/${domain}.log"
local logdir=$(get_domain_logdir "$domain" || echo "")
local access_log=$(get_domain_access_log "$domain" || echo "")
# Simple domain entry - Format: DOMAIN|domain|owner|docroot|logdir|access_log # Check status for non-cPanel domains
echo "DOMAIN|$domain|$owner|$docroot|$logdir|$access_log" >> "$SYSREF_DB" current_domain=$((current_domain + 1))
show_progress $current_domain $total_domains "Checking domain status codes..."
local status_result=$(check_domain_status "$domain")
IFS='|' read -r http_code https_code status_summary <<< "$status_result"
# Simple format for non-cPanel (with status codes)
echo "DOMAIN|$domain|$user||$log_path||$is_primary|local||$http_code|$https_code|$status_summary" >> "$SYSREF_DB"
seen_domains["$domain"]=1
done
fi
done done
finish_progress finish_progress
# Check /etc/localdomains (cPanel local domains not yet added)
if [ -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" >> "$SYSREF_DB"
seen_domains["$domain"]=1
done < /etc/localdomains
fi
# Check /etc/remotedomains (cPanel remote MX domains - no status check for remote MX)
if [ -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" >> "$SYSREF_DB"
seen_domains["$domain"]=1
done < /etc/remotedomains
fi
echo "" >> "$SYSREF_DB" echo "" >> "$SYSREF_DB"
} }
@@ -279,35 +407,14 @@ build_wordpress_section() {
for wp_config in $wp_configs; do for wp_config in $wp_configs; do
local wp_dir=$(dirname "$wp_config") local wp_dir=$(dirname "$wp_config")
# Extract username/domain from path (panel-agnostic) # Extract username from path (/home/username/...)
local username="" local username=$(echo "$wp_dir" | cut -d'/' -f3)
# Try to get domain from path - check if it's in a subdomain or addon domain folder
local path_after_home=$(echo "$wp_dir" | sed "s|^/home/$username/||")
local domain="" local domain=""
case "$SYS_CONTROL_PANEL" in # Check for common domain folder patterns
cpanel)
# cPanel: /home/username/...
username=$(echo "$wp_dir" | cut -d'/' -f3)
;;
plesk)
# Plesk: /var/www/vhosts/domain.com/...
domain=$(echo "$wp_dir" | cut -d'/' -f5)
username=$(get_domain_owner "$domain" 2>/dev/null || echo "unknown")
;;
interworx)
# InterWorx: /chroot/home/user/var/domain.com/...
username=$(echo "$wp_dir" | cut -d'/' -f4)
;;
*)
# Standalone: try to extract from path
username=$(stat -c "%U" "$wp_dir" 2>/dev/null || echo "unknown")
;;
esac
# If domain not set yet (cPanel/InterWorx/Standalone), try to infer from path
if [ -z "$domain" ] && [ "$SYS_CONTROL_PANEL" = "cpanel" ]; then
# cPanel: check if this is primary domain or addon/subdomain
local path_after_home=$(echo "$wp_dir" | sed "s|^/home/$username/||")
if [[ "$path_after_home" == public_html ]]; then if [[ "$path_after_home" == public_html ]]; then
# This is the primary domain - get it from user info # This is the primary domain - get it from user info
domain=$(grep "USER|${username}|" "$SYSREF_DB" 2>/dev/null | cut -d'|' -f3 || true) domain=$(grep "USER|${username}|" "$SYSREF_DB" 2>/dev/null | cut -d'|' -f3 || true)
@@ -319,7 +426,6 @@ build_wordpress_section() {
# Might be addon/parked domain with own directory # Might be addon/parked domain with own directory
domain=$(echo "$path_after_home" | cut -d'/' -f1) domain=$(echo "$path_after_home" | cut -d'/' -f1)
fi fi
fi
# Try to get actual domain from WP database options (more reliable) # Try to get actual domain from WP database options (more reliable)
local db_name=$(grep "DB_NAME" "$wp_config" | grep -oP "'[^']+'" 2>/dev/null | tail -1 | tr -d "'" || true) local db_name=$(grep "DB_NAME" "$wp_config" | grep -oP "'[^']+'" 2>/dev/null | tail -1 | tr -d "'" || true)