Project

General

Profile

Download (3.56 KB) Statistics
| Branch: | Tag: | Revision:
1 3f0357fc Ermal Lu?i
<?php
2
/*
3 c5d81585 Renato Botelho
 * diag_authentication.php
4 fd9ebcd5 Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 402c98a2 Reid Linnemann
 * Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * All rights reserved.
10 fd9ebcd5 Stephen Beaver
 *
11 b12ea3fb Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 *
15 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
16 fd9ebcd5 Stephen Beaver
 *
17 b12ea3fb Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 */
23 3f0357fc Ermal Lu?i
24
##|+PRIV
25
##|*IDENT=page-diagnostics-authentication
26 5230f468 jim-p
##|*NAME=Diagnostics: Authentication
27 3f0357fc Ermal Lu?i
##|*DESCR=Allow access to the 'Diagnostics: Authentication' page.
28
##|*MATCH=diag_authentication.php*
29
##|-PRIV
30
31 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
32 e26b805c Renato Botelho
require_once("auth.inc");
33 3f0357fc Ermal Lu?i
34
if ($_POST) {
35
	$pconfig = $_POST;
36
	unset($input_errors);
37
38 51c72717 jim-p
	global $debug;
39
	$debug = ($_POST['debug'] == 'yes');
40
41 3f0357fc Ermal Lu?i
	$authcfg = auth_get_authserver($_POST['authmode']);
42 5f601060 Phil Davis
	if (!$authcfg) {
43 5db70796 Phil Davis
		$input_errors[] =  sprintf(gettext('%s is not a valid authentication server'), $_POST['authmode']);
44 5f601060 Phil Davis
	}
45 3f0357fc Ermal Lu?i
46 eeceb2ca Augustin-FL
	if (empty($_POST['username'])) {
47 f8ec8de4 Renato Botelho
		$input_errors[] = gettext("A username and password must be specified.");
48 5f601060 Phil Davis
	}
49 3f0357fc Ermal Lu?i
50
	if (!$input_errors) {
51 c4a9f99a jim-p
		$attributes = array();
52 51950f70 Renato Botelho
		if (authenticate_user($_POST['username'], $_POST['password'], $authcfg, $attributes)) {
53 5db70796 Phil Davis
			$savemsg = sprintf(gettext('User %s authenticated successfully.'), $_POST['username']);
54 c4a9f99a jim-p
			$groups = getUserGroups($_POST['username'], $authcfg, $attributes);
55 8545adde k-paulius
			$savemsg .= "&nbsp;" . gettext("This user is a member of groups") . ": <br /><br />";
56 45d6ada5 Sjon Hortensius
			$savemsg .= "<ul>";
57 947141fd Phil Davis
			foreach ($groups as $group) {
58 45d6ada5 Sjon Hortensius
				$savemsg .= "<li>" . "{$group} " . "</li>";
59 947141fd Phil Davis
			}
60 45d6ada5 Sjon Hortensius
			$savemsg .= "</ul>";
61
62 fb0f22c0 Ermal Lu?i
		} else {
63 f8ec8de4 Renato Botelho
			$input_errors[] = gettext("Authentication failed.");
64 fb0f22c0 Ermal Lu?i
		}
65 3f0357fc Ermal Lu?i
	}
66 79e14f1c Phil Davis
} else {
67
	if (isset($config['system']['webgui']['authmode'])) {
68 1e45d13f Christian McDonald
		$pconfig['authmode'] = config_get_path('system/webgui/authmode');
69 79e14f1c Phil Davis
	} else {
70
		$pconfig['authmode'] = "Local Database";
71
	}
72 3f0357fc Ermal Lu?i
}
73 79e14f1c Phil Davis
74 699737d9 Phil Davis
$pgtitle = array(gettext("Diagnostics"), gettext("Authentication"));
75 d71fc5d3 jim-p
$shortcut_section = "authentication";
76 3f0357fc Ermal Lu?i
include("head.inc");
77
78 947141fd Phil Davis
if ($input_errors) {
79 45d6ada5 Sjon Hortensius
	print_input_errors($input_errors);
80 947141fd Phil Davis
}
81 45d6ada5 Sjon Hortensius
82 947141fd Phil Davis
if ($savemsg) {
83 7c945f74 k-paulius
	print_info_box($savemsg, 'success', false);
84 947141fd Phil Davis
}
85 45d6ada5 Sjon Hortensius
86 37676f4e jim-p
$form = new Form(false);
87 45d6ada5 Sjon Hortensius
88
$section = new Form_Section('Authentication Test');
89
90 3e90d18b PiBa-NL
foreach (auth_get_authserver_list() as $key => $auth_server) {
91
	$serverlist[$key] = $auth_server['name'];
92 947141fd Phil Davis
}
93 45d6ada5 Sjon Hortensius
94
$section->addInput(new Form_Select(
95
	'authmode',
96 fe54f091 Phil Davis
	'*Authentication Server',
97 45d6ada5 Sjon Hortensius
	$pconfig['authmode'],
98
	$serverlist
99 3728bbe5 NOYB
))->setHelp('Select the authentication server to test against.');
100 45d6ada5 Sjon Hortensius
101
$section->addInput(new Form_Input(
102
	'username',
103 3e2028f4 Phil Davis
	'*Username',
104 45d6ada5 Sjon Hortensius
	'text',
105
	$pconfig['username'],
106 659a8a26 jim-p
	['placeholder' => 'Username', 'autocomplete' => 'new-password']
107 45d6ada5 Sjon Hortensius
));
108
109
$section->addInput(new Form_Input(
110
	'password',
111 3e2028f4 Phil Davis
	'*Password',
112 45d6ada5 Sjon Hortensius
	'password',
113
	$pconfig['password'],
114 659a8a26 jim-p
	['placeholder' => 'Password', 'autocomplete' => 'new-password']
115 45d6ada5 Sjon Hortensius
));
116
117 51c72717 jim-p
$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 45d6ada5 Sjon Hortensius
$form->add($section);
125 37676f4e jim-p
126
$form->addGlobal(new Form_Button(
127
	'Submit',
128 faab522f Renato Botelho
	'Test',
129 37676f4e jim-p
	null,
130
	'fa-wrench'
131
))->addClass('btn-primary');
132
133 45d6ada5 Sjon Hortensius
print $form;
134
135 bf980226 Colin Fleming
include("foot.inc");