Sunday, January 28, 2007

Step Config radius server


การติดตั้ง RADIUS Server For LinuxTLE7.0 + phpMyprepaid0.3.2RC
Software ที่ต้องการ

Mysql-server
Mysql-Client
Apache
phpMyAdmin2.6.0
phpMyprepaid0.3.2RC
freeradius-1.1.2
Openssl




***************************************
ขั้นตอนการติดตั้ง MySQL


(1) ใช้คำสั่งapt-get install mysqlapt-get install mysql-server
(2) สั่งให้ทำงานทุกครั้งที่บูทเครื่องchkconfig mysqld on
(3) สั่งให้ทำงานด้วยคำสั่งว่า
/etc/init.d/mysqld start
Initializing MySQL database: [ OK ]
Starting MySQL: [ OK ]

(4) ตรวจสถานะของ MySQL
/etc/init.d/mysqld status
mysqld (pid 4054) is running...

(5) ติดตั้ง Username and Password ของ MySQL

mysqladmin -uroot password mysqldroot

quit;
เสร็จสิ้นการติดตั้ง MySQL




*************************************


ขั้นตอนการติดตั้ง www server ด้วยโปรแกรม httpd (apache 2.0)



(1) ใช้คำสั่งapt-get install httpdapt-get install httpd-manual

(2) ติดตั้ง mod_ssl เพิ่มเติมด้วยคำสั่งapt-get install mod_ssl

(3) สั่งให้ทำงานทุกครั้งที่บูทเครื่องchkconfig httpd on

(4) สั่งให้ทำงานด้วยคำสั่งว่า/etc/init.d/httpd startStarting httpd: [ OK ]

(5) แก้ไขแฟ้ม/etc/httpd/conf/httpd.conf ให้มีบรรทัดข้อความดังนี้

(6) เอา Comment หน้าคำว่า DefaultLanguage nl ออก

(7) ให้เพิ่มบรรทัดใหม่ข้อความว่า DefaultLanguage th

(8) ให้เพิ่มบรรทัดใหม่ข้อความว่า AddLanguage th .th

(9) ให้เพิ่มข้อความอักษร th แทรกเข้าไป กลายเป็น LanguagePriority th en ca ca da de .

(10) เดิมมีบรรทัดว่า AddDefaultCharset UTF-8ให้แก้ไขข้อความอักษรจาก UTF- 8เป็นTIS-620

(11) ให้เพิ่มบรรทัดใหม่ข้อความว่า AddCharset TIS-620 .tis- 620 .th

(12) แก้ไขใหม่เป็น Options FollowSymLinks

(13) เอา Comment หน้าคำว่าแล้วเปิด Function ที่ครอบข้อมูลนี้ออกเพื่อใช้งาน

DocumentRoot /var/www/html //Localhost
ServerName origin.hostname.domain // Domain Name

(14) เอา Comment หน้าคำว่า

AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Order allow,deny
Allow from all
Order deny,allow
Deny from all




***************************************

ขั้นตอนการติดตั้ง PhpMyAdmin

download phpMyAdmin-2.6.0.tar.gz เก็บไว้ที่
cd /var/www/htmlแตก filetar -xzvf phpMyAdmin-2.6.0.tar.gzcd phpMyadmin
แก้ไข file config.inc.php
โดยใช้คำสั่ง gedit config.inc.php

(1) ใส่ Host URL

$cfg['PmaAbsoluteUri'] = 'https://localhost/phpMyAdmin';

(2) ใส่ Host ของ Server

$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '80';

(3) ใส่ ชนิดของการ Authen

$cfg['Servers'][$i]['auth_type'] = 'config';

(4) ใส่ UserName PassWord ของ MySQL

$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'mysqlradius';

(5) ทำการ Configure ทั้ง 3 ส่วน




*****************************************


ขั้นตอนการติดตั้ง PhPMyPrepaid

