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>

2008年12月25日 星期四

Make SDL program to have console output instead of stdout.txt and stderr.txt under Windows

SDL_Init() routes stdout and stderr to the respective files. You can revert this by adding the following lines after the call to SDL_Init in your code:

freopen( "CON", "w", stdout );
freopen( "CON", "w", stderr );

* If that doesn't work try adding these 2 lines at the very beginning of your code (SDL_Init wrapper or in top of your main)

int main( int argc, char *argv[] )

2008年12月18日 星期四

Boot a Virtual Machine from command and Control it through Remote Desktop Protocol on Ubuntu

1. we will need VBoxHeadless command to run virtual machine in background, free version of virtualbox in ubuntu repository doesn't have it. so we need to install official version
from http://www.virtualbox.org/wiki/Linux_Downloads

complie VirtualBox Modules

sudo /etc/init.d/vboxdrv setup

2. set up your virtual machine completely through GUI, Applications -> System Tools -> Sun xVM VirtualBox. if you can't find the icon, just relog desktop environment after installed

change Settings -> Remote Display -> Enable VRDP Server
Authentication Method = Null

its unsafe but we will set something for security on windows later

3. command-line usage

start a virtual machine

VBoxHeadless -startvm "name"
or
VBoxHeadless -startvm "uuid"

poweroff a virtual machine

VBoxManage controlvm "name" acpipowerbutton

show info about a running virtual machine

VBoxManage showvminfo "name"

4. your login screen of guest windows has a shutdown button, it means anyone who connect to the right port can shutdown your machine. we have to hide it by changing the registry below

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system\shutdownwithoutlogon -> 0

5. the last thing I must remind is remember to logout / switch user then windows will back to login screen. if you are afraid of forgetting to do so, try set screensaver with password protection. nobody can kick you if you are connecting and occupying the port.

2008年12月17日 星期三

Play restricted formats on Ubuntu

1. the package, ubuntu-restricted-extras supports for mp3 playback and decoding, various other audio formats, microsoft fonts, java runtime environment, flash plugin, lame, and dvd playback.

sudo apt-get install ubuntu-restricted-extras

2. about real media files like .rm .rmvb, you'll need w32 codecs because there is no native support in linux

adding the repositories

sudo wget http://www.medibuntu.org/sources.list.d/hardy.list --output-document=/etc/apt/sources.list.d/medibuntu.list

3. add the gpg key

sudo apt-get update && sudo apt-get install medibuntu-keyring && sudo apt-get update

4. install codecs

sudo apt-get install w32codecs

5. to play encrypted dvd, the libdvdcss2 package is essential. it is a simple library designed for accessing dvd without having to bother about the decryption

sudo apt-get install libdvdcss2

2008年12月13日 星期六

VirtualBox Open Source Edition on Ubuntu

1. install open source edition of virtualbox and its module

sudo apt-get install virtualbox-ose virtualbox-ose-modules-generic

2. from console output or /var/log/apt/term.log, you can see there is no matching virtualbox-ose module for kernel 2.6.24-22. virtualbox-ose-modules-generic is linked to kernel 2.6.24-21 so apt-get installs linux-image-2.6.24-21-generic automatically.

in short, we have to change default boot number of grub to kernel 2.6.24-21

sudo vi /boot/grub/menu.lst
--
default n

3. scim conflicts with virtualbox-ose. it results keyboard is locked in both host and guest os when you press key or mouse which is captuered in guest os. below is the solution

sudo apt-get install scim-bridge-client-qt
im-switch -z en_US -s scim-bridge

4. reboot then done

5. before sharing folders between host and guest, you must install Guest Additions. once installed it, go to Devices -> Shared Folders.. to set your sharing folders. if guest os is windows, run

net use x: \\vboxsvr\FolderName

2008年11月18日 星期二

Add image resizing and rotating to Gnome on Ubuntu

1. the package name is nautilus-image-converter, nautilus extension to mass resize or rotate images

sudo apt-get install nautilus-image-converter

2. logout and login again, or reboot, you will find right-click pop menu on image has the features we need

2008年11月17日 星期一

Set up a Tor relay node on Ubuntu

1. verify that your clock is set correctly

2. install tor

sudo apt-get install tor

3. make sure to define at least Nickname and the listening port, ORPort

sudo vi /etc/tor/torrc

--
.
.
SocksPort 9050 # what port to open for local application connections
SocksListenAddress 127.0.0.1 # accept connections only from localhost
.
Nickname ididnteditheconfig
.
RelayBandwidthRate 20 KBytes # Throttle traffic to 100KB/s (800Kbps)
RelayBandwidthBurst 40 KBytes # But allow bursts up to 200KB/s (1600Kbps)
.
ORPort 9001
.
.

5. restart tor to reload config

sudo /etc/init.d/tor restart

4. add this line to privoxy configuration file /etc/privoxy/config

forward-socks4a / localhost:9050 .

it means tor listens socks4a on port 9050
In the SOCKS 4A protocol, the DNS resolution of the target hostname happens on the SOCKS server, while in SOCKS 4 it happens locally.

5. according the default setting in /etc/privoxy/config

listen-address 127.0.0.1:8118

port 8118 should be used as http proxy

6. when your browser is set with privoxy proxy, you can check this website to verify

https://torcheck.xenobite.eu/


7. when you check log file, /var/log/tor/log
you may notice the warning message

MMM ddd hh:mm:ss.xxx [warn] Your application (using socks4 to port 80) is giving Tor only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4A (e.g. via privoxy or socat) instead. For more information, please see http://wiki.noreply.org/noreply/TheOnionRouter/TorFAQ#SOCKSAndDNS.