Forum Moderators: coopster

Message Too Old, No Replies

execute commands with root privileges from browser

how to execute root commands from GUI

         

phparion

8:18 am on Mar 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello

I am making an installer which will be run by the user in browser. However, I have to install some and modify some softwares on the system for which I will use different commands to download, compile and install. Now the problem is that if the user uses this GUI in the browser i.e by installing under web server then the scripts are executed with the php user permissions and not root. Is there any method in php that I can use to send commands in exec() or system() and those commands should be executed with the root user permissions?

I have the root access info with me.

If this is not possible in php then can I do it with PERL?

thank you

PHP_Chimp

7:38 pm on Mar 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would have to suggest that you think very very seriously about allowing people to run as root on the system.

Just imagine someone that doesnt know what the below code does runs it as root -


rm -rf /

If you would be happy giving someone the privilege to run that command then there are ways of doing what you want.
The first I can think of is running php as root. Even the thought of that sends a shiver down my spine.

However if you want your file system to survive then DO NOT UNDER ANY CIRCUMSTANCE allow people who should not be give root access the ability to kill your system. There is a reason that root access is not granted to every person that accesses the system.

If people must run root commands from a remote system then get them to ssh (or whatever encrypted communication type you use) into the system and run them from a terminal.

phparion

5:01 am on Mar 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thank you for your reply. I already know what you have said. But in my case this will be only one-time-script and server owner will run it. After completion he will remove the script from his server.

I do not want to run PHP under root because this script is one-timer then removed from server forever. The purpose of this script is to configure servers to run a video-encoding and conversion software. Once it has configured the server we do not need it anymore and no stranger got to run it ever.

So besides, running php under root and using ssh, is there any other solution?

I want to give the user a GUI so that he can configure the options with ease and without going into technical details which may be too much to digest for him.

thank you

phparion

5:09 am on Mar 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



BTW, if you have used WHM or Cpanel they both perform such tasks from GUI which require root permissions. I am not sure how do they do it.

jatar_k

2:09 pm on Mar 5, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I agree with PHP_Chimp not a great idea and there really isn't any point to it

if you need to update software on the server then that should be done by an admin anyway, any joe user shouldn't be able to do this via GUI, there is a reason it was done this way.

so it seems a pointless excercise that will also put you in a position of programming for all possible server setups. If you make a mistake, you could be liable.

Lay out the instructions and have an admin do it

>> CPanel

yea
[google.com...]