Download hpMyAdmin0.3.2RC.tar.gz เก็บไว้ที่
cd /var/www/htmlแตก filetar –xzvf hpMyAdmin0.3.2RC.tar.gz
cd phpMyadmin

(1) แก้ไข File dbconnect.php

เมื่อทำการติดตั้งเสร็จก็ทำการ Brows Website ไปที่
https://localhost/phpmyprepaid เสร็จก็เราก็จะได้ Table ใน Database ครบทุก Filed โดย Brows ไปที่ https://localhost/phpMyAdmin เราก็จะเห็น Table ใน Database ดังนี้



รูปที่ 77 แสดง Table ที่สร้าง https://localhost/phpMyAdmin



(2) แก้ไข File Disconnect
รูปที่ 78 แสดง Configure File Disconnect.php

(3) แก้ไข File Userdisconnect
รูปที่ 79 แสดง Configure File Userdisconnect.php

Brows Website ไปที่
https://localhost/phpmyprepaid แล้ว Create UserName Password ของ Admin หลังจากนั้นก็ทำการ Login เข้าสู่ระบบ รูปที่ 80 แสดง Login เข้าสู่ระบบ
File dbconnect.php
$my_host="localhost";
$my_user="root"; เป็น user name ที่เข้าไปจัดการ da
$my_pass="mysqlradius"; เป็น password
ที่เข้าไปจัดการ da
$my_dbase="radius";
$connect=mysql_connect($my_host, $my_user, $my_pass);
$db=mysql_select_db($my_dbase);
if ($db=!1 or $connect==NULL) $buttonID="badconfigmysql";
?>
File body.php จาก code

//////////////////////////////////////////////////////////
// Include whatever button was pressed. //
// not the best way of doing this but it works //
//////////////////////////////////////////////////////////
if((!isset($button)) && isset($_SESSION['button'])){
$buttonID = $_SESSION['button'];
}
ให้แก้เป็น

//////////////////////////////////////////////////////////
// Include whatever button was pressed. //
// not the best way of doing this but it works //
//////////////////////////////////////////////////////////
if ( isset($_POST['buttonID'])) {
$buttonID = $_POST['buttonID'];
} elseif((!isset($button)) && isset($_SESSION['button'])){
$buttonID = $_SESSION['button'];
}




******************************************

ขั้นตอนการติดตั้ง Freeradius-1.1.2

Download Freeradius-1.1.2.tar.gz เก็บไว้ที่
cd /usr/local/src แตก filetar –xzvf Freeradius-1.1.2.tar.gz
cd freeradius1.1.2./configuremake
เป็นขั้นตอนในการ Compile โปรแกรม freeradius makeinstall
เป็นขั้นตอนในการ Install โปรแกรม freeradius
สั่ง Run Debug Mode



