I want to create a web page that allows the user to initiate a reboot on the linux server. Obviously, this will be available only to system admins, and will also be controlled using iptables.
Below is an example of code that I was thinking about using, but I wanted to know if there is another way to do this and how to use it on a web page? Also, is there anything else I should consider?
$command = "cat $pass | su -c 'shutdown -r now'";
$output = array();
try{
echo shell_exec($command);
exec($command, $output);
system($command, $output);
}
catch(Exception $e) {
print "Unable to shutdown system...\n";
}
foreach ($output as $line) {
print "$line<br>";
}
Thanks in advance.
source
share