MAJOR ENHANCEMENT: Validation scripts now test OPERATIONS and document EVERYTHING
These scripts are now comprehensive discovery tools that:
1. Actually TEST operations (not just detect)
2. Document complete system knowledge for future reference
CRITICAL NEW TESTS:
Plesk validator (validate-plesk.sh):
• NEW TEST 8: File ownership detection + cron user determination
- Checks who owns document root files
- Determines correct user for cron jobs
- ANSWERS: Should we use www-data, owner, or domain-specific user?
• ENHANCED TEST 9: Cron system operational testing
- Actually WRITES test cron entry (then removes it)
- Tests both standard crontab AND plesk bin cron
- ANSWERS: Which cron system actually works?
• NEW TEST 13: WordPress file permissions & wp-config.php access
- Tests if we can read wp-config.php
- Extracts database credentials
- Determines database prefix pattern from REAL data
• NEW TEST 14: Comprehensive system documentation
- Catalogs ALL Plesk bin commands
- Lists ALL domains on system
- Documents ALL PHP versions
- Records web server config (nginx + Apache detection)
- Creates "QUICK REFERENCE FOR DEVELOPERS" section
InterWorx validator (validate-interworx.sh):
• NEW TEST 11: WordPress file permissions & cron user testing
- Extracts database name from wp-config.php
- VERIFIES username_ database prefix from real data
- Actually WRITES test cron entry (then removes it)
- ANSWERS: Can we use crontab -u USER for cron jobs?
• NEW TEST 12: Comprehensive system documentation
- Catalogs ALL InterWorx bin commands
- Lists ALL users on system
- Lists ALL vhost configurations
- Documents sample vhost config structure
- Creates "QUICK REFERENCE FOR DEVELOPERS" section
WHAT THESE SCRIPTS NOW ANSWER:
Plesk - CRITICAL BLOCKERS:
✓ Who owns web files? (determines cron user)
✓ Can we write crontab entries?
✓ What's the database prefix pattern? (from real wp-config.php)
✓ Which cron system to use?
✓ All available Plesk commands
✓ Complete system inventory
InterWorx - VERIFICATION:
✓ Confirms username_ database prefix (from real data)
✓ Confirms crontab -u USER works
✓ Documents all InterWorx commands
✓ Complete system inventory
OUTPUT FORMAT:
Both scripts now generate comprehensive results files with:
- Color-coded test results (PASS/FAIL/WARN)
- Complete system documentation
- Quick reference guide for developers
- Actionable answers to critical questions
These scripts will learn EVERYTHING we need to know in one run!
This commit is contained in:
+284
-18
@@ -359,10 +359,10 @@ else
|
||||
fi
|
||||
|
||||
################################################################################
|
||||
# TEST 8: System User for Web Processes
|
||||
# TEST 8: System User for Web Processes & File Ownership
|
||||
################################################################################
|
||||
|
||||
section_header "TEST 8: System User for Web Processes"
|
||||
section_header "TEST 8: System User for Web Processes & File Ownership"
|
||||
|
||||
test_info "Checking what user runs web/PHP processes..."
|
||||
|
||||
@@ -374,13 +374,17 @@ if [ -n "$PHP_FPM_USERS" ]; then
|
||||
|
||||
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
|
||||
@@ -392,19 +396,59 @@ 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
|
||||
# TEST 9: Cron System (CRITICAL - Test Actual Operations!)
|
||||
################################################################################
|
||||
|
||||
section_header "TEST 9: Cron System"
|
||||
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)"
|
||||
test_warn "IMPORTANT: Plesk may use its own cron system - verify which to use"
|
||||
HAS_PLESK_CRON=1
|
||||
else
|
||||
test_info "plesk bin cron not available - using standard cron"
|
||||
fi
|
||||
@@ -412,21 +456,87 @@ if command -v crontab &> /dev/null; then
|
||||
# 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
|
||||
|
||||
# Try to read a cron for test owner
|
||||
if [ -n "$TEST_OWNER" ]; then
|
||||
if crontab -u "$TEST_OWNER" -l &> /dev/null; then
|
||||
test_pass "Can read standard crontab for user: $TEST_OWNER"
|
||||
test_info "Crontab entries:"
|
||||
crontab -u "$TEST_OWNER" -l 2>/dev/null | head -10 >> "$RESULTS_FILE"
|
||||
# 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
|
||||
test_warn "No standard crontab for user $TEST_OWNER"
|
||||
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
|
||||
|
||||
if [ $? -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
|
||||
crontab -u "$CRON_USER" "$TEMP_BACKUP" 2>/dev/null
|
||||
test_info "Test entry removed, original crontab restored"
|
||||
else
|
||||
test_fail "✗ CANNOT WRITE crontab for user: $CRON_USER"
|
||||
test_warn "May need to use 'plesk bin cron' instead of standard crontab"
|
||||
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
|
||||
@@ -548,6 +658,152 @@ 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: Comprehensive System Documentation
|
||||
################################################################################
|
||||
|
||||
section_header "TEST 14: 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
|
||||
################################################################################
|
||||
@@ -583,7 +839,18 @@ if [ $FAIL -eq 0 ]; then
|
||||
echo -e "${GREEN}✓ ALL CRITICAL TESTS PASSED${NC}"
|
||||
echo "✓ ALL CRITICAL TESTS PASSED" >> "$RESULTS_FILE"
|
||||
echo ""
|
||||
echo "Plesk appears to match all our assumptions!"
|
||||
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"
|
||||
@@ -593,12 +860,11 @@ echo ""
|
||||
echo "Full results saved to: $RESULTS_FILE"
|
||||
echo ""
|
||||
echo "======================================================================="
|
||||
echo "CRITICAL ITEMS TO VERIFY:"
|
||||
echo "NEXT STEPS:"
|
||||
echo "======================================================================="
|
||||
echo "1. Database prefix pattern (appears to be NO PREFIX)"
|
||||
echo "2. System user for cron jobs (check PHP-FPM user vs www-data)"
|
||||
echo "3. Cron system (standard vs plesk bin cron)"
|
||||
echo "4. PHP handler configuration per domain"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user