I am trying to implement one PHP GUI that first establishes an SSH connection to a server and then it opens a Telnet connection to one machine that want to send a command to reboot. I have already tried the commands on a CLI (The SSH connection, Telnet connection, and the reboot command through this Telnet session).
But in my implementation I think I am missing something while trying to send the command to the Telnet session. Can some one give me a clue ?
<?php
function rebootMachine() {
$original_Timeout=ini_get('default_socket_timeout');
ini_set('default_socket_timeout',10);
/IP addresses of the Server and the Machine
$server_ip = 10.0.0.1 ;
$machine_ip = 10.10.0.1;
//Telnet port to the Machine
$port_telnet = 49150;
$connection=@ssh2_connect($server_ip,22);
if(false==$connection){
echo "Server is unreacheable";
}else{
//conection the the Server
$auth=@ssh2_auth_password($connection, 'username','password');
if(false==$auth){
echo 'Authentication failed';
}else{
//Conection to the machine by Telnet
$stream=@ssh2_exec($connection, 'telnet machine_ip port_tcp');
if (false==$stream){
echo 'error';
}else{
//command to reboot the Machine
$stream_telnet=exec(":SYSTEM:REBOOT");
}
fclose($stream);
}
}
}