Web Hosting Talk







View Full Version : server reboot code (is this right)


VDRS Host
10-15-2006, 02:55 PM
i was thinking of embarking on the road of building my own control panel. I was gonna hvae a area where you can eboot the server and shut it down ect.

is this code thats about to follow right to reboot a server?
echo 'Server Rebooting.......';
shell_exec('reboot');
echo '<pre>$output</pre>';


it should say whilst the server is rebooting "Server Rebooting....."

mwatkins
10-15-2006, 03:43 PM
Just be aware: Your PHP code would have to run as a privileged user in order to reboot. You'll need to be exceedingly careful if the PHP process is running as root or root equiv... any exploit of your code could well have root access. Consider that as you are designing your system.

Cheers

VDRS Host
10-15-2006, 05:03 PM
so is that code right? and im aware of the risk

StevenG
10-17-2006, 07:50 AM
so is that code right? and im aware of the risk

Assuming that /sbin/reboot or /sbin/shutdown (if you use that instead) is in the users path who runs that script, yeah it would work, but you would be better to tighten securtiy up on that and use the full path to that binary as well imho.

VDRS Host
10-17-2006, 01:42 PM
i think ill set up a testing server and try it out. thanks anyway.

tobiasly
10-17-2006, 02:59 PM
The usual course of action for such a system where you must be able to kick off superuser jobs from a website (server admin stuff, backups, etc.) is to have a secondary cronjob or daemon that the website communicates with in a secure fashion (such as encrypted using a shared key).

That secondary process runs as root and can perform only a limited set of functions, while the PHP script runs as the Apache user as usual. This way you can further minimize your attack risk by not having PHP execute root code directly.

azizny
10-17-2006, 03:51 PM
Just a note, when the server is rebooting, connection is lost.

Thus after:
shell_exec('reboot');

No code will be executed.

am I wrong?

Peace,

RH Swaroop
10-17-2006, 06:48 PM
Just a note, when the server is rebooting, connection is lost.

Thus after:
shell_exec('reboot');

No code will be executed.

am I wrong?

Peace,
You are theoretically (sp?) right but the server doesn't immediately reboot. The output should show up before it gets booted.

VDRS Host
10-18-2006, 02:21 PM
yeh thats what i thought.

clubreseau
10-21-2006, 12:26 PM
on debian sarge you use ./reboot

Xeentech
10-22-2006, 04:59 AM
How would ./reboot work unless you were in /sbin? If you're in /home/xeen as your CWD, then ./reboot would try to execute /home/xeen/reboot

Slidey
10-23-2006, 07:01 AM
you could always shutdown -t 10, which will give you 10 seconds of gracetime before it starts - you could then actually check that the shutdown command is running, and cleanly logout..