Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
/*
4
Copyright (c) 2003, Michael Bretterklieber <michael@bretterklieber.com>
5
All rights reserved.
6
 
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions
9
are met:
10
 
11
1. Redistributions of source code must retain the above copyright
12
   notice, this list of conditions and the following disclaimer.
13
2. Redistributions in binary form must reproduce the above copyright
14
   notice, this list of conditions and the following disclaimer in the
15
   documentation and/or other materials provided with the distribution.
16
3. The names of the authors may not be used to endorse or promote products
17
   derived from this software without specific prior written permission.
18
 
19
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 
30
This code cannot simply be copied and put under the GNU Public License or
31
any other GPL-like (LGPL, GPL2) License.
32
 
33
    $Id: radius-auth.php 257341 2008-04-13 10:31:44Z mbretter $
34
*/
35
 
36
if ($argv[1] == 'pearcvs') {
37
    ini_set('include_path', '..:../..:' . ini_get('include_path'));
38
    require_once 'RADIUS.php';
39
    require_once 'Crypt_CHAP/CHAP.php';
40
} else {
41
    require_once 'Auth/RADIUS.php';
42
    require_once 'Crypt/CHAP.php';
43
}
44
 
45
//$type = 'PAP';
46
//$type = 'CHAP_MD5';
47
$type = 'MSCHAPv1';
48
//$type = 'MSCHAPv2';
49
 
50
$username = 'sepp';
51
$password = 'sepp';
52
 
53
$classname = 'Auth_RADIUS_' . $type;
54
$rauth = new $classname($username, $password);
55
$rauth->addServer('localhost', 0, 'testing123');
56
//$rauth->setConfigfile('/etc/radius.conf');
57
// turn of standard attributes
58
//$rauth->useStandardAttributes = false;
59
$rauth->username = $username;
60
 
61
switch($type) {
62
case 'CHAP_MD5':
63
case 'MSCHAPv1':
64
    $classname = $type == 'MSCHAPv1' ? 'Crypt_CHAP_MSv1' : 'Crypt_CHAP_MD5';
65
    $crpt = new $classname;
66
    $crpt->password = $password;
67
    $rauth->challenge = $crpt->challenge;
68
    $rauth->chapid = $crpt->chapid;
69
    $rauth->response = $crpt->challengeResponse();
70
    $rauth->flags = 1;
71
// If you must use deprecated and weak LAN-Manager-Responses use this:
72
//    $rauth->lmResponse = $crpt->lmChallengeResponse();
73
//    $rauth->flags = 0;
74
    break;
75
 
76
case 'MSCHAPv2':
77
    $crpt = new Crypt_CHAP_MSv2;
78
    $crpt->username = $username;
79
    $crpt->password = $password;
80
    $rauth->challenge = $crpt->authChallenge;
81
    $rauth->peerChallenge = $crpt->peerChallenge;
82
    $rauth->chapid = $crpt->chapid;
83
    $rauth->response = $crpt->challengeResponse();
84
    break;
85
 
86
default:
87
    $rauth->password = $password;
88
    break;
89
}
90
 
91
if (!$rauth->start()) {
92
    printf("Radius start: %s<br>\n", $rauth->getError());
93
    exit;
94
}
95
 
96
 
97
$result = $rauth->send();
98
if (PEAR::isError($result)) {
99
    printf("Radius send failed: %s<br>\n", $result->getMessage());
100
    exit;
101
} else if ($result === true) {
102
    printf("Radius Auth succeeded<br>\n");
103
} else {
104
    printf("Radius Auth rejected<br>\n");
105
}
106
 
107
// get attributes, even if auth failed
108
if (!$rauth->getAttributes()) {
109
    printf("Radius getAttributes: %s<br>\n", $rauth->getError());
110
} else {
111
    $rauth->dumpAttributes();
112
}
113
 
114
$rauth->close();
115
 
116
 
117
?>