File: eapmschapv2.php

package info (click to toggle)
php-dapphp-radius 2.5.8-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 304 kB
  • sloc: php: 2,095; makefile: 15; xml: 9
file content (39 lines) | stat: -rw-r--r-- 1,326 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php

/**
 * RADIUS client example using EAP-MS-CHAP-V2.
 *
 * Tested on Windows Server 2012 R2, 2016, and 2019 Standard Network Policy Server.
 */

error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once __DIR__ . '/../autoload.php';

$server = (getenv('RADIUS_SERVER_ADDR')) ?: '192.168.0.20';
$user   = (getenv('RADIUS_USER'))        ?: 'nemo';
$pass   = (getenv('RADIUS_PASS'))        ?: 'arctangent';
$secret = (getenv('RADIUS_SECRET'))      ?: 'xyzzy5461';
$debug  = in_array('-v', $_SERVER['argv']);

$radius = new \Dapphp\Radius\Radius();
$radius->setServer($server)            // IP or hostname of RADIUS server
       ->setSecret($secret)            // RADIUS shared secret
       ->setAttribute(32, 'login')               // NAS port
       ->setDebug((bool)$debug);

// Send access request for user nemo
echo "Sending EAP-MSCHAP-v2 access request to $server with username $user\n";
$response = $radius->accessRequestEapMsChapV2($user, $pass);

if ($response === false) {
    // false returned on failure
    echo sprintf("Access-Request failed with error %d (%s).\n",
        $radius->getErrorCode(),
        $radius->getErrorMessage()
    );
} else {
    // access request was accepted - client authenticated successfully
    echo "Success!  Received Access-Accept response from RADIUS server.\n";
}