<html> | |
<head> | |
<title>Web-based Terminal</title> | |
</head> | |
<body> | |
<h1>Web-based Terminal</h1> | |
<div id="terminal-output"></div> | |
<input type="text" id="command-input" autofocus> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.2.0/socket.io.js"></script> | |
<script> | |
var socket = io.connect('http://' + document.domain + ':' + location.port); | |
socket.on('connect', function() { | |
console.log('Connected to server'); | |
}); | |
socket.on('output', function(data) { | |
var outputDiv = document.getElementById('terminal-output'); | |
outputDiv.innerHTML += '<pre>' + data + '</pre>'; | |
outputDiv.scrollTop = outputDiv.scrollHeight; | |
}); | |
document.getElementById('command-input').addEventListener('keypress', function(event) { | |
if (event.key === 'Enter') { | |
var command = event.target.value; | |
socket.emit('command', command); | |
event.target.value = ''; | |
} | |
}); | |
</script> | |
</body> | |
</html> | |