2

This code not running when in PHP code called from web. but it runs on cli normally. chmod of sh file is 777.

$c = shell_exec('printf "{$res}" | ./new-openvpn-client.sh {$user}');
duac
  • 37
  • 2

2 Answers2

0

As mentioned in the other answer, a single quoted string will not parse variables, so you need to use double-quoted. But you also need to ensure the arguments to your external commands are properly quoted and sanitized. Use escapeshellarg() for that.

$res = escapeshellarg($res);
$user = escapeshellarg($user);
$c = shell_exec("printf $res | ./new-openvpn-client.sh $user");

And it's very unlikely that ./new-openvpn-client.sh is going to resolve properly. Put the script in a reasonable location like /usr/local/bin/ and provide the full path in the command.

miken32
  • 39,644
  • 15
  • 91
  • 133
  • interestingly not triggering shel exec but echoes at every solution. is there a safemode or something for this. i have placed sh under /usr/bin – duac Sep 26 '18 at 14:38
  • also s this is not working $re=shell_exec('useradd asdfg1'); this is openvpn methods useradd and passwd – duac Sep 26 '18 at 14:57
0

This is a permission issue on application executables. I have resolved through giving true permission to apache user.

duac
  • 37
  • 2