重設 HP 1810G-24 的方法很簡單,首先準備二根迴紋針

然後在前面面版有二個小孔,分別有 Reset 和 Clear 的文字

接下來同時將迴紋針插進並壓著裡面的按鈕,此時面板上的燈號就會改變,這時可以先放開 Reset 那邊的針

待燈號回復到正常的綠燈後即可鬆開 Clear,這時就會還原到初始值了

Switch 的 IP 就會回到 192.168.2.10

Posted by bojack at 痞客邦 PIXNET 留言(0) 引用(0) 人氣()

最近裝了一台 Ubuntu,因裡面安裝了某個程式支援中文介面,但在 SSH 連線的情況下中文者是亂碼,如下圖所示

其實要修改很簡單,在 putty 上按右鍵,選擇 Change Settings...

點選 Window -> Appearance 後,點選畫面右邊的 Change 變更字型

字型請選細明體,字集務必選成 CHINESE_BIG5,好了之後按確定

接下來再點選到 Translation,Remote character set: 請選成 UTF-8,好了之後按 Apply

重新再下一次指令,中文可以正常顯示了!

參考資料

[1] [ ubuntu ] 解決 PuTTy 連線 ubuntu 顯示亂碼問題

Posted by bojack at 痞客邦 PIXNET 留言(1) 引用(0) 人氣()

原則上確定系統 kernel 是否支援 md

# cat /usr/src/sys/i386/conf/GENERIC | grep 'md'
device          md              # Memory "disks"

沒有支援的話請重編 Kernel,接下來查看一下您原本的 SWAP 空間

# swapinfo -h
Device          1K-blocks     Used    Avail Capacity
/dev/ad1s1b      1048576       0B      1G     0%

目前我這台是 1G,假設我想要加到 2G 的話請用下面指令,並且修改權限

# dd if=/dev/zero of=/usr/swap0 bs=1024k count=1024
# chmod 0600 /usr/swap0

最後在 /etc/rc.conf  加入這一行

swapfile="/usr/swap0"

好了之後重開機即可生效,若不想重開機可使用下列指令

# mdconfig -a -t vnode -f /usr/swap0 -u 0 && swapon /dev/md0

參考資料

[1] 小惡魔 – 電腦技術 – 工作筆記 – AppleBOY - [FreeBSD]解決swap不夠的情況:Add Swap Space

 

Posted by bojack at 痞客邦 PIXNET 留言(0) 引用(0) 人氣()

其實這個技術出來很久很久了,早在以前自己有架設 WordPress 時發現到這東西

以往寫程式式,網址呈現的樣子大概會是這樣

http://www.bojack.net/news/index.php?newsid=10

而利用 mod_rewrite 可以讓網址做些許的改變,就像下面這二行範例一樣

http://www.bojack.net/news/10 or

http://www.bojack.net/news/10.html

至於為什麼要這麼做,就個人的感受是網址至少看起來簡潔了不少

另外 gslin 大神說明也指出,這樣做的話會使得系統程式較有彈性,程式若有做改變時對使用者來說也不會有太多餘影響

而最近幫單位寫了一個類似免費空間 ( Free File Hosting ) 的介面,因為同仁常因 E-mail 附件超過了限制的大小 ( ex: 20M ) 時常常向 MIS 求救

於是這個系統就這樣產生了 ~ 其中就有用到 mod_rewrite 的功能

首先要讓 Apache 支援 mod_rewrite,可以在 httpd.conf 看有沒有這一行

LoadModule rewrite_module modules/mod_rewrite.so

接下來要準備設定 mod_rewrite,原則上有二種寫法,一種是直接寫在 httpd.conf 裡面,另一種是寫在 .htaccess 裡面

若要寫在 .htaccess 也要特別注意 Apache 是否有支援,假設我的網頁是放在 /www/htdocs/freefile 底下

那麼建議在 httpd.conf 加入這些設定,Apache 預設是將 AllowOverride 設定為 None,所以在您要使用的地方先開啟它,這樣才會讓 .htaccess 生效

<Directory /www/htdocs/freefile>
 AllowOverride All
 Order deny,allow
 Deny from all
