|
| 1 | +## Name: |
| 2 | + |
| 3 | +**Dapphp\Radius** - A pure PHP RADIUS client based on the SysCo/al implementation |
| 4 | + |
| 5 | +## Version: |
| 6 | + |
| 7 | +**2.5.0** |
| 8 | + |
| 9 | +## Author: |
| 10 | + |
| 11 | +Drew Phillips <drew@drew-phillips.com> |
| 12 | +SysCo/al <developer@sysco.ch> (http://developer.sysco.ch/php/) |
| 13 | + |
| 14 | +## Requirements: |
| 15 | + |
| 16 | +* PHP 5.3 or greater |
| 17 | + |
| 18 | +## Description: |
| 19 | + |
| 20 | +**Dapphp\Radius** is a pure PHP RADIUS client for authenticating users against |
| 21 | +a RADIUS server in PHP. It currently supports basic RADIUS auth using PAP, |
| 22 | +CHAP (MD5), MSCHAP v1, and EAP-MSCHAP v2. The current 2.5.x branch is tested |
| 23 | +to work with Microsoft Windows Server 2012 Network Policy Server and FreeRADIUS |
| 24 | +2 and above and most likely works with other RADIUS server implementations. |
| 25 | +PAP authentication has been tested on Microsoft Radius server IAS, Mideye |
| 26 | +RADIUS Server, Radl, RSA SecurID, VASCO Middleware 3.0 server, WinRadius, and |
| 27 | +ZyXEL ZyWALL OTP. |
| 28 | + |
| 29 | +The PHP mcrypt extension is required if using MSCHAP v1 or v2. |
| 30 | + |
| 31 | +## Installation: |
| 32 | + |
| 33 | +The recommended way to install `dapphp/radius` is using [Composer](https://getcomposer.org). |
| 34 | +If you are already using composer, simple run `composer require dapphp/radius` or add |
| 35 | +`dapphp/radius` to your composer.json file's `require` section. |
| 36 | + |
| 37 | +Standalone installation is also supported and a SPL autoloader is provided. |
| 38 | +(Don't use the standalone autoloader if you're using Composer!). |
| 39 | + |
| 40 | +To install standalone, download the release archive and extract to a location |
| 41 | +on your server. In your application, `require_once 'radius/autoload.php';` and |
| 42 | +then you can use the class. |
| 43 | + |
| 44 | +## Examples: |
| 45 | + |
| 46 | +See the `examples/` directory for working examples (change the server address |
| 47 | +and credentials to test). |
| 48 | + |
| 49 | +## Synopsis: |
| 50 | + |
| 51 | +<?php |
| 52 | +
|
| 53 | +use Dapphp\Radius\Radius; |
| 54 | +
|
| 55 | +require_once '/path/to/radius/autoload.php'; |
| 56 | +// or, if using composer |
| 57 | +require_once '/path/to/vendor/autoload.php'; |
| 58 | +
|
| 59 | +$client = new Radius(); |
| 60 | +
|
| 61 | +// set server, secret, and basic attributes |
| 62 | +$client->setServer('12.34.56.78') // RADIUS server address |
| 63 | + ->setSecret('radius shared secret') |
| 64 | + ->setNasIpAddress('10.0.1.2') // NAS server address |
| 65 | + ->setAttribute(32, 'login'); // NAS identifier |
| 66 | + |
| 67 | +// PAP authentication; returns true if successful, false otherwise |
| 68 | +$authenticated = $client->accessRequest($username, $password); |
| 69 | + |
| 70 | +// CHAP-MD5 authentication |
| 71 | +$client->setChapPassword($password); // set chap password |
| 72 | +$authenticated = $client->accessRequest($username); // authenticate, don't specify pw here |
| 73 | + |
| 74 | +// MSCHAP v1 authentication |
| 75 | +$client->setMSChapPassword($password); // set ms chap password (uses mcrypt) |
| 76 | +$authenticated = $client->accessRequest($username); |
| 77 | + |
| 78 | +// EAP-MSCHAP v2 authentication |
| 79 | +$authenticated = $client->accessRequestEapMsChapV2($username, $password); |
| 80 | + |
| 81 | +if ($authenticated === false) { |
| 82 | + // false returned on failure |
| 83 | + echo sprintf( |
| 84 | + "Access-Request failed with error %d (%s).\n", |
| 85 | + $client->getErrorCode(), |
| 86 | + $client->getErrorMessage() |
| 87 | + ); |
| 88 | +} else { |
| 89 | + // access request was accepted - client authenticated successfully |
| 90 | + echo "Success! Received Access-Accept response from RADIUS server.\n"; |
| 91 | +} |
| 92 | + |
| 93 | +## Advanced Usage: |
| 94 | + |
| 95 | +// Setting vendor specific attributes |
| 96 | +// Many vendor IDs are available in \Dapphp\Radius\VendorId |
| 97 | +// e.g. \Dapphp\Radius\VendorId::MICROSOFT |
| 98 | +$client->setVendorSpecificAttribute($vendorId, $attributeNumber, $rawValue); |
| 99 | + |
| 100 | +// Retrieving attributes from RADIUS responses after receiving a failure or success response |
| 101 | +$value = $client->getAttribute($attributeId); |
| 102 | + |
| 103 | +// Get an array of all received attributes |
| 104 | +$attributes = getReceivedAttributes(); |
| 105 | + |
| 106 | +// Debugging |
| 107 | +// Prior to sending a request, call |
| 108 | +$client->setDebug(true); // enable debug output on console |
| 109 | +// Shows what attributes are sent and received, and info about the request/response |
| 110 | + |
| 111 | + |
| 112 | +## TODO: |
| 113 | + |
| 114 | +- Set attributes by name, rather than number |
| 115 | +- Vendor specific attribute dictionaries? |
| 116 | +- Test with more implementations and confirm working |
| 117 | +- Accounting? |
| 118 | + |
| 119 | +## Copyright: |
| 120 | + |
| 121 | + Copyright (c) 2008, SysCo systemes de communication sa |
| 122 | + SysCo (tm) is a trademark of SysCo systemes de communication sa |
| 123 | + (http://www.sysco.ch/) |
| 124 | + All rights reserved. |
| 125 | + |
| 126 | + Copyright (c) 2016, Drew Phillips |
| 127 | + (https://drew-phillips.com) |
| 128 | + |
| 129 | + Pure PHP radius class is free software; you can redistribute it and/or |
| 130 | + modify it under the terms of the GNU Lesser General Public License as |
| 131 | + published by the Free Software Foundation, either version 3 of the License, |
| 132 | + or (at your option) any later version. |
| 133 | + |
| 134 | + Pure PHP radius class is distributed in the hope that it will be useful, |
| 135 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 136 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 137 | + GNU Lesser General Public License for more details. |
| 138 | + |
| 139 | + You should have received a copy of the GNU Lesser General Public |
| 140 | + License along with Pure PHP radius class. |
| 141 | + If not, see <http://www.gnu.org/licenses/> |
0 commit comments