Project

General

Profile

Download (3.25 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 0284d79e jim-p
 * Copyright (c) 2014-2020 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
	$authcfg = auth_get_authserver($_POST['authmode']);
39 5f601060 Phil Davis
	if (!$authcfg) {
40 5db70796 Phil Davis
		$input_errors[] =  sprintf(gettext('%s is not a valid authentication server'), $_POST['authmode']);
41 5f601060 Phil Davis
	}
42 3f0357fc Ermal Lu?i
43 eeceb2ca Augustin-FL
	if (empty($_POST['username'])) {
44 f8ec8de4 Renato Botelho
		$input_errors[] = gettext("A username and password must be specified.");
45 5f601060 Phil Davis
	}
46 3f0357fc Ermal Lu?i
47
	if (!$input_errors) {
48 c4a9f99a jim-p
		$attributes = array();
49 51950f70 Renato Botelho
		if (authenticate_user($_POST['username'], $_POST['password'], $authcfg, $attributes)) {
50 5db70796 Phil Davis
			$savemsg = sprintf(gettext('User %s authenticated successfully.'), $_POST['username']);
51 c4a9f99a jim-p
			$groups = getUserGroups($_POST['username'], $authcfg, $attributes);
52 8545adde k-paulius
			$savemsg .= "&nbsp;" . gettext("This user is a member of groups") . ": <br /><br />";
53 45d6ada5 Sjon Hortensius
			$savemsg .= "<ul>";
54 947141fd Phil Davis
			foreach ($groups as $group) {
55 45d6ada5 Sjon Hortensius
				$savemsg .= "<li>" . "{$group} " . "</li>";
56 947141fd Phil Davis
			}
57 45d6ada5 Sjon Hortensius
			$savemsg .= "</ul>";
58
59 fb0f22c0 Ermal Lu?i
		} else {
60 f8ec8de4 Renato Botelho
			$input_errors[] = gettext("Authentication failed.");
61 fb0f22c0 Ermal Lu?i
		}
62 3f0357fc Ermal Lu?i
	}
63 79e14f1c Phil Davis
} else {
64
	if (isset($config['system']['webgui']['authmode'])) {
65
		$pconfig['authmode'] = $config['system']['webgui']['authmode'];
66
	} else {
67
		$pconfig['authmode'] = "Local Database";
68
	}
69 3f0357fc Ermal Lu?i
}
70 79e14f1c Phil Davis
71 699737d9 Phil Davis
$pgtitle = array(gettext("Diagnostics"), gettext("Authentication"));
72 d71fc5d3 jim-p
$shortcut_section = "authentication";
73 3f0357fc Ermal Lu?i
include("head.inc");
74
75 947141fd Phil Davis
if ($input_errors) {
76 45d6ada5 Sjon Hortensius
	print_input_errors($input_errors);
77 947141fd Phil Davis
}
78 45d6ada5 Sjon Hortensius
79 947141fd Phil Davis
if ($savemsg) {
80 7c945f74 k-paulius
	print_info_box($savemsg, 'success', false);
81 947141fd Phil Davis
}
82 45d6ada5 Sjon Hortensius
83 37676f4e jim-p
$form = new Form(false);
84 45d6ada5 Sjon Hortensius
85
$section = new Form_Section('Authentication Test');
86
87 3e90d18b PiBa-NL
foreach (auth_get_authserver_list() as $key => $auth_server) {
88
	$serverlist[$key] = $auth_server['name'];
89 947141fd Phil Davis
}
90 45d6ada5 Sjon Hortensius
91
$section->addInput(new Form_Select(
92
	'authmode',
93 fe54f091 Phil Davis
	'*Authentication Server',
94 45d6ada5 Sjon Hortensius
	$pconfig['authmode'],
95
	$serverlist
96 3728bbe5 NOYB
))->setHelp('Select the authentication server to test against.');
97 45d6ada5 Sjon Hortensius
98
$section->addInput(new Form_Input(
99
	'username',
100 3e2028f4 Phil Davis
	'*Username',
101 45d6ada5 Sjon Hortensius
	'text',
102
	$pconfig['username'],
103 659a8a26 jim-p
	['placeholder' => 'Username', 'autocomplete' => 'new-password']
104 45d6ada5 Sjon Hortensius
));
105
106
$section->addInput(new Form_Input(
107
	'password',
108 3e2028f4 Phil Davis
	'*Password',
109 45d6ada5 Sjon Hortensius
	'password',
110
	$pconfig['password'],
111 659a8a26 jim-p
	['placeholder' => 'Password', 'autocomplete' => 'new-password']
112 45d6ada5 Sjon Hortensius
));
113
114
$form->add($section);
115 37676f4e jim-p
116
$form->addGlobal(new Form_Button(
117
	'Submit',
118 faab522f Renato Botelho
	'Test',
119 37676f4e jim-p
	null,
120
	'fa-wrench'
121
))->addClass('btn-primary');
122
123 45d6ada5 Sjon Hortensius
print $form;
124
125 bf980226 Colin Fleming
include("foot.inc");