2010年7月23日

簡易購物車做法

使用三個陣列記錄購物車內容

$cart[id] 記錄商品ID
$cart[quantity] 記錄商品數量
$cart[price] 記錄商品價格

ID就是商品唯一識別碼
數量跟價格是方便最後結帳統計使用

再來就是幾個有用的函數

in_array("字串",$arr);
判斷是否在陣列內

$key = array_search("字串",$arr);
找到字串在陣列人的KEY值.

$cart[id] = something;
將something加入陣列內

unset ($arr [$key])
清空$arr[$key]的值,該位置還在.

$arr = array_values($arr);
將清空後的位置移除.

count($cart[id)
算出陣列個數

以上,基本購物車功能(加入、改數量、移除)都可以做出來了.

2010年7月7日

rsync 全自動異地備援筆記.

PC A 的資料要同步到 PC B做異地備援
1.由PC-B 連至PC-A把資料抓回來.
2.使用DSA金鑰來達到不用密碼連進PC-A
3.將同步指令加入crontab

要免密碼連進PC-A,要先在PC-B產生DSA(公/私)鑰,再把公鑰放到PC-A給ssh驗證

root@PC-B:~/.ssh#ssh-keygen -d

Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): <-不輸入, 使用預設值
Enter passphrase (empty for no passphrase): <-不輸入
Enter same passphrase again: <-不輸入
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
11:22:33:44:55:66:77:88:99:00:11:22:33:44:55:66 root@xxx.com.tw

如此便產生了金鑰 id_dsa, id_dsa.pub

再來要把公鑰傳至PC-A

root@PC-B:~/.ssh#scp id_dsa.pub PC-A的IP:/root/.ssh/authorized_keys2
root@PC-A's password: <-現在還要密碼.

id_dsa.pub 100%
************************************************************************* 123 00:00
root@PC-B:~/.ssh#  <--傳過去了

現在執行 ssh PC-A 如果直接進去,應該就ok了.

接著安裝 rsync (PC-A PC-B都裝)
apt-get install rsync
接著假設要將 PC-A 的 /data 同步到 PC-B /backup
測試看看...
root@PC-B:~/.ssh# rsync -alv -e ssh PC-A的IP:/data/  /backup

是最重要的就是上面這一行了!~
順利的話,應該會看到在傳檔的畫面.


-R 保留相對路徑
-a --archive 保留檔案權限
-z 傳輸時壓縮資料


如此寫成 sync.sh
再修改權限 chmod 700
再加入 crontab
0 0 * * 0 /someplace/sync.sh &>/dev/null

記得加後面那個 &>/dev/null 才不會每次執行都寄mail給root

2010年7月3日

debian找出系統不再使用的套件

deborphan 可以找出系統不再使用套件

以下指令可以找出並同時移除
deborphan xargs apt-get -y remove --purge

Proftp筆記

#要設定下面這二個東西,登入時才不會等待很久。

IdentLookups off
UseReverseDNS off

重編核心加入netfilter patch

apt-get install kernel-package

apt-get install linux-source-2.6.18
apt-get install libncurses5-dev
cd /usr/src
tar xvf linux-source-2.6.18.tar.gz
cd /usr/src/linux-source-2.6.18
make menuconfig

/usr/src/linux-source-2.6.18# patch -p1 < kernel-2.6.18-2.6.19-layer7-2.9.patch
patching file include/linux/netfilter_ipv4/ip_conntrack.h
patching file include/linux/netfilter_ipv4/ipt_layer7.h
patching file net/ipv4/netfilter/Kconfig
patching file net/ipv4/netfilter/Makefile
Hunk #1 succeeded at 64 (offset 1 line).
patching file net/ipv4/netfilter/ip_conntrack_core.c
Hunk #1 succeeded at 338 (offset 1 line).
patching file net/ipv4/netfilter/ip_conntrack_standalone.c
Hunk #1 succeeded at 193 (offset 1 line).
patching file net/ipv4/netfilter/ipt_layer7.c
patching file net/ipv4/netfilter/regexp/regexp.c
patching file net/ipv4/netfilter/regexp/regexp.h
patching file net/ipv4/netfilter/regexp/regmagic.h
patching file net/ipv4/netfilter/regexp/regsub.c

make oldconfig (如果之前已經有編譯過 kernel source, 需先執行 make mrproper)
make menuconfig


make bzImage (kernel 2.4 需先執行 make dep)
make modules
make modules_install
make install

iptables

chmod +x ./extensions/.layer7-test
iptables -t mangle -A PREROUTING -m layer7 --l7proto yahoo -j DROP

Samba在Windows下檔名顯示設定

/etc/samba/smb.conf
[global]

dos charset=big5
unix charset=big5
==================================================================
display charset = UTF8
dos charset= cp950
unix charset= UTF8

SAMBA帳密同步

SAMBA帳密同步 筆記


pdbedit -L
pdbedit -a user 新增使用者
pdbedit -x user 刪除使用者

套件:libpam-smbpass

1.編輯/etc/pam.d/common-password
新增password sufficient pam_smbpass.so audit use_first_pass

2.執行 passwd username
 條件:系統及Samba均有該username帳號