2009年3月11日 星期三

Map Remote Servers into the Space of the Local Apache Server with Authentication on Ubuntu

1. delete symbolic link of the default proxy.conf

sudo rm /etc/apache2/mods-enabled/proxy.conf

2. make another copy of proxy.conf in the same folder, mods-enabled

sudo cp /etc/apache2/mods-available/proxy.conf /etc/apache2/mods-enabled/proxy.conf

3. edit it

sudo vi /etc/apache2/mods-enabled/proxy.conf
--

ProxyVia On

ProxyPass /mirror/ http://address:port/
ProxyPassReverse /mirror/ http://address:port/

<Location /motion/>
AuthName "TITLE"
AuthType Basic
AuthUserFile /var/www/.htpasswd
require valid-user
</Location>

# ProxyPass causes a local request for the http://localhost/mirror/ to be internally converted into a proxy request to http://address:port/
# ProxyPassReverse provides location header on http adjusting which redirects http://localhost/mirror/sub/ to http://address:port/sub/ also

4. generate apache password file, /var/www/.htpasswd

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

2009年3月10日 星期二

Convert Text to Hex on Linux

xxd creates a hex dump of a given file or standard input.


echo "something" | xxd -c 256 -ps


-c 256: 256 octets per line
-ps: plain style

2009年2月17日 星期二

Create Torrent with Multiple Trackers on Linux

RubyTorrent is the best torrent creator, works in both CLI and GUI. download it from http://benclarke.ca/rubytorrent/

1. extract

tar xzf rubytorrent-0.071.tar.gz

2. as it written entirely in the ruby programming language, you have to install ruby and libgtk2-ruby ( for GTK+ interface )

sudo apt-get install ruby libgtk2-ruby

3. command-line program is torrent.rb, the usage is

./torrent.rb -a tracker1 -a tracker2,tracker3 -f FILE -o TORRENT

# try tracker1 then try either tracker2 or tracker3 in random order
# you can specify only one parameter after -f so you will need create a directory for all files and sub-directories you need

2009年2月3日 星期二

Quick command-line Numeral Conversion within Shell

(hex)15A -> (dec)346

echo 'ibase=16;obase=A;15A' | bc

ibase = input base
obase = output base
the default notation for both is decimal
if you want to specify decimal for obase, you should use obase=A ( A in hex = 10 in decimal )
input number must be in upper case

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.