[root@RADIUS bin]# radiusd -Xxx -A
Sun Dec 3 16:56:07 2006 : Info: Starting - reading configuration files ...
Sun Dec 3 16:56:07 2006 : Debug: reread_config: reading radiusd.conf
Sun Dec 3 16:56:07 2006 : Debug: Config: including file: /usr/local/etc/raddb/proxy.conf
Sun Dec 3 16:56:07 2006 : Debug: Config: including file: /usr/local/etc/raddb/clients.conf
Sun Dec 3 16:56:07 2006 : Debug: Config: including file: /usr/local/etc/raddb/snmp.conf
Sun Dec 3 16:56:07 2006 : Debug: Config: including file: /usr/local/etc/raddb/eap.conf
Sun Dec 3 16:56:07 2006 : Debug: Config: including file: /usr/local/etc/raddb/sql.conf
Sun Dec 3 16:56:07 2006 : Debug: main: prefix = "/usr/local"
Sun Dec 3 16:56:07 2006 : Debug: main: localstatedir = "/usr/local/var"
Sun Dec 3 16:56:07 2006 : Debug: main: logdir = "/usr/local/var/log/radius"
Sun Dec 3 16:56:07 2006 : Debug: main: libdir = "/usr/local/lib"
Sun Dec 3 16:56:07 2006 : Debug: main: radacctdir = "/usr/local/var/log/radius/radacct"
Sun Dec 3 16:56:07 2006 : Debug: main: hostname_lookups = yes
Sun Dec 3 16:56:07 2006 : Debug: main: max_request_time = 30
Sun Dec 3 16:56:07 2006 : Debug: main: cleanup_delay = 5
Sun Dec 3 16:56:07 2006 : Debug: main: max_requests = 1024
Sun Dec 3 16:56:07 2006 : Debug: main: delete_blocked_requests = 0
Sun Dec 3 16:56:07 2006 : Debug: main: port = 1812
Sun Dec 3 16:56:07 2006 : Debug: main: allow_core_dumps = yes
Sun Dec 3 16:56:07 2006 : Debug: main: log_stripped_names = yes
Sun Dec 3 16:56:07 2006 : Debug: main: log_file = "/usr/local/var/log/radius/radius.log"
Sun Dec 3 16:56:07 2006 : Debug: main: log_auth = yes
Sun Dec 3 16:56:07 2006 : Debug: main: log_auth_badpass = yes
Sun Dec 3 16:56:07 2006 : Debug: main: log_auth_goodpass = yes
Sun Dec 3 16:56:07 2006 : Debug: main: pidfile = "/usr/local/var/run/radiusd/radiusd.pid"
Sun Dec 3 16:56:07 2006 : Debug: main: user = "(null)"
Sun Dec 3 16:56:07 2006 : Debug: main: group = "(null)"
Sun Dec 3 16:56:07 2006 : Debug: main: usercollide = no
Sun Dec 3 16:56:07 2006 : Debug: main: lower_user = "admin"
Sun Dec 3 16:56:07 2006 : Debug: main: lower_pass = "admin"
Sun Dec 3 16:56:07 2006 : Debug: main: nospace_user = "no"
Sun Dec 3 16:56:07 2006 : Debug: main: nospace_pass = "no"
Sun Dec 3 16:56:07 2006 : Debug: main: checkrad = "/usr/local/sbin/checkrad"
Sun Dec 3 16:56:07 2006 : Debug: main: proxy_requests = yes
Sun Dec 3 16:56:07 2006 : Debug: proxy: retry_delay = 5
Sun Dec 3 16:56:07 2006 : Debug: proxy: retry_count = 3
Sun Dec 3 16:56:07 2006 : Debug: proxy: synchronous = yes
Sun Dec 3 16:56:07 2006 : Debug: proxy: default_fallback = yes
Sun Dec 3 16:56:07 2006 : Debug: proxy: dead_time = 120
Sun Dec 3 16:56:07 2006 : Debug: proxy: post_proxy_authorize = yes
Sun Dec 3 16:56:07 2006 : Debug: proxy: wake_all_if_all_dead = no
Sun Dec 3 16:56:07 2006 : Debug: security: max_attributes = 200
Sun Dec 3 16:56:07 2006 : Debug: security: reject_delay = 1
Sun Dec 3 16:56:07 2006 : Debug: security: status_server = yes
Sun Dec 3 16:56:07 2006 : Debug: main: debug_level = 0
Sun Dec 3 16:56:07 2006 : Debug: read_config_files: reading dictionary
Sun Dec 3 16:56:07 2006 : Debug: read_config_files: reading naslist
Sun Dec 3 16:56:07 2006 : Info: Using deprecated naslist file. Support for this will go away soon.Sun Dec 3 16:56:07 2006 : Debug: read_config_files: reading clients
Sun Dec 3 16:56:07 2006 : Info: Using deprecated clients file. Support for this will go away soon.Sun Dec 3 16:56:07 2006 : Debug: read_config_files: reading realms
Sun Dec 3 16:56:07 2006 : Error: There appears to be another RADIUS server running on the authentication port 1812

เสร็จสิ้นขั้นตอนการติดตั้ง Freeradius-1.1.2



********************************************

