Project

General

Profile

Download (3.13 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * diag_authentication.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 * http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 */
21

    
22
##|+PRIV
23
##|*IDENT=page-diagnostics-authentication
24
##|*NAME=Diagnostics: Authentication
25
##|*DESCR=Allow access to the 'Diagnostics: Authentication' page.
26
##|*MATCH=diag_authentication.php*
27
##|-PRIV
28

    
29
require_once("guiconfig.inc");
30
require_once("radius.inc");
31

    
32
if ($_POST) {
33
	$pconfig = $_POST;
34
	unset($input_errors);
35

    
36
	$authcfg = auth_get_authserver($_POST['authmode']);
37
	if (!$authcfg) {
38
		$input_errors[] =  sprintf(gettext('%s is not a valid authentication server'), $_POST['authmode']);
39
	}
40

    
41
	if (empty($_POST['username']) || empty($_POST['password'])) {
42
		$input_errors[] = gettext("A username and password must be specified.");
43
	}
44

    
45
	if (!$input_errors) {
46
		$attributes = array();
47
		if (authenticate_user($_POST['username'], $_POST['password'], $authcfg, $attributes)) {
48
			$savemsg = sprintf(gettext('User %s authenticated successfully.'), $_POST['username']);
49
			$groups = getUserGroups($_POST['username'], $authcfg, $attributes);
50
			$savemsg .= "&nbsp;" . gettext("This user is a member of groups") . ": <br /><br />";
51
			$savemsg .= "<ul>";
52
			foreach ($groups as $group) {
53
				$savemsg .= "<li>" . "{$group} " . "</li>";
54
			}
55
			$savemsg .= "</ul>";
56

    
57
		} else {
58
			$input_errors[] = gettext("Authentication failed.");
59
		}
60
	}
61
} else {
62
	if (isset($config['system']['webgui']['authmode'])) {
63
		$pconfig['authmode'] = $config['system']['webgui']['authmode'];
64
	} else {
65
		$pconfig['authmode'] = "Local Database";
66
	}
67
}
68

    
69
$pgtitle = array(gettext("Diagnostics"), gettext("Authentication"));
70
$shortcut_section = "authentication";
71
include("head.inc");
72

    
73
if ($input_errors) {
74
	print_input_errors($input_errors);
75
}
76

    
77
if ($savemsg) {
78
	print_info_box($savemsg, 'success', false);
79
}
80

    
81
$form = new Form(false);
82

    
83
$section = new Form_Section('Authentication Test');
84

    
85
foreach (auth_get_authserver_list() as $auth_server) {
86
	$serverlist[$auth_server['name']] = $auth_server['name'];
87
}
88

    
89
$section->addInput(new Form_Select(
90
	'authmode',
91
	'*Authentication Server',
92
	$pconfig['authmode'],
93
	$serverlist
94
))->setHelp('Select the authentication server to test against.');
95

    
96
$section->addInput(new Form_Input(
97
	'username',
98
	'*Username',
99
	'text',
100
	$pconfig['username'],
101
	['placeholder' => 'Username']
102
));
103

    
104
$section->addInput(new Form_Input(
105
	'password',
106
	'*Password',
107
	'password',
108
	$pconfig['password'],
109
	['placeholder' => 'Password']
110
));
111

    
112
$form->add($section);
113

    
114
$form->addGlobal(new Form_Button(
115
	'Submit',
116
	'Test',
117
	null,
118
	'fa-wrench'
119
))->addClass('btn-primary');
120

    
121
print $form;
122

    
123
include("foot.inc");
(5-5/225)