From 207c8257b710453556aeda463d54035a5387e0a0 Mon Sep 17 00:00:00 2001 From: cschantz Date: Thu, 20 Nov 2025 16:38:29 -0500 Subject: [PATCH] Remove testing directory and backup files - validation phase complete Validation phase successfully completed on production servers: - InterWorx: All 13 tests passed on real server - Plesk: All 15 tests passed on real server - All multi-panel assumptions verified - 38/38 modules validated Removed files: - testing/ directory (validation scripts, documentation, deployment tools) - modules/security/live-attack-monitor-v1.sh (old version) - modules/security/live-attack-monitor.sh.backup (local backup) - tmp/ contents (old runtime data) These files served their purpose during the validation phase and are no longer needed. All critical findings have been documented in REFDB_FORMAT.txt and incorporated into production code. Multi-panel support is now production-ready across all modules. --- modules/security/live-attack-monitor-v1.sh | 418 --------- testing/DEPLOYMENT.md | 289 ------ testing/README.md | 357 -------- testing/deploy-and-run.sh | 143 --- testing/validate-interworx.sh | 832 ------------------ testing/validate-plesk.sh | 972 --------------------- 6 files changed, 3011 deletions(-) delete mode 100755 modules/security/live-attack-monitor-v1.sh delete mode 100644 testing/DEPLOYMENT.md delete mode 100644 testing/README.md delete mode 100755 testing/deploy-and-run.sh delete mode 100755 testing/validate-interworx.sh delete mode 100755 testing/validate-plesk.sh diff --git a/modules/security/live-attack-monitor-v1.sh b/modules/security/live-attack-monitor-v1.sh deleted file mode 100755 index e5840be..0000000 --- a/modules/security/live-attack-monitor-v1.sh +++ /dev/null @@ -1,418 +0,0 @@ -#!/bin/bash - -################################################################################ -# Live Network Security Monitor -################################################################################ -# Purpose: Real-time monitoring of active attacks and suspicious traffic -# Use Case: When server is currently under attack, monitor all activity live -# Author: Server Toolkit -# -# FEATURES: -# - Multi-source monitoring (SSH, Web, Email, Firewall) -# - Real-time threat detection and classification -# - Color-coded alerts (Critical/High/Medium/Low) -# - Live statistics dashboard -# - Connection tracking and blocking suggestions -# - Attack pattern recognition -################################################################################ - -# Get script directory -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" -source "$SCRIPT_DIR/lib/common-functions.sh" -source "$SCRIPT_DIR/lib/system-detect.sh" -source "$SCRIPT_DIR/lib/ip-reputation.sh" - -# Require root -if [ "$EUID" -ne 0 ]; then - print_error "This script must be run as root" - exit 1 -fi - -# Color definitions for threat levels -CRITICAL_COLOR='\033[1;41;97m' # White on Red background -HIGH_COLOR='\033[1;31m' # Bold Red -MEDIUM_COLOR='\033[1;33m' # Bold Yellow -LOW_COLOR='\033[0;36m' # Cyan -INFO_COLOR='\033[0;37m' # White -NC='\033[0m' - -# Configuration -REFRESH_INTERVAL=2 # Seconds between dashboard refreshes -MAX_DISPLAY_LINES=30 -THREAT_THRESHOLD_HIGH=10 # Requests per second from single IP -THREAT_THRESHOLD_MEDIUM=5 - -# Temporary files for tracking - use fixed directory for subshell access -TEMP_DIR="/tmp/live-monitor-current" -rm -rf "$TEMP_DIR" 2>/dev/null # Clean any previous session -mkdir -p "$TEMP_DIR" -touch "$TEMP_DIR/recent_events" - -# Cleanup function to kill all child processes -cleanup() { - echo "" - echo "Stopping monitoring processes..." - - # Kill all processes in this process group - kill $(jobs -p) 2>/dev/null - - # Also kill any stray tail processes monitoring our logs - pkill -P $$ 2>/dev/null - - # Clean up temp directory - rm -rf "$TEMP_DIR" 2>/dev/null - - # Restore cursor - tput cnorm - - echo "βœ“ Cleanup complete" - exit 0 -} - -trap cleanup EXIT INT TERM - -# Statistics counters -declare -A IP_COUNTER -declare -A IP_THREAT_LEVEL -declare -A ATTACK_TYPE_COUNTER -declare -A BLOCKED_IPS -TOTAL_EVENTS=0 -TOTAL_THREATS=0 -START_TIME=$(date +%s) - -# Hide cursor for cleaner display -tput civis - -################################################################################ -# Threat Classification Functions -################################################################################ - -classify_threat_level() { - local count="$1" - - if [ "$count" -ge "$THREAT_THRESHOLD_HIGH" ]; then - echo "CRITICAL" - elif [ "$count" -ge "$THREAT_THRESHOLD_MEDIUM" ]; then - echo "HIGH" - else - echo "MEDIUM" - fi -} - -get_threat_color() { - local level="$1" - - case "$level" in - CRITICAL) echo "$CRITICAL_COLOR" ;; - HIGH) echo "$HIGH_COLOR" ;; - MEDIUM) echo "$MEDIUM_COLOR" ;; - LOW) echo "$LOW_COLOR" ;; - *) echo "$INFO_COLOR" ;; - esac -} - -identify_attack_type() { - local log_line="$1" - - # SSH brute force - if echo "$log_line" | grep -qi "Failed password\|authentication failure"; then - echo "SSH_BRUTEFORCE" - # SQL injection attempts - elif echo "$log_line" | grep -qiE "union.*select|concat.*\(|substring.*\(|' or '1'='1"; then - echo "SQL_INJECTION" - # XSS attempts - elif echo "$log_line" | grep -qiE "/dev/null | while read -r line; do - if echo "$line" | grep -qi "Failed password\|authentication failure"; then - local ip=$(echo "$line" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1) - if [ -n "$ip" ]; then - process_threat_event "$ip" "SSH_BRUTEFORCE" "$line" - fi - fi - done & - fi -} - -monitor_web_attacks() { - # Monitor Apache access logs for web attacks - local access_log="/var/log/apache2/domlogs/*" - - if ls $access_log >/dev/null 2>&1; then - tail -n 0 -F $access_log 2>/dev/null | while read -r line; do - local ip=$(echo "$line" | awk '{print $1}') - local request=$(echo "$line" | awk '{print $7}') - - # Check for suspicious patterns - if echo "$line" | grep -qiE "union.*select|/dev/null | while read -r line; do - if echo "$line" | grep -qi "Firewall\|iptables\|DENY"; then - local ip=$(echo "$line" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1) - if [ -n "$ip" ]; then - BLOCKED_IPS[$ip]=1 - log_event "$ip" "FIREWALL_BLOCK" "${LOW_COLOR}" "Blocked by firewall" - fi - fi - done & - fi -} - -monitor_cphulk_blocks() { - # Monitor cPHulk blocks - if [ -x "/usr/local/cpanel/bin/cphulk_pam_ctl" ]; then - # Poll cPHulk status periodically - while true; do - whmapi1 cphulkd_list_blocks 2>/dev/null | grep -E "ip:" | while read -r line; do - local ip=$(echo "$line" | awk '{print $2}') - if [ -n "$ip" ] && [ -z "${BLOCKED_IPS[$ip]}" ]; then - BLOCKED_IPS[$ip]=1 - log_event "$ip" "CPHULK_BLOCK" "${MEDIUM_COLOR}" "Blocked by cPHulk" - fi - done - sleep 5 - done & - fi -} - -################################################################################ -# Event Processing -################################################################################ - -process_threat_event() { - local ip="$1" - local attack_type="$2" - local details="$3" - - # Update counters - ((IP_COUNTER[$ip]++)) - ((ATTACK_TYPE_COUNTER[$attack_type]++)) - ((TOTAL_EVENTS++)) - ((TOTAL_THREATS++)) - - # Classify threat level - local threat_level=$(classify_threat_level "${IP_COUNTER[$ip]}") - IP_THREAT_LEVEL[$ip]="$threat_level" - - # Track in centralized IP reputation database - # Map attack types to reputation flags - local rep_attack_type="SUSPICIOUS" - case "$attack_type" in - SSH_BRUTEFORCE) rep_attack_type="BRUTEFORCE" ;; - SQL_INJECTION) rep_attack_type="SQL_INJECTION" ;; - XSS_ATTACK) rep_attack_type="XSS" ;; - PATH_TRAVERSAL) rep_attack_type="PATH_TRAVERSAL" ;; - EXPLOIT) rep_attack_type="EXPLOIT" ;; - DDOS) rep_attack_type="DDOS" ;; - BOT) rep_attack_type="BOT" ;; - *) rep_attack_type="SCANNER" ;; - esac - flag_ip_attack "$ip" "$rep_attack_type" 0 "$attack_type: $details" >/dev/null 2>&1 & - - # Log to feed - log_event "$ip" "$attack_type" "$(get_threat_color "$threat_level")" "$details" -} - -log_event() { - local ip="$1" - local attack_type="$2" - local color="$3" - local details="$4" - - local timestamp=$(date '+%H:%M:%S') - local icon=$(get_attack_icon "$attack_type") - local hits="${IP_COUNTER[$ip]:-1}" - - # Truncate details if too long - details=$(echo "$details" | cut -c1-60) - - # Format: [TIME] ICON IP (hits) - TYPE - details - printf "${color}[%s] %s %-15s (%3d) %-20s %s${NC}\n" \ - "$timestamp" "$icon" "$ip" "$hits" "$attack_type" "$details" \ - >> "$TEMP_DIR/recent_events" -} - -################################################################################ -# Main Monitoring Loop -################################################################################ - -main() { - print_banner "Live Network Security Monitor" - - echo "" - echo "Starting multi-source threat monitoring..." - echo " β€’ SSH brute force detection" - echo " β€’ Web attack detection (SQL, XSS, etc.)" - echo " β€’ Firewall block monitoring" - echo " β€’ cPHulk activity monitoring" - echo "" - echo "Press Ctrl+C to stop..." - sleep 3 - - # Start all monitoring processes - monitor_ssh_attacks - monitor_web_attacks - monitor_firewall_blocks - monitor_cphulk_blocks - - # Main display loop - while true; do - draw_header - draw_statistics_panel - draw_live_feed - draw_action_suggestions - - sleep "$REFRESH_INTERVAL" - done -} - -# Run main -main diff --git a/testing/DEPLOYMENT.md b/testing/DEPLOYMENT.md deleted file mode 100644 index 5207575..0000000 --- a/testing/DEPLOYMENT.md +++ /dev/null @@ -1,289 +0,0 @@ -# Deploying Validation Scripts to Test Servers - -## Quick Deploy Methods - -### Method 1: SCP (Simplest - If You Have SSH Access) - -```bash -# From your current server (where scripts are): - -# Deploy to InterWorx server: -scp /root/server-toolkit/testing/validate-interworx.sh root@interworx-server-ip:/tmp/ - -# Deploy to Plesk server: -scp /root/server-toolkit/testing/validate-plesk.sh root@plesk-server-ip:/tmp/ - -# Then SSH and run: -ssh root@interworx-server-ip -chmod +x /tmp/validate-interworx.sh -/tmp/validate-interworx.sh - -# Get results back: -scp root@interworx-server-ip:/tmp/interworx-validation-results.txt ./ -``` - -### Method 2: GitHub (If Toolkit is in Git Repo) - -```bash -# On test server: -cd /tmp -git clone https://github.com/YOUR_USERNAME/server-toolkit.git -cd server-toolkit/testing -chmod +x validate-*.sh - -# Run appropriate script: -./validate-interworx.sh # On InterWorx -./validate-plesk.sh # On Plesk - -# Results in: /tmp/interworx-validation-results.txt -``` - -### Method 3: Wget/Curl (If Scripts Are Hosted) - -```bash -# On test server: -cd /tmp - -# Download script: -wget https://your-server.com/validate-interworx.sh -# OR -curl -O https://your-server.com/validate-interworx.sh - -chmod +x validate-interworx.sh -./validate-interworx.sh -``` - -### Method 4: Copy-Paste (If No Direct Access) - -```bash -# On your current server, display the script: -cat /root/server-toolkit/testing/validate-interworx.sh - -# On test server, create file: -nano /tmp/validate-interworx.sh -# Paste content, save - -chmod +x /tmp/validate-interworx.sh -/tmp/validate-interworx.sh -``` - -### Method 5: Archive and Transfer - -```bash -# Create archive on current server: -cd /root/server-toolkit -tar -czf /tmp/validation-scripts.tar.gz testing/ - -# Transfer via SCP: -scp /tmp/validation-scripts.tar.gz root@test-server:/tmp/ - -# On test server: -cd /tmp -tar -xzf validation-scripts.tar.gz -cd testing -chmod +x validate-*.sh -./validate-interworx.sh -``` - ---- - -## Step-by-Step: Recommended Workflow - -### For InterWorx Server: - -1. **Transfer script:** - ```bash - scp /root/server-toolkit/testing/validate-interworx.sh root@INTERWORX_IP:/tmp/ - ``` - -2. **SSH to server:** - ```bash - ssh root@INTERWORX_IP - ``` - -3. **Make executable and run:** - ```bash - chmod +x /tmp/validate-interworx.sh - /tmp/validate-interworx.sh - ``` - -4. **Watch the output** - it will show real-time test results with colors - -5. **When done, review results:** - ```bash - less /tmp/interworx-validation-results.txt - ``` - -6. **Get results back to your machine:** - ```bash - # From your local machine: - scp root@INTERWORX_IP:/tmp/interworx-validation-results.txt ./interworx-results.txt - ``` - -### For Plesk Server: - -Same steps, just replace: -- `validate-interworx.sh` β†’ `validate-plesk.sh` -- `interworx-validation-results.txt` β†’ `plesk-validation-results.txt` - ---- - -## What You'll See During Execution - -``` -======================================================================= -INTERWORX VALIDATION SCRIPT -======================================================================= -This script will verify all assumptions about InterWorx -Results will be saved to: /tmp/interworx-validation-results.txt - -Started: Wed Nov 20 14:30:22 EST 2025 -======================================================================= - -======================================================================= -TEST 1: Control Panel Detection -======================================================================= -[PASS] InterWorx installation directory exists: /usr/local/interworx -[PASS] InterWorx config file exists: /usr/local/interworx/iworx.ini -[INFO] InterWorx version: 7.10.2 - -======================================================================= -TEST 2: File System Structure -======================================================================= -[PASS] Found test user: testuser with domain: example.com -[PASS] Document root exists: /home/testuser/example.com/html -[PASS] Log directory exists: /home/testuser/var/example.com/logs -[PASS] Access log exists: /home/testuser/var/example.com/logs/access_log -... -``` - ---- - -## After Running - What to Do - -### 1. Review the Results File - -```bash -# Quick summary: -grep -E "PASS|FAIL|WARN" /tmp/interworx-validation-results.txt | sort | uniq -c - -# See critical answers: -grep -A5 "QUICK REFERENCE FOR DEVELOPERS" /tmp/interworx-validation-results.txt - -# See directory structures: -grep -A20 "DIRECTORY STRUCTURE" /tmp/interworx-validation-results.txt -``` - -### 2. Share Results - -**Option A: Copy entire file content** -```bash -cat /tmp/interworx-validation-results.txt -# Copy and paste to pastebin/gist/email -``` - -**Option B: Transfer file back** -```bash -scp root@test-server:/tmp/interworx-validation-results.txt ./ -``` - -**Option C: Email from server** -```bash -mail -s "InterWorx Validation Results" your@email.com < /tmp/interworx-validation-results.txt -``` - -### 3. Look for Critical Info - -Search the results file for: -```bash -# Cron user answer: -grep "ANSWER.*cron" /tmp/interworx-validation-results.txt - -# Database prefix answer: -grep -i "database prefix" /tmp/interworx-validation-results.txt - -# Failed tests: -grep "FAIL" /tmp/interworx-validation-results.txt -``` - ---- - -## Troubleshooting - -### "Permission denied" -```bash -# Make sure script is executable: -chmod +x /tmp/validate-interworx.sh - -# Run as root: -sudo /tmp/validate-interworx.sh -``` - -### "Command not found: tree" -**This is OK!** Scripts have fallback to `find` command. Output will still work. - -### "No test user/domain found" -This means server has no hosting accounts set up. Script will still run but some tests will show WARN. - -### Script hangs or takes long time -- Database connection tests may wait for timeout if MySQL isn't accessible -- Large servers with many domains may take 2-3 minutes -- This is normal - let it complete - ---- - -## Security Notes - -- βœ… Scripts are **read-only** - they don't modify anything (except brief cron test) -- βœ… Cron test writes entry then **immediately removes it** -- βœ… Results file is in `/tmp/` - automatically cleaned on reboot -- βœ… No sensitive passwords are logged -- ⚠️ Results file contains domain names, usernames, file paths -- ⚠️ Remove results file after review: `rm /tmp/*-validation-results.txt` - ---- - -## Expected Runtime - -- **InterWorx**: 30-60 seconds (depends on # of users/domains) -- **Plesk**: 30-90 seconds (depends on # of domains) - ---- - -## What Gets Created - -**Files created:** -- `/tmp/interworx-validation-results.txt` OR `/tmp/plesk-validation-results.txt` -- `/tmp/iworx_cron_backup_*` (temporary, auto-deleted) -- `/tmp/plesk_cron_backup_*` (temporary, auto-deleted) - -**No permanent changes** to the system. - ---- - -## Quick Command Reference - -```bash -# Deploy -scp validate-interworx.sh root@SERVER:/tmp/ - -# Run -ssh root@SERVER "/tmp/validate-interworx.sh" - -# Get results -scp root@SERVER:/tmp/interworx-validation-results.txt ./ - -# One-liner (deploy, run, get results): -scp validate-interworx.sh root@SERVER:/tmp/ && \ - ssh root@SERVER "chmod +x /tmp/validate-interworx.sh && /tmp/validate-interworx.sh" && \ - scp root@SERVER:/tmp/interworx-validation-results.txt ./ -``` - ---- - -## Need Help? - -If you encounter issues: -1. Check `/tmp/interworx-validation-results.txt` for error details -2. Run with bash debugging: `bash -x /tmp/validate-interworx.sh` -3. Share the results file with the development team diff --git a/testing/README.md b/testing/README.md deleted file mode 100644 index a096beb..0000000 --- a/testing/README.md +++ /dev/null @@ -1,357 +0,0 @@ -# Multi-Panel Testing & Validation Guide - -## Overview - -This directory contains automated validation scripts to test the multi-panel refactoring work on real InterWorx and Plesk servers. - -**Status**: All 38 modules have been refactored for multi-panel support (100% complete) - -**Supported Panels**: -- βœ… **cPanel** - Fully tested and working (primary platform) -- πŸ§ͺ **InterWorx** - Refactored, needs validation -- πŸ§ͺ **Plesk** - Refactored, needs validation -- βœ… **Standalone Apache** - Basic support working - ---- - -## Quick Start - -### On InterWorx Server: -```bash -# Copy validation script to InterWorx server -scp testing/validate-interworx.sh root@interworx-server:/tmp/ - -# SSH to server and run -ssh root@interworx-server -chmod +x /tmp/validate-interworx.sh -/tmp/validate-interworx.sh - -# Review results -cat /tmp/interworx-validation-results.txt -``` - -### On Plesk Server: -```bash -# Copy validation script to Plesk server -scp testing/validate-plesk.sh root@plesk-server:/tmp/ - -# SSH to server and run -ssh root@plesk-server -chmod +x /tmp/validate-plesk.sh -/tmp/validate-plesk.sh - -# Review results -cat /tmp/plesk-validation-results.txt -``` - ---- - -## What Gets Validated - -### InterWorx Validation (`validate-interworx.sh`) - -Tests 10 critical areas: - -1. **Control Panel Detection** - - Verifies `/usr/local/interworx` exists - - Checks InterWorx version - - Validates installation - -2. **File System Structure** - - Document root: `/home/USER/DOMAIN/html/` βœ… (verified from official docs) - - Home directories: `/home/USER/` - - Domain structure detection - -3. **Log File Locations** - - Access logs: `/home/USER/var/DOMAIN/logs/access_log` βœ… (verified) - - Error logs: `/home/USER/var/DOMAIN/logs/error_log` βœ… (verified) - - Transfer logs: `/home/USER/var/DOMAIN/logs/transfer.log` βœ… (verified) - -4. **Domain β†’ User Mapping** - - Tests vhost config parsing: `/etc/httpd/conf.d/vhost_*.conf` - - Validates `ServerName` + `SuexecUserGroup` lookup method - -5. **User β†’ Domains Mapping** - - Method 1: Parse vhost configs for user - - Method 2: Filesystem discovery - - Compares both methods - -6. **Database Prefix Pattern** - - **VERIFIED**: Uses `username_` prefix (same as cPanel) - - Source: https://appendix.interworx.com/current/siteworx/mysql/database-guide.html - - Tests against real databases - -7. **Cron System** - - Validates standard `crontab -u USER` works - - Checks `/var/spool/cron` directory - -8. **PHP Configuration** - - Lists available PHP versions - - Checks PHP-FPM pool configs - - Tests vhost PHP handler settings - -9. **WordPress Detection** - - Searches for `wp-config.php` files - - Validates path pattern: `/home/USER/DOMAIN/html/wp-config.php` - - Tests user/domain extraction from path - -10. **InterWorx CLI Tools** - - Checks for nodeworx/siteworx commands - - Lists available CLI tools - -### Plesk Validation (`validate-plesk.sh`) - -Tests 12 critical areas: - -1. **Control Panel Detection** - - Verifies `/usr/local/psa` exists - - Checks `plesk` command availability - - Gets Plesk version - -2. **File System Structure** - - Document root: `/var/www/vhosts/DOMAIN/httpdocs/` - - Domain root: `/var/www/vhosts/DOMAIN/` - - Directory structure validation - -3. **Log File Locations** - - Access logs: `/var/www/vhosts/system/DOMAIN/logs/access_log` - - SSL access logs: `/var/www/vhosts/system/DOMAIN/logs/access_ssl_log` - - Error logs: `/var/www/vhosts/system/DOMAIN/logs/error_log` - - PHP error logs: `/var/www/vhosts/DOMAIN/httpdocs/error_log` - -4. **Plesk bin Commands** - - Tests `plesk bin subscription` command - - Lists available commands - -5. **Domain β†’ User Mapping** - - Tests `plesk bin subscription --info DOMAIN` - - Validates `Owner:` field extraction - - Checks for alternative `Login:` field - -6. **User β†’ Domains Mapping** - - Tests `plesk bin subscription --list -owner USERNAME` - - Alternative: filesystem discovery - -7. **Database Prefix Pattern** - - **TO VERIFY**: Appears to use NO PREFIX (bare database names) - - Tests real database list - - Checks for prefix patterns - -8. **System User for Web Processes** - - **CRITICAL**: Determines what user runs PHP/Apache - - Checks PHP-FPM process ownership - - Tests Apache process user - - Important for cron job management! - -9. **Cron System** - - Tests standard `crontab -u USER` - - Checks for `plesk bin cron` (Plesk custom cron) - - **TO VERIFY**: Which cron system to use? - -10. **PHP Configuration** - - Checks `/opt/plesk/php` directory - - Lists PHP versions - - Tests PHP handler per domain - -11. **WordPress Detection** - - Searches for `wp-config.php` files - - Validates path pattern: `/var/www/vhosts/DOMAIN/httpdocs/wp-config.php` - - Tests domain/owner extraction - -12. **Apache/Web Server Configuration** - - Checks for nginx (Plesk often uses nginx + Apache) - - Validates config directories - ---- - -## Validation Results - -Each script produces: -- **Color-coded console output** (green=pass, red=fail, yellow=warn) -- **Detailed results file** in `/tmp/` -- **Test summary** with pass/fail/warn counts - -### Exit Codes: -- `0` = All critical tests passed -- `1` = Some tests failed (review required) - ---- - -## What to Look For - -### βœ… PASS - Good! -- All assumptions verified -- Paths exist and match expected patterns -- Commands work as expected - -### ⚠️ WARN - Investigate -- Feature exists but may not be configured yet -- Alternative methods available -- Non-critical differences found - -### βœ— FAIL - Action Required -- Assumption is wrong -- Required file/command missing -- Pattern doesn't match expectations -- **Report back to development team!** - ---- - -## Critical Items to Verify - -### InterWorx - RESOLVED βœ… -- βœ… File paths (verified from official docs) -- βœ… Database prefix pattern (`username_` confirmed) -- ⏳ Domainβ†’User lookup (needs real server test) -- ⏳ Userβ†’Domains lookup (needs real server test) - -### Plesk - NEEDS VERIFICATION πŸ§ͺ -- ❓ Database prefix (appears to be NO PREFIX) -- ❓ System user for cron jobs (www-data? apache? per-domain user?) -- ❓ Cron system (standard vs `plesk bin cron`) -- ❓ PHP handler selection per domain -- ⏳ All lookup methods (needs real server test) - ---- - -## After Running Validation - -### 1. Review Results File -```bash -# InterWorx -cat /tmp/interworx-validation-results.txt | grep -E "PASS|FAIL|WARN" | sort | uniq -c - -# Plesk -cat /tmp/plesk-validation-results.txt | grep -E "PASS|FAIL|WARN" | sort | uniq -c -``` - -### 2. Report Issues -If you find **FAIL** results: - -1. Copy the full results file -2. Note the specific test that failed -3. Check if it's a critical assumption (database prefix, file paths, lookups) -4. Report back with: - - Panel type and version - - Failed test name - - Actual vs expected behavior - - Full error output - -### 3. Test Actual Modules -After validation passes, test real modules: - -#### Simple Tests First: -```bash -# Test log discovery -./modules/security/tail-apache-access.sh - -# Test traffic monitoring -./modules/security/web-traffic-monitor.sh - -# Test error analysis -./modules/website/website-error-analyzer.sh -``` - -#### Complex Tests: -```bash -# Test WordPress cron (most complex) -./modules/website/wordpress/wordpress-cron-manager.sh --list - -# Test 500 error tracking -./modules/website/500-error-tracker.sh -``` - ---- - -## Testing Priority - -### Phase 1: Validation Scripts ⏳ -Run `validate-interworx.sh` and `validate-plesk.sh` on real servers - -**Goal**: Verify all file paths, commands, and lookup methods work - -### Phase 2: Simple Module Testing -Test Class B modules (system detection only): -- `tail-apache-access.sh` -- `tail-apache-error.sh` -- `web-traffic-monitor.sh` - -**Goal**: Verify SYS_LOG_DIR detection and log discovery works - -### Phase 3: Complex Module Testing -Test Class C modules (user/domain management): -- `website-error-analyzer.sh` -- `500-error-tracker.sh` -- `wordpress-cron-manager.sh` (most complex!) - -**Goal**: Verify all lookup methods and multi-panel logic works - -### Phase 4: Production Readiness -- Fix any issues found -- Update documentation -- Add any missing edge cases -- Performance testing - ---- - -## Known Issues & Limitations - -### InterWorx -- Database prefix pattern was documented incorrectly (now fixed) -- All other assumptions verified from official documentation -- Needs real server testing to confirm - -### Plesk -- Database prefix pattern unclear (appears to be NO PREFIX) -- System user for cron jobs unknown (affects wordpress-cron-manager.sh) -- May use custom cron system (`plesk bin cron`) -- All assumptions need real server verification - -### All Panels -- Scripts assume bash 4.0+ -- Some features are cPanel-only (clearly marked with panel checks) -- Acronis backup modules have not been tested on non-cPanel systems - ---- - -## Next Steps - -1. **Get access to test servers** - - InterWorx test server - - Plesk test server (both RHEL and Debian-based) - -2. **Run validation scripts** - - Execute both validators - - Collect results - - Document any failures - -3. **Fix issues found** - - Update code if assumptions are wrong - - Adjust case statements as needed - - Update REFDB_FORMAT.txt documentation - -4. **Test real modules** - - Start with simple scripts - - Progress to complex scripts - - Test edge cases - -5. **Update documentation** - - Document verified behaviors - - Add platform-specific notes - - Update testing requirements - ---- - -## Contact - -For questions or to report validation results, contact the development team with: -- Full validation results file -- Panel type and version -- Any errors or unexpected behavior -- Suggestions for improvements - ---- - -**Last Updated**: 2025-11-20 -**Refactoring Status**: 100% complete (38/38 modules) -**Validation Status**: Scripts ready, awaiting test server access diff --git a/testing/deploy-and-run.sh b/testing/deploy-and-run.sh deleted file mode 100755 index 43d38b2..0000000 --- a/testing/deploy-and-run.sh +++ /dev/null @@ -1,143 +0,0 @@ -#!/bin/bash - -################################################################################ -# Quick Deploy & Run Validation Scripts -# Usage: ./deploy-and-run.sh -################################################################################ - -set -e - -if [ $# -lt 2 ]; then - echo "Usage: $0 " - echo "" - echo "Examples:" - echo " $0 192.168.1.100 interworx" - echo " $0 plesk.example.com plesk" - echo "" - exit 1 -fi - -SERVER="$1" -PANEL="$2" - -# Validate panel type -if [[ "$PANEL" != "interworx" ]] && [[ "$PANEL" != "plesk" ]]; then - echo "Error: Panel must be 'interworx' or 'plesk'" - exit 1 -fi - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -SCRIPT_NAME="validate-${PANEL}.sh" -SCRIPT_PATH="${SCRIPT_DIR}/${SCRIPT_NAME}" -RESULTS_FILE="${PANEL}-validation-results.txt" - -# Check if script exists -if [ ! -f "$SCRIPT_PATH" ]; then - echo "Error: Script not found: $SCRIPT_PATH" - exit 1 -fi - -echo "=======================================================================" -echo "VALIDATION SCRIPT DEPLOYMENT" -echo "=======================================================================" -echo "Server: $SERVER" -echo "Panel: $PANEL" -echo "Script: $SCRIPT_NAME" -echo "=======================================================================" -echo "" - -# Step 1: Deploy script -echo "[1/4] Deploying script to server..." -if scp "$SCRIPT_PATH" "root@${SERVER}:/tmp/${SCRIPT_NAME}"; then - echo "βœ“ Script deployed successfully" -else - echo "βœ— Failed to deploy script" - echo "Tip: Make sure SSH key authentication is set up, or use: ssh-copy-id root@${SERVER}" - exit 1 -fi - -echo "" - -# Step 2: Make executable and run -echo "[2/4] Running validation script on server..." -echo "This may take 1-2 minutes..." -echo "" - -if ssh "root@${SERVER}" "chmod +x /tmp/${SCRIPT_NAME} && /tmp/${SCRIPT_NAME}"; then - echo "" - echo "βœ“ Validation completed successfully" -else - echo "" - echo "⚠ Validation script encountered issues (check output above)" - echo "Continuing to retrieve results file..." -fi - -echo "" - -# Step 3: Retrieve results -echo "[3/4] Retrieving results file..." -if scp "root@${SERVER}:/tmp/${RESULTS_FILE}" "./${RESULTS_FILE}"; then - echo "βœ“ Results file retrieved: ./${RESULTS_FILE}" -else - echo "βœ— Failed to retrieve results file" - exit 1 -fi - -echo "" - -# Step 4: Show summary -echo "[4/4] Generating summary..." -echo "" -echo "=======================================================================" -echo "VALIDATION SUMMARY" -echo "=======================================================================" - -# Count results -PASS_COUNT=$(grep -c "^\[PASS\]" "$RESULTS_FILE" 2>/dev/null || echo "0") -FAIL_COUNT=$(grep -c "^\[FAIL\]" "$RESULTS_FILE" 2>/dev/null || echo "0") -WARN_COUNT=$(grep -c "^\[WARN\]" "$RESULTS_FILE" 2>/dev/null || echo "0") - -# Ensure counts are integers -PASS_COUNT=$(echo "$PASS_COUNT" | head -1 | tr -d '\n') -FAIL_COUNT=$(echo "$FAIL_COUNT" | head -1 | tr -d '\n') -WARN_COUNT=$(echo "$WARN_COUNT" | head -1 | tr -d '\n') - -# Default to 0 if empty -PASS_COUNT=${PASS_COUNT:-0} -FAIL_COUNT=${FAIL_COUNT:-0} -WARN_COUNT=${WARN_COUNT:-0} - -echo "PASS: $PASS_COUNT" -echo "FAIL: $FAIL_COUNT" -echo "WARN: $WARN_COUNT" -echo "" - -if [ "$FAIL_COUNT" -eq 0 ] 2>/dev/null; then - echo "βœ“ All critical tests passed!" -else - echo "⚠ Some tests failed - review results file" - echo "" - echo "Failed tests:" - grep "^\[FAIL\]" "$RESULTS_FILE" 2>/dev/null || true -fi - -echo "" -echo "=======================================================================" -echo "CRITICAL ANSWERS FOUND" -echo "=======================================================================" - -# Extract critical answers -grep -A10 "QUICK REFERENCE FOR DEVELOPERS" "$RESULTS_FILE" 2>/dev/null | head -15 || echo "See full results file" - -echo "" -echo "=======================================================================" -echo "NEXT STEPS" -echo "=======================================================================" -echo "1. Review full results: cat ${RESULTS_FILE}" -echo "2. Check directory structures: grep 'DIRECTORY STRUCTURE' ${RESULTS_FILE}" -echo "3. Share results with development team if needed" -echo "" -echo "Full results file: $(pwd)/${RESULTS_FILE}" -echo "=======================================================================" - -exit 0 diff --git a/testing/validate-interworx.sh b/testing/validate-interworx.sh deleted file mode 100755 index aee39a2..0000000 --- a/testing/validate-interworx.sh +++ /dev/null @@ -1,832 +0,0 @@ -#!/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 -################################################################################ - -# Note: NOT using 'set -e' so script continues even if individual tests fail - -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 -E "^version\s*=" /usr/local/interworx/iworx.ini 2>/dev/null | head -1 | 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 (InterWorx uses transfer.log NOT access_log) - if [ -f "$EXPECTED_LOG_DIR/transfer.log" ]; then - test_pass "Access log exists: $EXPECTED_LOG_DIR/transfer.log" - test_pass "VERIFIED: InterWorx uses 'transfer.log' for access logs" - else - test_warn "Access log NOT found (may not have traffic yet or may be symlink)" - 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 - -################################################################################ -# TEST 11: WordPress File Permissions & Cron User Testing -################################################################################ - -section_header "TEST 11: WordPress File Permissions & Cron User Testing" - -if [ -n "$FIRST_WP" ]; then - test_info "Testing WordPress file access: $FIRST_WP" - - # Check if we can read wp-config.php - if [ -r "$FIRST_WP" ]; then - test_pass "βœ“ CAN READ wp-config.php as root" - - # Check file ownership - WP_OWNER=$(stat -c '%U' "$FIRST_WP" 2>/dev/null || stat -f '%Su' "$FIRST_WP" 2>/dev/null) - WP_PERMS=$(stat -c '%a' "$FIRST_WP" 2>/dev/null || stat -f '%Lp' "$FIRST_WP" 2>/dev/null) - - test_info "wp-config.php owner: $WP_OWNER" - test_info "wp-config.php permissions: $WP_PERMS" - - # Try to extract database info - DB_NAME=$(grep "DB_NAME" "$FIRST_WP" 2>/dev/null | head -1 | cut -d"'" -f4) - DB_USER=$(grep "DB_USER" "$FIRST_WP" 2>/dev/null | head -1 | cut -d"'" -f4) - - if [ -n "$DB_NAME" ]; then - test_pass "βœ“ Can extract database name: $DB_NAME" - test_info "Database user: $DB_USER" - - # Verify username_ prefix pattern - if echo "$DB_NAME" | grep -qE "^${WP_USER}_"; then - test_pass "βœ“ Database follows username_ prefix pattern: $DB_NAME" - elif echo "$DB_NAME" | grep -q "_"; then - test_warn "Database has underscore but doesn't match username_ pattern: $DB_NAME" - else - test_warn "Database has NO underscore: $DB_NAME" - fi - else - test_warn "Could not extract database info from wp-config.php" - fi - - # CRITICAL TEST: Test cron operations for WordPress user - if [ -n "$WP_USER" ]; then - test_info "CRITICAL TEST: Testing cron operations for user: $WP_USER" - - # Test if we can read/write crontab - if crontab -u "$WP_USER" -l &> /dev/null; then - test_pass "βœ“ CAN READ crontab for WordPress user: $WP_USER" - test_info "Current crontab:" - crontab -u "$WP_USER" -l 2>/dev/null | head -10 >> "$RESULTS_FILE" - else - CRON_ERR=$? - if [ "$CRON_ERR" -eq 1 ]; then - test_info "User $WP_USER has no crontab (OK - means empty)" - else - test_warn "Cannot read crontab for $WP_USER (exit code: $CRON_ERR)" - fi - fi - - # Test write operation - test_info "ATTEMPTING: Test cron write (will be immediately removed)..." - TEMP_BACKUP="/tmp/iworx_cron_backup_$$" - crontab -u "$WP_USER" -l > "$TEMP_BACKUP" 2>/dev/null || echo "# No existing crontab" > "$TEMP_BACKUP" - - (crontab -u "$WP_USER" -l 2>/dev/null; echo "# TEST - InterWorx Validation") | crontab -u "$WP_USER" - 2>/dev/null - CRON_WRITE_STATUS=$? - - if [ "$CRON_WRITE_STATUS" -eq 0 ]; then - test_pass "βœ“ CAN WRITE crontab for user: $WP_USER" - test_pass "ANSWER: Use 'crontab -u $WP_USER' for WordPress cron jobs" - if crontab -u "$WP_USER" "$TEMP_BACKUP" 2>/dev/null; then - test_info "Test entry removed, crontab restored" - else - test_warn "Failed to restore original crontab - manual check recommended" - fi - else - test_fail "βœ— CANNOT WRITE crontab for user: $WP_USER" - # Attempt to restore anyway in case partial write occurred - crontab -u "$WP_USER" "$TEMP_BACKUP" 2>/dev/null - fi - rm -f "$TEMP_BACKUP" - fi - - else - test_fail "βœ— CANNOT READ wp-config.php (permission denied)" - fi - - # Check WordPress directory ownership - WP_DIR=$(dirname "$FIRST_WP") - WP_DIR_OWNER=$(stat -c '%U:%G' "$WP_DIR" 2>/dev/null || stat -f '%Su:%Sg' "$WP_DIR" 2>/dev/null) - WP_DIR_PERMS=$(stat -c '%a' "$WP_DIR" 2>/dev/null || stat -f '%Lp' "$WP_DIR" 2>/dev/null) - - test_info "WordPress dir: $WP_DIR" - test_info "WordPress dir owner: $WP_DIR_OWNER" - test_info "WordPress dir permissions: $WP_DIR_PERMS" -fi - -################################################################################ -# TEST 12: Directory Structure Visualization -################################################################################ - -section_header "TEST 12: Directory Structure Visualization" - -test_info "Documenting directory structure for critical paths..." - -# Function to create a tree-like view (limited depth) -create_tree() { - local path="$1" - local depth="${2:-2}" - local prefix="${3:-}" - - if [ ! -d "$path" ]; then - return - fi - - # Use tree command if available, otherwise use find - if command -v tree &> /dev/null; then - tree -L "$depth" -F "$path" 2>/dev/null || find "$path" -maxdepth "$depth" -type d 2>/dev/null | head -50 - else - find "$path" -maxdepth "$depth" 2>/dev/null | head -50 | sed 's|[^/]*/| |g' - fi -} - -# Document user/domain directory structure -if [ -n "$TEST_USER" ] && [ -n "$TEST_DOMAIN" ]; then - echo "" >> "$RESULTS_FILE" - echo "=== USER DIRECTORY STRUCTURE: $TEST_USER ===" >> "$RESULTS_FILE" - echo "" >> "$RESULTS_FILE" - - test_info "Documenting user structure for $TEST_USER..." - - USER_PATH="/home/$TEST_USER" - if [ -d "$USER_PATH" ]; then - echo "Full path: $USER_PATH" >> "$RESULTS_FILE" - echo "" >> "$RESULTS_FILE" - - # Show top level - echo "Top level:" >> "$RESULTS_FILE" - ls -lh "$USER_PATH" 2>/dev/null | head -20 >> "$RESULTS_FILE" - - echo "" >> "$RESULTS_FILE" - echo "Tree view (depth 2):" >> "$RESULTS_FILE" - create_tree "$USER_PATH" 2 >> "$RESULTS_FILE" 2>&1 - fi - - # Document specific domain structure - echo "" >> "$RESULTS_FILE" - echo "=== DOMAIN DIRECTORY STRUCTURE: $TEST_DOMAIN ===" >> "$RESULTS_FILE" - DOMAIN_PATH="/home/$TEST_USER/$TEST_DOMAIN" - if [ -d "$DOMAIN_PATH" ]; then - echo "Full path: $DOMAIN_PATH" >> "$RESULTS_FILE" - echo "" >> "$RESULTS_FILE" - create_tree "$DOMAIN_PATH" 3 >> "$RESULTS_FILE" 2>&1 - fi - - # Document var/logs structure - echo "" >> "$RESULTS_FILE" - echo "=== LOG DIRECTORY STRUCTURE: $TEST_DOMAIN ===" >> "$RESULTS_FILE" - VAR_PATH="/home/$TEST_USER/var/$TEST_DOMAIN" - if [ -d "$VAR_PATH" ]; then - echo "Full path: $VAR_PATH" >> "$RESULTS_FILE" - echo "" >> "$RESULTS_FILE" - create_tree "$VAR_PATH" 2 >> "$RESULTS_FILE" 2>&1 - - # List actual log files with sizes - echo "" >> "$RESULTS_FILE" - echo "Log files:" >> "$RESULTS_FILE" - ls -lh "$VAR_PATH/logs/" 2>/dev/null >> "$RESULTS_FILE" - fi -fi - -# Document general /home structure (sample user) -echo "" >> "$RESULTS_FILE" -echo "=== GENERAL /home STRUCTURE ===" >> "$RESULTS_FILE" -test_info "Documenting /home structure..." - -if [ -d "/home" ]; then - echo "Users in /home:" >> "$RESULTS_FILE" - ls -lh /home/ 2>/dev/null | grep "^d" | head -10 >> "$RESULTS_FILE" - - # Show one sample user structure - if [ -n "$TEST_USER" ]; then - echo "" >> "$RESULTS_FILE" - echo "Sample user structure: $TEST_USER (depth 1)" >> "$RESULTS_FILE" - ls -lh "/home/$TEST_USER/" 2>/dev/null >> "$RESULTS_FILE" - fi -fi - -# Document InterWorx directory structure -echo "" >> "$RESULTS_FILE" -echo "=== INTERWORX SYSTEM DIRECTORIES ===" >> "$RESULTS_FILE" -test_info "Documenting InterWorx system directories..." - -if [ -d "/usr/local/interworx" ]; then - echo "/usr/local/interworx structure (depth 1):" >> "$RESULTS_FILE" - ls -lh /usr/local/interworx/ 2>/dev/null >> "$RESULTS_FILE" -fi - -# Document Apache config directory -echo "" >> "$RESULTS_FILE" -echo "=== APACHE CONFIG DIRECTORY ===" >> "$RESULTS_FILE" -if [ -d "/etc/httpd/conf.d" ]; then - echo "/etc/httpd/conf.d vhost configs:" >> "$RESULTS_FILE" - ls -lh /etc/httpd/conf.d/vhost_*.conf 2>/dev/null | head -10 >> "$RESULTS_FILE" -fi - -################################################################################ -# TEST 13: Comprehensive System Documentation -################################################################################ - -section_header "TEST 13: Comprehensive System Documentation" - -test_info "Gathering complete system information for future reference..." - -# Document all InterWorx commands -test_info "Cataloging InterWorx bin commands..." -if [ -d "/usr/local/interworx/bin" ]; then - echo "" >> "$RESULTS_FILE" - echo "=== ALL INTERWORX BIN COMMANDS ===" >> "$RESULTS_FILE" - ls -1 /usr/local/interworx/bin >> "$RESULTS_FILE" -fi - -# Document InterWorx version details -test_info "Documenting InterWorx version..." -if [ -f "/usr/local/interworx/iworx.ini" ]; then - echo "" >> "$RESULTS_FILE" - echo "=== INTERWORX VERSION DETAILS ===" >> "$RESULTS_FILE" - grep -E "version|product" /usr/local/interworx/iworx.ini 2>/dev/null >> "$RESULTS_FILE" -fi - -# Document all users and domains -test_info "Cataloging all users and domains..." -ALL_USERS=$(find /home -maxdepth 1 -type d ! -name "home" ! -name "lost+found" 2>/dev/null | xargs -n1 basename | sort) -if [ -n "$ALL_USERS" ]; then - USER_COUNT=$(echo "$ALL_USERS" | wc -l) - echo "" >> "$RESULTS_FILE" - echo "=== ALL USERS ON SYSTEM (Total: $USER_COUNT) ===" >> "$RESULTS_FILE" - echo "$ALL_USERS" >> "$RESULTS_FILE" -fi - -# Document all vhost configs -test_info "Cataloging vhost configurations..." -if [ -d "/etc/httpd/conf.d" ]; then - VHOST_COUNT=$(find /etc/httpd/conf.d -name "vhost_*.conf" 2>/dev/null | wc -l) - echo "" >> "$RESULTS_FILE" - echo "=== VHOST CONFIGURATIONS (Total: $VHOST_COUNT) ===" >> "$RESULTS_FILE" - find /etc/httpd/conf.d -name "vhost_*.conf" -exec basename {} \; 2>/dev/null | sort >> "$RESULTS_FILE" -fi - -# Document PHP versions -test_info "Documenting PHP versions..." -echo "" >> "$RESULTS_FILE" -echo "=== PHP VERSIONS AVAILABLE ===" >> "$RESULTS_FILE" -which php 2>/dev/null >> "$RESULTS_FILE" -php -v 2>/dev/null | head -1 >> "$RESULTS_FILE" -find /usr/bin /opt -name "php[0-9]*" -type f 2>/dev/null | head -10 >> "$RESULTS_FILE" - -# Document web server -test_info "Documenting web server..." -echo "" >> "$RESULTS_FILE" -echo "=== WEB SERVER CONFIGURATION ===" >> "$RESULTS_FILE" -httpd -v 2>&1 >> "$RESULTS_FILE" || apache2 -v 2>&1 >> "$RESULTS_FILE" -if ps aux | grep -v grep | grep -q "httpd"; then - echo "Apache: RUNNING" >> "$RESULTS_FILE" -fi - -# Document database server -test_info "Documenting database server..." -echo "" >> "$RESULTS_FILE" -echo "=== DATABASE SERVER ===" >> "$RESULTS_FILE" -if command -v mysql &> /dev/null; then - mysql -V >> "$RESULTS_FILE" 2>&1 -fi - -# Sample vhost config (sanitized) -test_info "Documenting sample vhost config structure..." -if [ -n "$FIRST_VHOST" ]; then - echo "" >> "$RESULTS_FILE" - echo "=== SAMPLE VHOST CONFIG STRUCTURE ===" >> "$RESULTS_FILE" - echo "File: $(basename "$FIRST_VHOST")" >> "$RESULTS_FILE" - echo "Key directives found:" >> "$RESULTS_FILE" - grep -E "ServerName|ServerAlias|DocumentRoot|SuexecUserGroup|php" "$FIRST_VHOST" 2>/dev/null >> "$RESULTS_FILE" -fi - -# Create quick reference for developers -echo "" >> "$RESULTS_FILE" -echo "=======================================================================" >> "$RESULTS_FILE" -echo "QUICK REFERENCE FOR DEVELOPERS" >> "$RESULTS_FILE" -echo "=======================================================================" >> "$RESULTS_FILE" -echo "" >> "$RESULTS_FILE" -echo "Home directories: /home/USERNAME/" >> "$RESULTS_FILE" -echo "Document roots: /home/USERNAME/DOMAIN/html/" >> "$RESULTS_FILE" -echo "Access logs: /home/USERNAME/var/DOMAIN/logs/transfer.log (VERIFIED)" >> "$RESULTS_FILE" -echo "Error logs: /home/USERNAME/var/DOMAIN/logs/error_log" >> "$RESULTS_FILE" -echo "WordPress: /home/USERNAME/DOMAIN/html/wp-config.php" >> "$RESULTS_FILE" -echo "Vhost configs: /etc/httpd/conf.d/vhost_*.conf" >> "$RESULTS_FILE" -echo "" >> "$RESULTS_FILE" -echo "Database prefix: username_ (VERIFIED from official docs)" >> "$RESULTS_FILE" - -if [ -n "$WP_USER" ]; then - echo "" >> "$RESULTS_FILE" - echo "Sample WordPress user: $WP_USER" >> "$RESULTS_FILE" - echo "Cron command: crontab -u $WP_USER" >> "$RESULTS_FILE" -fi - -if [ -n "$DB_NAME" ]; then - echo "" >> "$RESULTS_FILE" - echo "Sample database: $DB_NAME" >> "$RESULTS_FILE" -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 validation successful!" - echo "" - echo "CRITICAL ANSWERS DISCOVERED:" - echo " β€’ Database prefix: username_ (verified)" - if [ -n "$WP_USER" ]; then - echo " β€’ Cron user: $WP_USER" - fi - if [ -n "$DB_NAME" ]; then - echo " β€’ Sample database: $DB_NAME" - fi -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 "NEXT STEPS:" -echo "=======================================================================" -echo "1. Review $RESULTS_FILE for complete details" -echo "2. Report findings to development team" -echo "3. Test actual toolkit modules if validation passed" -echo "=======================================================================" - -exit 0 diff --git a/testing/validate-plesk.sh b/testing/validate-plesk.sh deleted file mode 100755 index 5e10cb0..0000000 --- a/testing/validate-plesk.sh +++ /dev/null @@ -1,972 +0,0 @@ -#!/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 -################################################################################ - -# Note: NOT using 'set -e' so script continues even if individual tests fail - -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" <> "$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 - Plesk uses "Owner's contact name:" format - # Example: "Owner's contact name: LW Support (admin)" -> extract "admin" - # Uses tail -1 to get the last parentheses in case of multiple - OWNER=$(echo "$SUBSCRIPTION_INFO" | grep -i "^Owner's contact name:" | sed "s/^Owner's contact name:[[:space:]]*//" | grep -oE '\([^)]+\)' | tail -1 | tr -d '()') - - if [ -n "$OWNER" ]; then - test_pass "Found Owner's contact name field: $OWNER" - test_pass "VERIFIED: Domainβ†’User lookup works via: plesk bin subscription --info DOMAIN | grep \"Owner's contact name\"" - 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's contact name)" - TEST_OWNER="$OWNER" - else - test_fail "Could not find Owner's contact name 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 & File Ownership -################################################################################ - -section_header "TEST 8: System User for Web Processes & File Ownership" - -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)" - WEB_USER="www-data" - elif echo "$PHP_FPM_USERS" | grep -q "apache"; then - test_info "PHP-FPM uses apache (RHEL/CentOS pattern)" - WEB_USER="apache" - else - test_info "PHP-FPM uses custom user(s)" - WEB_USER=$(echo "$PHP_FPM_USERS" | head -1) - fi -else - test_warn "No PHP-FPM processes found" - WEB_USER="www-data" # Default assumption -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 - -# CRITICAL: Check file ownership of WordPress/web files -if [ -n "$TEST_DOMAIN" ]; then - DOCROOT="/var/www/vhosts/$TEST_DOMAIN/httpdocs" - if [ -d "$DOCROOT" ]; then - FILE_OWNER=$(stat -c '%U' "$DOCROOT" 2>/dev/null || stat -f '%Su' "$DOCROOT" 2>/dev/null) - FILE_GROUP=$(stat -c '%G' "$DOCROOT" 2>/dev/null || stat -f '%Sg' "$DOCROOT" 2>/dev/null) - - if [ -n "$FILE_OWNER" ]; then - test_pass "Document root owner: $FILE_OWNER:$FILE_GROUP" - - # Check if files are owned by web user or domain-specific user - if [ "$FILE_OWNER" = "$WEB_USER" ]; then - test_info "Files owned by web process user ($WEB_USER)" - test_pass "ANSWER: Use 'crontab -u $WEB_USER' for cron jobs" - CRON_USER="$WEB_USER" - elif [ "$FILE_OWNER" = "$TEST_OWNER" ]; then - test_info "Files owned by domain owner ($TEST_OWNER)" - test_pass "ANSWER: Use 'crontab -u $TEST_OWNER' for cron jobs" - CRON_USER="$TEST_OWNER" - else - test_warn "Files owned by different user: $FILE_OWNER (not web user or domain owner)" - test_info "ANSWER: Use 'crontab -u $FILE_OWNER' for cron jobs" - CRON_USER="$FILE_OWNER" - fi - - # Test a sample file inside - if [ -f "$DOCROOT/index.php" ] || [ -f "$DOCROOT/index.html" ]; then - SAMPLE_FILE=$(find "$DOCROOT" -maxdepth 1 -type f -name "index.*" 2>/dev/null | head -1) - if [ -n "$SAMPLE_FILE" ]; then - SAMPLE_OWNER=$(stat -c '%U' "$SAMPLE_FILE" 2>/dev/null || stat -f '%Su' "$SAMPLE_FILE" 2>/dev/null) - test_info "Sample file owner: $SAMPLE_OWNER (file: $(basename "$SAMPLE_FILE"))" - fi - fi - else - test_fail "Could not determine file ownership" - fi - fi -fi - -################################################################################ -# TEST 9: Cron System (CRITICAL - Test Actual Operations!) -################################################################################ - -section_header "TEST 9: Cron System (CRITICAL - Test Actual Operations!)" - -if command -v crontab &> /dev/null; then - test_pass "crontab command available" - - # Check for plesk bin cron command - HAS_PLESK_CRON=0 - if plesk bin cron --help &> /dev/null 2>&1; then - test_pass "plesk bin cron command available (Plesk custom cron management)" - HAS_PLESK_CRON=1 - 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" - test_info "Cron files found:" - ls -lh /var/spool/cron/ 2>/dev/null >> "$RESULTS_FILE" - elif [ -d "/var/spool/cron/crontabs" ]; then - test_pass "Standard cron spool directory exists: /var/spool/cron/crontabs" - test_info "Cron files found:" - ls -lh /var/spool/cron/crontabs/ 2>/dev/null >> "$RESULTS_FILE" - else - test_warn "Standard cron spool directory not found" - fi - - # CRITICAL TEST: Try to read/write cron for different users - if [ -n "$CRON_USER" ]; then - test_info "CRITICAL TEST: Testing cron operations for user: $CRON_USER" - - # Test 1: Can we read the crontab? - if crontab -u "$CRON_USER" -l &> /dev/null; then - test_pass "βœ“ CAN READ crontab for user: $CRON_USER" - test_info "Current crontab entries:" - crontab -u "$CRON_USER" -l 2>/dev/null >> "$RESULTS_FILE" - else - CRON_READ_ERR=$? - if [ "$CRON_READ_ERR" -eq 1 ]; then - test_info "User $CRON_USER has no crontab (this is OK - means empty)" - else - test_warn "Cannot read crontab for $CRON_USER (exit code: $CRON_READ_ERR)" - fi - fi - - # Test 2: Can we write a test cron entry? (ACTUALLY TEST IT) - test_info "ATTEMPTING: Test cron write operation (will be immediately removed)..." - - # Backup existing crontab - TEMP_BACKUP="/tmp/plesk_cron_backup_$$" - crontab -u "$CRON_USER" -l > "$TEMP_BACKUP" 2>/dev/null || echo "# No existing crontab" > "$TEMP_BACKUP" - - # Try to add a test entry - TEST_CRON_ENTRY="# TEST ENTRY - Plesk Validation - Will be removed" - (crontab -u "$CRON_USER" -l 2>/dev/null; echo "$TEST_CRON_ENTRY") | crontab -u "$CRON_USER" - 2>/dev/null - CRON_WRITE_STATUS=$? - - if [ "$CRON_WRITE_STATUS" -eq 0 ]; then - test_pass "βœ“ CAN WRITE crontab for user: $CRON_USER" - test_pass "ANSWER: Standard crontab works - use 'crontab -u $CRON_USER'" - - # Restore original crontab immediately - if crontab -u "$CRON_USER" "$TEMP_BACKUP" 2>/dev/null; then - test_info "Test entry removed, original crontab restored" - else - test_warn "Failed to restore original crontab - manual check recommended" - fi - else - test_fail "βœ— CANNOT WRITE crontab for user: $CRON_USER" - test_warn "May need to use 'plesk bin cron' instead of standard crontab" - # Attempt to restore anyway in case partial write occurred - crontab -u "$CRON_USER" "$TEMP_BACKUP" 2>/dev/null - fi - - rm -f "$TEMP_BACKUP" - fi - - # Test plesk bin cron if available - if [ "$HAS_PLESK_CRON" -eq 1 ] && [ -n "$TEST_DOMAIN" ]; then - test_info "Testing Plesk cron management for domain: $TEST_DOMAIN" - - # Try to list cron jobs via plesk - PLESK_CRONS=$(plesk bin cron -l -domain "$TEST_DOMAIN" 2>/dev/null) - if [ $? -eq 0 ]; then - test_pass "βœ“ Can list Plesk cron jobs for domain" - if [ -n "$PLESK_CRONS" ]; then - test_info "Plesk cron jobs found:" - echo "$PLESK_CRONS" | head -20 >> "$RESULTS_FILE" - else - test_info "No Plesk cron jobs configured for domain" - fi - else - test_warn "Cannot list Plesk cron jobs (may need different syntax)" - fi - fi - - # Document which method to use - echo "" >> "$RESULTS_FILE" - echo "=== CRON MANAGEMENT CONCLUSION ===" >> "$RESULTS_FILE" - if [ -n "$CRON_USER" ]; then - echo "RECOMMENDED: Use standard crontab -u $CRON_USER for cron jobs" >> "$RESULTS_FILE" - fi - if [ "$HAS_PLESK_CRON" -eq 1 ]; then - echo "ALTERNATIVE: Plesk bin cron available but may be for web UI management only" >> "$RESULTS_FILE" - 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 - -################################################################################ -# TEST 13: WordPress File Permissions & wp-config.php Access -################################################################################ - -section_header "TEST 13: WordPress File Permissions & wp-config.php Access" - -if [ -n "$FIRST_WP" ]; then - test_info "Testing WordPress file access: $FIRST_WP" - - # Check if we can read wp-config.php - if [ -r "$FIRST_WP" ]; then - test_pass "βœ“ CAN READ wp-config.php as root" - - # Check file ownership - WP_OWNER=$(stat -c '%U' "$FIRST_WP" 2>/dev/null || stat -f '%Su' "$FIRST_WP" 2>/dev/null) - WP_PERMS=$(stat -c '%a' "$FIRST_WP" 2>/dev/null || stat -f '%Lp' "$FIRST_WP" 2>/dev/null) - - test_info "wp-config.php owner: $WP_OWNER" - test_info "wp-config.php permissions: $WP_PERMS" - - # Try to extract database info - DB_NAME=$(grep "DB_NAME" "$FIRST_WP" 2>/dev/null | head -1 | cut -d"'" -f4) - DB_USER=$(grep "DB_USER" "$FIRST_WP" 2>/dev/null | head -1 | cut -d"'" -f4) - - if [ -n "$DB_NAME" ]; then - test_pass "βœ“ Can extract database name: $DB_NAME" - test_info "Database user: $DB_USER" - - # Check if DB name has prefix - if echo "$DB_NAME" | grep -q "_"; then - test_info "Database has underscore (may have prefix)" - else - test_info "Database has NO underscore (likely no prefix)" - fi - else - test_warn "Could not extract database info from wp-config.php" - fi - - else - test_fail "βœ— CANNOT READ wp-config.php (permission denied)" - fi - - # Check WordPress installation directory - WP_DIR=$(dirname "$FIRST_WP") - test_info "WordPress directory: $WP_DIR" - - # List directory permissions - WP_DIR_OWNER=$(stat -c '%U:%G' "$WP_DIR" 2>/dev/null || stat -f '%Su:%Sg' "$WP_DIR" 2>/dev/null) - WP_DIR_PERMS=$(stat -c '%a' "$WP_DIR" 2>/dev/null || stat -f '%Lp' "$WP_DIR" 2>/dev/null) - - test_info "WordPress dir owner: $WP_DIR_OWNER" - test_info "WordPress dir permissions: $WP_DIR_PERMS" -fi - -################################################################################ -# TEST 14: Directory Structure Visualization -################################################################################ - -section_header "TEST 14: Directory Structure Visualization" - -test_info "Documenting directory structure for critical paths..." - -# Function to create a tree-like view (limited depth) -create_tree() { - local path="$1" - local depth="${2:-2}" - local prefix="${3:-}" - - if [ ! -d "$path" ]; then - return - fi - - # Use tree command if available, otherwise use find - if command -v tree &> /dev/null; then - tree -L "$depth" -F "$path" 2>/dev/null || find "$path" -maxdepth "$depth" -type d 2>/dev/null | head -50 - else - find "$path" -maxdepth "$depth" 2>/dev/null | head -50 | sed 's|[^/]*/| |g' - fi -} - -# Document domain directory structure -if [ -n "$TEST_DOMAIN" ]; then - echo "" >> "$RESULTS_FILE" - echo "=== DOMAIN DIRECTORY STRUCTURE: $TEST_DOMAIN ===" >> "$RESULTS_FILE" - echo "" >> "$RESULTS_FILE" - - test_info "Documenting domain structure for $TEST_DOMAIN..." - - DOMAIN_PATH="/var/www/vhosts/$TEST_DOMAIN" - if [ -d "$DOMAIN_PATH" ]; then - echo "Full path: $DOMAIN_PATH" >> "$RESULTS_FILE" - echo "" >> "$RESULTS_FILE" - create_tree "$DOMAIN_PATH" 3 >> "$RESULTS_FILE" 2>&1 - fi - - # Document log directory structure - echo "" >> "$RESULTS_FILE" - echo "=== LOG DIRECTORY STRUCTURE: $TEST_DOMAIN ===" >> "$RESULTS_FILE" - LOG_PATH="/var/www/vhosts/system/$TEST_DOMAIN" - if [ -d "$LOG_PATH" ]; then - echo "Full path: $LOG_PATH" >> "$RESULTS_FILE" - echo "" >> "$RESULTS_FILE" - create_tree "$LOG_PATH" 2 >> "$RESULTS_FILE" 2>&1 - - # List actual log files with sizes - echo "" >> "$RESULTS_FILE" - echo "Log files:" >> "$RESULTS_FILE" - ls -lh "$LOG_PATH/logs/" 2>/dev/null >> "$RESULTS_FILE" - fi -fi - -# Document general vhosts structure -echo "" >> "$RESULTS_FILE" -echo "=== GENERAL VHOSTS STRUCTURE ===" >> "$RESULTS_FILE" -test_info "Documenting /var/www/vhosts structure..." - -if [ -d "/var/www/vhosts" ]; then - echo "Depth 1 view of /var/www/vhosts:" >> "$RESULTS_FILE" - ls -lh /var/www/vhosts/ 2>/dev/null | head -20 >> "$RESULTS_FILE" - - # Show one sample domain structure - SAMPLE_DOMAIN=$(find /var/www/vhosts -maxdepth 1 -type d ! -name "vhosts" ! -name "system" ! -name "default" 2>/dev/null | head -1) - if [ -n "$SAMPLE_DOMAIN" ]; then - echo "" >> "$RESULTS_FILE" - echo "Sample domain structure: $(basename "$SAMPLE_DOMAIN")" >> "$RESULTS_FILE" - create_tree "$SAMPLE_DOMAIN" 2 >> "$RESULTS_FILE" 2>&1 - fi -fi - -# Document Plesk directory structure -echo "" >> "$RESULTS_FILE" -echo "=== PLESK SYSTEM DIRECTORIES ===" >> "$RESULTS_FILE" -test_info "Documenting Plesk system directories..." - -if [ -d "/usr/local/psa" ]; then - echo "/usr/local/psa structure (depth 1):" >> "$RESULTS_FILE" - ls -lh /usr/local/psa/ 2>/dev/null >> "$RESULTS_FILE" -fi - -# Document PHP directory structure -echo "" >> "$RESULTS_FILE" -echo "=== PHP DIRECTORY STRUCTURE ===" >> "$RESULTS_FILE" -if [ -d "/opt/plesk/php" ]; then - echo "/opt/plesk/php structure:" >> "$RESULTS_FILE" - create_tree "/opt/plesk/php" 2 >> "$RESULTS_FILE" 2>&1 -fi - -################################################################################ -# TEST 15: Comprehensive System Documentation -################################################################################ - -section_header "TEST 15: Comprehensive System Documentation" - -test_info "Gathering complete system information for future reference..." - -# Document all Plesk binaries -test_info "Cataloging Plesk bin commands..." -if [ -d "/usr/local/psa/bin" ]; then - echo "" >> "$RESULTS_FILE" - echo "=== ALL PLESK BIN COMMANDS ===" >> "$RESULTS_FILE" - ls -1 /usr/local/psa/bin >> "$RESULTS_FILE" -fi - -# Document Plesk version info -test_info "Documenting Plesk version details..." -if command -v plesk &> /dev/null; then - echo "" >> "$RESULTS_FILE" - echo "=== PLESK VERSION DETAILS ===" >> "$RESULTS_FILE" - plesk version 2>/dev/null >> "$RESULTS_FILE" -fi - -# Document all domains on system -test_info "Cataloging all domains on system..." -ALL_DOMAINS=$(find /var/www/vhosts -maxdepth 1 -type d ! -name "vhosts" ! -name "system" ! -name "default" ! -name "chroot" 2>/dev/null | xargs -n1 basename | sort) -if [ -n "$ALL_DOMAINS" ]; then - DOMAIN_COUNT=$(echo "$ALL_DOMAINS" | wc -l) - echo "" >> "$RESULTS_FILE" - echo "=== ALL DOMAINS ON SYSTEM (Total: $DOMAIN_COUNT) ===" >> "$RESULTS_FILE" - echo "$ALL_DOMAINS" >> "$RESULTS_FILE" -fi - -# Document PHP versions available -test_info "Documenting all PHP versions..." -echo "" >> "$RESULTS_FILE" -echo "=== PHP VERSIONS AVAILABLE ===" >> "$RESULTS_FILE" -if [ -d "/opt/plesk/php" ]; then - ls -1d /opt/plesk/php/*/ 2>/dev/null | xargs -n1 basename >> "$RESULTS_FILE" -fi -which php 2>/dev/null >> "$RESULTS_FILE" -php -v 2>/dev/null | head -1 >> "$RESULTS_FILE" - -# Document Apache/nginx configuration -test_info "Documenting web server setup..." -echo "" >> "$RESULTS_FILE" -echo "=== WEB SERVER CONFIGURATION ===" >> "$RESULTS_FILE" -if ps aux | grep -v grep | grep -q "nginx"; then - echo "nginx: RUNNING" >> "$RESULTS_FILE" - nginx -v 2>&1 >> "$RESULTS_FILE" -fi -if ps aux | grep -v grep | grep -q "httpd\|apache"; then - echo "Apache: RUNNING" >> "$RESULTS_FILE" - httpd -v 2>&1 >> "$RESULTS_FILE" || apache2 -v 2>&1 >> "$RESULTS_FILE" -fi - -# Document database server -test_info "Documenting database server..." -echo "" >> "$RESULTS_FILE" -echo "=== DATABASE SERVER ===" >> "$RESULTS_FILE" -if command -v mysql &> /dev/null; then - mysql -V >> "$RESULTS_FILE" 2>&1 -fi - -# Create a quick reference for developers -echo "" >> "$RESULTS_FILE" -echo "=======================================================================" >> "$RESULTS_FILE" -echo "QUICK REFERENCE FOR DEVELOPERS" >> "$RESULTS_FILE" -echo "=======================================================================" >> "$RESULTS_FILE" -echo "" >> "$RESULTS_FILE" -echo "Document roots: /var/www/vhosts/DOMAIN/httpdocs/" >> "$RESULTS_FILE" -echo "Access logs: /var/www/vhosts/system/DOMAIN/logs/access_log" >> "$RESULTS_FILE" -echo "Error logs: /var/www/vhosts/system/DOMAIN/logs/error_log" >> "$RESULTS_FILE" -echo "WordPress: /var/www/vhosts/DOMAIN/httpdocs/wp-config.php" >> "$RESULTS_FILE" -echo "" >> "$RESULTS_FILE" - -if [ -n "$CRON_USER" ]; then - echo "Cron user: $CRON_USER" >> "$RESULTS_FILE" - echo "Cron command: crontab -u $CRON_USER" >> "$RESULTS_FILE" -fi - -if [ -n "$DB_NAME" ]; then - echo "" >> "$RESULTS_FILE" - echo "Sample database: $DB_NAME" >> "$RESULTS_FILE" - if echo "$DB_NAME" | grep -q "_"; then - echo "Database prefix: APPEARS TO HAVE PREFIX" >> "$RESULTS_FILE" - else - echo "Database prefix: APPEARS TO BE NO PREFIX" >> "$RESULTS_FILE" - fi -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 "Plesk validation successful!" - echo "" - echo "CRITICAL ANSWERS DISCOVERED:" - if [ -n "$CRON_USER" ]; then - echo " β€’ Cron user: $CRON_USER" - fi - if [ -n "$DB_NAME" ]; then - echo " β€’ Database pattern: $(echo "$DB_NAME" | grep -q "_" && echo "HAS PREFIX" || echo "NO PREFIX")" - fi - if [ -n "$FILE_OWNER" ]; then - echo " β€’ File ownership: $FILE_OWNER" - fi -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 "NEXT STEPS:" -echo "=======================================================================" -echo "1. Review $RESULTS_FILE for complete details" -echo "2. Report findings to development team" -echo "3. Test actual toolkit modules if validation passed" -echo "=======================================================================" - -exit 0