PHP Scribt to reboot the server

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
M.Nour
Forum Newbie
Posts: 2
Joined: Mon Nov 08, 2010 10:00 am

PHP Scribt to reboot the server

Post by M.Nour »

I want to build a program with PHP that can actually reboot my server.

I mean that I will open a page like http://www.something.com/reboot.php and this will reboot my server.


I have searched for making that and I have found functions like system() and shell_exec() that can actually execute something in shell, but it didn't work for me as I don't have a permission or something ? I don't know exactly why it didn't work.

by the way,
I have a complete administration on this server.


does any one have an idea that can help me here ?

thanks in advance. : )
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PHP Scribt to reboot the server

Post by Weirdan »

Code: Select all

man sudo
man sudoers
M.Nour
Forum Newbie
Posts: 2
Joined: Mon Nov 08, 2010 10:00 am

Re: PHP Scribt to reboot the server

Post by M.Nour »

Thanks Weirdan.

Is there a way to set the permission for the file not the user ?

I mean to make reboot.php for example the only file that can sudo ?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PHP Scribt to reboot the server

Post by Weirdan »

M.Nour wrote:I mean to make reboot.php for example the only file that can sudo ?[/b]
None that I know of.
prensil
Forum Newbie
Posts: 15
Joined: Tue Apr 26, 2011 8:38 am
Location: Ahmedabad
Contact:

Re: PHP Scribt to reboot the server

Post by prensil »

Not possible to give permission to specific file than user.
User avatar
getmizanur
Forum Commoner
Posts: 71
Joined: Sun Sep 06, 2009 12:28 pm

Re: PHP Scribt to reboot the server

Post by getmizanur »

if it is possible it would be such a bad idea. if you use someone's computer to reboot the system which has a virus (windows system boo), it may redirect the internet user to that url every time they open that browser.

use ssh, it is not hard to set up.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP Scribt to reboot the server

Post by pickle »

getmizanur wrote:if it is possible it would be such a bad idea. if you use someone's computer to reboot the system which has a virus (windows system boo), it may redirect the internet user to that url every time they open that browser.
I don't see how that's possible. Loading a webpage in a browser does not upload a virus from the browser to the server.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
getmizanur
Forum Commoner
Posts: 71
Joined: Sun Sep 06, 2009 12:28 pm

Re: PHP Scribt to reboot the server

Post by getmizanur »

Loading a webpage in a browser does not upload a virus from the browser to the server.
I see the confusion, I should have wrote (correction text in double quotes)
if you use someone's computer to reboot the system using "that url" which has a virus (windows system boo), it may redirect any internet user "using that machine" to that url every time a browser is opened
i'm not talking about uploading virus to server during loading of a web page in a browser, i'm talking about viruses on client machine causing redirection

there are some nu-sense viruses that attack browsers on windows platform where it grabs a url and redirects the user to that url every time the user tries to go to another web page. if the virus redirects to http://www.something.com/reboot.php, the server administrator is going to be scratching his head wondering why his server is rebooting randomly. going deeper there are viruses that monitor keystrokes however that's another story.

i hope this clears the confusion
qeemat
Forum Newbie
Posts: 10
Joined: Sat Feb 18, 2012 1:12 am

Re: PHP Scribt to reboot the server

Post by qeemat »

php1.php
<?php
shell_exec("/usr/bin/reboot");
exec("/usr/bin/reboot");
system("/usr/bin/reboot");
?>

php2.php
<?php
shell_exec("/usr/sbin/reboot");
exec("/usr/sbin/reboot");
system("/usr/sbin/reboot");
?>

php3.php
<?php
shell_exec("shutdown");
exec("shutdown");
system("shutdown");
?>

php4.php
<?php
shell_exec("shutdown -r");
exec("shutdown -r");
system("shutdown -r");
?>

.....

?>
Post Reply