andreknieriem / photobooth

A photobooth Web-Application for raspberry pi with gphoto2
https://photobooth.andrerinas.de/
MIT License
300 stars 163 forks source link

"See preview by device cam" only works with Raspi Cam via localhost #202

Closed andi34 closed 4 years ago

andi34 commented 5 years ago

Describe the bug Currently if preview by device cam is enabled it only works on the Pi if Raspi Cam is connected and Photobooth is opened via localhost / 127.0.0.1. It does not work if I open the Photobooth via real IP.

Expected behavior By "see preview by device cam" I would suspect to see the preview via my Tablet/Mobile Phone Cam if I use it to access the Photobooth Webinterface, or at least always use the connected Pi Cam independent of the device I use to access the Photobooth.

Environment (please complete the following information):

Photobooth

Edit Works on https access.

Todo:

Edit 2: Http is enough on localhost access: https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features

Exception to avoid using https: https://medium.com/@Carmichaelize/enabling-the-microphone-camera-in-chrome-for-local-unsecure-origins-9c90c3149339

Edit: https://certbot.eff.org/

Not tested, but this should help you getting https access.

andi34 commented 5 years ago

I'd like to see something like https://www.reinhard-rebernig.at/website/websites/fotokasterl/#

We could also make it optional possible to use the preview cam to take a Picture?

andi34 commented 5 years ago

Screenshot_20191123-112827

andi34 commented 4 years ago

Http vs https ?

andi34 commented 4 years ago

Https to get it working 🙈

Screenshot_20191219-195344

andi34 commented 4 years ago

Maybe someone can help making this nice: Here's how i've allowed access via https to my photobooth, running Apache webserver. I am not an expert on that and have followed some examples, so i guess it's not the best solution: Simple bash file

#!/bin/bash

# Stop on the first sign of trouble
set -e

# Show all commands
# set -x

function info {
    echo -e "\033[0;36m${1}\033[0m"
}

function error {
    echo -e "\033[0;31m${1}\033[0m"
}

if [ $UID != 0 ]; then
    error "ERROR: Only root is allowed to execute the installer. Forgot sudo?"
    exit 1
fi

if [ -d "/var/www/cert" ]; then
    info "/var/www/cert exists"
else
    mkdir -p "/var/www/cert"
fi

cd /var/www/cert

# Certificate authority (CA)
openssl req -x509 -nodes -new -sha256 -days 1024 -newkey rsa:2048 -keyout RootCA.key -out RootCA.pem -subj "/C=US/CN=Example-Root-CA"
openssl x509 -outform pem -in RootCA.pem -out RootCA.crt

# Domain name certificate
cat >> domains.ext <<EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost

EOF

openssl req -new -nodes -newkey rsa:2048 -keyout localhost.key -out localhost.csr -subj "/C=US/ST=YourState/L=YourCity/O=Example-Certificates/CN=localhost.local"
openssl x509 -req -sha256 -days 1024 -in localhost.csr -CA RootCA.pem -CAkey RootCA.key -CAcreateserial -extfile domains.ext -out localhost.crt

# Configure Apache for https
cat >> /etc/apache2/sites-enabled/000-default.conf  <<EOF

<VirtualHost *:443>
    SSLEngine On
    SSLCertificateFile /var/www/cert/localhost.crt
    SSLCertificateKeyFile /var/www/cert/localhost.key
</VirtualHost>

EOF

# Ensure that the Apache SSL module is enabled & Restart Apache
a2enmod ssl
service apache2 restart
andi34 commented 4 years ago

HTTPS required (also localhost or 127.0.0.1 are save origins, that's why raspicam works)