โครงสร้างของ File Freeradius ที่ทำการ ติดตั้งมีลักษณะตั้งนี้

(1) /usr/local/etc/raddb ใช้ในการ Configure File
(2) /usr/local/bin ใช้ในการทดสอบ Radius Client radtest
(3) /usr/local/sbin ใช้ในการ Run Debug Mode radiusd
(4) /etc/services ใช้ในการเปิด port 1812,1813
(5) /var/radius/log ใช้ในการดู Log file
(6) /usr/local/lib เป็น Library ของ Freeradius
(7) /usr/local/share/freeradius
(8) /usr/local/share/doc/freeradius-1.1.2 เป็น Document


*******************************************
ขั้นตอนการ Configure File

Cd /usr/local/etc/raddb
File ที่จะต้องทำการ Configure
(1) radiusd.conf
(2) clients.conf
(3) eap.conf
(4) sql.conf
(5) naslist
(6) client
(7) dictionary





**************************************************************

ขั้นตอนการ Config file radiusd.conf

config radiusd.conf

(1) เพิ่ม Modules sqlcounter noresetcounter เพื่อใจดการเกี่ยวกับเวลา

sqlcounter noresetcounter {
counter-name = Max-All-Session-Time
check-name = Max-All-Session
sqlmod-inst = sql
key = User-Name
reset = never
query = "SELECT SUM(AcctSessionTime) FROM radacct WHERE UserName='%{%k}'"
}

(2) แทรก Modules noresetcounter ที่ instantiate เพื่อทำการเรียกใช้ Modules sqlcounter ให้ทำงาน

instantiate {

noresetcounter

}

(3) แทรก Modules noresetcounter ที่ authorize เพื่อทำการเรียกใช้ Modules sqlcounter ให้ทำงาน ในส่วนของการตรวจสอบเวลา และ ยกเลิกการ Comment #sql ออก เพื่อเรียกใช้ข้อมูลจาก database ในการตรวจสอบ UserName password

authorize {.
...
sql
noresetcounter
...
}


(4) ยกเลิกการ Comment #sql ออก เพื่อเรียกใช้ข้อมูลจาก database ในการตรวจสอบ UserName password

accounting {

sql

}

(5) ยกเลิกการ Comment #sql ออก เพื่อเรียกใช้ข้อมูลจาก database ในการตรวจสอบ UserName password ในการทำ session
session {

sql

}
*********************************************************************************

ขั้นตอนการ Config file client.conf ใช้สำหรับรับ IP จาก Client ที่จะทำการ Connect เข้ามายัง Radius Server


client 10.114.0.0/24 {
secret = testing เป็น secret ที่ Client จะต้องใช้ในการ Connect เปรียบเหมือน Password
shortname= private-network
nastype = other
}






*************************************************************************


ขั้นตอนการ Config file eap.conf ใช้ในการเข้ารหัส ของ Radius Server ได้แก่ การเข้ารหัสแบบ


