240 lines
6.7 KiB
Bash
240 lines
6.7 KiB
Bash
#!/bin/bash
|
||
# ZitiNexus UI File Organization Audit Script
|
||
# This script checks for file organization issues that can break the UI system
|
||
|
||
echo "=============================================="
|
||
echo "ZitiNexus UI File Organization Audit"
|
||
echo "=============================================="
|
||
echo ""
|
||
|
||
# Initialize counters
|
||
ERRORS=0
|
||
WARNINGS=0
|
||
|
||
# Function to report error
|
||
report_error() {
|
||
echo "❌ ERROR: $1"
|
||
((ERRORS++))
|
||
}
|
||
|
||
# Function to report warning
|
||
report_warning() {
|
||
echo "⚠️ WARNING: $1"
|
||
((WARNINGS++))
|
||
}
|
||
|
||
# Function to report success
|
||
report_success() {
|
||
echo "✅ OK: $1"
|
||
}
|
||
|
||
echo "1. Checking for duplicate PHP files..."
|
||
echo "--------------------------------------"
|
||
|
||
# Check for duplicate index.php
|
||
if [ -f "UI/index.php" ]; then
|
||
report_error "UI/index.php exists (should be removed - use UI/public/index.php only)"
|
||
else
|
||
report_success "No duplicate index.php found"
|
||
fi
|
||
|
||
# Check for duplicate dashboard.php
|
||
if [ -f "UI/dashboard.php" ]; then
|
||
report_error "UI/dashboard.php exists (should be removed - use UI/public/dashboard.php only)"
|
||
else
|
||
report_success "No duplicate dashboard.php found"
|
||
fi
|
||
|
||
# Check for test files in production
|
||
if [ -d "UI/testfiles" ]; then
|
||
report_warning "UI/testfiles/ directory exists (should be removed in production)"
|
||
echo " Test files found:"
|
||
find UI/testfiles/ -name "*.php" -exec echo " - {}" \;
|
||
else
|
||
report_success "No testfiles directory found"
|
||
fi
|
||
|
||
echo ""
|
||
echo "2. Checking required directory structure..."
|
||
echo "-------------------------------------------"
|
||
|
||
# Check required directories
|
||
if [ -d "UI/public" ]; then
|
||
report_success "UI/public/ directory exists"
|
||
else
|
||
report_error "UI/public/ directory missing"
|
||
fi
|
||
|
||
if [ -d "UI/includes" ]; then
|
||
report_success "UI/includes/ directory exists"
|
||
else
|
||
report_error "UI/includes/ directory missing"
|
||
fi
|
||
|
||
if [ -d "UI/public/assets" ]; then
|
||
report_success "UI/public/assets/ directory exists"
|
||
else
|
||
report_error "UI/public/assets/ directory missing"
|
||
fi
|
||
|
||
if [ -d "UI/logs" ]; then
|
||
report_success "UI/logs/ directory exists"
|
||
else
|
||
report_warning "UI/logs/ directory missing (will be created automatically)"
|
||
fi
|
||
|
||
echo ""
|
||
echo "3. Checking required files..."
|
||
echo "-----------------------------"
|
||
|
||
# Check required public files
|
||
if [ -f "UI/public/index.php" ]; then
|
||
report_success "UI/public/index.php exists"
|
||
else
|
||
report_error "UI/public/index.php missing"
|
||
fi
|
||
|
||
if [ -f "UI/public/dashboard.php" ]; then
|
||
report_success "UI/public/dashboard.php exists"
|
||
else
|
||
report_error "UI/public/dashboard.php missing"
|
||
fi
|
||
|
||
# Check required include files
|
||
if [ -f "UI/includes/config.php" ]; then
|
||
report_success "UI/includes/config.php exists"
|
||
else
|
||
report_error "UI/includes/config.php missing"
|
||
fi
|
||
|
||
if [ -f "UI/includes/auth.php" ]; then
|
||
report_success "UI/includes/auth.php exists"
|
||
else
|
||
report_error "UI/includes/auth.php missing"
|
||
fi
|
||
|
||
if [ -f "UI/includes/api_client.php" ]; then
|
||
report_success "UI/includes/api_client.php exists"
|
||
else
|
||
report_error "UI/includes/api_client.php missing"
|
||
fi
|
||
|
||
if [ -f "UI/includes/enrollment.php" ]; then
|
||
report_success "UI/includes/enrollment.php exists"
|
||
else
|
||
report_error "UI/includes/enrollment.php missing"
|
||
fi
|
||
|
||
# Check required asset files
|
||
if [ -f "UI/public/assets/css/style.css" ]; then
|
||
report_success "UI/public/assets/css/style.css exists"
|
||
else
|
||
report_error "UI/public/assets/css/style.css missing"
|
||
fi
|
||
|
||
if [ -f "UI/public/assets/js/app.js" ]; then
|
||
report_success "UI/public/assets/js/app.js exists"
|
||
else
|
||
report_error "UI/public/assets/js/app.js missing"
|
||
fi
|
||
|
||
echo ""
|
||
echo "4. Checking for misplaced files..."
|
||
echo "----------------------------------"
|
||
|
||
# Check for PHP files in wrong locations
|
||
MISPLACED_FILES=$(find UI/ -maxdepth 1 -name "*.php" -not -name "index.php" -not -name "dashboard.php" 2>/dev/null)
|
||
if [ -n "$MISPLACED_FILES" ]; then
|
||
report_warning "PHP files found in UI root directory:"
|
||
echo "$MISPLACED_FILES" | while read file; do
|
||
echo " - $file"
|
||
done
|
||
else
|
||
report_success "No misplaced PHP files in UI root"
|
||
fi
|
||
|
||
# Check for assets in wrong locations
|
||
if [ -d "UI/assets" ]; then
|
||
report_error "UI/assets/ directory exists (should be UI/public/assets/)"
|
||
fi
|
||
|
||
echo ""
|
||
echo "5. Checking file permissions (if running as root/sudo)..."
|
||
echo "---------------------------------------------------------"
|
||
|
||
if [ "$EUID" -eq 0 ] || [ -n "$SUDO_USER" ]; then
|
||
# Check if files are owned by www-data (common web server user)
|
||
if [ -d "UI" ]; then
|
||
OWNER=$(stat -c '%U' UI 2>/dev/null || echo "unknown")
|
||
if [ "$OWNER" = "www-data" ]; then
|
||
report_success "UI directory owned by www-data"
|
||
else
|
||
report_warning "UI directory owned by $OWNER (consider changing to www-data for web server)"
|
||
fi
|
||
fi
|
||
else
|
||
echo "ℹ️ Skipping permission check (not running as root/sudo)"
|
||
fi
|
||
|
||
echo ""
|
||
echo "6. Checking for debug files..."
|
||
echo "------------------------------"
|
||
|
||
# Check for debug files
|
||
DEBUG_FILES=$(find UI/ -name "debug-*.php" -o -name "test-*.php" -o -name "*-debug.php" 2>/dev/null)
|
||
if [ -n "$DEBUG_FILES" ]; then
|
||
report_warning "Debug files found (should be removed in production):"
|
||
echo "$DEBUG_FILES" | while read file; do
|
||
echo " - $file"
|
||
done
|
||
else
|
||
report_success "No debug files found"
|
||
fi
|
||
|
||
echo ""
|
||
echo "=============================================="
|
||
echo "AUDIT SUMMARY"
|
||
echo "=============================================="
|
||
|
||
if [ $ERRORS -eq 0 ] && [ $WARNINGS -eq 0 ]; then
|
||
echo "🎉 EXCELLENT: File organization is perfect!"
|
||
echo " No errors or warnings found."
|
||
elif [ $ERRORS -eq 0 ]; then
|
||
echo "✅ GOOD: No critical errors found."
|
||
echo " $WARNINGS warning(s) found - consider addressing them."
|
||
else
|
||
echo "🚨 ISSUES FOUND:"
|
||
echo " $ERRORS critical error(s) that MUST be fixed"
|
||
echo " $WARNINGS warning(s) that should be addressed"
|
||
echo ""
|
||
echo "RECOMMENDED ACTIONS:"
|
||
|
||
if [ -f "UI/index.php" ] || [ -f "UI/dashboard.php" ]; then
|
||
echo "1. Remove duplicate PHP files:"
|
||
[ -f "UI/index.php" ] && echo " rm UI/index.php"
|
||
[ -f "UI/dashboard.php" ] && echo " rm UI/dashboard.php"
|
||
fi
|
||
|
||
if [ -d "UI/testfiles" ]; then
|
||
echo "2. Remove test files directory:"
|
||
echo " rm -rf UI/testfiles/"
|
||
fi
|
||
|
||
if [ ! -d "UI/public" ] || [ ! -d "UI/includes" ]; then
|
||
echo "3. Create missing required directories"
|
||
fi
|
||
|
||
echo "4. Review DEVELOPMENT_INSTRUCTIONS.md for detailed guidance"
|
||
fi
|
||
|
||
echo ""
|
||
echo "For detailed guidelines, see: UI/DEVELOPMENT_INSTRUCTIONS.md"
|
||
echo "=============================================="
|
||
|
||
# Exit with error code if critical errors found
|
||
if [ $ERRORS -gt 0 ]; then
|
||
exit 1
|
||
else
|
||
exit 0
|
||
fi
|