聚會時間公告: 因應COSCUP 2011, Kalug 8月份休會一次

五月 25, 2011
» 500 Internal Server Error



五月 3, 2011
» T1/E1 Pinout (RJ-48C)

T1/E1 wiring may use either a RJ45, DB15 or BNC connectors. The pinout shown uses RJ45 connectors - its formal name is USOC RJ-48C and is defined in ANSI T1-403-1989. T1 is a North America (primarily) digital service providing 1.544 Mbps. E1 is a European/Rest of World standard providing digital service at 2.048 Mbps. CATegory 5(e) cabling is used to provide balanced pairs. The color coding for Cat 5(e) cabling may be 568A or 568B.

RJ45 PinSignalNotes
1RX1 (Ring - negative)
2RX2 (TIP - positive)
3FGND (RX GND)Ground/Shield
4TX1 (Ring - negative)
5TX2 (TIP - positive)
6FGND (TX GND)Ground/Shield

十月 13, 2010
» 收到附件檔名為winmail.dat檔時的處理方法

我想有在收信的網友們應該對 "winmail.dat" 檔案不陌生吧?當對方是使用outlook寄信時,往往會收到這個附加檔案,但是這個檔案應該怎麼轉換成Linux能處理的檔案類型呢?Linux裡面有一隻小程式名叫 "tnef",利用這隻小程式就可以把原始的附加檔案給還原回來了。

原來winmail.dat的檔案格式是 Transport Neutral Encapsulation Format 。

十月 5, 2009
» Cisco Config Class

最近在忙ISMS的事情,對於每週要備份一次全校的Switch Configure總覺得很不耐煩,在萬般無奈下寫了一個Class,之後就可以透過這個Class來自動備份了,有興趣的人也可以到OpenFoundry去下載下來玩玩。內含範例程式及文件說明。

svn co http://svn.openfoundry.org/ciscoconfig ciscoconfig

五月 15, 2009
» Install Two HP FC1142SR 4Gb PCI-e HBA Card Using QLogic Fibre Channel HBA Driver (qla2xxx-8.02.21) in Ubuntu 8.04.1

Make Provision Driver Building Environment

  1. apt-get install build-essential
  2. apt-get install kernel-package
  3. make sure that can find linux-source tarball (ex: linux-source-2.6.24.tar.bz2) in path: /usr/src
  4. extract and decompress linux-source tarball (ex: tar -xvjf linux-source-2.6.24.tar.bz2)
  5. change directory to /lib/modules/{kernel version} (ex: cd /lib/modules/`uname -r`)
  6. create a link to linux-headers path with the name build. (ex: ln -s /usr/src/`uname -r` build)
  7. create a link to linux-source path with the name build. (ex: ln -s /usr/src/linux-source-2.6.24 source)
Download QLogic Fibre Channel HBA Driver Source Code
  1. change to your home directory
  2. wget ftp://ftp.qlogic.com/outgoing/linux/beta/8.x/qla2xxx-src-v8.02.21.tar.gz
  3. extract and decompress source code tarball file (ex: tar -xvzf qla2xxx-src-v8.02.21.tar.gz)
Modify The Driver Source Code
  1. edit file extras/build.sh at first line "#!/bin/sh" to "#!/bin/bash"
    in Ubuntu Linux the default "sh" had been symbolic linking to "dash", there are some functions can't be executable in build.sh scrip.
  2. edit file qla_def.h, remark line 33 ~ 35.
  3. edit file qla_isr.c,. replace "SA_INTERRUPT|SA_SHIRQ" with "IRQF_DISABLED|IRQF_SHARED" at line 2100.
  4. edit file qla_os.c, add "struct" in front of "kmem_cache *srb_cachep;" at line 40.
  5. remove ones of NULL at line 5723 in file qla_os.c
  6. replace "pci_module_init" with "pci_register_driver" at line 5759 in file qla_os.c
Get ready to build Driver
  1. change user to root.
  2. execute "extras/build.sh" in qla2xxx-8.02.21 directory.
Now You Can Install this Driver, If Everything is O Kay.
  1. execute "extras/build.sh install" to install Driver.
  2. execute "update-initramfs -v -u -k `uname -r`" to update initramfs image.
Reboot System to Test New Initial Ramdisk and Pray It Can Work..... just kindling ^_^

If this Document can help you,
me. Thanks a lot.

十二月 8, 2008
» DHCP OPTION 43 for Lightweight Cisco Aironet Access Points Configuration Example

ddns-update-style none;

option time-offset 28800;
option domain-name-servers;

#Define Space
option space Cisco_LWAPP_AP;
option Cisco_LWAPP_AP.server-address code 43 = string;

class "Vendor-Identifier" {
match option vendor-class-identifier;

subnet netmask {

option routers;
option subnet-mask;
option domain-name "AP.Example.com";
option broadcast-address;

#Wireless Controler IP Address Configure Option
subclass "Vendor-Identifier" "Airespace.AP1200" {
option vendor-class-identifier "Airespace 1200";
vendor-option-space Cisco_LWAPP_AP;
option Cisco_LWAPP_AP.server-address "";

subclass "Vendor-Identifier" "Cisco AP c1500" {
option vendor-class-identifier "Cisco AP c1500";
vendor-option-space Cisco_LWAPP_AP;
option Cisco_LWAPP_AP.server-address "";

subclass "Vendor-Identifier" "Cisco AP c1200" {
option vendor-class-identifier "Cisco AP c1200";
vendor-option-space Cisco_LWAPP_AP;
option Cisco_LWAPP_AP.server-address "";

range dynamic-bootp;

default-lease-time 43200;
max-lease-time 86400;

九月 26, 2008
» Resetting MySQL Root Password on Unix Systems

Use the following procedure for resetting the password for any MySQL root accounts on Unix. The instructions assume that you will start the server so that it runs using the Unix login account that you normally use for running the server. For example, if you run the server using the mysql login account, you should log in as mysql before using the instructions. (Alternatively, you can log in as root, but in this case you must start start mysqld with the --user=mysql option. If you start the server as root without using --user=mysql, the server may create root-owned files in the data directory, such as log files, and these may cause permission-related problems for future server startups. If that happens, you will need to either change the ownership of the files to mysql or remove them.)

  1. Log on to your system as the Unix mysql user that the mysqld server runs as.

  2. Locate the .pid file that contains the server's process ID. The exact location and name of this file depend on your distribution, hostname, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/. Generally, the filename has an extension of .pid and begins with either mysqld or your system's hostname.

    You can stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process, using the pathname of the .pid file in the following command:

    shell> kill `cat /mysql-data-directory/host_name.pid`

    Note the use of backticks rather than forward quotes with the cat command; these cause the output of cat to be substituted into the kill command.

  3. Create a text file and place the following statements in it. Replace the password with the password that you want to use.

    UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';

    The UPDATE and FLUSH statements each must be written on a single line. The UPDATE statement resets the password for all existing root accounts, and the FLUSH statement tells the server to reload the grant tables into memory.

  4. Save the file. For this example, the file will be named /home/me/mysql-init. The file contains the password, so it should not be saved where it can be read by other users.

  5. Start the MySQL server with the special --init-file option:

    shell> mysqld_safe --init-file=/home/me/mysql-init &

    The server executes the contents of the file named by the --init-file option at startup, changing each root account password.

  6. After the server has started successfully, delete /home/me/mysql-init.

You should now be able to connect to MySQL as root using the new password.

Alternatively, on any platform, you can set the new password using the mysql client (but this approach is less secure):

  1. Stop mysqld and restart it with the --skip-grant-tables option.

  2. Connect to the mysqld server with this command:

    shell> mysql
  3. Issue the following statements in the mysql client. Replace the password with the password that you want to use.

    mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
    -> WHERE User='root';

You should now be able to connect to MySQL as root using the new password.

一月 13, 2008
» 在Ubuntu上安裝兩張HP FC1142SR 4Gb PCI-e HBA Card實現Failover的功能

原本在Ubuntu 7.10上所提供的HBA (Fibre Channel Host Bus Adapter) module並不支援Failover的功能,所以只好Download HP官方的Package下來試試看,沒想到HP的RPM Package只支援RedHat及SuSe。與RPM Package裡的Install Scripts奮鬥了許多天及經歷了無數次的失敗,自尊心備受打擊的我只好放棄HP的RPM Package,轉而去尋找新的解決辦法,正巧看到QLogic的官方網站所提供的原始碼可以在別的平台上編譯,下載下來後試著編譯看看,發現感覺還不賴,裡面提供的Install Scripts不會讓我已經很脆弱的自尊心再次受到打擊,Readme檔案裡寫的安裝步驟也是屬於Monkey等級 (只要是Monkey看的懂,照著做就一定會成功的等級)很適合禁不起任何打擊的我,但是愉快的過程總是短暫的,在編譯的時候居然跳出了錯誤的訊息,說找不到Linux的Source Code,仔細看了一下錯誤的訊息,發現Install Scripts去找Linux Source Code的路徑不對,但是我也懶的改了,所以就只單純建了一個symbolic link想騙過Install Scripts,沒想到還真的騙過去了 (真不愧是Monkey Level),最後編譯完成後也同時更新了initrd的image就懷著滿心的期待把系統Reboot了,沒想到開機完成後SAN的設備居然告訴我Link Failure,還好這時我的自尊心已經恢復的差不多了,看一下開機時的訊息(使用dmesg的指令)發現HBA的Module 在initalize時發生了錯誤,無法被載入到Kernel裡,發生錯誤的Function為"pci_module_init()",請示過Google大神後,Google大神回覆說可以把pci_module_init()pci_register_driver()置換就可以了,所以我又回到放有原始碼的QLogic目錄裡尋找Source Code裡有使用到pci_module_init()的檔案(用grep -r pci_module_init *.c的指令)發現有5的檔案,分別是ql2100.cql2200.cql2300.cql2322.c以及ql2400.c。將這些檔案修改後從新再編譯一次,之後再從新更新一次initrd image。更新完initrd image後重新開機後就發現可以將SAN給掛在上了,真是可喜可賀啊,差點就要開香檳慶祝了。以下是我的步驟:

  1. 先變身成Super User (sudo su -)
  2. 安裝build-essential (apt-get install build-essential)
  3. 安裝linux-headers-2.6.22-14-generic (apt-get install linux-headers-2.6.22-14-generic)
  4. 安裝linux-source-2.6.22 (apt-get install linux-source-2.6.22)
  5. 解開在/usr/src/linux-source的Package (tar -xvjf linux-source-2.6.22.tar.bz2)
  6. /lib/modules/2.6.22-14-generic目錄裡建立一個symbolic link名稱為source,連結指到/usr/src/linux-source-2.6.22 (ln -s /usr/src/linux-source-2.6.22 /lib/modules/2.6.22-14-generic/source)
  7. 在QLogic的官方網站下載qla2xxx-v8.01.07.15-2-dist.tgz (wget http://download.qlogic.com/drivers/60471/qla2xxx-v8.01.07.15-2-dist.tgz)
  8. 解開qla2xxx-v8.01.07.15-2-dist.tgz (tar -xvzf qla2xxx-v8.01.07.15-2-dist.tgz)
  9. 解開後進入到目錄裡 (cd qlogic)
  10. 執行./drvrsetup
  11. 執行完畢後會產生名稱為qla2xxx-的目錄
  12. 切換到qla2xxx-目錄裡 (cd qla2xxx-
  13. 因原先寫的原始碼在載入module時所使用的function並不適用於目前的kernel,所以要修正一下,先執行grep -r pci_module_init *將不符合的檔案列出,並修改列出的檔案,把pci_module_init置換成pci_register_driver
  14. 執行extras/build.sh new進行編譯module的動作
  15. 若編譯的過程中沒有錯誤的話,就可以執行extras/build.sh install來安裝module
  16. 安裝完後要執行update-initramfs -c建立新的initrd影像檔
  17. reboot來啟用新的initrd

十月 19, 2007
» Postfix With SMTP-AUTH And TLS (Mandriva)

Install the required packages (Postfix, cyrus-sasl, imap, etc.) like this:

urpmi cyrus-sasl libsasl2 libsasl2-devel libsasl2-plug-plain libsasl2-plug-anonymous libsasl2-plug-crammd5 libsasl2-plug-digestmd5 libsasl2-plug-gssapi libsasl2-plug-login postfix imap

Then run (make sure that you use the correct values for mydomain, myhostname, and mydestination):

postconf -e 'mydomain = example.com'
postconf -e 'myhostname = server1.$mydomain'
postconf -e 'mydestination = /etc/postfix/local-host-names, localhost.example.com'
postconf -e 'smtpd_sasl_local_domain ='
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'smtpd_sasl_security_options = noanonymous'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
postconf -e 'inet_interfaces = all'
postconf -e 'mynetworks ='
touch /etc/postfix/local-host-names
touch /var/lib/mailman/data/aliases

Edit /etc/sasl2/smtpd.conf. It should look like this:

vi /etc/sasl2/smtpd.conf

# SASL library configuration file for postfix
# all parameters are documented into:
# /usr/share/doc/cyrus-sasl/options.html

# The mech_list parameters list the sasl mechanisms to use,
# default being all mechs found.
mech_list: plain login

# To authenticate using the separate saslauthd daemon, (e.g. for
# system or ldap users). Also see /etc/sysconfig/saslauthd.
pwcheck_method: saslauthd
saslauthd_path: /var/lib/sasl2/mux

# To authenticate against users stored in sasldb.
#pwcheck_method: auxprop
#auxprop_plugin: sasldb
#sasldb_path: /var/lib/sasl2/sasl.db

Create the SSL certificate needed for TLS:

mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024

chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csr

openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt

openssl rsa -in smtpd.key -out smtpd.key.unencrypted

mv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650

and configure Postfix for TLS:

postconf -e 'smtpd_tls_auth_only = no'
postconf -e 'smtp_use_tls = yes'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtp_tls_note_starttls_offer = yes'
postconf -e 'smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key'
postconf -e 'smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt'
postconf -e 'smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem'
postconf -e 'smtpd_tls_loglevel = 1'
postconf -e 'smtpd_tls_received_header = yes'
postconf -e 'smtpd_tls_session_cache_timeout = 3600s'
postconf -e 'tls_random_source = dev:/dev/urandom'

Now start Postfix, saslauthd, imap and pop3:

chkconfig imap on
chkconfig imaps on
chkconfig ipop3 on
chkconfig pop3s on
/etc/init.d/postfix restart
/etc/init.d/saslauthd restart
/etc/init.d/xinetd restart

To see if SMTP-AUTH and TLS work properly now run the following command:

telnet localhost 25

After you have established the connection to your Postfix mail server type

ehlo localhost

If you see the lines




everything is fine:

[root@server1 ssl]# telnet localhost 25

Connected to localhost.localdomain (
Escape character is '^]'.
220 server1.example.com ESMTP Postfix (2.4.5) (Mandriva Linux)
ehlo localhost
250-SIZE 10240000
250 DSN
221 2.0.0 Bye
Connection closed by foreign host.

[root@server1 ssl]#



to return to the system's shell.

八月 30, 2007
» PHP的STDIN(標準輸入)、STDOUT(標準輸出)及STDERR(標準錯誤輸出)

有管理過Unix like的作業系統或是有在撰寫Unix like程式的人往往會使用到標準輸入(STDIN)、輸出(STDOUT)及錯誤輸出(STDERR)的管線來完成一些訊息的輸入、輸出及錯誤訊息的表達。


/* 判斷STDIN是否已經預先被定義了 */
if(!defined("STDIN")) {
define("STDIN", fopen('php://stdin','r'));

/* 透過標準格式化輸出函數將字串印出 */
printf("Please Input some thing:\n");

/* 利用fscanf()的函數來讀取預先定義好的STDIN,並將其直傳入$input的變數中 */
fscanf(STDIN, "%s", $input);

/* 透過標準格式化輸出函數將$input變數的值印出 */
printf("Your input data is \"%s\"\n", $input);

/* 判斷STDERR是否已經預先被定義了 */
if(!defined("STDERR")) {
define("STDERR", fopen('php://stderr','w'));

/* 透過標準格式化輸出函數將字串印出 */
printf("Standard Message Output\n");

/* 利用fprintf()的函數將訊息寫入預先定義好的STDERR */
fprintf(STDERR, "Standard Error Message Output\n");


» 科研沒挑戰 引進人才也白搭









韓國工業界在十年前,和我們平起平坐,為什麼現在已經超過了我們?因為他們已經在基礎科技上,打下了很好的基礎。他們不斷在挑戰高難度的技術發展,一定要 擁有獨立自主的技術,而儘量地不依靠外國。他們在經歷如此高難度的挑戰以後,已經變成了世界頂尖的工程師。



我建議政府策畫幾個難度較高的計畫,責成政府或民間單位在不依賴外國技術的原則之下完成這些計畫。舉例來說,我們可以要求設計一些通訊工業上所需要的積體 電路,十分精準的步進馬達,或者一個高規格的控制器。如此不僅在很多技術上可以獨立自主,最重要的是國家會多了一大批十分有競爭力的工程師。




七月 23, 2007
» 如何掛載initrd的影像檔

initrd的檔案格式在kernel 2.4及kernel 2.6是不一樣的
kernel 2.4的掛載方式:

  1. mkdir initrd
  2. cp /boot/inirtd.img ./initrd.img.gz
  3. gunzip initrd.img.gz
  4. mount -t ext -o loop initrd.img ./initrd
kernel 2.6的目前還沒研究出掛載的方式,但可以用cpio把整個影像檔解開來:
  1. mkdir initrd
  2. cp /boot/inirtd.img ./initrd.img.gz
  3. gunzip initrd.img.gz
  4. cp initrd.img initrd/
  5. cd initrd/
  6. cpio -i --make-directories < initrd.ing

» tzerming

$ setterm -dump 3 -----> 錄 tty3 的東東 , 產生 screen.dump
$ setterm -append -----> 錄 目前 tty 加在 screen.dump 的尾巴
$ setterm -h | less -----> 看看 它的功能


dd if=/dev/tty1 of=capture_filename bs=2000 count=1
vi capture_filename 即可看到剛才tty1上的螢幕內容

dd if=/dev/tty1 of=capture_filename bs=4004 count=1
vi capture_filename 可看到剛才tty1上的螢幕內容及色彩編碼
前四個字元值 列數 每列字元數 游標位置列 游標水平位置
只要 cat capture_filename > /dev/tty3




A Django site.