2009年1月4日 星期日

Set up a Webcam Security System on Ubuntu

1. plug your webcam into usb slot, some useful commands to diagnose hardware information

dmesg # print bootup messages
lsusb # list usb devices

2. install motion, the package provide motion detection for webcam or netcam

sudo apt-get install motion

3. modify configuration file

sudo vi /etc/motion/motion.conf
--
.
.
# Image width (pixels). Valid range: Camera dependent, default: 352
width 640

# Image height (pixels). Valid range: Camera dependent, default: 288
height 480
.
.
# The mini-http server listens to this port for requests (default: 0 = disabled)
webcam_port 8081
.
.
# Restrict webcam connections to localhost only (default: on)
webcam_localhost on
.
.

4. according to the above settings, you can watch live webcam only from localhost. i would to like to access it from anywhere with authentication, so i pick up mod_proxy to satisfy my needs

sudo cp /etc/apache2/mods-available/proxy.conf /etc/apache2/mods-enabled/proxy.conf
sudo ln -s /etc/apache2/mods-available/proxy.load /etc/apache2/mods-enabled/proxy.load
sudo ln -s /etc/apache2/mods-available/proxy_http.load /etc/apache2/mods-enabled/proxy_http.load

5. map internal web pages to main apache web server

<IfModule mod_proxy.c>
ProxyRequests Off
<Proxy *>
AddDefaultCharset off
Order deny,allow
Allow from all
AuthName "Live Webcam Server"
AuthType Basic
AuthUserFile /var/www/.htpasswd
require valid-user
</Proxy>
ProxyVia On
ProxyPass /motion http://localhost:8081
</IfModule>

to understand all parameters, please refer to http://httpd.apache.org/docs/2.0/mod/mod_proxy.html

6. create a password file for the username

sudo htpasswd -c /var/www/.htpasswd username

7. nobody can access .htpasswd through http request just because of this section in /etc/apache2/apache2.conf

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>

沒有留言: