<?php
/**
 * WAF 403 Blocked View
 *
 * @package VMPFence
 * @since 2.0.0
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>403 Forbidden - WAF Blocked</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: #333;
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            padding: 20px;
        }
        .container {
            background: white;
            border-radius: 10px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
            max-width: 700px;
            width: 100%;
            padding: 40px;
        }
        .shield-icon {
            text-align: center;
            font-size: 64px;
            color: #d32f2f;
            margin-bottom: 20px;
        }
        h1 {
            color: #d32f2f;
            font-size: 32px;
            margin-bottom: 10px;
            text-align: center;
        }
        h2 {
            color: #666;
            font-size: 18px;
            font-weight: normal;
            margin-bottom: 30px;
            text-align: center;
        }
        .details {
            background: #f5f5f5;
            border-left: 4px solid #d32f2f;
            padding: 20px;
            border-radius: 5px;
            margin-top: 20px;
        }
        .details h3 {
            font-size: 16px;
            margin-bottom: 15px;
            color: #333;
        }
        .details p {
            margin: 8px 0;
            font-size: 14px;
            line-height: 1.6;
        }
        .details strong {
            color: #555;
            display: inline-block;
            min-width: 120px;
        }
        .violation-list {
            margin-top: 15px;
            background: white;
            padding: 15px;
            border-radius: 4px;
        }
        .violation-item {
            padding: 8px 0;
            border-bottom: 1px solid #eee;
            font-size: 13px;
        }
        .violation-item:last-child {
            border-bottom: none;
        }
        .badge {
            display: inline-block;
            padding: 3px 8px;
            border-radius: 3px;
            font-size: 11px;
            font-weight: 600;
            text-transform: uppercase;
        }
        .badge-xss { background: #ffebee; color: #c62828; }
        .badge-sqli { background: #fff3e0; color: #e65100; }
        .badge-rfi { background: #fce4ec; color: #880e4f; }
        .badge-lfi { background: #f3e5f5; color: #6a1b9a; }
        .badge-rce { background: #ffcdd2; color: #b71c1c; }
        .info {
            margin-top: 30px;
            padding: 15px;
            background: #e3f2fd;
            border-radius: 5px;
            font-size: 14px;
            color: #1565c0;
            line-height: 1.6;
        }
        .footer {
            margin-top: 30px;
            text-align: center;
            font-size: 12px;
            color: #999;
        }
        .request-id {
            font-family: 'Courier New', monospace;
            background: #263238;
            color: #4db6ac;
            padding: 2px 6px;
            border-radius: 3px;
            font-size: 12px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="shield-icon">🛡️</div>
        <h1>Access Denied</h1>
        <h2>Web Application Firewall Blocked Your Request</h2>

        <div class="details">
            <h3>Security Violation Detected</h3>
            <p><strong>Time:</strong> <?php echo esc_html(current_time('mysql')); ?></p>
            <p><strong>Your IP:</strong> <?php echo esc_html($ip ?? $_SERVER['REMOTE_ADDR']); ?></p>
            <!-- <p><strong>Request ID:</strong> <span class="request-id"><?php echo esc_html($request_id ?? uniqid('waf_')); ?></span></p> -->
            <p><strong>Total Score:</strong> <?php echo esc_html($total_score ?? 0); ?></p>

            <?php if (!empty($violations)): ?>
            <div class="violation-list">
                <strong>Violations Detected:</strong>
                <?php foreach ($violations as $violation): ?>
                <div class="violation-item">
                    <span class="badge badge-<?php echo esc_attr(strtolower($violation['category'] ?? 'unknown')); ?>">
                        <?php echo esc_html($violation['category'] ?? 'Unknown'); ?>
                    </span>
                    <?php echo esc_html($violation['description'] ?? 'Security rule triggered'); ?>
                    (Score: <?php echo esc_html($violation['score'] ?? 0); ?>)
                </div>
                <?php endforeach; ?>
            </div>
            <?php endif; ?>
        </div>

        <div class="info">
            <strong>What happened?</strong><br>
            Our Web Application Firewall detected potentially malicious patterns in your request. This could be due to:
            <ul style="margin: 10px 0 0 20px;">
                <li>Malicious payload in request parameters</li>
                <li>SQL injection attempt</li>
                <li>Cross-site scripting (XSS) attempt</li>
                <li>Remote file inclusion attempt</li>
                <li>Command injection attempt</li>
            </ul>
        </div>

        <?php if (!empty($custom_text)): ?>
        <hr style="border: none; border-top: 1px solid #ddd; margin: 30px 0;">
        <div class="custom-message" style="background: #f8f9fa; border: 1px solid #e9ecef; border-radius: 5px; padding: 20px; color: #495057;">
            <?php echo $custom_text; ?>
        </div>
        <?php endif; ?>

        <div class="info" style="background: #fff3e0; color: #e65100;">
            <strong>If you believe this is a false positive:</strong><br>
            Please contact the website administrator with the Request ID shown above. They can review this block and whitelist legitimate requests if necessary.
        </div>

        <div class="footer">
            Protected by VMPFence Security Plugin
        </div>
    </div>
</body>
</html>
