php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80930 Reqex data do not get stored into $match[0]
Submitted: 2021-04-03 08:00 UTC Modified: 2021-04-11 04:22 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: benjamin dot lugger at gmail dot com Assigned:
Status: No Feedback Package: expect (PECL)
PHP Version: 7.3.27 OS: Linux 5.10.17-v7l+ #1403 SMP Mon
Private report: No CVE-ID: None
 [2021-04-03 08:00 UTC] 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:


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-03 08:02 UTC] 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:03 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
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
 [2021-04-03 08:08 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
> The same script hat been testet on a system running php5. There it works fine

so you are jumping from php5 straight to 7.3.23 in 2021?
congratulations..... this is asking for troubles in many ways

7.3 is BTW also EOL end of the year
anywayyxs, fix the subject and get a useable reproducer
 [2021-04-03 08:21 UTC] benjamin dot lugger at gmail dot com
pear help version
PEAR Version: 1.10.6
PHP Version: 7.3.27-1~deb10u1
Zend Engine Version: 3.3.27
Running on: pi 5.10.17-v7l+ #1403 SMP Mon Feb 22 11:33:35 GMT 2021 armv7l
 [2021-04-03 08:22 UTC] benjamin dot lugger at gmail dot com
-Summary: None +Summary: Reqex data do not get stored into $match[0]
 [2021-04-03 08:22 UTC] benjamin dot lugger at gmail dot com
Subject changed.
 [2021-04-03 08:25 UTC] benjamin dot lugger at gmail dot com
-Package: *Regular Expressions +Package: expect
 [2021-04-03 08:25 UTC] benjamin dot lugger at gmail dot com
Package changed to expect.
 [2021-04-03 19:32 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2021-04-03 19:32 UTC] requinix@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


We can't reproduce something that has ssh commands to your router. You're going to have to debug this yourself, possibly by pulling out expect entirely and reading and writing commands manually, until you can reach a point where you've definitively identified that there is a bug in expect.
 [2021-04-11 04:22 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC