0

I have a problem trying to run passthru function in my php code (Joomla module). the code is following (this is only a snippet)

ob_start();
passthru("/usr/bin/whois 85.70.231.130 | /usr/bin/grep 'address:'",$code);
$whoisData = ob_get_contents();
ob_end_clean();
$whoisData = str_replace("address:", "", $whoisData);
$whoisArray = split("\n",$whoisData);
echo trim($whoisArray[1]);    

when I run this on my localhost, it echoes what it should, but when I run this code on the production server, it echoes nothing and the $code variable contains 127 (command not found). I tryied add absolute paths to these commands into the passthru function, but it didn't helped. Interesting is, that when I run the code right from terminal via ssh and php command, it runs well, but when it's called from application context it doesn't. Does anybody know what I should to do?thanks

SOME EDITS.. safe_mode is on webserver does not see into /usr/bin and /bin/ folders so what is the best way how to run these commands from php?

simekadam
  • 7,334
  • 11
  • 56
  • 79

3 Answers3

2

usr/bin/grep doesn't look like a valid path to a command.

The missing / at the beginning of the path to the second command might explain the command not found error... even if the first whois command is found.

Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
  • ouch sorry, I edited the code which I posted here, the snippet came from my small test file, where wasn't it up to date, but on production server where I am testing it, is it ok..So thanks, it is not the point:) I'll edit the post. – simekadam Apr 06 '11 at 11:31
1

Have you looked to see if your webserver / php is running chrooted?

print_r(glob('/*'));
if (file_exists('/usr/bin/grep') && file_exists('/usr/bin/whois')) {
   print "maybe its a permissions thing?\n";
} else {
   print "can't see executables required\n";
}

should give you a clue.

symcbean
  • 47,736
  • 6
  • 59
  • 94
  • So it seems not to be running chrooted..It prints this warning: Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/bin/grep) is not within the allowed path(s): (/mnt/data/accounts/m/medusedesign/data/www/new2:/tmp/uploads) in /mnt/data/accounts/m/medusedesign/data/www/new2/untitled.php on line 11 – simekadam Apr 06 '11 at 17:53
0

So I have already solved my problem with phpwhois library. I seems like with my server configuration is it unlikely that these functions will be working well. So thanks for your help:)

simekadam
  • 7,334
  • 11
  • 56
  • 79