(1) EAP (Extensible Authentication Protocol )
(2) PEAP (Protected Extensible Authentication protocol)
(3) MSCHAP (Microsoft Challenge Handshake Protocol)
(4) GTC (Generic Token Card)
(5) MD5 (Message Digest #5)
(6) LEAP (Lightweight Extensible Authentication Protocol )
(7) TLS (Transport Layer Security)
(8) TTLS (Tunneled Transport Layer Security )

eap{
default_eap_type = peap
timer_expire = 60
ignore_unknown_eap_types = no
cisco_accounting_username_bug = no
tls {
private_key_password = whatever
private_key_file = ${raddbdir}/certs/cert-srv.pem
certificate_file = ${raddbdir}/certs/cert-srv.pem
CA_file = ${raddbdir}/certs/demoCA/cacert.pem
dh_file = ${raddbdir}/certs/dh
random_file = ${raddbdir}/certs/random
fragment_size = 1024
include_length = yes
check_crl = yes
check_cert_issuer = "/C=GB/ST=Berkshire/L=Newbury/O=My Company Ltd"
check_cert_cn = %{User-Name}
cipher_list = "DEFAULT"
}

Peap {
default_eap_type = mschapv2

}
}

********************************************


ขั้นตอนการ Config file sql.conf ใช้ในการติดต่อกับฐานข้อมูลที่สร้างขึ้น


server = "localhost"
login = "root"
password = "mysqlradius"

****************************************

ขั้นตอนการ Config file naslist เป็นไฟล์ ที่บ่งบอกว่า Client นั้นเป็น อุปกรณ์ชนิดใด ถ้าเป็น portslave จะทำการตรวจสอบ User Account จากเครื่อง Server

ถ้าเป็น other จะทำการตรวจสอบจากเครื่อง PC เป็นเครื่องเอง
localhost local portslave
10.114.0.2 private-network other

***************************************


ข ั้นตอนการ Config file client เป็นไฟล์ที่กำหนดว่าจะอนุญาตให้อุปกรณ์ NAS ใดมีสิทธิ์ในการตรวจสอบสิทธิ์ User Account และ Password ได้บ้าง


localhost testing123
10.114.0.2 testing

************************************************

ขั้นตอนการ Config file Dictionary เป็นไฟล์ที่บ่บอกถึง Attribute ของ Client เพื่อบอกเวลาในการใช้งานของ Client


ATTRIBUTE Max-All-Session 3000 integer





***********************************************


ขั้นตอนการทดสอบระบบ run Debug Mode


radiusd -X
ใช้เพื่อทำการตรวจสอบการทำงานของ Radius Server ว่ามี Error หรือไม่

***************************************


Test radius

ใช้ในการตรวจสอบการ Connect ของ Client มายัง Radius Server


radtest cigpin6 test 10.114.0.2 1812 testing
rad_recv: Access-Request packet from host 10.114.0.46:3072, id=1, length=171
User-Name = "cigpin6"
NAS-IP-Address = 10.114.0.46
Called-Station-Id = "00904c910001"
Calling-Station-Id = "0012f0a41c6c"
NAS-Identifier = "00904c910001"
NAS-Port = 20
Framed-MTU = 1400
State = 0xa999bff286555c9e267e8a51df061523
NAS-Port-Type = Wireless-802.11
EAP-Message = 0x020800261900170301001bc9c82c0f5375762e255c1efebde18382d938a47fcaed093c610505 Message-Authenticator = 0x6e82f497e345957e69e799272fa6ecaa
Processing the authorize section of radiusd.conf
modcall: entering group authorize for request 45
modcall[authorize]: module "preprocess" returns ok for request 45
modcall[authorize]: module "chap" returns noop for request 45
modcall[authorize]: module "mschap" returns noop for request 45
rlm_realm: No '@' in User-Name = "cigpin6", looking up realm NULL
rlm_realm: No such realm "NULL"
modcall[authorize]: module "suffix" returns noop for request 45
rlm_eap: EAP packet type response id 8 length 38
rlm_eap: No EAP Start, assuming it's an on-going EAP conversation
modcall[authorize]: module "eap" returns updated for request 45
users: Matched entry DEFAULT at line 152
modcall[authorize]: module "files" returns ok for request 45
radius_xlat: 'cigpin6'
rlm_sql (sql): sql_set_user escaped user --> 'cigpin6'
radius_xlat: 'SELECT id, UserName, Attribute, Value, op FROM radcheck WHERE Username = 'cigpin6' ORDER BY id'
rlm_sql (sql): Reserving sql socket id: 3
rlm_sql_mysql: query: SELECT id, UserName, Attribute, Value, op FROM radcheck WHERE Username = 'cigpin6' ORDER BY id
radius_xlat: 'SELECT radgroupcheck.id,radgroupcheck.GroupName,radgroupcheck.Attribute,radgroupcheck.Value,radgroupcheck.op FROM radgroupcheck,usergroup WHERE usergroup.Username = 'cigpin6' AND usergroup.GroupName = radgroupcheck.GroupName ORDER BY radgroupcheck.id'
rlm_sql_mysql: query: SELECT radgroupcheck.id,radgroupcheck.GroupName,radgroupcheck.Attribute,radgroupcheck.Value,radgroupcheck.op FROM radgroupcheck,usergroup WHERE usergroup.Username = 'cigpin6' AND usergroup.GroupName = radgroupcheck.GroupName ORDER BY radgroupcheck.id
radius_xlat: 'SELECT id, UserName, Attribute, Value, op FROM radreply WHERE Username = 'cigpin6' ORDER BY id'
rlm_sql_mysql: query: SELECT id, UserName, Attribute, Value, op FROM radreply WHERE Username = 'cigpin6' ORDER BY id
radius_xlat: 'SELECT radgroupreply.id,radgroupreply.GroupName,radgroupreply.Attribute,radgroupreply.Value,radgroupreply.op FROM radgroupreply,usergroup WHERE usergroup.Username = 'cigpin6' AND usergroup.GroupName = radgroupreply.GroupName ORDER BY radgroupreply.id'
rlm_sql_mysql: query: SELECT radgroupreply.id,radgroupreply.GroupName,radgroupreply.Attribute,radgroupreply.Value,radgroupreply.op FROM radgroupreply,usergroup WHERE usergroup.Username = 'cigpin6' AND usergroup.GroupName = radgroupreply.GroupName ORDER BY radgroupreply.id
rlm_sql (sql): Released sql socket id: 3
modcall[authorize]: module "sql" returns ok for request 45
modcall: leaving group authorize (returns updated) for request 45
rad_check_password: Found Auth-Type EAP
auth: type "EAP"
Processing the authenticate section of radiusd.conf
modcall: entering group authenticate for request 45
rlm_eap: Request found, released from the list
rlm_eap: EAP/peap
rlm_eap: processing type peap
rlm_eap_peap: Authenticate
rlm_eap_tls: processing TLS
eaptls_verify returned 7
rlm_eap_tls: Done initial handshake
eaptls_process returned 7
rlm_eap_peap: EAPTLS_OK
rlm_eap_peap: Session established. Decoding tunneled attributes.
rlm_eap_peap: Received EAP-TLV response.
rlm_eap_peap: Tunneled data is valid.
rlm_eap_peap: Success
rlm_eap: Freeing handler
modcall[authenticate]: module "eap" returns ok for request 45
modcall: leaving group authenticate (returns ok) for request 45
Processing the session section of radiusd.conf
modcall: entering group session for request 45
radius_xlat: '/usr/local/var/log/radius/radutmp'
modcall[session]: module "radutmp" returns ok for request 45
modcall: leaving group session (returns ok) for request 45
Sending Access-Accept of id 1 to 10.114.0.46 port 3072
MS-MPPE-Recv-Key = 0x011bc97b1fa2811eb55cb77bf8e794c71068c53017bc01c045befba31321f375
MS-MPPE-Send-Key = 0x92d5375e63c2ecfa501c403af6d7f71b5c4ada43e9fb3fbfe15bf50fe0a1796a
EAP-Message = 0x03080004
Message-Authenticator = 0x00000000000000000000000000000000
User-Name = "cigpin6"
Finished request 45
Going to the next request
Waking up in 6 seconds...
--- Walking the entire request list ---
Cleaning up request 45 ID 1 with timestamp 45790f16
Nothing to do. Sleeping until we see a request.

***********************************


kill radius Server


กด Contrlo C เพื่อหยุดการทำงานของ Radius Server และใช้คำสั่ง
kill -9 `ps -A grep radiusd gawk '{ print $1 }'`
เพื่อ ทำลาย Service ของ Server หลังจากนั้นค่อย Run ขึ้นมาใหม่ โดยใช้คำสั่ง radius –X
เป็นการเริ่มการทำงานใหม่ คล้ายกันกับการ Restart ระบบ

******************** The End **********************

No comments: