2008年3月31日 星期一

使用 Apache + AD 來做網頁資料夾的認證

<Directory />
Options All ExecCGI -Indexes
Order allow,deny
Allow from all
# LDAP Authentication & Authorization is final; do not check other databases
AuthLDAPAuthoritative on
# Do basic password authentication in the clear
AuthType Basic
# The name of the protected area or "realm"
AuthName "Something you want"
# Active Directory requires an authenticating DN to access records
AuthLDAPBindDN cn=LDAP_Username,cn=Users,dc=yourdomain,dc=com
# This is the password for the AuthLDAPBindDN user in Active Directory
AuthLDAPBindPassword LDAP_Password
# The LDAP query URL
AuthLDAPURL "ldap://ldap.yourdomain.com:389/ou=demo,dc=yourdomain,dc=com?sAMAccountName?sub?(objectClass=*)"

Require valid-user
</Directory>


2008年3月27日 星期四

用 LDIFDE 來更新 AD 使用者資訊

資料來源:
http://edu.uuu.com.tw/ucomtips/010802.htm
http://edu.uuu.com.tw/ucomtips/011016.htm

LDIFDE這一個指令是利用LDIF的檔案格式將資料以LDAP的協定匯入AD。

匯出 AD 的資料:
ldifde -f export2.ldf -u -d ou=教師,dc=admaster,dc=ttcps,dc=tpc,dc=edu,dc=tw -r objectClass=user -l dn,displayname

  • -f指定了匯出檔案的名稱。
  • -u指定了匯出檔案的編碼格式為Unicode,假如匯出的資料中包含了中文,那麼這一個參數一定要指定,否則匯出的資料會變成亂碼。
  • -d的功能在設定匯出的範圍,假如不指定的話LDIFDE指令會把AD中所有的資料匯出。
  • -d 的後面空一格直接接要匯出範圍的distinguished name。例如:-d ou=demo,dc=uuu,dc=com,代表要匯出的部分為uuu.com AD domain下的demo OU。
  • -r指定的是匯出AD的物件類型,不指定的話代表要LDIFDE指令把AD中所有的物件通通匯出。
  • -r ObjectClass=user表示要匯出的物件類型為使用者物件。
  • 最後-l代表要匯出該物件的那一個屬性。不指定的話則所有的屬性都會被匯出。屬性與屬性之間用逗號(",")來區隔。例如:-l dn,displayname 代表要匯出的屬性只有distinguished name及顯示名稱。

AD的常用欄位名稱:
標籤名稱 AD屬性的中文顯示名稱 AD屬性的英文顯示名稱 AD屬性的欄位名稱
一般/General 姓氏 First name sn
名字 Last name givenName
英文縮寫 Initials initials
顯示名稱 Display name displayName
描述 description description
辦公室 Office physicalDeliveryOfficeName
電話號碼 Telephone Number telephoneNumber
電子郵件 E-mail mail
網頁 Web page wWWHomePage
地址/Address 國家(地區) Country/region c
省份 State/province st
縣/市 City l
街道 Street streetAddress
郵遞區號 Zip/Postal Code postalCode
郵政信箱 P.O. Box postOfficeBox
帳戶/Account 使用者登入名稱 User logon name userPrincipalName
使用者登入名稱(Windows 2000前版) User logonname(pre-Windows 2000) sAMAccountName
設定檔/Profile 設定檔路徑 Profile path profilePath
登入指令檔 Logon script scriptPath
主資料夾 Home folder homeDirectory
電話/Telephones 住宅 Home homePhone
呼叫器 Pager pager
行動電話 Mobile mobile
傳真 Fax facsimileTelephoneNumber
IP電話 IP phone ipPhone
注意事項 Notes info
組織/Organization 職稱 Title title
部門 Department department
公司 Company company
主管 Manager manager
屬下 Direct report directReports

準備更新AD的檔案:
-------------------------

dn: CN=lkk,OU=教師,DC=admaster,DC=ttcps,DC=tpc,DC=edu,DC=tw
changetype: modify
replace: mail
l: lkk@mail.ttcps.tpc.edu.tw
-

dn: CN=sdd,OU=教師,DC=admaster,DC=ttcps,DC=tpc,DC=edu,DC=tw
changetype: modify
replace: mail
l: sdd@mail.ttcps.tpc.edu.tw
-

-------------------------
其中第一行"dn: CN=lkk,OU=教師,DC=admaster,DC=ttcps,DC=tpc,DC=edu,DC=tw"指定了要修改的使用者物件為lkk,接下來第二行"changetype: modify"宣告了這一整筆紀錄是要用來修改AD的資料,第三行則指定了到底要修改的屬性欄位是那一個,在這一個例子中,我們所指定的是位於使用者帳號物件"一般"標籤中的"電子郵件"欄位,它在AD中的欄位名稱為l(是L(location),不是1234的1),因此第三行用"replace: l"來指定。最後,第四行則指定了l這一個欄位中新的值為lkk@mail.ttcps.tpc.edu.tw,而且必須在次一行加上一個"-"才可以,這是檔案格式的規定。

將檔案存文字檔(若有中文請存成 unicode 編碼)
指令:
ldifde -i -f modify.ldf



phpBB3 使用 LDAP 認證時的 email 屬性

一開始在 email 屬性填入 email 時會出現錯誤。
原來是 Administrator 的 email 屬性是空的,到 AD 伺服器把 email 屬性填入之後就 OK 了。

2008年3月22日 星期六

自製遠端開機命令

收集學生機 MAC Address(使用 AMD 的 Magic Packet Utility)
Magic Packets → Create a List of Hosts

下載 Depicus 的 Wake On Lan Commend Line
http://www.depicus.com/wake-on-lan/wake-on-lan-cmd.aspx
語法
wolcmd [macaddress] 255.255.255.255 255.255.255.255

把學生機 MAC 填入做成 bat 檔

2008年3月2日 星期日

Yum 更新錯誤

最近各伺服器在做 Yum 更新時皆出現錯誤,如下

yum -y update
Setting up Update Process
Setting up Repos
ftp://apt.nc.hcc.edu.tw/pub/fedora/linux/core/3/i386/os/repodata/repomd.xml: [Errno 4] IOError: [Errno ftp error] 500 OOPS: vsftpd: refusing to run with writable anonymous root
Trying other mirror.
Cannot open/read repomd.xml file for repository: base
failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.

後來用 FTP 軟體試著連上 apt.nc.hcc.edu.tw ,該伺服器無法以 anonymous 連上 ...??? 是把服務關掉了嗎?沒辦法,只好捨近求遠,改回預設的設定。

FC3 到這邊除了比較慢一點之外應該是沒問題了,接下來 FC5 的更新出問題:

yum -y update
Loading "installonlyn" plugin
Setting up Update Process
Setting up repositories
core [1/4]
core 100% |=========================| 951 B 00:00
crash-hat [2/4]
http://crash.fce.vutbr.cz/crash-hat/5/repodata/repomd.xml: [Errno 14] HTTP Error 404: Date: Mon, 03 Mar 2008 02:02:02 GMT
Server: Apache/2.2.6 (Fedora)
Content-Length: 312
Connection: close
Content-Type: text/html; charset=iso-8859-1
Trying other mirror.
Cannot open/read repomd.xml file for repository: crash-hat
failure: repodata/repomd.xml from crash-hat: [Errno 256] No more mirrors to try.
Error: failure: repodata/repomd.xml from crash-hat: [Errno 256] No more mirrors to try.

連到 crash.fce.vutbr.cz 發現該伺服器只剩下 centos 的更新,所以應該是不能用了,在網路上找到了另一台 Server ,把 /etc/yum.repo.d/crash-hat.repo 中的設定改成

baseurl=http://crash-hat.mirrors.redwire.net/crash-hat/$releasever/

OK了!

著作人