rszimm / sprinklers_pi

Sprinkling System Control Program for the Raspberry Pi
GNU General Public License v2.0
310 stars 100 forks source link

password #67

Closed toshibochan closed 7 years ago

toshibochan commented 8 years ago

thanks for make great sprinkler system. you can add password for login to the web app?

nhorvath commented 7 years ago

It wasn't really designed with a session or authentication in mind. I would suggest using nginx or apache as a proxy in front of sprinklerspi and use http basic auth capability of those.

alessandro-dallatorre commented 7 years ago

I would suggest exposing to the internet using ngrok as a tunnelling system with authentication. I chose this option myself, I found it handy.

sudo wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip
unzip ngrok-stable-linux-arm.zip
<sign up into ngrok web portal and create an authtoken>
./ngrok authtoken <your_brand_new_authtoken>
./ngrok http -auth="username:password" -region eu 8080
mikedevita commented 7 years ago

You can follow this guide on how to get nginx working with http basic auth and using nginx as a reverse proxy in front of the sprinkler software.

https://www.digitalocean.com/community/tutorials/how-to-set-up-basic-http-authentication-with-nginx-on-ubuntu-14-04

you'll need to add the following lines inside of your location / {} block

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://<ip_to_pi_web>:<port_to_pi_web>;

so something like this should be sufficient:

 location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_pass http://<ip_to_pi_web>:<port_to_pi_web>;
    auth_basic "Private Property";
    auth_basic_user_file /etc/nginx/.htpasswd;
 }