Jump to content

Help: Shutting down my PHP Server via a link.


climbjm

Recommended Posts

The Story/Setup:

I have an Ubuntu FF Server up and running.  However it is very noisy and it sits in my bedroom with the printer and all my other networking stuff.

 

However, if I am not at home... I would like a way for my wife to be able to shut the box off without having to SSH into the box, but instead click a simple link to turn it off.  However, nothing has worked so far.

 

Anyone have any ideas?

 

What I have so far:

        $v = "";

        if($_GET['command']=='shutdown')
        {
                echo("<h1>SHUTTING DOWN SERVER</h1>");
                $loadpage=false; // for something else, ignore this
                $v .= shell_exec('sync');
                $v .= shell_exec('sync');
                $v .= shell_exec('shutdown');
                echo("".$v."");
        }

// much later down the road

 

<li><a href="index.php?command=shutdown">Shutdown the
Server</a>

 

When I run this... it displays the "<h1>SHUTTING DOWN SERVER</h1>" but does not shut down the server.

 <?php

function kill($_GET['command']=='shutdown'){
       if(shall_exec::is_running($_GET['command']=='shutdown')){
           shell_exec("kill -KILL ,$_GET['command']=='shutdown'");
           return true;
       }else return false; ?>

First u must be sure u are executing commands, as having safe_mode on will stop functions like shell_exec(), exec(), system(), passthru() and ` (backtick operator).

 

Im far from a linux profficient, but not sure apache will have the privileges to run a shutdown command. U can grant those permissions, but again ull face the problem that anyone can shutdown (or whatever) your web server from a simple script. Hope it helped.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.