Project

General

Profile

Download (3.12 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
/* $Id$ */
4
/*
5
    openvpn.auth-user.php
6

    
7
    Copyright (C) 2008 Shrew Soft Inc
8
    Copyright (C) 2010 Ermal Lu?i
9
    All rights reserved.
10

    
11
    Redistribution and use in source and binary forms, with or without
12
    modification, are permitted provided that the following conditions are met:
13

    
14
    1. Redistributions of source code must retain the above copyright notice,
15
       this list of conditions and the following disclaimer.
16

    
17
    2. Redistributions in binary form must reproduce the above copyright
18
       notice, this list of conditions and the following disclaimer in the
19
       documentation and/or other materials provided with the distribution.
20

    
21
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
    POSSIBILITY OF SUCH DAMAGE.
31

    
32
	DISABLE_PHP_LINT_CHECKING
33
*/
34
/*
35
	pfSense_BUILDER_BINARIES:	
36
	pfSense_MODULE:	openvpn
37
*/
38
/*
39
 * OpenVPN calls this script to authenticate a user
40
 * based on a username and password. We lookup these
41
 * in our config.xml file and check the credentials.
42
 */
43

    
44
require_once("config.inc");
45
require_once("radius.inc");
46
require_once("auth.inc");
47
require_once("interfaces.inc");
48

    
49
/**
50
 * Get the NAS-Identifier
51
 *
52
 * We will use our local hostname to make up the nas_id
53
 */
54
if (!function_exists("getNasID")) {
55
function getNasID()
56
{
57
    global $g;
58

    
59
    $nasId = "";
60
    exec("/bin/hostname", $nasId);
61
    if(!$nasId[0])
62
        $nasId[0] = "{$g['product_name']}";
63
    return $nasId[0];
64
}
65
}
66

    
67
/**
68
 * Get the NAS-IP-Address based on the current wan address
69
 *
70
 * Use functions in interfaces.inc to find this out
71
 *
72
 */
73
if (!function_exists("getNasIP")) {
74
function getNasIP()
75
{
76
    $nasIp = get_interface_ip();
77
    if(!$nasIp)
78
        $nasIp = "0.0.0.0";
79
    return $nasIp;
80
}
81
}
82
/* setup syslog logging */
83
openlog("openvpn", LOG_ODELAY, LOG_AUTH);
84

    
85
/* read data from environment */
86
$username = getenv("username");
87
$password = getenv("password");
88

    
89
if (!$username || !$password) {
90
	syslog(LOG_ERR, "invalid user authentication environment");
91
	exit(-1);
92
}
93

    
94
/* Replaced by a sed with propper variables used below(ldap parameters). */
95
//<template>
96

    
97
$authenticated = false;
98
foreach ($authmodes as $authmode) {
99
	$authcfg = auth_get_authserver($authmode);
100
	if (!$authcfg && $authmode != "local")
101
		continue;
102

    
103
	$authenticated = authenticate_user($username, $password, $authcfg);
104
	if ($authenticated == true)
105
		break;
106
}
107

    
108
if ($authenticated == false) {
109
	syslog(LOG_WARNING, "user {$username} could not authenticate.\n");
110
	exit(-1);
111
}
112

    
113
syslog(LOG_WARNING, "user {$username} authenticated\n");
114

    
115
exit(0);
116

    
117
?>
(27-27/51)