[Linux] เพิ่มความสามารถให้ squid cache video ได้

โดยปกติแล้ว squid ไม่สามารถ cache พวก youtube ได้ซึ่งถ้ามัน cache ได้ก็จะ ประหยัด bandwidth ได้มาก
Download program จาก h**p://cachevideos.com/
ผมลอง test install บน
– Ubuntu 9.04
– Squid 2.7 STABLE3
– Lighttpd
– Videocache 1.9.2

เริ่มจาก Ubuntu
$sudo apt-get install python-urlgrabber
ส่วน module ของ python-iniparse_0.3.1-1_all.deb ต้องไป download จาก h**p://code.google.com/p/iniparse/
$sudo dpkg -i python-iniparse_0.3.1-1_all.deb
ส่วนโปรแกรม videocache จาก http://cachevideos.com/download
$tar xvfz videocache-1.9.2.tar.gz
$cp videocache-1.9.2
$sudo cp -r videocache /usr/share/
$sudo cp videocache-sysconfig.conf /etc/videocache.conf
$cd /var/www
$sudo mkdir videocache
$sudo videocache/tmp videocache/youtube videocache/metacafe videocache/dailymotion videocache/google videocache/redtube videocache/xtube videocache/vimeo videocache/wrzuta videocache/youporn videocache/soapbox videocache/tube8 videocache/tvuol videocache/bliptv videocache/break
$sudo chown -R proxy:proxy videocache <-- user,group proxy เป็น user ของ process squid
$sudo mkdir /var/log/videocache
$sudo chown -R proxy:proxy /var/log/videocache
แก้ไข config ของ videocache
$sudo vi /etc/videocache.conf
cache_host = x.x.x.x <== เป็น ip ของ server
proxy = http://x.x.x.x:3128/ <== เป็น ip และ port ของ squid
base_dir = /var/www/videocache/ <== เป็นที่เก็บ cache ของ videocache ซึ่งจะต้องมีการเรียกใช้ผ่าน lighttpd ด้วยครับ
logdir = /var/log/videocache/
$sudo vi /etc/lighttpd/lighttp.conf
server.document-root = “/var/www/”
server.port = 80

$sudo vi /etc/squid/squid.conf
โดยเพิ่มที่ด้านล่างของไฟล์ ได้เลยครับ
# –BEGIN– videocache config for squid
url_rewrite_program /usr/bin/python /usr/share/videocache/videocache.py
url_rewrite_children 7
acl videocache_allow_url url_regex -i .youtube.com/get_video?
acl videocache_allow_url url_regex -i .youtube.com/videoplayback .youtube.com/videoplay .youtube.com/get_video?
acl videocache_allow_url url_regex -i .youtube.com/videoplayback .youtube.com/videoplay .youtube.com/get_video?
acl videocache_allow_url url_regex -i .youtube.[a-z][a-z]/videoplayback .youtube.[a-z][a-z]/videoplay .youtube.[a-z][a-z]/get_video?
acl videocache_allow_url url_regex -i .googlevideo.com/videoplayback .googlevideo.com/videoplay .googlevideo.com/get_video?
acl videocache_allow_url url_regex -i .google.com/videoplayback .google.com/videoplay .google.com/get_video?
acl videocache_allow_url url_regex -i .google.[a-z][a-z]/videoplayback .google.[a-z][a-z]/videoplay .google.[a-z][a-z]/get_video?
acl videocache_allow_url url_regex -i (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/videoplayback?
acl videocache_allow_url url_regex -i (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/videoplay?
acl videocache_allow_url url_regex -i (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/get_video?
acl videocache_allow_url url_regex -i proxy[a-z0-9-][a-z0-9][a-z0-9][a-z0-9]?.dailymotion.com/
acl videocache_allow_url url_regex -i vid.akm.dailymotion.com/
acl videocache_allow_url url_regex -i [a-z0-9][0-9a-z][0-9a-z]?[0-9a-z]?[0-9a-z]?.xtube.com/(.*)flv
acl videocache_allow_url url_regex -i bitcast.vimeo.com/vimeo/videos/
acl videocache_allow_url url_regex -i va.wrzuta.pl/wa[0-9][0-9][0-9][0-9]?
acl videocache_allow_url url_regex -i .files.youporn.com/(.*)/flv/
acl videocache_allow_url url_regex -i .msn.com.edgesuite.net/(.*).flv
acl videocache_allow_url url_regex -i media[a-z0-9]?[a-z0-9]?[a-z0-9]?.tube8.com/ mobile[a-z0-9]?[a-z0-9]?[a-z0-9]?.tube8.com/
acl videocache_allow_url url_regex -i .mais.uol.com.br/(.*).flv
acl videocache_allow_url url_regex -i .video[a-z0-9]?[a-z0-9]?.blip.tv/(.*).(flv|avi|mov|mp3|m4v|mp4|wmv|rm|ram)
acl videocache_allow_url url_regex -i video.break.com/(.*).(flv|mp4)
acl videocache_allow_dom dstdomain .mccont.com .metacafe.com .redtube.com .cdn.dailymotion.com
acl videocache_deny_url url_regex -i http://[a-z][a-z].youtube.com http://www.youtube.com
url_rewrite_access deny videocache_deny_url
url_rewrite_access allow videocache_allow_url
url_rewrite_access allow videocache_allow_dom
redirector_bypass on
# –END– videocache config for squid

ดูจาก forum ของ videocache.com ครับต้องแก้ code ของ videocache.py ด้วย

$sudo vi /usr/share/videocache/videocache.py

if enable_google_cache:
if (host.find(‘.youtube.com’) > -1 or host.find(‘.youtube.com’) > -1 or re.compile(‘.youtube.[a-z][a-z]’).search(host) or re.compile(‘^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$’).match(host)) and (path.find(‘videoplayback’) > -1 or path.find(‘videoplay’) > -1 or path.find(‘get_video’) > -1) and path.find(‘get_video_info’) < 0:
type = ‘YOUTUBE’
arglist = params.split(‘&’)
dict = {}
for arg in arglist:
try:
dict[arg.split(‘=’)[0]] = arg.split(‘=’)[1]
except:
continue
if dict.has_key(‘video_id’):
video_id = dict[‘video_id’]
elif dict.has_key(‘docid’):
video_id = dict[‘docid’]
elif dict.has_key(‘id’):
video_id = dict[‘id’]
else:
video_id = None
if video_id is not None:
new_url = submit_video(pid, client, type, url, video_id)
else:
log(format%(pid, client, ‘-‘, ‘URL_ERROR’, type, ‘docid not found in ‘ + new_url))

จากนั้น start process ของ squid และ lighttp
$sudo /etc/init.d/squid start
$sudo /etc/init.dlighttpd start
ดู logging จาก /var/log/squid/access.log, /var/log/videocache/videocache.log
$sudo tail -f /var/log/squid/access.log
$sudo tail -f /var/log/videocache/videocache.log

เมื่อเราเปิด video จาก youtube ดูในครั้งที่ 2 จะมีการเปิดจาก cache ครับสังเกตุง่ายๆครับว่าตรงมุมซ้ายด้านล่างของ firefox จะเห็นเป็น ip ของ server

[FreeBSD] ลงโปรแกรม netatalk เอาไว้ share ให้ mac

# pkg_add -r netatalk
# vi /usr/local/etc/pam.d/netatalk
###
netatalk auth required pam_unix.so try_first_pass
netatalk account required pam_unix.so try_first_pass
netatalk session required pam_permit.so
###
vi /etc/rc.conf
netatalk_enable=”YES”
atalkd_enable=”NO”
papd_enable=”NO”
cnid_metad_enable=”NO”
afpd_enable=”YES”
timelord_enable=”NO”
#—- start service
#/usr/local/etc/rc.d/netatalk start
จากนั้นก็ใช้ mac ทำการ connect โดยเปิด finder-> Go -> Connect to server ,
Server address: afp://username@192.168.1.1 –> Connect

[Dynamips] script สำหรับ start process dynamips

vi dynamips.sh

#!/usr/local/bin/bash
# Script for start dynamips process

DYNAMIPS_BIN=/usr/local/bin/dynamips
WORKDIR=/dynamips/cache
PORT_START=3600
NUM_PROC=12

case “$1” in
start)
cd $WORKDIR
i=0
while [ $i -ne $NUM_PROC ]
do
(( PORT = $PORT_START + $i ))
echo “Start dynamips hypervisor port $PORT “
nice $DYNAMIPS_BIN -H $PORT -l /dev/null > /dev/null 2>&1 &
(( i = i + 1 ))
done
exit 0
;;
stop)
echo “Stop dynamips all process ..”
pkill -9 dynamips
;;
restart)
$0 stop
$0 start
;;
*)
echo “Usage: `basename $0` {start|stop|restart}” >&2
exit 64
;;
esac

[FreeBSD] Create RamDisk on FreeBSD

vi mkramdisk.sh

#!/bin/sh
MOUNT_DIR=”/dynamips/cache”
SIZE=512M

case “$1” in
start)
/sbin/mdmfs -S -s $SIZE md0 $MOUNT_DIR
echo “$SIZE ramdisk created on /dev/md0 and mounted on $MOUNT_DIR”
exit 0
;;
stop)
/sbin/umount $MOUNT_DIR
/sbin/mdconfig -d -u 0
echo “ramdisk unmounted from $MOUNT_DIR and deleted from /dev/md0”
;;
restart)
$0 stop
$0 start
;;
*)
echo “Usage: `basename $0` {start|stop|restart}” >&2
exit 64
;;
esac

[FreeBSD] Example /etc/pf.conf

vi /etc/rc.conf
pf_enable=”YES” <== enable pf vi /etc/pf.conf
## Macros
SYN_ONLY=”S/FSRA”
EXT_NIC=”bge0″
INT_NIC=”bge1″

ALLOWED_ICMP=”echoreq”
ALLOWED_TCP=”{ 22,80 }”
TRUSTED_IP=”{ 10.0.0.0/24, 1.1.1.1 }”

