I have got in my network topology:machine_1, server_1 and machine_2.
I am developing an application that will be hosted in machine_1. One of the functionalities of the application is to connect to the server_1 through a ssh connection (I have used ssh2_exec) and then the server_1 is able to reach machine_2 .
What I want to do is to send a telnet command inside this server_1 to the machine_2. As I have made the connection to the server_1 through the ssh2_exec command, is there a way to establish this telnet connection and then send the telnet command in PHP?
*obs: I am just able to send the command to the machine_2 through an established telnet connection from server_1.
<?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_2= 10.10.0.1;
$command =“ system:REBOOT”;
//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_2 by Telnet
$stream=@ssh2_exec($connection, 'telnet $machine_2 $port_telnet');
if (false==$stream){
echo 'error';
}else{
//command to reboot the Machine
}
fclose($stream);
}
}
}