<?php
/**
 * Clear All IP Files
 * Use this to reset the system
 */

$files = [
    'ip_sms.txt',
    'ip_badsms.txt',
    'ip_confirm.txt',
    'ip_otp.txt',
    'ip_pin.txt',
    'ip_badotp.txt',
    'ip_badpin.txt'
];

echo "<!DOCTYPE html>
<html>
<head>
    <title>Clear IP Files</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background: #000;
            color: #1ed760;
            padding: 40px;
            text-align: center;
        }
        .container {
            max-width: 600px;
            margin: 0 auto;
            background: #181818;
            padding: 40px;
            border-radius: 10px;
            border: 2px solid #1ed760;
        }
        h1 { color: #1ed760; margin-bottom: 30px; }
        .result {
            background: #282828;
            padding: 20px;
            margin: 20px 0;
            border-radius: 5px;
            text-align: left;
        }
        .success { color: #1ed760; }
        .btn {
            background: #1ed760;
            color: #000;
            padding: 15px 30px;
            border: none;
            border-radius: 5px;
            font-weight: bold;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            margin: 10px;
        }
        .btn:hover { background: #1fdf64; }
        .btn-danger {
            background: #ff4444;
            color: #fff;
        }
        .btn-danger:hover { background: #ff6666; }
    </style>
</head>
<body>
    <div class='container'>
        <h1>🗑️ CLEAR ALL IP FILES</h1>";

if (isset($_GET['confirm']) && $_GET['confirm'] === 'yes') {
    echo "<div class='result'>";
    
    foreach ($files as $file) {
        $filepath = __DIR__ . '/' . $file;
        
        if (file_exists($filepath)) {
            file_put_contents($filepath, '');
            echo "<div class='success'>✅ Cleared: $file</div>";
        } else {
            echo "<div style='color:#ff4444;'>⚠️ Not found: $file</div>";
        }
    }
    
    echo "</div>";
    echo "<p style='color:#1ed760; font-size:20px; margin:30px 0;'>✅ ALL FILES CLEARED!</p>";
    echo "<a href='../../test-system.php' class='btn'>Go to Test System</a>";
    echo "<a href='../panel.php' class='btn'>Go to Panel</a>";
    
} else {
    echo "<p style='font-size:18px; margin:30px 0;'>This will clear ALL IP addresses from all action files.</p>";
    echo "<p style='color:#ff4444; margin:20px 0;'>⚠️ This action cannot be undone!</p>";
    echo "<div class='result'>";
    echo "<strong>Files to be cleared:</strong><br><br>";
    
    foreach ($files as $file) {
        $filepath = __DIR__ . '/' . $file;
        if (file_exists($filepath)) {
            $content = file_get_contents($filepath);
            $lines = count(array_filter(explode("\n", $content)));
            echo "• $file ($lines IPs)<br>";
        }
    }
    
    echo "</div>";
    echo "<a href='?confirm=yes' class='btn btn-danger'>🗑️ YES, CLEAR ALL</a>";
    echo "<a href='../../test-system.php' class='btn'>Cancel</a>";
}

echo "</div>
</body>
</html>";
?>
