Bug #80930 [Com]: None
| From: | rtrtrtrtrt at dfdfdfdf dot dfd | Date: | Sat, 03 Apr 2021 08:03:46 +0000 |
| Subject: | Bug #80930 [Com]: None | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233136@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80930&edit=1
ID: 80930
Comment by: rtrtrtrtrt at dfdfdfdf dot dfd
Reported by: benjamin dot lugger at gmail dot com
Summary: None
Status: Open
Type: Bug
Package: *Regular Expressions
Operating System: Linux 5.10.17-v7l+ #1403 SMP Mon
PHP Version: 7.3.27
Block user comment: N
Private report: N
New Comment:
1: "None" is not a appealign subject
2: how is that related to regular expressions
3: this is not a reproducer somone can use, wll, to reproduce it
a reproducer can be taken and executed as it is on teh developer side
Previous Comments:
------------------------------------------------------------------------
[2021-04-03 08:02:39] benjamin dot lugger at gmail dot com
The same script hat been testet on a system running php5. There it works fine.
------------------------------------------------------------------------
[2021-04-03 08:00:03] benjamin dot lugger at gmail dot com
Description:
------------
The script is used to access a router using SSH. This works fine.
It is also possible to issue commands on the router.
But it is not possible to get the information into the variable $match[0].
I have installed the latest pecl release on a Pi as well on other Ubuntos running PHP7. The problem
seems to be related to php7. I did not change the php.ini. The installation was simple doing the
following commands on a PI.
sudo apt-get -y install php-pecl-http
sudo apt-get -y install php-pear
sudo pecl channel-update pecl.php.net
sudo apt-get -y install tcl tcl-expect tcl-expect-dev php-dev tcl-dev expect-dev
sudo pecl install expect
I also added the entry for the expect.so in the php.ini. Otherwise the script would not work at all.
As mentioned, the scrip can access the router and issue commands. This can be seen when setting
"ini_set ("expect.loguser", "On");". For whatever reason the script is
not able to store the regexpt :-) data in $match[0].
Test script:
---------------
<?php
$username = 'username;
$password = 'password';
$testip = 'ipaddress';
define('PASSWORD', 'PASSWORD'); define('ENABLE', 'ENABLE');
define('YESNO', 'YESNO'); define('CONFIRM', 'CONFIRM');
define('SHELL', 'SHELL');
ini_set ("expect.loguser", "Off");
ini_set ("expect.match_max", 10000000);
ini_set ("expect.timeout", 120);
$stream = expect_popen ("ssh -c aes256-cbc -oKexAlgorithms=+diffie-hellman-group1-sha1
".$username."@".$testip);
$command01 = '';
while (true) {
switch (expect_expectl ($stream, array (
array ("assword:", PASSWORD), // SSH is asking for password
array (">", ENABLE, EXP_EXACT), // ENABLE
array ("yes/no)?", YESNO), // SSH is asking whether to store the host entry
array ("confirm", CONFIRM), // SSH is asking whether to store the host entry
array (".*#", SHELL, EXP_REGEXP), // Command Prompt
), $match)) {
# Case Password
case PASSWORD:
fputs ($stream, $password."\n");
break;
# Case Password Yes/No
case YESNO:
fputs ($stream, "yes"."\n");
break;
# Case CLI Commands
case SHELL:
if ($command01 == '') {
fputs ($stream, "term len 0"."\n");
$command01 = 'done';
sleep(1);
break;
}
else {
$show = sendCommand($stream, "show clock");
print "OUTPUT:\n$show\n";
$show = sendCommand($stream, "logout");
break 2;
}
# Case
case EXP_TIMEOUT:
# Case
case EXP_EOF:
break 2;
default:
die ("Error has occurred!");
}
}
fclose ($stream);
function sendCommand($mystream, $mycommand)
{
fputs ($mystream, $mycommand."\n");
switch (expect_expectl ($mystream, array (array (".*#", SHELL, EXP_REGEXP)), $match)) {
case SHELL:
return $match[0];
break;
}
}
?>
Expected result:
----------------
TESTSYSTEM1:/home # php ssh2.php
OUTPUT:
show clock
07:46:12.240 UTC Sat Apr 3 2021
ROUTER#
Actual result:
--------------
TESTSYSTEM2:/home $ php ssh2.php
ROUTER:
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80930&edit=1