การติดตั้ง FreeRadius และ phpmyprepaid บน ubuntu 8.04

การติดตั้ง FreeRadius และ phpmyprepaid บน ubuntu 8.04

โดย อดิศร ขาวสังข์
จัดทำเมื่อ 15/11/2008
ติดตั้งบน Ubuntu 8.04
ขั้นตอน

  1. หากยังไม่ติดตั้ง apache และ php ให้ติดตั้งด้วยคำสั่ง
    apt-get install apache2 php5 php5-mysql
  2. สั่งให้ apache ทำงานด้วยคำสั่ง
    /etc/init.d/apache2 restart
  3. หากยังไม่ติดตั้ง mysql ให้ติดตั้งด้วยคำสั่ง
    apt-get install mysql-server
  4. หากยังไม่ติดตั้ง FreeRadius ให้ติดตั้งด้วยคำสั่ง
    apt-get install freeradius freeradius-mysql
  5. สั่งให้ FreeRadius ทำงานด้วยคำสั่ง
    /etc/init.d/freeradius start
  6. เข้าสู่โปรแกรม mysql ด้วย username คือ root และ password ที่ได้กำหนดไว้ด้วยคำสั่ง
    mysql –u root –p
    แล้วป้อนรหัสผ่านของ root
  7. ทำการสร้าง Database ชื่อ phpmyprepaid เพื่อใช้ในการเก็บบัญชีผู้ใช้งาน (สามารถจะใช้ชื่อฐานข้อมูลอื่นก็ได้) ด้วยคำสั่งดังนี้
    CREATE DATABASE phpmyprepaid;
  8. กำหนดสิทธิให้กับบัญชีผู้ใช้งานบน mysql ที่ชื่อว่า phpmyprepaid พร้อม password คือ radpass (user และ password สามารถเปลี่ยนแปลงได้ตามความเหมาะสม) ด้วยคำสั่ง
    GRANT ALL PRIVILEGES ON phpmyprepaid.* to ‘phpmyprepaid’@’localhost’ IDENTIFIED BY ‘radpass’;
    FLUSH PRIVILEGES;
  9. ออกจาก mysql ด้วยคำสั่ง quit
  10. แก้ไขไฟล์ /etc/freeradius/sql.conf เพื่อให้เรียกใช้ฐานข้อมูล phpmyprepaid ด้วยสิทธิผู้ใช้เป็น phpmyprepaid ซึ่งมี password เป็น radpass  ดังนี้
    # Connection info:
    server = “localhost”
    login = “phpmyprepaid”
    password = “radpass”
    # Database table configuration for everything except Oracle
    radius_db = “phpmyprepaid”
  11. ทำการกำหนด password ให้กับเครื่อง Client ที่จะเข้าใช้งาน FreeRadius ที่ไฟล์ /etc/freeradius/cliens.conf โดยกำหนดให้ client 127.0.0.1 มีค่า secret = radiussecret
    client localhost {
    secret = radiussecret
    {
    ในกรณีที่อนุญาตให้เครื่อง client อื่นเข้ามาใ้้ช้งาน FreeRadius เช่น client ที่มี IP เป็น 172.24.51.16 ก็ให้กำหนดค่าเพิ่มเติมดังนี้
    client 172.24.51.16 {
    secret = radiussecret
    shortname = chilli
    }
  12. ในกรณีที่จะอนุญาตให้เครื่อง Client อื่น ๆ (ที่ไม่ใช่เครื่องตัวเอง หรือ Localhost) เข้ามาใช้งาน FreeRadius ได้นั้นจะต้องทำการเพิ่มข้อมูลในไฟล์ /etc/freeradius/naslist ซึ่งในที่นี้คือเพิ่มบรรทัดสุดท้ายดังต่อไปนี้เข้าไป# NAS Name                  Short Name                 Type
    #—————-                   ———-                         —-
    #portmaster1.isp.com      pm1.NY                    livingston
    #portmaster2.isp.com      pm1.LA                     livingston
    localhost                          local                          portslave
    chilli                                  chilli                          other
  13. แก้ไขไฟล์ /etc/freeradius/sql.conf กำหนดให้ค่า readclients = yes เพื่อที่จะทำให้ radius client อ่านค่าจาก database
  14. แก้ไขไฟล์ /etc/freeradius/radiusd.conf ดังนี้
    • ในส่วนของ  accounting {……} ให้เอาเครื่องหมาย  # หน้าคำว่า sql ออก เพื่อเรียกใช้ข้อมูลจาก database ในการตรวจสอบ username , password ในการทำ accounting
    • ในส่วน session {……} ให้เอาเครื่องหมาย # หน้าคำว่า sql ออก เพื่อเรียกใช้ข้อมูลจาก database ในการตรวจสอบ username, password ในการทำ session
    • ในส่วนของ authorize {……} ให้เอาเครื่องหมาย # ไว้หน้าคำว่า file  และเอาเครื่องหมาย # ออกจากคำว่า sql
  15. ทำการ restart FreeRadius ด้วยคำสั่ง
    /etc/init.d/freeradius restart
  16. ตอนนี้ ทั้ง freeradius และ mysql พร้อม database phpmyprepaid ว่าง ๆ พร้อมแล้ว
    ต่อไปจะทำการติดตั้งโปรแกรม phpmyprepaid แล้วรันโปรแกรมผ่านเว็บบราวเซอร์
    จากนั้นจะเซ็ตค่าต่าง ๆ บนหน้าเว็บ ทำให้ได้ table ต่าง ๆ ที่จำเป็นใช้งานเกิดขึ้น
  17. ย้ายเข้าไปในไดเรกทอรี /var/www/ ด้วยคำสั่ง
    cd /var/www
  18. ดาวน์โหลดโปรแกรม phpmyprepaid เวอร์ชั่น 0.4 RC2 ด้วยคำสั่ง wget ดังนี้
    wget http://downloads.sourceforge.net/phpmyprepaid/phpmyprepaid04RC2.tgz
  19. คลายแฟ้มออกมาจะได้ไดเรกทอรี phpmyprepaid
    tar zxvf phpmyprepaid04RC2.tgz
  20. ติดตั้งโปรแกรม  rrdtool ด้วยคำสั่ง
    apt-get install rrdtool
  21. เปิด browser และเรียกไปที่ http://host/phpmyprepaid/www   แล้วระบบจะเปิดไฟล์ setup.php ดังรูป 
  22. ขั้นที่ 2 เป็นเรื่องของ License ให้คลิ๊กช่อง I Accept แล้วคลิ๊กปุ่ม Next 
  23. ขั้นตอนที่ 3 ถ้าเจอปัญหาดังรูปให้ใช้คำสั่ง
    chmod 777 /var/www/phpmyprepaid/www
    แล้วจะได้ผลลัพท์ดังรูป

     

  24. ขั้นตอนที่ 4 จะเป็นดังรูป ให้ป้อนค่าให้ถูกต้องโดยเฉพาะค่า Phpmyprepaid path อาจจะต้องเปลี่ยนให้ตรงความเป็นจริง 
  25. ขั้นตอนเป็นการคอนฟิก Radius ก็ให้ป้อนข้อมูลให้ตรงตามรูป 
  26. ขั้นที่ 6 เป็นการจัดการเรื่อง User Interface ก็ให้ป้อนข้อมูลตามต้องการ แต่อย่าลืม user และ password ที่ได้กำหนดไว้ด้วย 
  27. ขั้นตอนที่ 7 เป็นการคอนฟิกฐานข้อมูล ให้ป้อนข้อมูลตรงกับที่ได้กำหนดไว้ดังรูป 
  28. เมื่อป้อนข้อมูลในขั้นตอนที่ 7 ถูกต้อง ก็จะได้ผลลัพท์ดังขั้นตอนที่ 8 
  29. ขั้นตอนที่ 9 เป็นการป้อนข้อมูล Location ดังรูป 
  30. ขั้นตอนที่ 11 เป็นการคอนฟิกข้อมูลทั่วไป ดังรูป 
  31. ขั้นตอนที่ 11 เป็นขั้นตอนสุดท้าย ให้อ่านข้อความด้วยนะครับเพราะมีคำแนะนำบางอย่างที่ต้องทำตามด้วย 
  32. จากนั้นเมื่อเราเรียกใช้งาน http://host/phpmyprepaid/www/ ก็จะได้หน้าตาดังรูป 
  33. เมื่อ Login เข้าสู่ระบบได้แล้ว จะได้ผลลัพท์ดังรูป 
  34. รูปข้างล่างเป็นตัวอย่างการเพิ่ม Account ที่สามารถกำหนดความเร็วในการ upload และ download ได้ 
  35. ทดสอบการทำงานของ FreeRadius ด้วยคำสั่ง radtest
    radtest  username  password  localhost 0 mysecret
    ถ้าเซ็ตอัพถูกต้องและป้อนค่าถูกต้องจะได้ผลลัพธ์ว่า Access-Accept ดังรูป

จบครับ
ที่มา: http://www.itmanage.info/technology/linux/ubuntu/freeradius_phpmyprepaid/install_freeradius_phpmyprepaid_ubutu_8_04.html

การติดตั้ง FreeRadius และ phpmyprepaid บน ubuntu 8.04

การติดตั้ง FreeRadius และ phpmyprepaid บน ubuntu 8.04

โดย อดิศร ขาวสังข์
จัดทำเมื่อ 15/11/2008
ติดตั้งบน Ubuntu 8.04
ขั้นตอน

  1. หากยังไม่ติดตั้ง apache และ php ให้ติดตั้งด้วยคำสั่ง
    apt-get install apache2 php5 php5-mysql
  2. สั่งให้ apache ทำงานด้วยคำสั่ง
    /etc/init.d/apache2 restart
  3. หากยังไม่ติดตั้ง mysql ให้ติดตั้งด้วยคำสั่ง
    apt-get install mysql-server
  4. หากยังไม่ติดตั้ง FreeRadius ให้ติดตั้งด้วยคำสั่ง
    apt-get install freeradius freeradius-mysql
  5. สั่งให้ FreeRadius ทำงานด้วยคำสั่ง
    /etc/init.d/freeradius start
  6. เข้าสู่โปรแกรม mysql ด้วย username คือ root และ password ที่ได้กำหนดไว้ด้วยคำสั่ง
    mysql –u root –p
    แล้วป้อนรหัสผ่านของ root
  7. ทำการสร้าง Database ชื่อ phpmyprepaid เพื่อใช้ในการเก็บบัญชีผู้ใช้งาน (สามารถจะใช้ชื่อฐานข้อมูลอื่นก็ได้) ด้วยคำสั่งดังนี้
    CREATE DATABASE phpmyprepaid;
  8. กำหนดสิทธิให้กับบัญชีผู้ใช้งานบน mysql ที่ชื่อว่า phpmyprepaid พร้อม password คือ radpass (user และ password สามารถเปลี่ยนแปลงได้ตามความเหมาะสม) ด้วยคำสั่ง
    GRANT ALL PRIVILEGES ON phpmyprepaid.* to ‘phpmyprepaid’@’localhost’ IDENTIFIED BY ‘radpass’;
    FLUSH PRIVILEGES;
  9. ออกจาก mysql ด้วยคำสั่ง quit
  10. แก้ไขไฟล์ /etc/freeradius/sql.conf เพื่อให้เรียกใช้ฐานข้อมูล phpmyprepaid ด้วยสิทธิผู้ใช้เป็น phpmyprepaid ซึ่งมี password เป็น radpass  ดังนี้
    # Connection info:
    server = “localhost”
    login = “phpmyprepaid”
    password = “radpass”
    # Database table configuration for everything except Oracle
    radius_db = “phpmyprepaid”
  11. ทำการกำหนด password ให้กับเครื่อง Client ที่จะเข้าใช้งาน FreeRadius ที่ไฟล์ /etc/freeradius/cliens.conf โดยกำหนดให้ client 127.0.0.1 มีค่า secret = radiussecret
    client localhost {
    secret = radiussecret
    {
    ในกรณีที่อนุญาตให้เครื่อง client อื่นเข้ามาใ้้ช้งาน FreeRadius เช่น client ที่มี IP เป็น 172.24.51.16 ก็ให้กำหนดค่าเพิ่มเติมดังนี้
    client 172.24.51.16 {
    secret = radiussecret
    shortname = chilli
    }
  12. ในกรณีที่จะอนุญาตให้เครื่อง Client อื่น ๆ (ที่ไม่ใช่เครื่องตัวเอง หรือ Localhost) เข้ามาใช้งาน FreeRadius ได้นั้นจะต้องทำการเพิ่มข้อมูลในไฟล์ /etc/freeradius/naslist ซึ่งในที่นี้คือเพิ่มบรรทัดสุดท้ายดังต่อไปนี้เข้าไป# NAS Name                  Short Name                 Type
    #—————-                   ———-                         —-
    #portmaster1.isp.com      pm1.NY                    livingston
    #portmaster2.isp.com      pm1.LA                     livingston
    localhost                          local                          portslave
    chilli                                  chilli                          other
  13. แก้ไขไฟล์ /etc/freeradius/sql.conf กำหนดให้ค่า readclients = yes เพื่อที่จะทำให้ radius client อ่านค่าจาก database
  14. แก้ไขไฟล์ /etc/freeradius/radiusd.conf ดังนี้
    • ในส่วนของ  accounting {……} ให้เอาเครื่องหมาย  # หน้าคำว่า sql ออก เพื่อเรียกใช้ข้อมูลจาก database ในการตรวจสอบ username , password ในการทำ accounting
    • ในส่วน session {……} ให้เอาเครื่องหมาย # หน้าคำว่า sql ออก เพื่อเรียกใช้ข้อมูลจาก database ในการตรวจสอบ username, password ในการทำ session
    • ในส่วนของ authorize {……} ให้เอาเครื่องหมาย # ไว้หน้าคำว่า file  และเอาเครื่องหมาย # ออกจากคำว่า sql
  15. ทำการ restart FreeRadius ด้วยคำสั่ง
    /etc/init.d/freeradius restart
  16. ตอนนี้ ทั้ง freeradius และ mysql พร้อม database phpmyprepaid ว่าง ๆ พร้อมแล้ว
    ต่อไปจะทำการติดตั้งโปรแกรม phpmyprepaid แล้วรันโปรแกรมผ่านเว็บบราวเซอร์
    จากนั้นจะเซ็ตค่าต่าง ๆ บนหน้าเว็บ ทำให้ได้ table ต่าง ๆ ที่จำเป็นใช้งานเกิดขึ้น
  17. ย้ายเข้าไปในไดเรกทอรี /var/www/ ด้วยคำสั่ง
    cd /var/www
  18. ดาวน์โหลดโปรแกรม phpmyprepaid เวอร์ชั่น 0.4 RC2 ด้วยคำสั่ง wget ดังนี้
    wget http://downloads.sourceforge.net/phpmyprepaid/phpmyprepaid04RC2.tgz
  19. คลายแฟ้มออกมาจะได้ไดเรกทอรี phpmyprepaid
    tar zxvf phpmyprepaid04RC2.tgz
  20. ติดตั้งโปรแกรม  rrdtool ด้วยคำสั่ง
    apt-get install rrdtool
  21. เปิด browser และเรียกไปที่ http://host/phpmyprepaid/www   แล้วระบบจะเปิดไฟล์ setup.php ดังรูป 
  22. ขั้นที่ 2 เป็นเรื่องของ License ให้คลิ๊กช่อง I Accept แล้วคลิ๊กปุ่ม Next 
  23. ขั้นตอนที่ 3 ถ้าเจอปัญหาดังรูปให้ใช้คำสั่ง
    chmod 777 /var/www/phpmyprepaid/www
    แล้วจะได้ผลลัพท์ดังรูป

     

  24. ขั้นตอนที่ 4 จะเป็นดังรูป ให้ป้อนค่าให้ถูกต้องโดยเฉพาะค่า Phpmyprepaid path อาจจะต้องเปลี่ยนให้ตรงความเป็นจริง 
  25. ขั้นตอนเป็นการคอนฟิก Radius ก็ให้ป้อนข้อมูลให้ตรงตามรูป 
  26. ขั้นที่ 6 เป็นการจัดการเรื่อง User Interface ก็ให้ป้อนข้อมูลตามต้องการ แต่อย่าลืม user และ password ที่ได้กำหนดไว้ด้วย 
  27. ขั้นตอนที่ 7 เป็นการคอนฟิกฐานข้อมูล ให้ป้อนข้อมูลตรงกับที่ได้กำหนดไว้ดังรูป 
  28. เมื่อป้อนข้อมูลในขั้นตอนที่ 7 ถูกต้อง ก็จะได้ผลลัพท์ดังขั้นตอนที่ 8 
  29. ขั้นตอนที่ 9 เป็นการป้อนข้อมูล Location ดังรูป 
  30. ขั้นตอนที่ 11 เป็นการคอนฟิกข้อมูลทั่วไป ดังรูป 
  31. ขั้นตอนที่ 11 เป็นขั้นตอนสุดท้าย ให้อ่านข้อความด้วยนะครับเพราะมีคำแนะนำบางอย่างที่ต้องทำตามด้วย 
  32. จากนั้นเมื่อเราเรียกใช้งาน http://host/phpmyprepaid/www/ ก็จะได้หน้าตาดังรูป 
  33. เมื่อ Login เข้าสู่ระบบได้แล้ว จะได้ผลลัพท์ดังรูป 
  34. รูปข้างล่างเป็นตัวอย่างการเพิ่ม Account ที่สามารถกำหนดความเร็วในการ upload และ download ได้ 
  35. ทดสอบการทำงานของ FreeRadius ด้วยคำสั่ง radtest
    radtest  username  password  localhost 0 mysecret
    ถ้าเซ็ตอัพถูกต้องและป้อนค่าถูกต้องจะได้ผลลัพธ์ว่า Access-Accept ดังรูป

จบครับ
ที่มา: http://www.itmanage.info/technology/linux/ubuntu/freeradius_phpmyprepaid/install_freeradius_phpmyprepaid_ubutu_8_04.html

การติดตั้ง radius server ด้วยโปรแกรม freeradius

เป็นคำแนะนำติดตั้งจัดการปรับแต่ง radius server
ต้นแบบทดสอบด้วย linux fedora core 3,2,1 ใช้งานภายในมหาวิทยาลัยสงขลานครินทร์

วิธีติดตั้ง radius server ด้วยโปรแกรม freeradius
*** แหล่งข้อมูลต้นฉบับ freeradius คือ http://www.freeradius.org/

  1. ติดตั้งโปรแกรม freeradius ด้วยคำสั่ง
    apt-get install freeradius
  2. แก้ไขให้ทำงานทุกครั้งที่บูทเครื่อง
    chkconfig radiusd on
  3. สั่งให้ทำงานด้วยคำสั่งว่า
    /etc/init.d/radiusd start
    Starting RADIUS server: [ OK ]
  4. ตรวจสอบว่าโปรแกรมทำงานแล้วด้วยคำสั่ง
    /etc/init.d/radiusd status
    ได้ผลออกมาดังตัวอย่าง
    radiusd (pid 19180) is running…
  5. แฟ้มที่เกี่ยวข้อง
    • /var/log/radius/radius.log
    • /etc/raddb/radiusd.conf
    • /etc/raddb/clients.conf
  6. เมื่อให้ radiusd ทำงานแล้ว เริ่มขั้นตอนทดสอบระบบโดยป้อนตัวอย่างคำสั่งดังนี้radtest root password-root localhost 0 testing123
    *** จากตัวอย่าง password-root คือรหัสผ่านของ root
    ได้ผลข้อความตอบกลับดังตัวอย่าง
    Sending Access-Request of id 43 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “password-root”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    Re-sending Access-Request of id 43 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “{\277\033\t\217\224\n\021\036\271$\301\026\234\353\225”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Reject packet from host 127.0.0.1:1812, id=43, length=20

    แสดงว่าระบบใช้งานได้แล้ว ถึงแม้ว่าจะมีการแจ้งว่า Access-Reject
    เป็นสาเหตุเนื่องจากไม่มีสิทธิในการอ่านแฟ้ม /etc/shadow ของระบบ

  7. หากต้องการให้ใช้กับบัญชีผู้ใช้ระบบ UNIX
    ต้องตั้งค่าให้อ่านแฟ้ม /etc/shadow ได้
    โดยแก้ไขแฟ้ม /etc/raddb/radiusd.conf
    ทำการ comment ยกเลิกบรรทัดข้อความจากเดิม
    user = radiusd
    group = radiusd
    ให้เป็น
    #user = radiusd
    #group = radiusd
    เสร็จแล้วให้ restart ระบบ radiusd ใหม่ด้วยคำสั่ง /etc/init.d/radiusd restart
    ต่อไปลองป้อนตัวอย่างคำสั่งเดิมเพื่อทดสอบดังนี้
    radtest root password-root localhost 0 testing123
    คราวนี้จะได้ผลข้อความว่า
    Sending Access-Request of id 82 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “password-root”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=82, length=20
    โดยมีผลการแจ้งว่า Access-Accept ถูกต้องตามต้องการ
  8. หากต้องการให้ radius client เข้ามาติดต่อใช้งานระบบ radiusd นี้ได้
    ให้แก้ไขแฟ้ม /etc/raddb/clients.conf ให้มีค่าดังตัวอย่างนี้
    client 10.0.1.0/24 {
    secret = mytestkey
    shortname = private-network
    }
    ตัวอย่างคือให้ radius client ที่มีหมายเลข ip 10.0.1.x
    สามารถเข้ามาใช้ด้วย secret key ว่า mytestkey
    เมื่อแก้ไขเสร็จแล้วให้ reload ใหม่ด้วยคำสั่ง /etc/init.d/radiusd reload
    ลองทดสอบด้วยคำสั่งตัวอย่าง
    radtest root passwordroot 10.0.1.1 0 mytestkey
    *** ค่า passwordroot คือ รหัสผ่านของ root และ 10.0.1.1 คือหมายเลข ip ของ radius server
    ได้ผลแสดงข้อความดังตัวอย่าง
    Sending Access-Request of id 246 to 10.0.1.1:1812
    User-Name = “root”
    User-Password = “passwordroot”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 10.0.1.1:1812, id=246, length=20ถึงขั้นตอนนี้เป็นอันเปิดใช้ระบบ radiusd ได้แล้ว
  9. หากต้องการให้ใช้ได้ดับ LDAP ด้วยให้แก้ไขแฟ้ม /etc/raddb/radiusd.conf
    เพื่อให้รองรับและเชื่อมต่อกับ LDAP server ดังนี้ต้องแก้ไขส่วนของ modules โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    modules {

    ldap {
    **** ให้แก้ไขค่าของ server , basedn ดังตัวอย่าง
    server = “myldap.net”
    basedn = “dc=my, dc=net”
    **** ให้ comment บรรทัด access_attr เพื่อยกเลิกค่า เนื่องจากไม่ได้ใช้รูปแบบนี้
    # access_attr = “dialupAccess”

    *** ในส่วนของ modules แก้ไขเพียงแค่นี้
    ต่อไปแก้ไขส่วนของ authorize โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    authorize {

    # Read the ‘users’ file
    files
    *** ให้แก้ไขโดยแทรกเพิ่มบรรทัดข้อความว่า ldap ก่อนบรรทัดคำว่า files
    เพื่อให้ระบบทำการลำดับ authorize ด้วยแบบ ldap ก่อน
    หากไม่พบก็จะต่อด้วยแบบ files (แฟ้ม /etc/shadow)
    ถ้ากลับลำดับการ authorize อาจพบปัญหาผิดพลาดได้
    ดังตัวอย่างหลังการแทรกเพิ่มข้อความ
    # Read the ‘users’ file
    ldap
    files
    *** ในส่วนของ authorize แก้ไขเพียงแค่นี้
    ต่อไปแก้ไขส่วนของ authenticate โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    authenticate {

    # Auth-Type LDAP {
    # ldap
    # }
    *** ให้แก้ไขด้วยการ uncomment บรรทัดข้อความเพื่อให้ระบบกำหนดวิธี LDAP
    Auth-Type LDAP {
    ldap
    }
    *** ในส่วนของ authenticate แก้ไขเพียงแค่นี้

    เสร็จแล้วให้ reload ใหม่ด้วยคำสั่ง /etc/init.d/radiusd reload
    ทดสอบใช้งานได้เลย

  10. แนะนำให้ยกเลิกการกำหนดค่าการทำงานบางตัวที่ไม่ได้ใช้งาน
    โดยการ comment บรรทัดข้อความในแฟ้ม /etc/raddb/radiusd.confถ้าไม่ได้ใช้เป็น proxy radius ควรยกเลิก
    โดยเปลี่ยนจากเดิม proxy_requests = yes
    ให้เป็น proxy_requests = no

    ควรยกเลิกบาง authorize ที่ไม่ได้ใช้เช่น
    authorize {
    # preprocess
    # chap
    # mschap
    # suffix
    # ldap —> ระบบ ldap
    # files –> ระบบ UNIX หรือแฟ้ม /etc/shadow

  11. การแสดงผลรายงานจำเป็นต้องหาโปรแกรมมาต่างหาก
    ขอแนะนำตัวอย่างโปรแกรมแสดงผลรายงาน

    • ต้นแหล่งข้อมูลคือ http://www.tummy.com/radiusContext/
      สามารถได้ดาวน์โหลดโปรแกรมได้ที่
      ftp://ftp.psu.ac.th/pub/freeradius/radiusContext-1.93.tar.gz
    • ให้ดาวน์โหลดมาแล้วขยายแฟ้มเก็บไว้ที่ /root ด้วยตัวอย่างคำสั่ง
      tar -C /root -zxvf radiusContext-1.93.tar.gz
    • สร้าง directory สำหรับแสดงผลบนเวบ ดังตัวอย่างคือ
      mkdir /var/www/html/radiusreport
      จะแสดงผลบนโฮมพจ http://x.x.x.x/radius-report
    • ตัวอย่าง ขั้นตอนที่ใช้สำหรับประมวลผลรวมข้อมูลจาก
      /var/log/radius/radacct ไปเก็บไว้เพื่อแสดงผลที่ /var/www/html/radius-report
      *** ภายใน /var/log/radius/radacct จะแยกเก็บข้อมูลเป็น directory ของ
      แต่ละหมายเลข ip ทำให้อาจยุ่งยากต่อการรวบรวมข้อมูล/root/radiusContext-1.93/raddetail /var/log/radius/radacct/*/*
      /root/radiusContext-1.93/stdreport -D /var/www/html/radius-report

      *** ต้องใช้คำสั่งเหล่านี้ทุกครั้งเพื่อปรับปรุงผลรายงาน

    • ทดสอบผลรายงานได้เลยที่ http://x.x.x.x/radius-report

ที่มา: http://zeous21.exteen.com/20050919/radius-server-freeradius

การติดตั้ง radius server ด้วยโปรแกรม freeradius

เป็นคำแนะนำติดตั้งจัดการปรับแต่ง radius server
ต้นแบบทดสอบด้วย linux fedora core 3,2,1 ใช้งานภายในมหาวิทยาลัยสงขลานครินทร์

วิธีติดตั้ง radius server ด้วยโปรแกรม freeradius
*** แหล่งข้อมูลต้นฉบับ freeradius คือ http://www.freeradius.org/

  1. ติดตั้งโปรแกรม freeradius ด้วยคำสั่ง
    apt-get install freeradius
  2. แก้ไขให้ทำงานทุกครั้งที่บูทเครื่อง
    chkconfig radiusd on
  3. สั่งให้ทำงานด้วยคำสั่งว่า
    /etc/init.d/radiusd start
    Starting RADIUS server: [ OK ]
  4. ตรวจสอบว่าโปรแกรมทำงานแล้วด้วยคำสั่ง
    /etc/init.d/radiusd status
    ได้ผลออกมาดังตัวอย่าง
    radiusd (pid 19180) is running…
  5. แฟ้มที่เกี่ยวข้อง
    • /var/log/radius/radius.log
    • /etc/raddb/radiusd.conf
    • /etc/raddb/clients.conf
  6. เมื่อให้ radiusd ทำงานแล้ว เริ่มขั้นตอนทดสอบระบบโดยป้อนตัวอย่างคำสั่งดังนี้radtest root password-root localhost 0 testing123
    *** จากตัวอย่าง password-root คือรหัสผ่านของ root
    ได้ผลข้อความตอบกลับดังตัวอย่าง
    Sending Access-Request of id 43 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “password-root”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    Re-sending Access-Request of id 43 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “{\277\033\t\217\224\n\021\036\271$\301\026\234\353\225”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Reject packet from host 127.0.0.1:1812, id=43, length=20

    แสดงว่าระบบใช้งานได้แล้ว ถึงแม้ว่าจะมีการแจ้งว่า Access-Reject
    เป็นสาเหตุเนื่องจากไม่มีสิทธิในการอ่านแฟ้ม /etc/shadow ของระบบ

  7. หากต้องการให้ใช้กับบัญชีผู้ใช้ระบบ UNIX
    ต้องตั้งค่าให้อ่านแฟ้ม /etc/shadow ได้
    โดยแก้ไขแฟ้ม /etc/raddb/radiusd.conf
    ทำการ comment ยกเลิกบรรทัดข้อความจากเดิม
    user = radiusd
    group = radiusd
    ให้เป็น
    #user = radiusd
    #group = radiusd
    เสร็จแล้วให้ restart ระบบ radiusd ใหม่ด้วยคำสั่ง /etc/init.d/radiusd restart
    ต่อไปลองป้อนตัวอย่างคำสั่งเดิมเพื่อทดสอบดังนี้
    radtest root password-root localhost 0 testing123
    คราวนี้จะได้ผลข้อความว่า
    Sending Access-Request of id 82 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “password-root”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=82, length=20
    โดยมีผลการแจ้งว่า Access-Accept ถูกต้องตามต้องการ
  8. หากต้องการให้ radius client เข้ามาติดต่อใช้งานระบบ radiusd นี้ได้
    ให้แก้ไขแฟ้ม /etc/raddb/clients.conf ให้มีค่าดังตัวอย่างนี้
    client 10.0.1.0/24 {
    secret = mytestkey
    shortname = private-network
    }
    ตัวอย่างคือให้ radius client ที่มีหมายเลข ip 10.0.1.x
    สามารถเข้ามาใช้ด้วย secret key ว่า mytestkey
    เมื่อแก้ไขเสร็จแล้วให้ reload ใหม่ด้วยคำสั่ง /etc/init.d/radiusd reload
    ลองทดสอบด้วยคำสั่งตัวอย่าง
    radtest root passwordroot 10.0.1.1 0 mytestkey
    *** ค่า passwordroot คือ รหัสผ่านของ root และ 10.0.1.1 คือหมายเลข ip ของ radius server
    ได้ผลแสดงข้อความดังตัวอย่าง
    Sending Access-Request of id 246 to 10.0.1.1:1812
    User-Name = “root”
    User-Password = “passwordroot”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 10.0.1.1:1812, id=246, length=20ถึงขั้นตอนนี้เป็นอันเปิดใช้ระบบ radiusd ได้แล้ว
  9. หากต้องการให้ใช้ได้ดับ LDAP ด้วยให้แก้ไขแฟ้ม /etc/raddb/radiusd.conf
    เพื่อให้รองรับและเชื่อมต่อกับ LDAP server ดังนี้ต้องแก้ไขส่วนของ modules โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    modules {

    ldap {
    **** ให้แก้ไขค่าของ server , basedn ดังตัวอย่าง
    server = “myldap.net”
    basedn = “dc=my, dc=net”
    **** ให้ comment บรรทัด access_attr เพื่อยกเลิกค่า เนื่องจากไม่ได้ใช้รูปแบบนี้
    # access_attr = “dialupAccess”

    *** ในส่วนของ modules แก้ไขเพียงแค่นี้
    ต่อไปแก้ไขส่วนของ authorize โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    authorize {

    # Read the ‘users’ file
    files
    *** ให้แก้ไขโดยแทรกเพิ่มบรรทัดข้อความว่า ldap ก่อนบรรทัดคำว่า files
    เพื่อให้ระบบทำการลำดับ authorize ด้วยแบบ ldap ก่อน
    หากไม่พบก็จะต่อด้วยแบบ files (แฟ้ม /etc/shadow)
    ถ้ากลับลำดับการ authorize อาจพบปัญหาผิดพลาดได้
    ดังตัวอย่างหลังการแทรกเพิ่มข้อความ
    # Read the ‘users’ file
    ldap
    files
    *** ในส่วนของ authorize แก้ไขเพียงแค่นี้
    ต่อไปแก้ไขส่วนของ authenticate โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    authenticate {

    # Auth-Type LDAP {
    # ldap
    # }
    *** ให้แก้ไขด้วยการ uncomment บรรทัดข้อความเพื่อให้ระบบกำหนดวิธี LDAP
    Auth-Type LDAP {
    ldap
    }
    *** ในส่วนของ authenticate แก้ไขเพียงแค่นี้

    เสร็จแล้วให้ reload ใหม่ด้วยคำสั่ง /etc/init.d/radiusd reload
    ทดสอบใช้งานได้เลย

  10. แนะนำให้ยกเลิกการกำหนดค่าการทำงานบางตัวที่ไม่ได้ใช้งาน
    โดยการ comment บรรทัดข้อความในแฟ้ม /etc/raddb/radiusd.confถ้าไม่ได้ใช้เป็น proxy radius ควรยกเลิก
    โดยเปลี่ยนจากเดิม proxy_requests = yes
    ให้เป็น proxy_requests = no

    ควรยกเลิกบาง authorize ที่ไม่ได้ใช้เช่น
    authorize {
    # preprocess
    # chap
    # mschap
    # suffix
    # ldap —> ระบบ ldap
    # files –> ระบบ UNIX หรือแฟ้ม /etc/shadow

  11. การแสดงผลรายงานจำเป็นต้องหาโปรแกรมมาต่างหาก
    ขอแนะนำตัวอย่างโปรแกรมแสดงผลรายงาน

    • ต้นแหล่งข้อมูลคือ http://www.tummy.com/radiusContext/
      สามารถได้ดาวน์โหลดโปรแกรมได้ที่
      ftp://ftp.psu.ac.th/pub/freeradius/radiusContext-1.93.tar.gz
    • ให้ดาวน์โหลดมาแล้วขยายแฟ้มเก็บไว้ที่ /root ด้วยตัวอย่างคำสั่ง
      tar -C /root -zxvf radiusContext-1.93.tar.gz
    • สร้าง directory สำหรับแสดงผลบนเวบ ดังตัวอย่างคือ
      mkdir /var/www/html/radiusreport
      จะแสดงผลบนโฮมพจ http://x.x.x.x/radius-report
    • ตัวอย่าง ขั้นตอนที่ใช้สำหรับประมวลผลรวมข้อมูลจาก
      /var/log/radius/radacct ไปเก็บไว้เพื่อแสดงผลที่ /var/www/html/radius-report
      *** ภายใน /var/log/radius/radacct จะแยกเก็บข้อมูลเป็น directory ของ
      แต่ละหมายเลข ip ทำให้อาจยุ่งยากต่อการรวบรวมข้อมูล/root/radiusContext-1.93/raddetail /var/log/radius/radacct/*/*
      /root/radiusContext-1.93/stdreport -D /var/www/html/radius-report

      *** ต้องใช้คำสั่งเหล่านี้ทุกครั้งเพื่อปรับปรุงผลรายงาน

    • ทดสอบผลรายงานได้เลยที่ http://x.x.x.x/radius-report

ที่มา: http://zeous21.exteen.com/20050919/radius-server-freeradius

Radius Servers Installation Guide (FreeRADIUS + Ubuntu + MySQL)

To install FreeRADIUS on Ubuntu and do some basic testings, you should follow the steps below:
1)     Install lamp-server: 
Actually, install MySQL and PHP are enough already. But to make sure that there are no dependencies errors later,
I prefer installing the whole      package (lamp-server stands for Linux-Apache-MySQL-PHP server).
We install lamp-server using the command below:
sudo tasksel install lamp-server
(you will need to enter root password, which is “setupRADIUS” by default, to continue the installation)
2)     Install freeradius package
sudo apt-get install freeradius
(Enter password when asked. When you are asked to continue, type ‘y’, then press Enter)
3)     Install freeradius with ldap authentication
sudo apt-get install freeradius-ldap
4)     Install freeradius to run with mysql
sudo apt-get install freeradius-mysql
5)     After finishing the above installations, restart the FreeRADIUS service
sudo /etc/init.d/freeradius restart
6)     Now, you can test the Radius Server using radtest, the command will be as below:

At this stage, you will get an error as follow:

If that’s the case, you can do the steps in part II.1/ to fix the error. The correct result should be as follow:

7)     Now, we create the database for FreeRADIUS and an user account which will be used by FreeRADIUS to access into database. We run the following command:

  • Login MySQL Database

(Enter the password for root user)

  • Then you can create user, database, and set permissions as follow:

8)     Then, you copy the folder sql (comes along with this document in the folder “necessary setup files”) into the folder /etc/freeradius/

9)     Import current schema of the database for FreeRADIUS into the “radius” database (the current Radius database schema for our project can be found in the file radius.sql, which comes along with this document in the folder “necessary setup files”)

10)    Configure the file /etc/freeradius/sites-enabled/default so that the FreeRADIUS can startup, creates a default virtual host, and connects to MySQL Database. We follow the below steps:
Run the command:
sudo gedit /etc/freeradius/sites-enabled/default
In the file “default”, you check if the following settings are correct or not (the settings in the below pictures are correct settings):
In the authorize{} module

