Skip to content

Commit

Permalink
Standardize options in examples; add -v option for verbose output in …
Browse files Browse the repository at this point in the history
…example scripts
  • Loading branch information
dapphp committed Jan 26, 2022
1 parent 41960b6 commit 7b2533f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,19 @@ then you can use the class.

## Examples:

See the `examples/` directory for working examples (change the server address
and credentials to test).
See the `examples/` directory for working examples. The RADIUS server address, secret, and credentials are read from
environment variables and default to:

RADIUS_SERVER_ADDR=192.168.0.20
RADIUS_USER=nemo
RADIUS_PASS=arctangent
RADIUS_SECRET=xyzzy5461

To print RADIUS debug info, specify the `-v` option.

Example:

RADIUS_SERVER_ADDR=10.0.100.1 RADIUS_USER=radtest php example/client.php -v

## Synopsis:

Expand Down
15 changes: 11 additions & 4 deletions example/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@

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('127.0.0.1') // IP or hostname of RADIUS server
->setSecret('testing123') // RADIUS shared secret
$radius->setServer($server) // IP or hostname of RADIUS server
->setSecret($secret) // RADIUS shared secret
->setNasIpAddress('127.0.0.1') // IP or hostname of NAS (device authenticating user)
->setAttribute(32, 'vpn') // NAS identifier
->setDebug(); // Enable debug output to screen/console
->setDebug((bool)$debug); // Enable debug output to screen/console

// Send access request for a user with username = 'username' and password = 'password!'
$response = $radius->accessRequest('username', 'password!');
echo "Sending access request to $server with username $user\n";
$response = $radius->accessRequest($user, $pass);

if ($response === false) {
// false returned on failure
Expand Down
6 changes: 4 additions & 2 deletions example/eapmschapv2.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
$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
->setNasIpAddress('127.0.0.1') // IP or hostname of NAS (device authenticating user)
->setNasPort(20); // NAS port
->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) {
Expand Down
18 changes: 13 additions & 5 deletions example/mschap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@

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('192.168.0.20') // IP or hostname of RADIUS server
->setSecret('xyzzy5461') // RADIUS shared secret
$radius->setServer($server) // IP or hostname of RADIUS server
->setSecret($secret) // RADIUS shared secret
->setNasIpAddress('127.0.0.1') // IP or hostname of NAS (device authenticating user)
->setNasPort(20); // NAS port
->setNasPort(20) // NAS port
->setDebug((bool)$debug);

$radius->setMSChapPassword('arctangent123$'); // set mschapv1 password for user
$radius->setMSChapPassword($pass); // set mschapv1 password for user

// Send access request for user nemo
$response = $radius->accessRequest('nemo');
echo "Sending MS-CHAP access request to $server with username $user\n";
$response = $radius->accessRequest($user);

if ($response === false) {
// false returned on failure
Expand Down

0 comments on commit 7b2533f

Please sign in to comment.