# Your Internet IP goes in the EXT_IP variable
EXT_IP=”1.2.3.4″

# Your private network IP goes in the INT_IP variable
# if you have two NICs on the machine
INT_IP=”192.168.1.1″

## TABLES

## GLOBAL OPTIONS
set block-policy drop

## TRAFFIC NORMALIZATION

## QUEUEING RULES

## TRANSLATION RULES (NAT)

## FILTER RULES

# Block everything (inbound AND outbound on ALL interfaces) by default (catch-all)
block all

# Default TCP policy
block return-rst in log on $EXT_NIC proto TCP all
pass in log quick on $EXT_NIC proto TCP from any to $EXT_IP port $ALLOWED_TCP flags $SYN_ONLY keep state

# Default UDP policy
block in log on $EXT_NIC proto udp all
# It’s rare to be hosting a service that requires UDP (unless you are hosting
# a dns server for example), so there typically won’t be any entries here.

# Default ICMP policy
block in log on $EXT_NIC proto icmp all
pass in log quick on $EXT_NIC proto icmp from any to $EXT_IP icmp-type $ALLOWED_ICMP keep state

# Default IP Policy
block in log on $EXT_NIC all
pass in log quick on $EXT_NIC from $TRUSTED_IP to $EXT_IP keep state

block out on $EXT_NIC all
pass out quick on $EXT_NIC from $EXT_IP to any keep state

# Allow the local interface to talk unrestricted
pass in quick on lo0 all
pass out quick on lo0 all

[Nokia] E71 ใช้ battery มากกว่าปกติเพราะ garmin xt

h**p://dotdoh.com/?p=394

If you have just installed Garmin Mobile XT version 5.0.0.20 on your Mobile Phone (So far only verified on my Nokia E71 running Symbian OS), you may have notice that your battery life for you mobile phone seems to have reduce substantially from about 2 days before the installation to about 1 day.

This it seem is due to a background process that Garmin Mobile XT starts upon boot up of your Symbian operating system as well as upon running of the Mobile XT software.

Things you will need to verify if you are affected by this background process.

1.) An installed version of Garmin Mobile XT (Duh….)

2.) JBak Task Manager. (You can download it from: http://jbak.ru/jbaktaskman_en.php)

Step 1 Start JBakTaskMan
Step 2 Select Menu >> Tools >> Processes
Step 3 Type TSRAutoStart.exe

If the process TSRAutoStart.exe is found, you are most likely affected by this background process wasting away your battery life.

How to kill the TSRAutostart?

Step 1 Follow the previous Step 1 – 3
Step 2 Select the process TSRAutoStart.exe
Step 3 Select Menu >> Terminate process

How to prevent TSRAutostart from auto loading upon boot up.

Step 1 Plug mobile phone to PC under Mass Storage mode (! important as directories used are otherwise hidden)
Step 2 Delete file CardRunner.RSC in directory under Mobile PhoneResourcepluginsCardRunner.RSC
Step 3 Delete the file CardRunner.dll in directory under Mobile PhonesysbinCardRunner.dll

Permanent Fix.

Well if you are seeking a permanent fix, you could always try downloading the latest version of Garmin Mobile XT (Link: http://www8.garmin.com/support/collection.jsp?product=010-11034-00).

As of version 5.0.0.40, this background process is now an option that can be switched off, saving you the trouble of killing the process each time you run Garmin.

Step 1 Start GMobileXT (Duh…)
Step 2 Goto Tools >> Settings >> System
Step 3 Scroll down all the way till you see the option “Launch background service”
Step 4 Select Disabled then Done to save

h**p://www.symbian-freak.com/forum/viewtopic.php?p=440972

After installing v5.0.0.x0:

Turn OFF your S60
Turn S60 back ON
Launch JBak Taskman to see if TSRAutoStart.exe is running in Memory in Menu -> Tools -> Processes even though it’s set as DISABLED by default in Tools -> Settings -> System -> Launch Background Services.

If TSRAutoStart.exe is running after S60 is turned ON, do this:

START GarminMXT v5.0.0.x0, goto Tools -> Settings -> System -> Launch Background Services and change to ENABLED.
EXIT GarminMXT, re-start GarminMXT and goto Tools -> Settings -> System -> Launch Background Services and change to DISABLED
Turn OFF S60
Turn ON S60
Launch JBak TaskMan to check that TSRAutoStart.exe ISN’T in Menu -> Tools -> Processes

Now:

START GarminMXT v5.0.0.x0
EXIT GarminMXT
Launch JBak TaskMan to check that TSRAutoStart.exe ISN’T in Menu -> Tools -> Processes

Now, you should find:

TSRAutoStart.exe doesn’t start when you first turn ON your S60
TSRAutoStart.exe now CLOSES automatically when you exit GarminMXT v5.0.0.x0
It appears that GarminMXT v5.0.0.x0 when being installed, doesn’t create the DISABLED entry and has to be done manually by setting to ENABLE, then DISABLE.