Project

General

Profile

Download (3.25 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-2022 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
	$authcfg = auth_get_authserver($_POST['authmode']);
39
	if (!$authcfg) {
40
		$input_errors[] =  sprintf(gettext('%s is not a valid authentication server'), $_POST['authmode']);
41
	}
42

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

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

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

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

    
75
if ($input_errors) {
76
	print_input_errors($input_errors);
77
}
78

    
79
if ($savemsg) {
80
	print_info_box($savemsg, 'success', false);
81
}
82

    
83
$form = new Form(false);
84

    
85
$section = new Form_Section('Authentication Test');
86

    
87
foreach (auth_get_authserver_list() as $key => $auth_server) {
88
	$serverlist[$key] = $auth_server['name'];
89
}
90

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

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

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

    
114
$form->add($section);
115

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

    
123
print $form;
124

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