(uncomment the sql setting)
In the accounting{} module

In the session{} module

In the post-auth{} module

11)    Now, we configure the “radiusd.conf”. This file contains general settings for the Radius Server. We follow the below steps:
sudo gedit /etc/freeradius/radiusd.conf
Then, we check if the settings in the file radiusd.conf are correct or not.
The port for radius server to listen for authentication request is 1812

Port for accounting is 1813

Some settings for logging username, password, etc

12)    Now, we configure the file “sql.conf”. This file contains information about how to connect to database, database tables that are used by the FreeRADIUS server, etc
Run the command:
sudo gedit /etc/freeradius/sql.conf
Then, you should check the following settings:

Check the setting that allow FreeRADIUS to read Radius Clients from database

In the module modules{}

13)    Now, you clear all contents in the file /etc/freeradius/clients.conf because when radius server start running, it will read Radius Clients from both clients.conf and database (current settings). So, we clear the file clients.conf so that radius server only load Radius Clients from database (and to avoid conflicts like clients.conf and database contain the same Radius Client)
14)    Now, the installation is finished. You can start using the Radius Server.
PS: sorry,the files about “necessary setup files” are some sql files,which are used to the sql table of the our project.
you just create table you used in MYSQL access.
ที่มา: http://www.mydeveloperblog.com/linux-tutorial/radius/radius-servers-installation-guide-freeradius-ubuntu-mysql/

