2012-03-03 225 views
9

我試圖驗證freeradius用戶對PHP腳本沒有成功。 我一直試圖幾個小時到config這個權利,而我發現,與谷歌的線程要麼deadlinked或過時的...Freeradius和PHP驗證腳本

radiusd.conf

prefix = /usr 
exec_prefix = /usr 
sysconfdir = /etc 
localstatedir = /var 
sbindir = ${exec_prefix}/sbin 
logdir = /var/log/freeradius 
raddbdir = /etc/freeradius 
radacctdir = ${logdir}/radacct 

# Name of the running server 
name = freeradius 

# Location of config and logfiles. 
confdir = ${raddbdir} 
run_dir = ${localstatedir}/run/${name} 

# Should likely be ${localstatedir}/lib/radiusd 
db_dir = ${raddbdir} 

libdir = /usr/lib/freeradius 

pidfile = ${run_dir}/${name}.pid 

# user/group: The name (or #number) of the user/group to run radiusd as. 
user = freerad 
group = freerad 

# max_request_time: The maximum time (in seconds) to handle a request. 
max_request_time = 30 

# cleanup_delay: The time to wait (in seconds) before cleaning up 
# a reply which was sent to the NAS. 
cleanup_delay = 5 

# max_requests: The maximum number of requests which the server keeps 
# track of. This should be 256 multiplied by the number of clients. 
# e.g. With 4 clients, this number should be 1024. 
max_requests = 1024 

# listen: Make the server listen on a particular IP address, and send 
# replies out from that address. This directive is most useful for 
# hosts with multiple IP addresses on one interface. 
listen { 
    type = auth 
    ipaddr = * 
    port = 0 
} 

# This second "listen" section is for listening on the accounting 
# port, too. 
listen { 
    ipaddr = * 
    port = 0 
    type = acct 
} 

hostname_lookups = no 
allow_core_dumps = no 
regular_expressions = yes 
extended_expressions = yes 

log { 
    destination = files 
    file = ${logdir}/radius.log 
    syslog_facility = daemon 
    stripped_names = no 
    auth = no 
    auth_badpass = no 
    auth_goodpass = no 
} 

checkrad = ${sbindir}/checkrad 

security { 
    max_attributes = 200 
    reject_delay = 1 
    status_server = yes 
} 

proxy_requests = off 

# CLIENTS CONFIGURATION 
client 0.0.0.0/0 { 
    secret = secret 
    shortname = wireless 
} 

# THREAD POOL CONFIGURATION 
thread pool { 
    start_servers = 5 
    max_servers = 32 
    min_spare_servers = 3 
    max_spare_servers = 10 
    max_requests_per_server = 0 
} 

# MODULE CONFIGURATION 
modules { 
    $INCLUDE ${confdir}/modules/ 
    $INCLUDE eap.conf 
} 

# Instantiation 
instantiate { 
    exec 
    expr 
    expiration 
    logintime 
} 

$INCLUDE policy.conf 

$INCLUDE sites-enabled/ 

模塊/ EXEC

exec { 
    wait = yes 
    program = "/usr/bin/php -f /usr/local/auth.php %{User-Name} %{User-Password}" 
    input_pairs = request 
    output_pairs = reply 
    shell_escape = yes 
} 

網站可用/默認

authorize { 
    preprocess 
    exec 
    chap 
    suffix 
    files 
    expiration 
    logintime 
    pap 
} 

authenticate { 
    Auth-Type PAP { 
     pap 
    } 
    Auth-Type CHAP { 
     chap 
    } 
    eap 
} 


preacct { 
    preprocess 
    acct_unique 
    suffix 
    files 
} 

accounting { 
    detail 
    radutmp 
    exec 
    attr_filter.accounting_response 
} 

session { 
    radutmp 
} 

post-auth { 
    exec 
    Post-Auth-Type REJECT { 
     attr_filter.access_reject 
    } 
} 

pre-proxy { 
} 

post-proxy { 
} 

雖然我沒有ID ea在用戶文件中放置什麼......

回答

15

其實很簡單。刪除你所做的一切並重新開始。

進入您的網站啓用/默認文件。

進入授權指令並添加此代碼。用適當的腳本替換yourscript.php。確保用戶radiusd有權訪問以運行腳本。

authorize{ 
    update control { 
     Auth-Type := `/usr/bin/php -f /etc/raddb/yourscript.php '%{User-Name}' '%{User-Password}' '%{Client-IP-Address}'` 
    } 

確保您的腳本在沒有引號的情況下回顯「接受」或「拒絕」。這應該驗證你的用戶。

因爲有人要求怎麼拉屬性 -

打開在/ etc/raddb /用戶文件並更新以下各項

DEFAULT Auth-Type = Accept 
Exec-Program-Wait = "/usr/bin/php -f /etc/raddb/yourscript.php '%{User-Name}' '%{User-Password}' '%{Client-IP-Address}'" 

基本上你告訴它,如果驗證類型是接受執行以下腳本並提取屬性。確保你的PHP腳本只是回顯屬性。根據供應商的不同,屬性顯然會有所不同。

Edits-

  • 添加的屬性信息

  • 加入 '%{客戶端IP地址}' 來指定用戶試圖將設備連接到

+0

嗨,怎麼可以這樣改閱讀比接受或拒絕更多的屬性?謝謝。 – Carca 2014-10-18 17:46:27

+0

查看我的更新回答@CarcaBot – ChrisG 2014-10-20 18:53:05

+0

請記住@CarcaBot,您將需要運行兩個腳本才能完成兩件事。 1)返回接受或拒絕。 2)發送屬性。兩者都需要做這項工作。 – ChrisG 2014-10-20 18:58:25

-1

我嘗試在Python和PHP中使用自定義腳本,
並找出Freeradius的Auth-Type將始終爲'Auth-Reject'
當腳本有一個非零返回碼。

所以我在PHP中使用「echo」,在Python中使用「print」替換返回碼。

像這樣在PHP

if(isUserValid($user['username'], $user['password'])) { 
    // do nothing 
    echo 'correct string'; 
} else { 
    echo 'incorrect string'; 
} 
return 0 //OR not return anything 

或在Python

if(login success): 
    print "correct string" 
else: 
    print "incorrect string" 

然後使用字符串來確定登錄成功或FREERADIUS失敗

if (Tmp-String-0 == 'correct string') { 
    update control { 
     Auth-type := Accept 
    } 
    update reply{ 
     reply-message += "password correct" 
    } 
    } 
    else { 
    reject 
    update reply{ 
     reply-message += "password incorrect" 
    } 
    }