Running root commands through a web server seems like a crazy idea to me, but anyway.
You can use sudo to not run any unwanted commands.
A small example taken from here is sudo config:
peter, %operator ALL= /sbin/, /usr/sbin, /usr/local/apps/check.pl
And in php:
exec( 'sudo /usr/local/apps/check.pl ...');
Be sure to avoid all arguments correctly, etc.
Or you could build the db table as follows:
commands ( action, serialized_parameters. result, return_code )
Use php to insert commands into this table, and another script that will be run in cron by different users. You will not have real-time results (but you can have them for 30 seconds), but the apache user will not be able to use any command directly (of course, you can easily limit actions when reading records).
Vyktor
source share