Add Reboot and Shutdown Buttons

Note: I do not recommend this approach. It requires granting higher than typical permissions to a user which is generally very limited.

Concept originally posted by “MBasile” at:

As you know or will soon learn, the Raspberry Pi does not deal well with being powered off without first being shut down.  These minor changes will give you the ability to reboot or shutdown your Raspberry Pi through the BrewPi web interface rather than needing to ssh in.

  1. Grant access to the web user to perform shutdown and reboots:
    sudo sh -c "echo \"www-data ALL=NOPASSWD: /sbin/reboot, /sbin/shutdown\" >> /etc/sudoers"
  2. Create two new PHP pages which will perform the shutdown and reboot functions:
    sudo echo "<?php system('sudo /sbin/reboot'); ?>" > "/var/www/html/reboot.php"
    sudo chmod 674 /var/www/html/reboot.php
    sudo chown www-data:www-data /var/www/html/reboot.php
    sudo echo "<?php system('sudo /sbin/shutdown -h now'); ?>" > "/var/www/html/shutdown.php"
    sudo chmod 674 /var/www/html/shutdown.php
    sudo chown www-data:www-data /var/www/html/shutdown.php
  3. Add the buttons to the Maintenance Panel (maintenance-panel.php) file:
    • At line 66 you will see this:
      <li><a href="#reprogram-arduino"><span>Reprogram <span class="boardMoniker">controller</span></span></a></li>

      Below that line add this:

      <li><a href="#shutdown"><span>Shutdown</span></a></li>
    • Append this block to the end of the file:
      <div id="shutdown">
       <script type="text/javascript">
       function shutdownonclick()
       shutdown_window ="shutdown.php",
       setTimeout("shutdown_window.close()", 2000);
       function rebootonclick()
       reboot_window ="reboot.php",
       setTimeout("reboot_window.close()", 2000);
       <button><a href="javascript: shutdownonclick()">Shutdown</a></button>
       <button><a href="javascript: rebootonclick()">Reboot</a></button>
  4. Test.