1
|
#!/usr/local/bin/php -f
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
openvpn.auth-ldap.php
|
6
|
|
7
|
Copyright (C) 2010 Ermal Luci
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
2. Redistributions in binary form must reproduce the above copyright
|
17
|
notice, this list of conditions and the following disclaimer in the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
*/
|
31
|
/*
|
32
|
pfSense_BUILDER_BINARIES:
|
33
|
pfSense_MODULE: openvpn
|
34
|
*/
|
35
|
|
36
|
/* setup syslog logging */
|
37
|
openlog("openvpn", LOG_ODELAY, LOG_AUTH);
|
38
|
|
39
|
/* read data from environment */
|
40
|
$username = getenv("username");
|
41
|
$password = getenv("password");
|
42
|
|
43
|
if (empty($username) || empty($password)) {
|
44
|
syslog(LOG_ERR, "invalid user authentication environment");
|
45
|
exit(-1);
|
46
|
}
|
47
|
|
48
|
/* Replaced by a sed with propper variables used below(server parameters). */
|
49
|
//<template>
|
50
|
|
51
|
$rauth = new Auth_RADIUS_PAP($username, $password);
|
52
|
/* Add server to our instance */
|
53
|
$rauth->addServer($radsrv, $radport, $radsecret);
|
54
|
|
55
|
if (!$rauth->start()) {
|
56
|
syslog(LOG_ERROR, "ERROR! . $rauth->getError());
|
57
|
exit(-2);
|
58
|
}
|
59
|
|
60
|
/* Send request */
|
61
|
$result = $rauth->send();
|
62
|
if (PEAR::isError($result)) {
|
63
|
syslog(LOG_WARNING, "Something went wrong trying to authenticate {$username}. " . $result->getMessage() . " \n");
|
64
|
exit(-1);
|
65
|
} else if ($result === true) {
|
66
|
syslog(LOG_WARNING, "user {$username} authenticated\n");
|
67
|
} else {
|
68
|
syslog(LOG_WARNING, "user {$username} could not authenticate. \n");
|
69
|
exit(-3);
|
70
|
}
|
71
|
|
72
|
// close OO RADIUS_AUTHENTICATION
|
73
|
$rauth->close();
|
74
|
|
75
|
exit(0);
|
76
|
|
77
|
?>
|