Radius Servers Installation Guide (FreeRADIUS + Ubuntu + MySQL)

To install FreeRADIUS on Ubuntu and do some basic testings, you should follow the steps below:
1)     Install lamp-server: 
Actually, install MySQL and PHP are enough already. But to make sure that there are no dependencies errors later,
I prefer installing the whole      package (lamp-server stands for Linux-Apache-MySQL-PHP server).
We install lamp-server using the command below:
sudo tasksel install lamp-server
(you will need to enter root password, which is “setupRADIUS” by default, to continue the installation)
2)     Install freeradius package
sudo apt-get install freeradius
(Enter password when asked. When you are asked to continue, type ‘y’, then press Enter)
3)     Install freeradius with ldap authentication
sudo apt-get install freeradius-ldap
4)     Install freeradius to run with mysql
sudo apt-get install freeradius-mysql
5)     After finishing the above installations, restart the FreeRADIUS service
sudo /etc/init.d/freeradius restart
6)     Now, you can test the Radius Server using radtest, the command will be as below:

At this stage, you will get an error as follow:

If that’s the case, you can do the steps in part II.1/ to fix the error. The correct result should be as follow:

7)     Now, we create the database for FreeRADIUS and an user account which will be used by FreeRADIUS to access into database. We run the following command:

  • Login MySQL Database

