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