Giter Club home page Giter Club logo

rpilo's Introduction

RPilo - Raspberry Pi PC Power Control Build Status

Python Fork Specific

This is a fork of https://github.com/malcolm-brooks/raspi-powerctl that aims to rebuild this app using Python and Flask rather than the original PHP.

Docker Use

To run this as a container, build the image (from the folder on your PC that contains the Dockerfile): docker build -t cultclassik/p4c .

Then run the container like so: docker run -d --name pypipower -p 5000:5000 --cap-add SYS_RAWIO --device /dev/mem cultclassik/p4c


Overview

This project contains the complete website root contents needed to host the PC Power Control site, allowing you to remotely power-on, sleep and shutdown one or more desktop computers.

Requirements

  • A Raspberry Pi or other GPIO equipped device capable of running a linux apache server.
  • A GPIO controlled switch connecting the power switch pins of your PC's motherboards (or multiple of these if you wish to control more than one machine). A wireing diagram for this can be found Here.

Getting Started

Install various dependancies and enable some extra apache modules.

$ sudo apt-get update
$ sudo apt-get install apache2 apache2-utils git libapache2-mod-php5 php5 python python-pip
$ sudo a2enmod php5 ssl
$ sudo a2dissite 000-default.conf

Clone this project into the apache website root directory.

$ sudo mkdir -p /var/www/html
$ sudo chown -R pi:pi /var/www/html
$ rm -r /var/www/html/*
$ git clone https://github.com/malcolm-brooks/pi-pc-power-switch.git /var/www/html/

Update the sudoers file to grand limited sudo permissions to the apache user ("www-data").

$ sudo visudo

Apache will need to run "vcgencmd" and "gpio-ctl.py" as root. Add the following lines:

# www-data ALL=(root) NOPASSWD: /var/www/html/cgi-bin/gpio-ctl.cgi [0-9] [0-9], /var/www/html/cgi-bin/gpio-ctl.cgi [0-9][0-9] [0-9]
# www-data ALL=(root) NOPASSWD: /opt/vc/bin/vcgencmd

Install the apache site configuration and then open /etc/apache2/sites-available/001-powerctl.conf" with your favourite text editor to update "raspberrypi" to the FQDN of your Raspberry Pi and "foobarbaz" to your DDNS domain name.

$ sudo cp /var/www/html/apache2_config/001-powerctl.conf /etc/apache2/sites-available/

Enable the site and restart the apache service to ensure the changes have been picked up.

$ sudo a2ensite 001-powerctl
$ sudo service apache2 restart

You should now be able to access your website via the hostname/ip address of your raspberry pi. Note, at this point you have not made this available to the outside world. If you chose to do this, it is reconmended that you enable ssl encryption with a free certificate "Let's Encrypt" (instructions available Here), and use apache to create user logins (instructions available Here) to stop unintended users being able to remote switch off your devices! The provided apache config can be used with such a setup.

Customization

Devices and services can be added to the site by creating 'private/private.config' (relative to your website root directory). A custom title and/or footer can be added to the site by creating 'site.config' (relative to your website root directory). See the example configuration below.

$ tree /var/www/html
/var/www/html
├── apache2_config
│   └── 001-powerctl.conf
├── includes
│   ├── footer.php
│   └── header.php
├── login.php
├── private
│   ├── action
│   │   ├── power-switch.php
│   │   └── service.php
│   ├── cgi-bin
│   │   └── gpio-ctl.cgi
│   ├── devices.php
│   ├── private.config
│   └── services.php
├── README.md
├── requirements.txt
├── site.config
└── static
    ├── favicon.ico
    └── styles.css
$
$ cat private/private.config
{
  "devices":
  [
    {
      "name": "Anonymous Coward's Desktop",
      "owner": "anonymouscoward",
      "host": "anonymous-desktop.local",
      "gpio": 7
    }
  ],
  "services":
  [
    {
      "name": "My Service"
      "user": "serviceuser",
      "host": "anonymous-desktop.local",
      "command": "service_name",
      "options": [ "start", "stop", "status" ]
    }
  ]
}
$
$ cat site.config
{
  "title": "System Control",
  "footer": "Hosted by Anonymous Coward"
}

Services

When adding services, the apache user ("www-data") will have to make a passwordless ssh connection to the host on which the service is run in order to execute commands to affect that service. This presents a security issue as anyone using this site could then potentially gain ssh access to that host.

To ensure this access is restriced as much as possible:

  1. Give the local root user (on the device running this site) passwordless ssh access to the server (instructions available Here).
  2. Update the sudoers file to grand limited sudo permissions to the apache user ("www-data").
$ sudo visudo
  1. In the example private/private.config Apache will need to run "service_name start", "service_name stop" and "service_name status" as root. Add the following lines:
www-data ALL=(root) NOPASSWD: /usr/bin/ssh [email protected] service_name start
www-data ALL=(root) NOPASSWD: /usr/bin/ssh [email protected] service_name stop
www-data ALL=(root) NOPASSWD: /usr/bin/ssh [email protected] service_name status

Docker Usage

Example usage: docker run --name rpilo -p 5000:5000 --cap-add SYS_RAWIO --device /dev/mem cultclassik/rpilo

rpilo's People

Contributors

cultclassik avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.