Project

General

Profile

Download (3.56 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-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 * http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23

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

    
31
require_once("guiconfig.inc");
32
require_once("auth.inc");
33

    
34
if ($_POST) {
35
	$pconfig = $_POST;
36
	unset($input_errors);
37

    
38
	global $debug;
39
	$debug = ($_POST['debug'] == 'yes');
40

    
41
	$authcfg = auth_get_authserver($_POST['authmode']);
42
	if (!$authcfg) {
43
		$input_errors[] =  sprintf(gettext('%s is not a valid authentication server'), $_POST['authmode']);
44
	}
45

    
46
	if (empty($_POST['username'])) {
47
		$input_errors[] = gettext("A username and password must be specified.");
48
	}
49

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

    
62
		} else {
63
			$input_errors[] = gettext("Authentication failed.");
64
		}
65
	}
66
} else {
67
	if (isset($config['system']['webgui']['authmode'])) {
68
		$pconfig['authmode'] = config_get_path('system/webgui/authmode');
69
	} else {
70
		$pconfig['authmode'] = "Local Database";
71
	}
72
}
73

    
74
$pgtitle = array(gettext("Diagnostics"), gettext("Authentication"));
75
$shortcut_section = "authentication";
76
include("head.inc");
77

    
78
if ($input_errors) {
79
	print_input_errors($input_errors);
80
}
81

    
82
if ($savemsg) {
83
	print_info_box($savemsg, 'success', false);
84
}
85

    
86
$form = new Form(false);
87

    
88
$section = new Form_Section('Authentication Test');
89

    
90
foreach (auth_get_authserver_list() as $key => $auth_server) {
91
	$serverlist[$key] = $auth_server['name'];
92
}
93

    
94
$section->addInput(new Form_Select(
95
	'authmode',
96
	'*Authentication Server',
97
	$pconfig['authmode'],
98
	$serverlist
99
))->setHelp('Select the authentication server to test against.');
100

    
101
$section->addInput(new Form_Input(
102
	'username',
103
	'*Username',
104
	'text',
105
	$pconfig['username'],
106
	['placeholder' => 'Username', 'autocomplete' => 'new-password']
107
));
108

    
109
$section->addInput(new Form_Input(
110
	'password',
111
	'*Password',
112
	'password',
113
	$pconfig['password'],
114
	['placeholder' => 'Password', 'autocomplete' => 'new-password']
115
));
116

    
117
$section->addInput(new Form_Checkbox(
118
	'debug',
119
	'Debug',
120
	'Set debug flag',
121
	($_POST['debug'] == 'yes')
122
))->setHelp('Sets the debug flag when performing authentication, which may trigger additional diagnostic entries in the system log (e.g. for LDAP).');
123

    
124
$form->add($section);
125

    
126
$form->addGlobal(new Form_Button(
127
	'Submit',
128
	'Test',
129
	null,
130
	'fa-wrench'
131
))->addClass('btn-primary');
132

    
133
print $form;
134

    
135
include("foot.inc");
(8-8/228)