2011年8月29日 星期一

[Tips] Ubuntu下PPPoE安裝設定

速記一下Ubuntu的PPPoE設定...

查詢有關PPPoE的package
$ sudo apt-cache search pppoe
pppoeconf - configures PPPoE/ADSL connections
pppoe - PPP over Ethernet driver
pppstatus - console-based PPP status monitor

安裝
$ sudo apt-get install pppoeconf pppoe pppstatus

設定
$ sudo pppoeconf

根據問題回答yes/no,並且設定帳號密碼,設定完成後將自動連線

中斷
$ sudo poff
若超過一個連線
$ sudo poff -a

重新建立連線
$ sudo pon dsl-provider

查詢log
$ sudo plog

預設撥接設定儲存位置,會override /etc/ppp/options
$ sudo vim /etc/ppp/peers/dsl-provider
lcp-echo-interval 30      # interval of sending request to adsl server
lcp-echo-failure 10       # times of retry if sending request fail
# Override any connect script that may have been set in /etc/ppp/options.
persist                   # auto dial-up if lost connection 
user "user@isp.net"       # dial-up user account

若是使用PAP驗證,則帳號密碼會儲存於
$ sudo vim /etc/ppp/pap-secrets
"user@isp.net" * "passowrd"

PPPoE斷線問題檢測先從查詢plog開始,若出現以下訊息表示超出嘗試次數還未能連接上
pppd[1624]: Timeout waiting for PADO packets

解決方法就是定時檢查連線狀態,若沒有連線則持續撥號,常用的檢查方法有ifconfig或是running process,簡單寫一下重新撥號的script
#!/bin/bash
# auto dial-up 

# check ifconfig or check running process
RETRY=5
PPP=`ifconfig|grep -in ppp`
until [ $RETRY -le 0 ] || [ -n "$PPP" ] || [ -e /var/run/ppp0.pid ]
do pon dsl-provider
  sleep 30
  PPP=`ifconfig|grep -in ppp`
  ((RETRY=RETRY-1))
done

reference:
* 使用 PPPoEConf 連接 Internet
* Linux PPP HOWTO

2011年8月26日 星期五

[資訊安全] Reversing for Newbies

今天逛到一個不錯的教學網站,希望練習練習,下次wargame能拿第一

2011年8月25日 星期四

[Network] Configuring multiple default routes and name resolving in Linux

problem description:
There are 2 NICs on my Ubuntu 10.10, I need to configure multiple default route and multiple name resolve with my host.

assume that my nic setting
$ ifconfig
wlan0: 192.168.2.115  netmask 255.255.255.0
       default gw 192.168.2.1
eth0:  10.157.132.104 netmask 255.255.240.0
       default gw 10.157.143.254

first you have to make sure your Linux kernel has support "policy routing"
$ cd /usr/src/linux
$ sudo make menuconfig
[*] Networking support  --->
      Networking options  --->    
        [*] IP: advanced router
        [*] IP: policy routing 
        [*] IP: use netfilter MARK value as routing key

create a new policy routing table entry(T2)
$ sudo echo "1 T2" >> /etc/iproute2/rt_tables

add new entry within this policy table
$ sudo ip route add 10.157.128.0/20 dev eth0 src 10.157.132.104 table T2
$ sudo ip route add default via 10.157.143.254 dev eth0 table T2
$ sudo ip rule add from 10.157.128.0/20 table T2
$ sudo ip rule add to 10.157.128.0/20 table T2

add nameserver
$ sudo echo "options rotate" > /etc/resolv.conf
$ sudo echo "nameserver 192.168.2.1" >> /etc/resolv.conf
$ sudo echo "nameserver 172.17.125.5" >> /etc/resolv.conf

I write a shell script for quickly configuring multiple default routes as below
#!/bin/bash

# first nic setting
IF1=wlan0
IP1=192.168.2.115
NM1=255.255.255.0
NT1=192.168.2.0/24
GW1=192.168.2.1

# second nic setting
IF2=eth0
IP2=10.157.132.104
NM2=255.255.240.0
NT2=10.157.128.0/20
GW2=10.157.143.254

# additional setting for second nic
IP3=172.17.125.5
NM3=255.255.255.0
NT3=172.17.125.0/24

# default gateway
DGW=${GW2}

# set ip/netmask
ifconfig ${IF2} ${IP2} netmask ${NM2}
ifconfig ${IF1} ${IP1} netmask ${NM1}

# create a new policy routing table entry
T2=`cat /etc/iproute2/rt_tables|awk '{print $2}'|grep -in T2|cut -d : -f 2`
if [ -z "$T2" ]; then
  echo "1 T2" >> /etc/iproute2/rt_tables
fi

# add new entry within this policy table
ip route add ${NT2} dev ${IF2} src ${IP2} table T2
ip route add default via ${GW2} dev ${IF2} table T2
ip rule add from ${NT2} table T2
ip rule add to ${NT2} table T2
ip rule add from ${NT3} table T2
ip rule add to ${NT3} table T2

# options timeout:1 rotate attempts:1
echo "options rotate"          >  /etc/resolv.conf
echo "nameserver 192.168.2.1"  >> /etc/resolv.conf
echo "nameserver 172.17.125.5" >> /etc/resolv.conf

reference:
* Configuring Multiple Default Routes in Linux --> works for me
* 雙網卡、兩個對外ip、共同存在並能上網
* Linux 用兩張網卡作不同子網路設定

2011年8月23日 星期二

[Tips] SQLite: unable to open database file

最近寫一些小的web service需要存取SQLite,發現在CLI模式下測試正常,可是透過web存取時出現
Warning: sqlite_query() [function.sqlite-query]: unable to open database file in ...
改了code裡面存取的權限後依然不行,
sqlite_open(db, 0666, error)

最後才發現web server要有整個directory的write permission

reference: SQLite3: Unable to Open Database File

2011年8月8日 星期一

[Android] htcDev

我lag了嗎?

今年六月HTCUplinq 2011的keynote宣佈要開放SenseUI的SDK,不過今天我才發現可以下載了... 目前還有unlock的bootloader和kernel source,未來應該會提供更多的資源吧,例如他們的app?

2011年7月5日 星期二

[多媒體] Setup Audio Streaming Service on Ubuntu (Icecast2+Ices2)

Due to a requirement of project, I tried to setup an audio streaming service before. I choose Icecast as my streaming server, and Ices2 to generates Ogg Vorbis sources for Icecast2 to stream. The details are as follows.

environment:
* server: ubuntu 10.04 (192.168.104.131)
* client: ubuntu 10.04 (192.168.104.1)

Icecast is free server software for streaming multimedia. Ices comes in two flavors, the 0.x flavor which supports sending an MP3 stream to an icecast server, and the 2.x flavor which supports sending an Ogg Vorbis stream to an icecast server. In summary, Icecast is a streaming server, and streamer, likes ices or darkice, providers streaming content.
Ices comes in two flavors, the 0.x flavor which supports sending an MP3 stream to an icecast server, and the 2.x flavor which supports sending an Ogg Vorbis stream to an icecast server.

1. Setup Icecast(2)
1.1 install required libraries
server$ sudo apt-get install icecast2
server$ sudo /etc/init.d/icecast2 start
icecast2 daemon disabled - read /etc/default/icecast2.

1.2 enable icecast2
server$ sudo vim /etc/default/icecast2
# Edit /etc/icecast2/icecast.xml and change at least the passwords.
# Change this to true when done to enable the init.d script
ENABLE=true

1.3 start icecast2
server$ sudo /etc/init.d/icecast2 start
Starting icecast2: Starting icecast2
Detaching from the console
icecast2.


2. Icecast2 + Ices2
2.1 install required libraries & setup environment
server$ sudo apt-get install ices2
server$ sudo mkdir /var/log/ices
server$ sudo mkdir -p /etc/ices2/music

2.2 modified default value (or not)
server$ sudo cp /usr/share/doc/ices2/examples/ices-playlist.xml /etc/ices2
server$ sudo vim /etc/ices2/ices-playlist.xml
<password>hackme</password>                         # modified me (or not)
<mount>/example1.ogg</mount>                        # modified me (or not)
<param name="file">/etc/ices2/playlist.txt</param>  # modified me

2.3 add playlist
server$ sudo cp /path/to/my_song_1.ogg /path/to/my_song_2.ogg /etc/ices2/music
server$ sudo ices2 /etc/ices2/ices-playlist.xml
server$ sudo vim /etc/ices2/playlist.txt
/etc/ices2/music/my_song_1.ogg
/etc/ices2/music/my_song_2.ogg

2.4 modified script of icecast2 to fit with ices
server$ sudo vim /etc/init.d/icecast2
#! /bin/sh
### BEGIN INIT INFO
# Provides:          icecast2
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts the icecast audio streaming server daemon
### END INIT INFO
#
# icecast2
#
#       Written by Miquel van Smoorenburg .
#       Modified for Debian 
#       by Ian Murdock .
#
#       Further modified by Keegan Quinn 
#       for use with Icecast 2
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/icecast2
NAME=icecast2
DESC=icecast2
ICES=/usr/bin/ices2                           # add this line
ICES_CONFIGFILE=/etc/ices2/ices-playlist.xml  # add this line

test -x $DAEMON || exit 0

# Defaults
CONFIGFILE="/etc/icecast2/icecast.xml"
CONFIGDEFAULTFILE="/etc/default/icecast2"
USERID=icecast2
GROUPID=icecast
ENABLE="false"

# Reads config file (will override defaults above)
[ -r "$CONFIGDEFAULTFILE" ] && . $CONFIGDEFAULTFILE

if [ "$ENABLE" != "true" ]; then
    echo "$NAME daemon disabled - read $CONFIGDEFAULTFILE."
    exit 0
fi

set -e

case "$1" in
    start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \
            --exec $DAEMON -- -b -c $CONFIGFILE
        echo "$NAME."
        ;;
    stop)
        echo -n "Stopping $DESC: "
        # Send TERM after 5 seconds, wait at most 30 seconds.
        start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --exec $DAEMON
        echo "$NAME."
        ;;
    reload|force-reload)
        echo "Reloading $DESC configuration files."
        start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON
        ;;
    restart)
        echo -n "Restarting $DESC: "
        # Send TERM after 5 seconds, wait at most 30 seconds.
        start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --exec $DAEMON
        start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \
            --exec $DAEMON -- -b -c $CONFIGFILE
        echo "$NAME."
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
        exit 1
        ;;
esac

exit 0

2.5 start ices2
server$ sudo ices2 /etc/ices2/ices-playlist.xml

2.6 receive audio streaming via browser
client$ firefox -url http://192.168.104.131:8000/example1.ogg


reference:
* The Linux MP3 & Ogg HOWTO : Streaming Servers and Web Interfaces
* The Linux MP3-HOWTO : Streaming MP3's.
* Ogg Vorbis Streaming: ices2 HOWTO
* Run Your Own Webradio Station With Icecast2 And Ices2 (part1)
* Run Your Own Webradio Station With Icecast2 And Ices2 (part2)

If you want to choose Apache + Musicindex as your streaming server, there are some references helps
* Stream your music with musicindex
* README of musicindex
* HowTo stream mp3 ogg mp4 files with Apache2 libapache2 mod musicindex