2

I'm trying to run a command from PHP to disconnect a user from OpenVPN Access Server

    $output = shell_exec('sacli --user test --client_reason EXPIRED DisconnectUser');
    echo "<pre>$output</pre>";

This won't work and doesn't disconnect user, I confirmed the full command works in the terminal.

If I just use shell_exec('sacli'); or shell_exec('sacli --help'); it will echo successfully:

sacli: No command specified

Use --help to show usage

Any help is appreciated,

Thanks!

Azzy
  • 23
  • 2
  • `I confirmed the full command works in the terminal.` as the same user you are running php as via http? – AD7six Jul 24 '22 at 07:13

1 Answers1

-1

The most common problem here is that you're not running it with sudo or as root user. Do that and it should work fine

  • Are you suggesting `shell_exec('sudo sacli…`? – AD7six Jul 23 '22 at 19:04
  • no, which user run this application this user have proper privilege or not i suggesting that thing. – Hasan Ali Haolader Jul 23 '22 at 19:08
  • That amounts to the same thing. It’s implied in the question this is http, not cli (because it has html in it) - running php with root privileges is a _huge_ risk and not something to recommend. It does indeed sound like a permission problem, fixing permissions so the php user can run that command if that’s the intention does sound like the necessary approach. -1 as written. – AD7six Jul 23 '22 at 19:11
  • I have added www-data to sudoers for testing purposes, so permissions shouldn't be an issue: www-data ALL=(ALL) NOPASSWD: ALL – Azzy Jul 24 '22 at 02:00