2012-03-03 23 views
9

私は、PHPスクリプトに対してfreeradiusユーザーを認証しようとしていますが、成功しません。 私はこの権利を設定への時間のためにしようとしてきた、と私はグーグルで見つかったすべてのスレッドが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を持っていませんが、あなたのユーザーファイルに何を入れるか...

答えて

15

実際にはかなり簡単です。あなたがやったすべてを取り除き、やり直してください。

サイト対応の/デフォルトファイルに移動します。

authorizeディレクティブに移動し、このコードを追加します。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 /ユーザーがfollowing-

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

を提出し、更新開きAcceptをクリックして次のスクリプトを実行し、属性を取得します。あなたのPHPスクリプトが属性をエコーするようにしてください。ベンダーによっては、属性が明らかに異なる場合があります。

Edits-

  • が追加され、ユーザが

+0

を文字列を使用AcceptまたはRejectよりも多くの属性を読み取ることができますか?ありがとう。 – Carca

+0

私の更新された答えを見る@CarcaBot – ChrisG

+0

@Carcaあなたは2つのことをするためには両方のスクリプトを実行する必要があります。 1)承諾または却下を返す。 2)属性を送信します。両方ともこの作業を行う必要があります。 – ChrisG

-1

に接続しようとしているデバイスを特定するための情報

  • 追加された '%{クライアントIPアドレスを}' 属性私はPythonとPHPでカスタムスクリプトを試します。
    そして、FreeradiusのAuth-Typeが常に 'Auth-Reject'になることを確認してください
    0123スクリプトにゼロ以外の戻りコードがある場合はです。

    私は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" 
        } 
        }