< /Directory>

最後就是寫 .htaccess 了,範例如下

RewriteEngine On //開啟Rewrite功能
RewriteRule ^([0-9A-Za-z]+).html$ index.php?name=$1 //Rewrite規則
RewriteRule ^([0-9a-z]+)/([0-9]*)$ index.php?name=$1&id=$2 //Rewrite規則

我們再拿第一個規則出來討論,就會長成這樣

RewriteRule ^([0-9A-Za-z]+).html$ index.php?name=$1 //Rewrite規則

這是套用前跟套用後的差別

http://www.bojack.net/news/index.php?name=Abc10

http://www.bojack.net/news/Abc10.html

至於第二個規則如下,看倌自行參考

http://www.bojack.net/news/index.php?name=abc10&id=10

http://www.bojack.net/news/abc10/10

上面的這些規則其實也就是正規化表示法 ( RegularExpresson ) 的應用,可自行 Google 查一下用法

參考資料

[1] Gea-Suan Lin's BLOG - 為什麼要使用 mod_rewrite?

[2] 風和日麗 天氣晴 - Apache 的 .htaccess 失效?

[3] 小開PHP私房菜 - mod_rewrite 網址轉換

[4] Apache’s AllowOverride All doesn’t do what you think it does

Posted by bojack at 痞客邦 PIXNET 留言(0) 引用(0) 人氣()

原則上需要工具 Win32DiskImager 再加上從 FreeBSD 官網 Download 的 IMG 即可

我是下載 FreeBSD-8.2-RELEASE-i386-memstick.img

下載 Win32DiskImager 執行後,瀏覽 FreeBSD-8.2-RELEASE-i386-memstick.img 後,Device 請選擇 USB 的磁碟編號

好了之後按下 Write 就會開始寫入,完成後它就是個可以用來開機跟安裝囉!

Posted by bojack at 痞客邦 PIXNET 留言(0) 引用(0) 人氣()

剛剛搞定了 Apache + SSL,再來補上一篇 :D

如果要強迫使用者只能走 HTTPS 連線,那就在 httpd.conf 設定一下

首先找到要強迫走 HTTPS 的 Directory,我把我的 DocumentRoot 的範例放上來

<Directory "/usr/local/www/apache22/data">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

</Directory>

加入上面紅色三行即可 :D

至於要用 PHP 程式去控制的話可以參考這一篇 [PHP] 強制使用https連線

參考資料

[1] 今天也要全力以赴 - Apache 強制使用https

[2] Allen開放源碼研究室 - [PHP] 強制使用https連線

Posted by bojack at 痞客邦 PIXNET 留言(0) 引用(0) 人氣()

這二天想做個 HTTPS 連線,把筆記再記一下好了

環境是 FreeBSD 8.2 + Apache 2.2,順序是

1. 自己當 CA

2. 自己再簽一張 Server 的憑證,並由 CA 來簽核它

前置作業如下

# cd /etc/ssl
# cp openssl.cnf openssl.cnf.org
# mkdir certs crl newcerts private
# echo "01" > serial
# touch index.txt
# openssl rand 1024 > ./private/.rand
# chmod 600 ./private/.rand

將 openssl.cnf 裡面這二行設定一下

# vi openssl.cnf
dir = /etc/ssl   # Where everything is kept
default_days = 3650   # how long to certify for

開始簽發一張 RootCA,CA 的期限設為 20 年

# openssl req -new -x509 -keyout private/cakey.pem -out cacert.pem -days 7305 -config openssl.cnf
Generating a 1024 bit RSA private key
..................................++++++
...............................................................................++++++
writing new private key to 'private/cakey.pem'
Enter PEM pass phrase: 請輸入公正單位密碼
Verifying - Enter PEM pass phrase: 請再一次輸入公正單位密碼
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:TW
State or Province Name (full name) [Some-State]:Taiwan
Locality Name (eg, city) []:Taipei
Organization Name (eg, company) [Internet Widgits Pty Ltd]:單位名稱
Organizational Unit Name (eg, section) []:部門名稱
Common Name (eg, YOUR name) []:請輸入完整的 DomainName
Email Address []:bojack@bojack.com
#

CA 製作好之後,接下來要來製作自己 Server 的憑證

# openssl req -nodes -new -x509 -keyout mykey.pem -out myreq.pem -days 365 -config openssl.cnf
Generating a 1024 bit RSA private key
...++++++
.............................................................++++++
writing new private key to 'mykey.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:TW
State or Province Name (full name) [Some-State]:Taiwan
Locality Name (eg, city) []:Taipei
Organization Name (eg, company) [Internet Widgits Pty Ltd]:單位名稱
Organizational Unit Name (eg, section) []:部門名稱
Common Name (eg, YOUR name) []:請輸入完整的 DomainName
Email Address []:bojack@bojack.com
# openssl x509 -x509toreq -in myreq.pem -signkey mykey.pem -out tmp.pem
Getting request Private Key
Generating certificate request
# openssl ca -config openssl.cnf -policy policy_anything -out mycert.pem -infiles tmp.pem
Using configuration from openssl.cnf
Enter pass phrase for /etc/ssl/private/cakey.pem:請輸入公正單位密碼
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Sep 14 03:16:27 2011 GMT
            Not After : Sep 13 03:16:27 2012 GMT
        Subject:
            countryName               = TW
            stateOrProvinceName       = Taiwan
            localityName              = Taipei
            organizationName          = 公司名稱
            organizationalUnitName    = 部門名稱
            commonName                = 機器完整 DomainName
            emailAddress              = bojack@bojack.com
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22
            X509v3 Authority Key Identifier:
                keyid:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22

Certificate is to be certified until Sep 13 03:16:27 2012 GMT (365 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
#

這樣子製作好的憑證就由 CA 簽好了(其實也只是自己球員當裁判 :p) 

最後來幫檔案搬個家也變個名稱

# cd /etc/ssl
# mv cacert.pem ./certs/ca.crt
# mv mycert.pem ./certs/server.crt
# mv mykey.pem ./private/server.key
# mv ./private/cakey.pem ./private/ca.key
# rm myreq.pem tmp.pem

把製作出來的金鑰設定一下權限

# chmod -R 400 private

到此為止咱們的憑證就製作完了,接下來要到 Apache 做後續的設定

先編輯 Apache 的設定檔 httpd.conf 找到這一行把前面的 # 拿掉

Include etc/apache22/extra/httpd-ssl.conf

接下來編輯 httpd-ssl.conf

#   General setup for the virtual host
DocumentRoot "/usr/local/www/apache22/data"
ServerName 主機名稱:443
ServerAdmin 網站管理者 E-mail
ErrorLog "/var/log/httpd-error.log"
TransferLog "/var/log/httpd-access.log"

SSLCertificateFile "/etc/ssl/certs/server.crt"
SSLCertificateKeyFile "/etc/ssl/private/server.key"
SSLCertificateChainFile "/etc/ssl/certs/ca.crt"

而 /etc/rc.conf 請確認改成這樣

apache22_enable="YES"
apache22_http_accept_enable="YES"
apache22_flags="-DSSL"

最後重新啟動 Apache 再連 https://你的主機/ 應該就 OK 了!

另外也有找到這一篇 FreeBSD 產生 apache2 ssl 認證,按照這做也是 OK 的

Posted by bojack at 痞客邦 PIXNET 留言(0) 引用(0) 人氣()

昨天上課時老師提到中毒的問題,許多同學就開始好奇發問了

「老師,現在智慧型手機那麼普遍,那手機也會中毒嗎?」

「會!」

「那手機怎麼樣會中毒呢?」

「原則上只要手機有上網就有機會中毒了」 <- 這句話說的很廣義,但仔細想想也沒錯

回來搜尋了一些新聞,可以先看這二篇 Lookout Mobile Security 該裝防毒軟體了,Android市場發現病毒iPhone 中毒 Rick Astley 上身!教你破解!

瞧,無論是 iPhone 或 Android 平台的手機都是有可能中毒的

那手機是怎麼被感染的呢,首先 iPhone 的部份最有可能就是做了 JB 後並未修改部份預設值進而造成手機被感染

可以參考這篇 阿維雜記本 - 解決iPhone中毒造成SSH無法連線的問題iPhone 的 iOS 算是封閉的系統,不過一旦經過 JB 後就有可能開啟漏洞了

Android 平台最直接的感染來源就是 Android Market 裡的 App 了,當然 Apple Store 裡的或許也有,只是 App 上架之前會經過較嚴謹的審核,所以目前還沒有這類的災情傳出

如果手機使用起來開始覺得愈來愈慢,網路傳輸的量異常的大時,或許手機已經中獎開始在亂打了(也有網友的情況是查到 iPad 不斷在亂發 E-mail)

Android 平台的手機就直接重刷吧,只不過要小心將備份資料倒回來時不要連同把病毒也倒回來

至於 iPhone 若有 JB 者請去修改一些預設帳號密碼來防護,可參考這篇 iPhone會中毒嗎?有防毒軟體可裝嗎?

最後,手機需不需要裝防毒軟體?這問題其實跟電腦需不需裝防毒軟體是一樣的 ~ 我常會跟朋友說,即便你裝了防火牆、防毒、防間諜、防廣告有的沒的

該中就是會中,防毒軟體通常都是收到樣本後才會產生出相關對應的定義檔,也才能辨識出這東西是病毒 ~ 因此完全依賴防毒軟體是無法確保手機或電腦是真正安全的

原則上不要亂下載 App,亂看網頁,JB 後請審慎調整系統預設值,至少可讓你的手機中毒的機會降到最低 : )

Posted by bojack at 痞客邦 PIXNET 留言(0) 引用(0) 人氣()

2006 年寫過一篇 @Unix-likes 系統中,如何消除檔案裡的 ^M,昨天看到 網絡技術日誌 這篇 Unix 及 Windows 文字檔案轉換

特別再記錄一下在 FreeBSD 裡怎麼做,原則上就是用這二個指令,dos2unix 跟 unix2dos

在 Windows 的環境裡面換行是用 Ctrl-m (^M),而在 UNIX 裡是用 EOL (End-Of-Line)

把檔案從 Unix 上下載到 Windows 裡做編輯時比較沒有感覺,不過一旦把編輯好的檔案扔回 Unix 後就會明顯看到有一堆 ^M

舉例來說這是一小段 PHP 的程式,看了實在很痛苦

<?php^M
^M
// Connect to  LDAP Server^M
$ldapconn = ldap_connect(" LDAP Server ")  or die("Could not connect to LDAP server.");^M
$set = ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);^M

現在解決的辦法就是用指令就可以搞定了

# dos2unix 原始檔名 目的檔名

參考文章

網絡技術日誌 - Unix 及 Windows  文字檔案轉換

Posted by bojack at 痞客邦 PIXNET 留言(0) 引用(0) 人氣()

瀏覽檔案的頁面

<form id="form1" name="form1" method="post" action="upload.php" enctype="multipart/form-data">
<input name="file1" type="file" id="file1" />
<input type="submit" name="button" id="button" value="上傳檔案" />
</form>

檔案上傳頁,上傳後我把檔名同時也改成當下的時間

$explode_filename = explode (".", $_FILES['file1']['name']);
$upload_filename = date("YmdHis") . "." . $explode_filename[1];
move_uploaded_file($_FILES["file1"]["tmp_name"],iconv("utf-8", "big5", $upload_filename));

特別要注意的是,我這二個網頁都是用 UTF-8 編碼,所以在處理檔案時得用 iconv 函式先轉換後再上傳,不然上傳後的檔案會無法開啟喔!

反之,若原本就是用 Big5 在處理的話,那麼就改成這樣即可

$explode_filename = explode (".", $_FILES['file1']['name']);
$upload_filename = date("YmdHis") . "." . $explode_filename[1];
move_uploaded_file($_FILES["file1"]["tmp_name"],$upload_filename);

Posted by bojack at 痞客邦 PIXNET 留言(2) 引用(0) 人氣()