When I execute the command enable with ssh2_exec()
, I can't load the page because it is waiting for the password.
I tried to do ssh2_exec(connection,'password')
and the problem persists.
My question is how to put the enable password ?
here is my code :
<?php
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
if(!($con = ssh2_connect("9.0.0.1", 22))){
echo "fail: unable to establish connection
";
} else {
// try to authenticate with username root, password secretpassword
if(!ssh2_auth_password($con, "mehdi", "123")) {
echo "fail: unable to authenticate
";
} else {
// allright, we're in!
echo "okay: logged in...
";
// execute a command
if (!($stream = ssh2_exec($con, 'enable'))) {
echo "fail: unable to execute command
";
} else {
// collect returning data from command
stream_set_blocking($stream, true);
ssh2_exec($con, 'PASSWORD');
$data = "";
while ($buf = fread($stream,4096)) {
$data .=PHP_EOL. date("Y-m-d H:i:s ").$buf;
$data .= PHP_EOL."------------------------------------------------------------------------------------------------------------------------
";
}
echo $data;
$fh = fopen("log".date("Y-m-d").".txt", 'a+') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
fclose($stream);
}
}
}
?>
ps: i am trying to configure a Cisco router