Hi everybody,
I've spent a lot of time in my php ssh2 problem. I try to etablish a connexion between php and a routeur CISCO. When I creat a ssh conexion in my shell, no problem, I can modify all the configuration without any restriction but when I do the same with PHP, it's not working. The script runs without visible error but doesn't do anything in the configuration. But the connexion is ok, authentification is ok, and when I look in my routeur terminal with telnet, I can see the adminitration session from php so he's connected !!!
I'm running PHP5.0.3, Apache 2 on Linux Ubuntu.
<?php
/* Notification à l'utilisateur si le serveur termine la connexion */
function my_ssh_disconnect($reason, $message, $language) {
printf("Le serveur s'est déconnecté avec le code [%d] et le message : %s\n",
$reason, $message);
}
$methods = array(
'kex' => 'diffie-hellman-group1-sha1',
'client_to_server' => array(
'crypt' => '3des-cbc',
'comp' => 'none'),
'server_to_client' => array(
'crypt' => 'aes256-cbc,aes192-cbc,aes128-cbc',
'comp' => 'none'));
$callbacks = array('disconnect' => 'my_ssh_disconnect');
$connection = ssh2_connect('192.168.100.2',22, $methods, $callbacks);
if (!$connection) die('Echec de la connexion');
if (ssh2_auth_password($connection, 'ciscoSDM', 'ciscoSDM')) {
echo "Identification réussi !\n";
} else {
die('Echec de l\'identification...');
}
$shell=ssh2_shell($connection, 'xterm');
$stderr_stream = ssh2_fetch_stream($shell, SSH2_STREAM_STDERR);
fwrite( $shell, "configure terminal \n");
fwrite( $shell, "telephony-service \n");
fwrite( $shell, "voicemail 777 \n");
fwrite( $shell, "exit \n");
fwrite( $shell, "exit \n");
fclose($shell);
Any advice or help will be extremely appreciated 😕
Thanks