How to achieve telnet and ssh login locally and use the operation command HTML page

Below is an example HTML webpage that allows you to log into a remote computer using telnet or ssh and use action commands:

<!DOCTYPE html>
<html>
<head>
<title>Telnet and SSH Login Operation Command Window</title>
</head>
<body>
<h1>Telnet and SSH Login Operation Command Window</h1>
<p>This is a webpage that allows you to login to a remote computer using telnet or ssh.</p>
<form action="/" method="post">
<input type="text" name="hostname" placeholder="Hostname">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<input type="radio" name="protocol" value="telnet" checked="checked"> Telnet
<input type="radio" name="protocol" value="ssh"> SSH
<input type="submit" value="Login">
</form>
<?php
if (isset($_POST['hostname']) && isset($_POST['username']) && isset($_POST['password'])) {
$hostname = $_POST['hostname'];
$username = $_POST['username'];
$password = $_POST['password'];
$protocol = $_POST['protocol'];

if ($protocol == "telnet") {
$command = "telnet $hostname";
} else if ($protocol == "ssh") {
$command = "ssh $username@$hostname";
}

exec($command, $output);

if ($output === 0) {
echo "Login successful.";
echo "<br>";
echo "Enter operating commands:";
while (true) {
$command = trim(fgets(STDIN));
if ($command == "exit") {
break;
}
$output = shell_exec($command);
echo $output;
}
} else {
echo "Login failed.";
}
}
?>
</body>
</html>

This code will create a web page that allows you to enter the remote computer's hostname, username, and password. You can then choose to log in to the remote computer using telnet or ssh. If the login is successful, the web page will prompt "login successful". It will then prompt you for an action command. You can enter any action command you would normally enter on a remote computer. After entering the command, you can type "exit" to exit the command prompt.

Guess you like

Origin blog.csdn.net/z306417888/article/details/130037635