2012-03-03 15 views
9

Sto provando ad autenticare gli utenti freeradius contro uno script PHP, senza successo. Ho cercato per ore per config questo diritto, e tutti i fili che ho trovato con Google sono o deadlinked o obsolete ...Freeradius e PHP auth script

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/ 

moduli/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 
} 

sites-available/default

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 { 
} 

anche se non ho id ea cosa mettere nel file degli utenti ...

risposta

15

In realtà è abbastanza facile. Rimuovi tutto ciò che hai fatto e ricomincia da capo.

Accedi al tuo file abilitato/predefinito.

Passare alla direttiva di autorizzazione e aggiungere questo codice in. Sostituire yourscript.php con lo script corretto. Assicurati che l'utente abbia accesso a radiusd per eseguire lo script.

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

Assicurarsi che lo script rispecchi "Accetta" o "Rifiuta" senza le virgolette. Questo dovrebbe autenticare il tuo utente.

Dal momento che qualcuno ha chiesto come tirare attributi -

aprire il file/etc/raddb/file di utenti e aggiornare i seguenti-

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

In sostanza si sta dicendo che se l'Auth-Type è Accetta per eseguire il seguente script e tirare gli attributi. Assicurati che il tuo script PHP ignori gli attributi. A seconda del venditore, gli attributi saranno ovviamente diversi.

Edits-

  • Aggiunto attributi informazioni

  • Aggiunto '% {Client-IP-Address}' per specificare il dispositivo che l'utente sta tentando di connettersi a

+0

Ciao, come può essere questo cambiato leggere anche più attributi di Accetta o Rifiuta? Grazie. – Carca

+0

Vedere la mia risposta aggiornata @CarcaBot – ChrisG

+0

Ricordare @CarcaBot che è necessario eseguire entrambi gli script per eseguire due operazioni. 1) Invio Accetta o Rifiuta. 2) Invia gli attributi. Entrambi sono tenuti a fare questo lavoro. – ChrisG

-1

Provo uno script personalizzato in Python e PHP,
e scopri che il tipo di autenticazione di Freeradius sarà sempre 'Auth-Reject'
quando lo script ha un codice di ritorno diverso da zero.

Quindi uso "echo" in PHP e "print" in Python sostituisce il codice di ritorno.

come questo in PHP

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

o in Python

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

quindi utilizzare la stringa per determinare il successo di accesso o fallire in 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" 
    } 
    }