Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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