Posted: Tue Jan 22, 2008 12:33 pm Post subject: Shutting down your network via PHP
Scenario
You have a Powerware (might work with other software) UPS that powers more than 1 PC but has limited Software, like Powerware's on Ubuntu for example.
This is where some SSH and PHP comes handy .. this is how I fixed it :
Somewhere on your server .. create a .htpasswd file :
mine is /home/yancho/.htpasswd by
Quote:
htpasswd -bc NAME username password
Somewhere else in your server .. create a PHP file .. find its directory and then in ur apache config do this :
Quote:
<Directory "/home/yancho/public_html/blabla/abc">
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/home/yancho/.htpasswd"
Require valid-user
Order Deny,Allow
Deny from all
Allow from 10.0.0.1
</Directory>
The PHP file i created is turnoff.php .. in it there is just these lines:
Code:
<?
echo "Shutting down the Ubuntu Server<br>";
$result = shell_exec('sudo /home/yancho/turnoff.sh');
echo $result;
?>
Ok now we create the turnoff.sh
Code:
#!/bin/bash
echo "Powering off the machine"
sudo shutdown -h now
Save and chmod +x turnoff.sh
Now we need to give the www-data which is the username Apache with PHP is running . .check urs by echoing from PHP script - using :
[php:1:76799d917d]
shell_exec('whoami');
[/php:1:76799d917d]
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum