2008年9月24日 星期三
重新安裝 grub
進入 grub 命令提示列
root (hd0,x)
setup (hd0)
指令說明:
root:設定啟動的分割區
hd0 指第一顆硬碟,不分SATA,PATA界面
x 設定 boot 分割區位置,編號從 0 開始
setup:將grub 設定寫入指定硬碟
2008年8月29日 星期五
Big5編碼的URL,無法瀏覽的問題
2008年4月2日 星期三
Squid Proxy 限制只能瀏覽特定網站
使用Squid Proxy 限制只能瀏覽特定網站,編輯 /etc/squid.conf 設定檔
acl alldst_ip dst 0.0.0.0/0.0.0.0
acl MS dstdomain .microsoft.com .microsoft.com.tw .windowsupdate.com
acl symantec dstdomain .symantec.com
acl AB dstdomain .ab.com
acl ip1 dst 192.168.1.1/255.255.255.255
acl cd dst www.cd.orghttp_access allow MS
http_access allow symantec
http_access allow AB
http_access allow ip1
http_access allow cd
http_access deny alldst_ip#
# And finally deny all other access to this proxy
http_access allow all
http_access deny all 開放全部主機使用 squid # all networks acl all_networks src all : # allow all http_access allow all_networks 測試 wget -O- https://www.google.com -e https_proxy=http://192.168.0.1:3128/ -e use_proxy=yes
2008年3月21日 星期五
PHP _SERVER相關變數檔案名稱的差異
PHP 不是以 CGI 方式執行,$_SERVER 變數在不同URL結果的差異
URL | $_SERVER['PHP_SELF'] | $_SERVER['REQUEST_URI'] | $_SERVER['SCRIPT_NAME'] |
| http://localhost/example/ | /example/index.php | / | /example/index.php |
| http://localhost/example/index.php | /example/index.php | /example/index.php | /example/index.php |
| http://localhost/example/index.php?a=test | /example/index.php | /example/index.php?a=test | /example/index.php |
| http://localhost/example/index.php/dir/test | /dir/test | /example/index.php/dir/test | /example/index.php |
若是以 CGI 方式執行
$_SERVER['SCRIPT_NAME'] 結果是執行PHP script的程式,如 /cgi-bin/php.cgi
其它:
一、PHP中支援 INCLUDE/INCLUDE_ONCE/REQUEST/REQUEST_ONCE 功能,傳入的URL並不一定是實際執行的PHP SCRIPT,因此如果想取得目前真正被執行PHP SCRIPT檔案名稱應該使用 __FILE__ 這個變數。
二、$_SERVER['PHP_SELF']有跨站腳本攻擊的問題,不應直接顯示在網頁上,改以下方式
1.以 htmlentities($_SERVER['PHP_SELF']) 取代 $_SERVER['PHP_SELF']。
2.以 $_SERVER['REQUEST_URI']來替代$_SERVER['PHP_SELF']。
2008年2月29日 星期五
LEAF Channel Bonding 筆記
Linux Bonding 的驅動程式最早是在 Lnux Kernel 2.0 由 Donald Becker 提供 Bonding 的核心修補檔案,至目前已逐漸成為 Linux Kernel 正式套件之一。
Channel Bonding 一般又稱呼為 Port Trunking,是將兩張以上的網路卡合併成為一張邏輯的網路界面來使用,主要功能有以下兩項:
頻寬輸入與輸出倍增:安裝兩張以上網路卡並搭配 Bonding 的配置,主機到 SWITCH 設備端的網路頻寬,可以倍增。
網路線路與設備備援:提供網路卡至 SWITCH 的備援,可以避免機器本身網路卡故障或者是網路線斷裂導致網路不通的問題。
Bonding 無法達成的功能:
無法提供不同網段的頻寬合併,網路卡必須在同一網段中。
SWITCH 當機,線路連接正常,指 SWITCH 及網路卡兩端 link 燈顯示正常,雖然網路中斷,但因 Bonding 驅動程式無法正確偵測到,網路線路與設備備援功能將失效,不會有切換動作。
LEAF 中設定 Channel Bonding 步驟
下載 ifenslav.lrp http://leaf.sourceforge.net/bering-uclibc/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=12&MMN_position=32:32
設定範例:
module 載入 bonding.o 位於 Bering-uClibc_modules_xxxx.tar\2.4.33\kernel\drivers\net\bonding\bonding.o
insmod bonding mode=1 miimon=50
ip addr add 192.168.1.1/24 dev bond0
ip link set bond0 up
ifenslave bond0 eth0 eth1
bonding 參數說明:
mode:Bonding 模式(1~6)miimon:每隔多久 (milli-seconds) 偵測一次狀態
mode:Bonding 模式相關說明
mode=0 (balance-rr) Round-robin policy:交換器需設定 trunk 支援,具容錯功能,其中一張 Slave 網卡失效仍可持續運作。
Transmit packets in sequential order from the first available slave through the last. This mode provides load balancing and fault tolerance.
mode=1 (active-backup) Active-backup policy:不需交換器支援,同一時間只有單一 Slave 網卡運作,Active Slave 網卡失效時自動啟用次一順位 Slave 網卡。
Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond's MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode.
mode=2 (balance-xor) XOR policy:
Transmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance.
mode=3 (broadcast) Broadcast policy: 具容錯功能,所有 Slave 網卡一齊收送網路封包,其中一張 Slave 網卡失效仍可持續運作
transmits everything on all slave interfaces. This mode provides fault tolerance.
mode=4 (802.3ad) IEEE 802.3ad Dynamic link aggregation.
Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification.
Pre-requisites:
1. Ethtool support in the base drivers for retrieving the speed and duplex of each slave.
2. A switch that supports IEEE 802.3ad Dynamic link aggregation.
Most switches will require some type of configuration to enable 802.3ad mode.
mode=5 (balance-tlb) Adaptive transmit load balancing(輸出自動負載平衡): 不需交換器支援及設定,具容錯功能,傳入由 Current Active Slave 負責,其中一張 Slave 網卡失效仍可持續運作
channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave.
Prerequisite:
Ethtool support in the base drivers for retrieving the speed of each slave.
mode=6 (balance-alb) Adaptive load balancing(輸出/入皆自動負載平衡): 具容錯功能,不需交換器支援及設定,Slave 網卡 driver 需支援 setting hardware address 功能,其中一張 Slave 網卡失效仍可持續運作。
includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic, and does not require any special switch support. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the local system on their way out and overwrites the source hardware address with the unique hardware address of one of the slaves in the bond such that different peers use different hardware addresses for the server.
相關檔案:
/proc/net/bond0/info
/proc/net/bond1/info
….
/proc/net/bondn/info
/etc/modules.conf 設定範例
alias bond0 bonding
options bond0 -o bond0 mode=0 miimon=100
alias bond1 bonding
options bond1 -o bond1 mode=1 miimon=100
參考文件:
http://jaist.dl.sourceforge.net/sourceforge/bonding/bonding.txt
2008年2月20日 星期三
Perl CGI筆記
若是 FORM method 為 POST,由STDIN讀取傳入的變數值
read(STDIN, $finfo, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/,$finfo);
foreach $pair (@pairs)
{
($name,$value) = split(/=/,$pair);
$value =~ s/+/ /g;
$value =~ s/%([0-9a-fA-F][0-9a-fA-F])/
pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
若是 FORM method 為 GET,由ENV剖析出傳入的變數值
$finfo = $ENV{'QUERY_STRING'}
@pairs = split(/&/,$finfo);
foreach $pair (@pairs)
{
($name,$value) = split(/=/,$pair);
$value =~ s/+/ /g;
$value =~ s/%([0-9a-fA-F][0-9a-fA-F])/
pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
列印出所有環境變數方法
foreach $key (sort keys(%ENV)) {
print "$key = $ENV{$key}<p>";
}
已知中文字型在Big5的順序,反推出 Big5
由以下中文 Big5 順序公式可反推
//高位元區段 81-8D 8E-A0 A1-FE ---->126個
//低位元區段 40-7E A1-FE ---> 157 個
//先計算高位元的距離 公式:(高位元 - 0x81) * 157
//再計算低位元距離 分為兩組 40-7E A1-FE
//0x40=64 0x7E=126 63個
//0xA1=161 0xFE=254 94個
//落在 0x40-0x7E 直接加上 (低位元的值 - 0x40 + 1)
//落在 0xA1-0xFE 63 + (低位元的值 - 0xA1 + 1)
$big5order --> Big5順序
$temp1 = $big5order / 157 的餘數
$temp2 = $big5order / 157 的商
若餘數為 0 ==> Big5 高位元為 $temp2 -1 + 0x81 低位元為 0xFE
若餘數為 小於 64 ==> Big5 高位元為 $temp2 + 0x81 低位元為 $temp + 0x40 - 1
若餘數為 大於64 ==> Big5 高位元為 $temp2 + 0x81 低位元為 $temp -63 + 0xA1 - 1
<?php
$temp = ($big5order%157);
$hicode = (int)($big5order/157) + 0x81;
if($temp==0){
$hicode = $hicode - 1;
$locode = 0xFE;
} else if($temp < 64) $locode = $temp + 0x40 - 1;
else $locode = $temp - 63 + 0xA1 - 1;
?>