(Enter the password for root user)

  • Then you can create user, database, and set permissions as follow:

8)     Then, you copy the folder sql (comes along with this document in the folder “necessary setup files”) into the folder /etc/freeradius/

9)     Import current schema of the database for FreeRADIUS into the “radius” database (the current Radius database schema for our project can be found in the file radius.sql, which comes along with this document in the folder “necessary setup files”)

10)    Configure the file /etc/freeradius/sites-enabled/default so that the FreeRADIUS can startup, creates a default virtual host, and connects to MySQL Database. We follow the below steps:
Run the command:
sudo gedit /etc/freeradius/sites-enabled/default
In the file “default”, you check if the following settings are correct or not (the settings in the below pictures are correct settings):
In the authorize{} module

(uncomment the sql setting)
In the accounting{} module

In the session{} module

In the post-auth{} module

11)    Now, we configure the “radiusd.conf”. This file contains general settings for the Radius Server. We follow the below steps:
sudo gedit /etc/freeradius/radiusd.conf
Then, we check if the settings in the file radiusd.conf are correct or not.
The port for radius server to listen for authentication request is 1812

Port for accounting is 1813

Some settings for logging username, password, etc

12)    Now, we configure the file “sql.conf”. This file contains information about how to connect to database, database tables that are used by the FreeRADIUS server, etc
Run the command:
sudo gedit /etc/freeradius/sql.conf
Then, you should check the following settings:

Check the setting that allow FreeRADIUS to read Radius Clients from database

In the module modules{}

13)    Now, you clear all contents in the file /etc/freeradius/clients.conf because when radius server start running, it will read Radius Clients from both clients.conf and database (current settings). So, we clear the file clients.conf so that radius server only load Radius Clients from database (and to avoid conflicts like clients.conf and database contain the same Radius Client)
14)    Now, the installation is finished. You can start using the Radius Server.
PS: sorry,the files about “necessary setup files” are some sql files,which are used to the sql table of the our project.
you just create table you used in MYSQL access.
ที่มา: http://www.mydeveloperblog.com/linux-tutorial/radius/radius-servers-installation-guide-freeradius-ubuntu-mysql/

การติดตั้ง FreeRADIUS on Ubuntu 12.04

FreeRadius
Developer Web Site
These programs are run from a terminal
checkrad, freeradius, raddebug, radmin, radwatch

$ freeradius -v
freeradius: FreeRADIUS Version 2.1.10, for host x86_64-pc-linux-gnu, built on Nov 24 2011 at 07:53:12

$ sudo /etc/init.d/freeradius restart
* Stopping FreeRADIUS daemon freeradius                                 [ OK ]
* Starting FreeRADIUS daemon freeradius                                 [ OK ]
log file 
/var/log/freeradius/radius.log

/etc/freeradius

Webmin
http://www.webmin.com/
https://localhost:10000/

Dialup Admin Administration interface
http://freeradius.org/dialupadmin.html

Projects related to FreeRADIUS
http://freeradius.org/related/

ติดตั้ง freeradius บน ubuntu

บันทึกนี้ปรับปรุงล่าสุดเมื่อ 15-02-2555
ดูแลโดย WIPAT

หมายเหตุ:  ต้องระวัง การปรับแต่งค่า freeradius 2.x บน ubuntu เปลี่ยนแปลงไปจาก freeradius 1.x ไปมาก

    http://opensource.cc.psu.ac.th/wiki-opensource/skins/monobook/bullet.gif); color: rgb(0, 0, 0); font-family: sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); “>

  • ทดสอบกับ ubuntu 10.04 และ freeradius 2.x
  • ต้นฉบับ freeradius อยู่ที่ http://opensource.cc.psu.ac.th/wiki-opensource/skins/monobook/external.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-top: 0px; padding-right: 13px; padding-bottom: 0px; padding-left: 0px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; “>http://freeradius.org
  • สมมติว่า radius server นี้มีหมายเลข ip เป็น 10.0.1.1
  1. ติดตั้งด้วยคำสั่ง sudo apt-get install freeradius freeradius-utils freeradius-mysql freeradius-ldap gawk
  2. สั่งให้ทำงานด้วยคำสั่ง sudo /etc/init.d/freeradius start
  3. ทดสอบว่า freeradius ติดตั้งใช้งานได้แล้วด้วยตัวอย่างคำสั่ง*** จากตัวอย่างให้แทนข้อความ your_root_password ด้วยรหัสผ่านของ root
    sudo radtest your_name your_password 127.0.0.1 0 testing123
    หากถูกต้องจะได้รับข้อความตอบกลับประมาณว่า
    Sending Access-Request of id 232 to 127.0.0.1 port 1812
    User-Name = “your-name”
    User-Password = “your_password”
    NAS-IP-Address = 255.255.255.255
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=232, length=20

    ถึงตอนนี้แสดงว่า freeradius ใช้งานได้แล้ว แต่ใช้ได้เพียง localhost คือ 127.0.0.1

  4. หากต้องการอนุญาติให้ radius client เข้ามาใช้ radius server นี้ได้
    ต้องแก้ไขสิทธิ์ที่แฟ้ม /etc/freeradius/clients.conf  ปรับตั้งให้มีค่าดังประมาณตัวอย่างนี้
    client 10.0.1.0/24 {
    secret          = mytestkey
    shortname       = private-network
    }
    ตัวอย่างนี้คือให้ radius client ที่มีหมายเลข ip 10.0.1.x  สามารถเข้ามาใช้ด้วย secret key ว่า mytestkey
    เมื่อแก้ไขเสร็จแล้วให้ reload ใหม่ ด้วยคำสั่ง  sudo /etc/init.d/freeradius force-reload
    ลองทดสอบด้วยคำสั่งตัวอย่าง sudo radtest your_name your_password 10.0.1.1 0 mytestkey
    *** ค่า your_password คือ รหัสผ่านของ your_name และ 10.0.1.1 คือหมายเลข ip ของ radius server
    ได้ผลแสดงข้อความดังตัวอย่าง
    Sending Access-Request of id 246 to 10.0.1.1:1812
    User-Name = “your_name”
    User-Password = “your_password”
    NAS-IP-Address = 255.255.255.255
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 10.0.1.1:1812, id=246, length=20ถึงขั้นตอนนี้เป็นอันเปิดบริการระบบ radius server ได้แล้ว
  5. ขั้นตอนการทำงานของ configuration ของ freeradius
    แฟ้ม /etc/freeradius/radiusd.conf  เป็นที่ปรับค่าของระบบต่างๆหากเป็น freeradius 2.x จะมีการแยกแฟ้มย่อยออกไปจาก /etc/freeradius/radiusd.conf
    ไปอยู่ที่ /etc/freeradius/sites-available/default  และ /etc/freeradius/modules
    หากเป็น freeradius 1.x ทุกอย่างจะกระจุกตัวในแฟ้ม /etc/freeradius/radiusd.conf

    เมื่อ radius server ได้รับการติดต่อจากผู้ใช้ radius client
    วิธีการตรวจสอบคุณสมบัติของผู้ใช้อยู่ในส่วนที่ชื่อ authorize {…}
    ภายใน authorize {…} นี้ ประกอบด้วยชื่อ modules ตรวจสอบต่างๆ

    หากคุณสมบัติไม่ตรง ปรกติแล้วระบบก็จะรีบดีดออกมาพร้อมแจ้ง reject
    แต่เราสามารถกำหนดให้ไปตรวจสอบต่อกับ authorize modules
    เรียงลำดับอันถัดๆไปที่เหลืออื่นๆได้อีก

    หากคุณสมบัติผ่าน ก็จะเข้าขั้นตอนตรวจสอบรหัสผ่านของผู้ใช้ว่าถูกต้องหรือไม่
    โดย authorize modules จะเลือก modules ที่ต้องการเอง จากส่วนที่ชื่อ authenticate {…}

    หากรหัสผ่านถูกต้อง ก็จะเข้าสู่ส่วนของ postauth {…}
    เป็นการตรวจสอบทิ้งท้ายก่อนส่งคืนค่ากลับให้แก่ radius client ที่ติดต่อมา

    การบันทึกประวัติใช้งานอยู่ในส่วน accounting {…}

    modules ทุกตัวที่ใช้งาน จะต้องได้รับการประกาศไว้ก่อนแล้ว
    หากเป็น freeradius 2.x จะแยก modules ออกเป็นแฟ้มย่อยๆอยู่ที่ directory ชื่อ /etc/freeradius/modules
    หากเป็น freeradius 1.x จะมี modules อยู่ในแฟ้ม /etc/freeradius/radiusd.conf พื้นที่ส่วนของชื่อ modules {…}

  6. หากต้องการตรวจสอบผู้ใช้กับ mail server ผ่าน imap/pop3 ให้ทำดังนี้ตัวอย่างนี้จะตรวจสอบกับ mail server ชื่อ your.mail.server
    ต้องติดตั้ง php และ php-imap ก่อนแล้ว ติดตั้งด้วยคำสั่ง sudo apt-get install php5 php5-imap php5-cli
    แก้ไขแฟ้ม /etc/php5/cli/conf.d/imap.ini ตรวจสอบ/เพิ่มให้มีบรรทัดตัวแปรว่า extension=imap.so

    ต่อไปสร้างแฟ้ม /etc/freeradius/imap.php ให้มีเนื้อหาว่า
    <?php
    error_reporting(0);
    $host = $argv[1];
    $username = $argv[2];
    $password = $argv[3];
    $service = $argv[4];
    $imap_host=”{” . $host . $service . “}”;
    $mbox = imap_open(“$imap_host”, “$username”, “$password”);
    $folders = imap_listmailbox($mbox, “$imap_host”, “*”);
    if ($folders == false) {
    echo “false”;
    } else {
    echo “true”;
    }
    imap_close($mbox);
    ?>

    สร้างแฟ้มคำสั่ง shell script ชื่อ  /etc/freeradius/imap-authen.sh มีเนื้อหาว่า
    #!/bin/bash
    #exit 0 = valid ; exit 1 = invalid
    AUTHEN_SHADOW=”YES”
    AUTHEN_MAIL=”YES”
    AUTHEN_LDAP=”NO”
    AUTHEN_PSU_PASSPORT=”NO”
    NAME=$(echo ${USER_NAME} | cut -d'”‘ -f2)
    PASSWORD=$(echo ${USER_PASSWORD} | cut -d'”‘ -f 2-|sed “s/\”$//”)
    KEY=”false”
    if [ “${AUTHEN_SHADOW}” = “YES” ] ; then
    KEY=$(/bin/sh /etc/freeradius/check-shadow.sh “${NAME}” “${PASSWORD}”)
    if [ “${KEY}” = “true” ] ; then
    exit 0
    fi
    fi
    if [ “${AUTHEN_LDAP}” = “YES” ] ; then
    KEY=$(/bin/sh /etc/freeradius/check-ldap.sh “${NAME}” “${PASSWORD}”)
    if [ “${KEY}” = “true” ] ; then
    exit 0
    fi
    fi
    if [ “${AUTHEN_PSU_PASSPORT}” = “YES” ] ; then
    USER=$(echo ${NAME} | cut -d’@’ -f1)
    KEY=$(/usr/bin/php /etc/freeradius/soap-authen.php ${USER} ${PASSWORD} $1 $2})
    if [ “${KEY}” = “true” ] ; then
    exit 0
    fi
    fi
    if [ “${AUTHEN_MAIL}” = “YES” ] ; then
    IS_EMAIL=$(echo ${NAME}|grep “@”)
    if [ -n “${IS_EMAIL}” ] ; then
    USER=$(echo ${NAME} | cut -d’@’ -f1)
    DOMAIN=$(echo ${NAME} | cut -d’@’ -f2)
    else
    USER=${NAME}
    DOMAIN=”mail.psu.ac.th”
    fi
    case ${DOMAIN} in
    psu.ac.th)
    HOST=”mail.psu.ac.th”
    SERVICE=”:143/imap/notls” ;;
    pharmacy.psu.ac.th)
    HOST=”mail.pharmacy.psu.ac.th”
    SERVICE=”:143/imap/notls” ;;
    pn.psu.ac.th)
    HOST=”bunga.pn.psu.ac.th”
    SERVICE=”:143/imap/notls” ;;
    gmail.com)
    HOST=”pop.gmail.com”
    SERVICE=”:995/pop3/ssl” ;;
    live.com)
    HOST=”pop3.live.com”
    USER=${NAME}
    SERVICE=”:995/pop3/ssl” ;;
    *)
    HOST=${DOMAIN}
    SERVICE=”:110/pop3/notls” ;;
    esac
    KEY=$(/usr/bin/php /etc/freeradius/imap.php ${HOST} ${USER} ${PASSWORD} ${SERVICE})
    if [ “${KEY}” = “true” ] ; then
    exit 0
    fi
    fi
    exit 1

    สร้างแฟ้มแบบ text ชื่อ /etc/freeradius/myusers มีเนื้อหาว่า
    DEFAULT Auth-Type := Accept
    Exec-Program-Wait=”/bin/sh /etc/freeradius/imap-authen.sh”

    หากเป็น freeradius 2.x ให้แก้ไขแฟ้ม /etc/freeradius/modules/files เติมข้อความต่อท้ายแฟ้มว่า
    files  myimap  {
    usersfile = ${confdir}/myusers
    }
    แล้วแก้ไขแฟ้ม /etc/freeradius/sites-available/default
    ที่ส่วนของ authorize {…} ประมาณบรรทัดที่ 152 ที่บริเวณข้อความขึ้นต้นด้วย authorize {

    #  Read the ‘users’ file
    files
    ให้ comment บรรทัด files เพื่อยกเลิกค่านี้  แล้วแทรกเพิ่มบรรทัดข้อความเพิ่ม กลายเป็นว่า
    #    files
    แทรกเพิ่มบรรทัดข้อความว่า myimap ต่อไปอีกบรรทัด กลายเป็นว่า
    #   files
    myimap

    เสร็จแล้วให้สั่งทำงานใหม่ด้วยคำสั่ง sudo /etc/init.d/freeradius force-reload
    แค่นี้ก็เสร็จแล้ว ทดสอบผลงานได้เลย

  7. หากต้องการว่าหลังผ่านการตรวจสอบ username/password ถูกต้องแล้ว
    จะทำการบันทึกลงแฟ้ม log file เก็บไว้ที่ /var/log/freeradius/myauthen และยังต้องการตรวจวิธีการพิเศษเฉพาะของตนเองเพิ่มเติมอีกตัวอย่างต้องการไม่อนุญาติให้ผู้ใช้ชื่อ demo และ abc ใช้งาน ให้ทำดังนี้
    สร้างแฟ้มคำสั่ง shell script ชื่อ  /etc/freeradius/my-authen.sh มีเนื้อหาว่า
    #!/bin/bash
    ###exit 0 = valid ; exit1 = invalid
    ALL_PASS=”YES”
    CHECK_STAFF=”NO”
    CHECK_STUDENT=”NO”
    export LANG=en.US
    MYDIR=”/var/log/freeradius/myauthen”
    if [ ! -d ${MYDIR} ] ; then
    mkdir -p ${MYDIR}
    fi
    TODAY=$(date “+%Y%m%d”)
    MYFILE=”${MYDIR}/${TODAY}”
    if [ ! -e ${MYFILE} ] ; then
    touch ${MYFILE}
    fi
    MYTIME=$(echo $1|awk ‘{print strftime(“%Y%m%d:%H:%M:%S”,$1)}’)
    echo “${MYTIME};${USER_NAME};$2;$1;PASS” >> ${MYFILE}
    MYUSER=$(echo $USER_NAME | cut -d'”‘ -f2)
    if [ “${ALL_PASS}” = “YES” ] ; then
    exit 0
    fi
    if [ “${CHECK_STAFF}” = “YES” ] ; then
    case “${MYUSER}” in
    demo) exit 1 ;;
    *) exit 0 ;;
    esac
    fi
    if [ “${CHECK_STUDENT}” = “YES” ] ; then
    case “${MYUSER}” in
    demo) exit 1 ;;
    *) exit 0 ;;
    esac
    fi
    exit 1

    หากเป็น freeradius 2.x  ให้แก้ไขแฟ้ม /etc/freeradius/modules/exec เติมข้อความต่อท้ายแฟ้มว่า
    exec my-auth {
    program = “/bin/sh /etc/freeradius/my-authen.sh %l %{Packet-Src-IP-Address}”
    wait = yes
    input_pairs = request
    output_pairs = reply
    packet_type = Access-Accept
    }
    แล้วแก้ไขแฟ้ม /etc/freeradius/sites-available/default
    ที่ส่วนของ post-auth {…} ประมาณบรรทัดที่ 439  ที่บริเวณข้อความขึ้นต้นด้วย post-auth {

    แทรกเพิ่มบรรทัดข้อความเพิ่ม
    my-auth

    เสร็จแล้วให้สั่งทำงานใหม่ด้วยคำสั่ง sudo /etc/init.d/freeradius force-reload

  8. การบันทึกประวัติการใช้งานของ radius โดย defualt จะบันทึกไว้ในพื้นที่  /var/log/freeradius/radacct
    โดยแยกเป็น directory ของแต่ละหมายเลข ip ของ radius client
    แล้วยังแตกย่อยออกเป็นแฟ้มของแต่วันอีก ซึ่งอาจไม่สะดวกต่อการวิเคราะห์ข้อมูล
    เราสามารถเพิ่ม module บันทึกประวัติการใช้งานเพิ่มเติมจากของเดิม ตัวอย่างคือ
    ต้องการบันทึกไว้ใน directory ชื่อ /var/log/freeradius/myaccount
    แล้วเก็บแฟ้มแยกเป็นรายวันในรูปแบบ 20060729 ภายในแฟ้มมีรูปแบบว่า
    20060729:15:54:05;”demo”;10.0.0.153;1154163245;”a5f56ebd6ebc1321″;Start;
    20060729:15:55:06;”demo”;10.0.0.153;1154163306;”a5f56ebd6ebc1321″;Stop;61ให้ทำดังนี้ สร้างแฟ้มคำสั่ง shell script ชื่อ  /etc/freeradius/log-radius-account.sh มีเนื้อหาว่า
    #!/bin/bash
    export LANG=en.US
    MYDIR=”/var/log/freeradius/myaccount”
    if [ ! -d ${MYDIR} ] ; then
    mkdir -p ${MYDIR}
    fi
    TODAY=$(date “+%Y%m%d”)
    myfile=”${MYDIR}/${TODAY}”
    if [ ! -e ${MYDIR} ] ; then
    touch ${MYDIR}
    fi
    MYTIME=$(echo $1|awk ‘{print strftime(“%Y%m%d:%H:%M:%S”,$1)}’)
    echo “${MYTIME};${USER_NAME};$2;$1;${ACCT_UNIQUE_SESSION_ID};${ACCT_STATUS_TYPE};${ACCT_SESSION_TIME}” >> ${MYFILE}
    แฟ้ม shell script จบแค่นี้

    หากเป็น freeradius 2.x  ให้แก้ไขแฟ้ม /etc/freeradius/modules/exec เติมข้อความต่อท้ายแฟ้มว่า
    exec my-log-account {
    wait = no
    program = “/bin/sh /etc/freeradius/log-radius-account.sh %l %{Packet-Src-IP-Address} ”
    }
    แล้วแก้ไขแฟ้ม /etc/freeradius/sites-available/default
    ที่ส่วนของ accounting  {…}ประมาณบรรทัดที่ 358  ที่บริเวณข้อความ accounting {

    detail
    ให้แทรกเพิ่มบรรทัดข้อความว่า
    my-log-account

    เสร็จแล้วให้สั่งทำงานใหม่ ด้วยคำสั่ง sudo /etc/init.d/freeradius force-reload

  9. radius server สามารถส่งค่าบอกเวลาที่ยังคงเหลือให้ใช้งาน
    โดยส่งค่ากลับมาที่ attribute ชื่อ Session-Timeout
    แต่ตัวมันเองคำนวณไม่เป็น ต้องหาวิธีอื่นในการคำนวณเวลา
    แล้วส่งกลับมาให้ radius ส่งคำตอบให้อีกทอดหนึ่งจากตัวอย่างข้อ 8 หากต้องการใส่ค่าเวลาที่เหลือในการใช้งาน
    ตัวอย่างเช่นเหลือ 120 วินาที ให้เพิ่มบรรทัดข้อความว่า
    echo “SESSION-TIMEOUT = \”120\””
    ลงไปก่อนบรรทัดข้อความ  exit 0 ดังตัวอย่าง
    #!/bin/bash
    ###exit 0 = valid ; exit1 = invalid
    MYUSER=$(echo $USER_NAME | cut -d'”‘ -f2)
    case “${MYUSER}” in
    demo) exit 1 ;;
    abc) exit 1 ;;
    *) echo “SESSION-TIMEOUT = \”120\””
    exit 0 ;;
    esac

    เสร็จแล้วให้สั่งทำงานใหม่ ด้วยคำสั่ง sudo /etc/init.d/freeradius force-reload
    แค่นี้ก็เสร็จแล้ว PC ที่ติดต่อเข้ามาจะได้รับคำตอบกลับไป
    ระบุว่าเหลือเวลาใช้งานอีกเท่าไร ขึ้นกับตัวเลขทีกำหนดส่งออกมา
    จากตัวอย่างให้แก้ไขตัวเลข 120 เป็นอื่นๆตามต้องการ

  10. การบันทึกประวัติการ authen radius ไว้ในพื้นที่  /var/log/freeradius/myauthen ให้ทำดังนี้
    สร้างแฟ้มคำสั่ง shell script ชื่อ  /etc/freeradius/log-radius-authen.sh มีเนื้อหาว่า
    #!/bin/bash
    export LANG=en.US
    MYDIR=”/var/log/freeradius/myauthen”
    if [ ! -d ${MYDIR} ] ; then
    mkdir -p ${MYDIR}
    fi
    TODAY=$(date “+%Y%m%d”)
    MYFILE=”${MYDIR}/${TODAY}”
    if [ ! -e ${MYFILE} ] ; then
    touch ${MYFILE}
    fi
    MYTIME=$(echo $1|awk ‘{print strftime(“%Y%m%d:%H:%M:%S”,$1)}’)
    echo “${MYTIME};${USER_NAME};$2;$1;CHECK_IN” >> ${MYFILE}
    แฟ้ม shell script จบแค่นี้หากเป็น freeradius 2.x  ให้แก้ไขแฟ้ม /etc/freeradius/modules/exec เติมข้อความต่อท้ายแฟ้มว่า
    exec my-log-authen {
    wait = no
    program = “/bin/sh /etc/freeradius/log-radius-authen.sh %l %{Packet-Src-IP-Address} ”
    }
    แล้วแก้ไขแฟ้ม /etc/freeradius/sites-available/default
    ที่ส่วนของ authorize  {…}ประมาณบรรทัดที่ 152  ที่บริเวณข้อความ authorize {

    #   files
    myimap
    ให้แทรกเพิ่มบรรทัดข้อความ กลายเป็นว่า
    my-log-authen
    #   files
    myimap

    เสร็จแล้วให้สั่งทำงานใหม่ ด้วยคำสั่ง sudo /etc/init.d/freeradius force-reload

  11. ตัวอย่างคำสั่งการทดสอบด้วยคำสั่ง radclient
    ทดสอบการ authen คำสั่งประมาณว่า
    echo “User-Name=mama,User-Password=123456” | radclient 10.0.1.2 auth mytestkeyทดสอบการ accounting ตอนเข้า คำสั่งประมาณว่า
    echo “User-Name=mama,Acct-Status-Type=Start” | radclient 10.0.1.2 acct mytestkey

    ทดสอบการ accounting ตอนออก คำสั่งประมาณว่า
    echo “User-Name=mama,Acct-Status-Type=Stop” | radclient 10.0.1.2 acct mytestkey

ที่มา: http://opensource.cc.psu.ac.th/%E0%B8%95%E0%B8%B4%E0%B8%94%E0%B8%95%E0%B8%B1%E0%B9%89%E0%B8%87_freeradius_%E0%B8%9A%E0%B8%99_ubuntu