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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
<?php
/*
Copyright (c) 2003, Michael Bretterklieber <michael@bretterklieber.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This code cannot simply be copied and put under the GNU Public License or
any other GPL-like (LGPL, GPL2) License.
$Id: radius-acct.php,v 1.3 2007/03/18 21:17:02 mbretter Exp $
*/
if(!extension_loaded('radius')) {
if (preg_match('/windows/i', getenv('OS'))) {
dl('php_radius.dll');
} else {
dl('radius.so');
}
}
$username = 'sepp';
$radserver = 'localhost';
$radport = 1813;
$starttime = time();
$sharedsecret = 'testing123';
if (!isset($REMOTE_ADDR)) $REMOTE_ADDR = '127.0.0.1';
$res = radius_acct_open();
echo "$res<br>\n";
//if (!radius_config($res, '/etc/radius.conf')) {
/*if (!radius_config($res, 'D:/php-devel/pear/PECL/radius/radius.conf')) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}*/
if (!radius_add_server($res, $radserver, $radport, $sharedsecret, 3, 3)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
if (!radius_create_request($res, RADIUS_ACCOUNTING_REQUEST)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
if (!radius_put_string($res, RADIUS_NAS_IDENTIFIER, isset($HTTP_HOST) ? $HTTP_HOST : 'localhost')) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
if (!radius_put_int($res, RADIUS_SERVICE_TYPE, RADIUS_FRAMED)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
if (!radius_put_int($res, RADIUS_FRAMED_PROTOCOL, RADIUS_PPP)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
if (!radius_put_string($res, RADIUS_CALLING_STATION_ID, isset($REMOTE_HOST) ? $REMOTE_HOST : '127.0.0.1') == -1) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
if (!radius_put_string($res, RADIUS_USER_NAME, $username)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
if (!radius_put_addr($res, RADIUS_FRAMED_IP_ADDRESS, $REMOTE_ADDR)) {
echo 'RadiusError1:' . radius_strerror($res). "\n<br>";
exit;
}
// RADIUS_START => start accounting
// RADIUS_STOP => stop accounting
if (!radius_put_int($res, RADIUS_ACCT_STATUS_TYPE, RADIUS_START)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
/* Generate a session ID */
$sessionid = sprintf("%s:%d-%s", $REMOTE_ADDR, getmypid(), get_current_user());
if (!radius_put_string($res, RADIUS_ACCT_SESSION_ID, $sessionid)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
// RADIUS_AUTH_RADIUS => authenticated via Radius
// RADIUS_AUTH_LOCAL => authenicated local
// RADIUS_AUTH_REMOTE => authenticated remote
if (!radius_put_int($res, RADIUS_ACCT_AUTHENTIC, RADIUS_AUTH_LOCAL)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
sleep(3);
// if RADIUS_ACCT_STATUS_TYPE == RADIUS_STOP
if (!radius_put_int($res, RADIUS_ACCT_TERMINATE_CAUSE, RADIUS_TERM_USER_REQUEST)) {
echo 'RadiusError2:' . radius_strerror($res). "\n<br>";
exit;
}
if (!radius_put_int($res, RADIUS_ACCT_SESSION_TIME, time() - $starttime)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
// endif
$req = radius_send_request($res);
if (!$req) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
switch($req) {
case RADIUS_ACCOUNTING_RESPONSE:
echo "Radius Accounting response<br>\n";
break;
default:
echo "Unexpected return value:$req\n<br>";
}
radius_close($res);
?>
|