I'm looking for a clean and secure way to run specific Linux system commands from a web interface.
Let's say I would like to
sudo -u differentuser ping 0.0.0.0. The IP address is supplied by user in a HTTP request and I'd like to print the result on a web page. What would be the best way to do this?
I was thinking about using PHP's
exec() command :
<?php echo exec('sudo -u differentuser ping ' . $_POST['ip']);
But this seems very dirty and unsecure and I'd have to add the apache user to the sudoers file.
What language would you use and how would you achieve this?
Thanks for your help.
Edit : the
sudo is important here, because I need to run those commands as a specific user different from the one used to host the web interface.