1
|
<?php
|
2
|
/*
|
3
|
* system_authservers.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
|
7
|
* Copyright (c) 2008 Shrew Soft Inc
|
8
|
* All rights reserved.
|
9
|
*
|
10
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
* you may not use this file except in compliance with the License.
|
12
|
* You may obtain a copy of the License at
|
13
|
*
|
14
|
* http://www.apache.org/licenses/LICENSE-2.0
|
15
|
*
|
16
|
* Unless required by applicable law or agreed to in writing, software
|
17
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
* See the License for the specific language governing permissions and
|
20
|
* limitations under the License.
|
21
|
*/
|
22
|
|
23
|
##|+PRIV
|
24
|
##|*IDENT=page-system-authservers
|
25
|
##|*NAME=System: Authentication Servers
|
26
|
##|*DESCR=Allow access to the 'System: Authentication Servers' page.
|
27
|
##|*MATCH=system_authservers.php*
|
28
|
##|-PRIV
|
29
|
|
30
|
require_once("guiconfig.inc");
|
31
|
require_once("auth.inc");
|
32
|
|
33
|
// Have we been called to populate the "Select a container" modal?
|
34
|
if ($_REQUEST['ajax']) {
|
35
|
|
36
|
$ous = array();
|
37
|
$authcfg = array();
|
38
|
|
39
|
$authcfg['ldap_port'] = $_REQUEST['port'];
|
40
|
$authcfg['ldap_basedn'] = $_REQUEST['basedn'];
|
41
|
$authcfg['host'] = $_REQUEST['host'];
|
42
|
$authcfg['ldap_scope'] = $_REQUEST['scope'];
|
43
|
$authcfg['ldap_binddn'] = $_REQUEST['binddn'];
|
44
|
$authcfg['ldap_bindpw'] = $_REQUEST['bindpw'];
|
45
|
$authcfg['ldap_urltype'] = $_REQUEST['urltype'];
|
46
|
$authcfg['ldap_protver'] = $_REQUEST['proto'];
|
47
|
$authcfg['ldap_authcn'] = explode(";", $_REQUEST['authcn']);
|
48
|
$authcfg['ldap_caref'] = $_REQUEST['cert'];
|
49
|
|
50
|
$ous = ldap_get_user_ous(true, $authcfg);
|
51
|
|
52
|
if (empty($ous)) {
|
53
|
print('<span class="text-danger">Could not connect to the LDAP server. Please check the LDAP configuration.</span>');
|
54
|
} else {
|
55
|
$modal = new Modal("Select LDAP containers for authentication", "containers", true);
|
56
|
$group = new Form_MultiCheckboxGroup('Containers');
|
57
|
|
58
|
if (is_array($ous)) {
|
59
|
$idx = 0;
|
60
|
|
61
|
foreach ($ous as $ou) {
|
62
|
$group->add(new Form_MultiCheckbox(
|
63
|
'ou' . $idx,
|
64
|
'',
|
65
|
$ou,
|
66
|
in_array($ou, $authcfg['ldap_authcn']),
|
67
|
$ou
|
68
|
));
|
69
|
|
70
|
$idx++;
|
71
|
}
|
72
|
}
|
73
|
|
74
|
$modal->add($group);
|
75
|
|
76
|
// Create a "Save button"
|
77
|
|
78
|
$btnsv = new Form_Button(
|
79
|
'svcontbtn',
|
80
|
'Save',
|
81
|
null,
|
82
|
'fa-save'
|
83
|
);
|
84
|
|
85
|
$btnsv->removeClass("btn-default)")->addClass("btn-primary");
|
86
|
|
87
|
$modal->addInput(new Form_StaticText(
|
88
|
'',
|
89
|
$btnsv
|
90
|
));
|
91
|
|
92
|
print($modal);
|
93
|
}
|
94
|
|
95
|
exit;
|
96
|
}
|
97
|
|
98
|
if (is_numericint($_GET['id'])) {
|
99
|
$id = $_GET['id'];
|
100
|
}
|
101
|
|
102
|
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
|
103
|
$id = $_POST['id'];
|
104
|
}
|
105
|
|
106
|
if (!is_array($config['system']['authserver'])) {
|
107
|
$config['system']['authserver'] = array();
|
108
|
}
|
109
|
|
110
|
$a_servers = auth_get_authserver_list();
|
111
|
foreach ($a_servers as $servers) {
|
112
|
$a_server[] = $servers;
|
113
|
}
|
114
|
|
115
|
if (!is_array($config['ca'])) {
|
116
|
$config['ca'] = array();
|
117
|
}
|
118
|
$a_ca =& $config['ca'];
|
119
|
|
120
|
$act = $_GET['act'];
|
121
|
if ($_POST['act']) {
|
122
|
$act = $_POST['act'];
|
123
|
}
|
124
|
|
125
|
if ($act == "del") {
|
126
|
|
127
|
if (!$a_server[$_GET['id']]) {
|
128
|
pfSenseHeader("system_authservers.php");
|
129
|
exit;
|
130
|
}
|
131
|
|
132
|
/* Remove server from main list. */
|
133
|
$serverdeleted = $a_server[$_GET['id']]['name'];
|
134
|
foreach ($config['system']['authserver'] as $k => $as) {
|
135
|
if ($config['system']['authserver'][$k]['name'] == $serverdeleted) {
|
136
|
unset($config['system']['authserver'][$k]);
|
137
|
}
|
138
|
}
|
139
|
|
140
|
/* Remove server from temp list used later on this page. */
|
141
|
unset($a_server[$_GET['id']]);
|
142
|
|
143
|
$savemsg = sprintf(gettext("Authentication Server %s deleted."), htmlspecialchars($serverdeleted));
|
144
|
write_config($savemsg);
|
145
|
}
|
146
|
|
147
|
if ($act == "edit") {
|
148
|
if (isset($id) && $a_server[$id]) {
|
149
|
|
150
|
$pconfig['type'] = $a_server[$id]['type'];
|
151
|
$pconfig['name'] = $a_server[$id]['name'];
|
152
|
|
153
|
if ($pconfig['type'] == "ldap") {
|
154
|
$pconfig['ldap_caref'] = $a_server[$id]['ldap_caref'];
|
155
|
$pconfig['ldap_host'] = $a_server[$id]['host'];
|
156
|
$pconfig['ldap_port'] = $a_server[$id]['ldap_port'];
|
157
|
$pconfig['ldap_timeout'] = $a_server[$id]['ldap_timeout'];
|
158
|
$pconfig['ldap_urltype'] = $a_server[$id]['ldap_urltype'];
|
159
|
$pconfig['ldap_protver'] = $a_server[$id]['ldap_protver'];
|
160
|
$pconfig['ldap_scope'] = $a_server[$id]['ldap_scope'];
|
161
|
$pconfig['ldap_basedn'] = $a_server[$id]['ldap_basedn'];
|
162
|
$pconfig['ldap_authcn'] = $a_server[$id]['ldap_authcn'];
|
163
|
$pconfig['ldap_extended_enabled'] = $a_server[$id]['ldap_extended_enabled'];
|
164
|
$pconfig['ldap_extended_query'] = $a_server[$id]['ldap_extended_query'];
|
165
|
$pconfig['ldap_binddn'] = $a_server[$id]['ldap_binddn'];
|
166
|
$pconfig['ldap_bindpw'] = $a_server[$id]['ldap_bindpw'];
|
167
|
$pconfig['ldap_attr_user'] = $a_server[$id]['ldap_attr_user'];
|
168
|
$pconfig['ldap_attr_group'] = $a_server[$id]['ldap_attr_group'];
|
169
|
$pconfig['ldap_attr_member'] = $a_server[$id]['ldap_attr_member'];
|
170
|
$pconfig['ldap_attr_groupobj'] = $a_server[$id]['ldap_attr_groupobj'];
|
171
|
$pconfig['ldap_utf8'] = isset($a_server[$id]['ldap_utf8']);
|
172
|
$pconfig['ldap_nostrip_at'] = isset($a_server[$id]['ldap_nostrip_at']);
|
173
|
$pconfig['ldap_rfc2307'] = isset($a_server[$id]['ldap_rfc2307']);
|
174
|
|
175
|
if (!$pconfig['ldap_binddn'] || !$pconfig['ldap_bindpw']) {
|
176
|
$pconfig['ldap_anon'] = true;
|
177
|
}
|
178
|
}
|
179
|
|
180
|
if ($pconfig['type'] == "radius") {
|
181
|
$pconfig['radius_host'] = $a_server[$id]['host'];
|
182
|
$pconfig['radius_auth_port'] = $a_server[$id]['radius_auth_port'];
|
183
|
$pconfig['radius_acct_port'] = $a_server[$id]['radius_acct_port'];
|
184
|
$pconfig['radius_secret'] = $a_server[$id]['radius_secret'];
|
185
|
$pconfig['radius_timeout'] = $a_server[$id]['radius_timeout'];
|
186
|
|
187
|
if ($pconfig['radius_auth_port'] &&
|
188
|
$pconfig['radius_acct_port']) {
|
189
|
$pconfig['radius_srvcs'] = "both";
|
190
|
}
|
191
|
|
192
|
if ($pconfig['radius_auth_port'] &&
|
193
|
!$pconfig['radius_acct_port']) {
|
194
|
$pconfig['radius_srvcs'] = "auth";
|
195
|
$pconfig['radius_acct_port'] = 1813;
|
196
|
}
|
197
|
|
198
|
if (!$pconfig['radius_auth_port'] &&
|
199
|
$pconfig['radius_acct_port']) {
|
200
|
$pconfig['radius_srvcs'] = "acct";
|
201
|
$pconfig['radius_auth_port'] = 1812;
|
202
|
}
|
203
|
|
204
|
}
|
205
|
}
|
206
|
}
|
207
|
|
208
|
if ($act == "new") {
|
209
|
$pconfig['ldap_protver'] = 3;
|
210
|
$pconfig['ldap_anon'] = true;
|
211
|
$pconfig['radius_srvcs'] = "both";
|
212
|
$pconfig['radius_auth_port'] = "1812";
|
213
|
$pconfig['radius_acct_port'] = "1813";
|
214
|
}
|
215
|
|
216
|
if ($_POST) {
|
217
|
unset($input_errors);
|
218
|
$pconfig = $_POST;
|
219
|
|
220
|
/* input validation */
|
221
|
|
222
|
if ($pconfig['type'] == "ldap") {
|
223
|
$reqdfields = explode(" ",
|
224
|
"name type ldap_host ldap_port " .
|
225
|
"ldap_urltype ldap_protver ldap_scope " .
|
226
|
"ldap_attr_user ldap_attr_group ldap_attr_member ldapauthcontainers");
|
227
|
|
228
|
$reqdfieldsn = array(
|
229
|
gettext("Descriptive name"),
|
230
|
gettext("Type"),
|
231
|
gettext("Hostname or IP"),
|
232
|
gettext("Port value"),
|
233
|
gettext("Transport"),
|
234
|
gettext("Protocol version"),
|
235
|
gettext("Search level"),
|
236
|
gettext("User naming Attribute"),
|
237
|
gettext("Group naming Attribute"),
|
238
|
gettext("Group member attribute"),
|
239
|
gettext("Authentication container"));
|
240
|
|
241
|
if (!$pconfig['ldap_anon']) {
|
242
|
$reqdfields[] = "ldap_binddn";
|
243
|
$reqdfields[] = "ldap_bindpw";
|
244
|
$reqdfieldsn[] = gettext("Bind user DN");
|
245
|
$reqdfieldsn[] = gettext("Bind Password");
|
246
|
}
|
247
|
}
|
248
|
|
249
|
if ($pconfig['type'] == "radius") {
|
250
|
$reqdfields = explode(" ", "name type radius_host radius_srvcs");
|
251
|
$reqdfieldsn = array(
|
252
|
gettext("Descriptive name"),
|
253
|
gettext("Type"),
|
254
|
gettext("Hostname or IP"),
|
255
|
gettext("Services"));
|
256
|
|
257
|
if ($pconfig['radius_srvcs'] == "both" ||
|
258
|
$pconfig['radius_srvcs'] == "auth") {
|
259
|
$reqdfields[] = "radius_auth_port";
|
260
|
$reqdfieldsn[] = gettext("Authentication port");
|
261
|
}
|
262
|
|
263
|
if ($pconfig['radius_srvcs'] == "both" ||
|
264
|
$pconfig['radius_srvcs'] == "acct") {
|
265
|
$reqdfields[] = "radius_acct_port";
|
266
|
$reqdfieldsn[] = gettext("Accounting port");
|
267
|
}
|
268
|
|
269
|
if (!isset($id)) {
|
270
|
$reqdfields[] = "radius_secret";
|
271
|
$reqdfieldsn[] = gettext("Shared Secret");
|
272
|
}
|
273
|
}
|
274
|
|
275
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
276
|
|
277
|
if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['host'])) {
|
278
|
$input_errors[] = gettext("The host name contains invalid characters.");
|
279
|
}
|
280
|
|
281
|
if (auth_get_authserver($pconfig['name']) && !isset($id)) {
|
282
|
$input_errors[] = gettext("An authentication server with the same name already exists.");
|
283
|
}
|
284
|
|
285
|
if (($pconfig['type'] == "ldap") || ($pconfig['type'] == "radius")) {
|
286
|
$to_field = "{$pconfig['type']}_timeout";
|
287
|
if (isset($_POST[$to_field]) && !empty($_POST[$to_field]) && (!is_numeric($_POST[$to_field]) || (is_numeric($_POST[$to_field]) && ($_POST[$to_field] <= 0)))) {
|
288
|
$input_errors[] = sprintf(gettext("%s Timeout value must be numeric and positive."), strtoupper($pconfig['type']));
|
289
|
}
|
290
|
}
|
291
|
|
292
|
if (!$input_errors) {
|
293
|
$server = array();
|
294
|
$server['refid'] = uniqid();
|
295
|
if (isset($id) && $a_server[$id]) {
|
296
|
$server = $a_server[$id];
|
297
|
}
|
298
|
|
299
|
$server['type'] = $pconfig['type'];
|
300
|
$server['name'] = $pconfig['name'];
|
301
|
|
302
|
if ($server['type'] == "ldap") {
|
303
|
|
304
|
if (!empty($pconfig['ldap_caref'])) {
|
305
|
$server['ldap_caref'] = $pconfig['ldap_caref'];
|
306
|
}
|
307
|
$server['host'] = $pconfig['ldap_host'];
|
308
|
$server['ldap_port'] = $pconfig['ldap_port'];
|
309
|
$server['ldap_urltype'] = $pconfig['ldap_urltype'];
|
310
|
$server['ldap_protver'] = $pconfig['ldap_protver'];
|
311
|
$server['ldap_scope'] = $pconfig['ldap_scope'];
|
312
|
$server['ldap_basedn'] = $pconfig['ldap_basedn'];
|
313
|
$server['ldap_authcn'] = $pconfig['ldapauthcontainers'];
|
314
|
$server['ldap_extended_enabled'] = $pconfig['ldap_extended_enabled'];
|
315
|
$server['ldap_extended_query'] = $pconfig['ldap_extended_query'];
|
316
|
$server['ldap_attr_user'] = $pconfig['ldap_attr_user'];
|
317
|
$server['ldap_attr_group'] = $pconfig['ldap_attr_group'];
|
318
|
$server['ldap_attr_member'] = $pconfig['ldap_attr_member'];
|
319
|
|
320
|
$server['ldap_attr_groupobj'] = empty($pconfig['ldap_attr_groupobj']) ? "posixGroup" : $pconfig['ldap_attr_groupobj'];
|
321
|
|
322
|
if ($pconfig['ldap_utf8'] == "yes") {
|
323
|
$server['ldap_utf8'] = true;
|
324
|
} else {
|
325
|
unset($server['ldap_utf8']);
|
326
|
}
|
327
|
if ($pconfig['ldap_nostrip_at'] == "yes") {
|
328
|
$server['ldap_nostrip_at'] = true;
|
329
|
} else {
|
330
|
unset($server['ldap_nostrip_at']);
|
331
|
}
|
332
|
if ($pconfig['ldap_rfc2307'] == "yes") {
|
333
|
$server['ldap_rfc2307'] = true;
|
334
|
} else {
|
335
|
unset($server['ldap_rfc2307']);
|
336
|
}
|
337
|
|
338
|
|
339
|
if (!$pconfig['ldap_anon']) {
|
340
|
$server['ldap_binddn'] = $pconfig['ldap_binddn'];
|
341
|
$server['ldap_bindpw'] = $pconfig['ldap_bindpw'];
|
342
|
} else {
|
343
|
unset($server['ldap_binddn']);
|
344
|
unset($server['ldap_bindpw']);
|
345
|
}
|
346
|
|
347
|
if ($pconfig['ldap_timeout']) {
|
348
|
$server['ldap_timeout'] = $pconfig['ldap_timeout'];
|
349
|
} else {
|
350
|
$server['ldap_timeout'] = 25;
|
351
|
}
|
352
|
}
|
353
|
|
354
|
if ($server['type'] == "radius") {
|
355
|
|
356
|
$server['host'] = $pconfig['radius_host'];
|
357
|
|
358
|
if ($pconfig['radius_secret']) {
|
359
|
$server['radius_secret'] = $pconfig['radius_secret'];
|
360
|
}
|
361
|
|
362
|
if ($pconfig['radius_timeout']) {
|
363
|
$server['radius_timeout'] = $pconfig['radius_timeout'];
|
364
|
} else {
|
365
|
$server['radius_timeout'] = 5;
|
366
|
}
|
367
|
|
368
|
if ($pconfig['radius_srvcs'] == "both") {
|
369
|
$server['radius_auth_port'] = $pconfig['radius_auth_port'];
|
370
|
$server['radius_acct_port'] = $pconfig['radius_acct_port'];
|
371
|
}
|
372
|
|
373
|
if ($pconfig['radius_srvcs'] == "auth") {
|
374
|
$server['radius_auth_port'] = $pconfig['radius_auth_port'];
|
375
|
unset($server['radius_acct_port']);
|
376
|
}
|
377
|
|
378
|
if ($pconfig['radius_srvcs'] == "acct") {
|
379
|
$server['radius_acct_port'] = $pconfig['radius_acct_port'];
|
380
|
unset($server['radius_auth_port']);
|
381
|
}
|
382
|
}
|
383
|
|
384
|
if (isset($id) && $config['system']['authserver'][$id]) {
|
385
|
$config['system']['authserver'][$id] = $server;
|
386
|
} else {
|
387
|
$config['system']['authserver'][] = $server;
|
388
|
}
|
389
|
|
390
|
write_config();
|
391
|
|
392
|
pfSenseHeader("system_authservers.php");
|
393
|
}
|
394
|
}
|
395
|
|
396
|
// On error, restore the form contents so the user doesn't have to re-enter too much
|
397
|
if ($_POST && $input_errors) {
|
398
|
$pconfig = $_POST;
|
399
|
$pconfig['ldap_authcn'] = $_POST['ldapauthcontainers'];
|
400
|
$pconfig['ldap_template'] = $_POST['ldap_tmpltype'];
|
401
|
}
|
402
|
|
403
|
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Authentication Servers"));
|
404
|
|
405
|
if ($act == "new" || $act == "edit" || $input_errors) {
|
406
|
$pgtitle[] = gettext('Edit');
|
407
|
}
|
408
|
$shortcut_section = "authentication";
|
409
|
include("head.inc");
|
410
|
|
411
|
if ($input_errors) {
|
412
|
print_input_errors($input_errors);
|
413
|
}
|
414
|
|
415
|
if ($savemsg) {
|
416
|
print_info_box($savemsg, 'success');
|
417
|
}
|
418
|
|
419
|
$tab_array = array();
|
420
|
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
|
421
|
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
|
422
|
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
|
423
|
$tab_array[] = array(gettext("Authentication Servers"), true, "system_authservers.php");
|
424
|
display_top_tabs($tab_array);
|
425
|
|
426
|
if (!($act == "new" || $act == "edit" || $input_errors)) {
|
427
|
?>
|
428
|
<div class="panel panel-default">
|
429
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Authentication Servers')?></h2></div>
|
430
|
<div class="panel-body">
|
431
|
<div class="table-responsive">
|
432
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
|
433
|
<thead>
|
434
|
<tr>
|
435
|
<th><?=gettext("Server Name")?></th>
|
436
|
<th><?=gettext("Type")?></th>
|
437
|
<th><?=gettext("Host Name")?></th>
|
438
|
<th><?=gettext("Actions")?></th>
|
439
|
</tr>
|
440
|
</thead>
|
441
|
<tbody>
|
442
|
<?php foreach ($a_server as $i => $server): ?>
|
443
|
<tr>
|
444
|
<td><?=htmlspecialchars($server['name'])?></td>
|
445
|
<td><?=htmlspecialchars($auth_server_types[$server['type']])?></td>
|
446
|
<td><?=htmlspecialchars($server['host'])?></td>
|
447
|
<td>
|
448
|
<?php if ($i < (count($a_server) - 1)): ?>
|
449
|
<a class="fa fa-pencil" title="<?=gettext("Edit server"); ?>" href="system_authservers.php?act=edit&id=<?=$i?>"></a>
|
450
|
<a class="fa fa-trash" title="<?=gettext("Delete server")?>" href="system_authservers.php?act=del&id=<?=$i?>"></a>
|
451
|
<?php endif?>
|
452
|
</td>
|
453
|
</tr>
|
454
|
<?php endforeach; ?>
|
455
|
</tbody>
|
456
|
</table>
|
457
|
</div>
|
458
|
</div>
|
459
|
</div>
|
460
|
|
461
|
<nav class="action-buttons">
|
462
|
<a href="?act=new" class="btn btn-success btn-sm">
|
463
|
<i class="fa fa-plus icon-embed-btn"></i>
|
464
|
<?=gettext("Add")?>
|
465
|
</a>
|
466
|
</nav>
|
467
|
<?php
|
468
|
include("foot.inc");
|
469
|
exit;
|
470
|
}
|
471
|
|
472
|
$form = new Form;
|
473
|
$form->setAction('system_authservers.php?act=edit');
|
474
|
|
475
|
$form->addGlobal(new Form_Input(
|
476
|
'userid',
|
477
|
null,
|
478
|
'hidden',
|
479
|
$id
|
480
|
));
|
481
|
|
482
|
$section = new Form_Section('Server Settings');
|
483
|
|
484
|
$section->addInput($input = new Form_Input(
|
485
|
'name',
|
486
|
'Descriptive name',
|
487
|
'text',
|
488
|
$pconfig['name']
|
489
|
));
|
490
|
|
491
|
$section->addInput($input = new Form_Select(
|
492
|
'type',
|
493
|
'Type',
|
494
|
$pconfig['type'],
|
495
|
$auth_server_types
|
496
|
))->toggles();
|
497
|
|
498
|
$form->add($section);
|
499
|
|
500
|
// ==== LDAP settings =========================================================
|
501
|
$section = new Form_Section('LDAP Server Settings');
|
502
|
$section->addClass('toggle-ldap collapse');
|
503
|
|
504
|
if (!isset($pconfig['type']) || $pconfig['type'] == 'ldap')
|
505
|
$section->addClass('in');
|
506
|
|
507
|
$section->addInput(new Form_Input(
|
508
|
'ldap_host',
|
509
|
'Hostname or IP address',
|
510
|
'text',
|
511
|
$pconfig['ldap_host']
|
512
|
))->setHelp('NOTE: When using SSL, this hostname MUST match the Common Name '.
|
513
|
'(CN) of the LDAP server\'s SSL Certificate.');
|
514
|
|
515
|
$section->addInput(new Form_Input(
|
516
|
'ldap_port',
|
517
|
'Port value',
|
518
|
'number',
|
519
|
$pconfig['ldap_port']
|
520
|
));
|
521
|
|
522
|
$section->addInput(new Form_Select(
|
523
|
'ldap_urltype',
|
524
|
'Transport',
|
525
|
$pconfig['ldap_urltype'],
|
526
|
array_combine(array_keys($ldap_urltypes), array_keys($ldap_urltypes))
|
527
|
));
|
528
|
|
529
|
if (empty($a_ca))
|
530
|
{
|
531
|
$section->addInput(new Form_StaticText(
|
532
|
'Peer Certificate Authority',
|
533
|
'No Certificate Authorities defined.<br/>Create one under <a href="system_camanager.php">System > Cert. Manager</a>.'
|
534
|
));
|
535
|
}
|
536
|
else
|
537
|
{
|
538
|
$ldapCaRef = [];
|
539
|
foreach ($a_ca as $ca)
|
540
|
$ldapCaRef[ $ca['refid'] ] = $ca['descr'];
|
541
|
|
542
|
$section->addInput(new Form_Select(
|
543
|
'ldap_caref',
|
544
|
'Peer Certificate Authority',
|
545
|
$pconfig['ldap_caref'],
|
546
|
$ldapCaRef
|
547
|
))->setHelp('This option is used if \'SSL Encrypted\' option is choosen. '.
|
548
|
'It must match with the CA in the AD otherwise problems will arise.');
|
549
|
}
|
550
|
|
551
|
$section->addInput(new Form_Select(
|
552
|
'ldap_protver',
|
553
|
'Protocol version',
|
554
|
$pconfig['ldap_protver'],
|
555
|
array_combine($ldap_protvers, $ldap_protvers)
|
556
|
));
|
557
|
|
558
|
$section->addInput(new Form_Input(
|
559
|
'ldap_timeout',
|
560
|
'Server Timeout',
|
561
|
'number',
|
562
|
$pconfig['ldap_timeout'],
|
563
|
['placeholder' => 25]
|
564
|
))->setHelp('Timeout for LDAP operations (seconds)');
|
565
|
|
566
|
$group = new Form_Group('Search scope');
|
567
|
|
568
|
$SSF = new Form_Select(
|
569
|
'ldap_scope',
|
570
|
'Level',
|
571
|
$pconfig['ldap_scope'],
|
572
|
$ldap_scopes
|
573
|
);
|
574
|
|
575
|
$SSB = new Form_Input(
|
576
|
'ldap_basedn',
|
577
|
'Base DN',
|
578
|
'text',
|
579
|
$pconfig['ldap_basedn']
|
580
|
);
|
581
|
|
582
|
|
583
|
$section->addInput(new Form_StaticText(
|
584
|
'Search scope',
|
585
|
'Level ' . $SSF . '<br />' . 'Base DN' . $SSB
|
586
|
));
|
587
|
|
588
|
$group = new Form_Group('Authentication containers');
|
589
|
$group->add(new Form_Input(
|
590
|
'ldapauthcontainers',
|
591
|
'Containers',
|
592
|
'text',
|
593
|
$pconfig['ldap_authcn']
|
594
|
))->setHelp('Note: Semi-Colon separated. This will be prepended to the search '.
|
595
|
'base dn above or the full container path can be specified containing a dc= '.
|
596
|
'component.<br/>Example: CN=Users;DC=example,DC=com or OU=Staff;OU=Freelancers');
|
597
|
|
598
|
$group->add(new Form_Button(
|
599
|
'Select',
|
600
|
'Select a container',
|
601
|
null,
|
602
|
'fa-search'
|
603
|
))->setAttribute('type','button')->addClass('btn-info');
|
604
|
|
605
|
$section->add($group);
|
606
|
|
607
|
$section->addInput(new Form_Checkbox(
|
608
|
'ldap_extended_enabled',
|
609
|
'Extended query',
|
610
|
'Enable extended query',
|
611
|
$pconfig['ldap_extended_enabled']
|
612
|
));
|
613
|
|
614
|
$group = new Form_Group('Query');
|
615
|
$group->addClass('extended');
|
616
|
|
617
|
$group->add(new Form_Input(
|
618
|
'ldap_extended_query',
|
619
|
'Query',
|
620
|
'text',
|
621
|
$pconfig['ldap_extended_query']
|
622
|
))->setHelp('Example: &(objectClass=inetOrgPerson)(mail=*@example.com)');
|
623
|
|
624
|
$section->add($group);
|
625
|
|
626
|
$section->addInput(new Form_Checkbox(
|
627
|
'ldap_anon',
|
628
|
'Bind anonymous',
|
629
|
'Use anonymous binds to resolve distinguished names',
|
630
|
$pconfig['ldap_anon']
|
631
|
));
|
632
|
|
633
|
$group = new Form_Group('Bind credentials');
|
634
|
$group->addClass('ldapanon');
|
635
|
|
636
|
$group->add(new Form_Input(
|
637
|
'ldap_binddn',
|
638
|
'User DN:',
|
639
|
'text',
|
640
|
$pconfig['ldap_binddn']
|
641
|
));
|
642
|
|
643
|
$group->add(new Form_Input(
|
644
|
'ldap_bindpw',
|
645
|
'Password',
|
646
|
'text',
|
647
|
$pconfig['ldap_bindpw']
|
648
|
));
|
649
|
$section->add($group);
|
650
|
|
651
|
if (!isset($id)) {
|
652
|
$template_list = array();
|
653
|
|
654
|
foreach ($ldap_templates as $option => $template) {
|
655
|
$template_list[$option] = $template['desc'];
|
656
|
}
|
657
|
|
658
|
$section->addInput(new Form_Select(
|
659
|
'ldap_tmpltype',
|
660
|
'Initial Template',
|
661
|
$pconfig['ldap_template'],
|
662
|
$template_list
|
663
|
));
|
664
|
}
|
665
|
|
666
|
$section->addInput(new Form_Input(
|
667
|
'ldap_attr_user',
|
668
|
'User naming attribute',
|
669
|
'text',
|
670
|
$pconfig['ldap_attr_user']
|
671
|
));
|
672
|
|
673
|
$section->addInput(new Form_Input(
|
674
|
'ldap_attr_group',
|
675
|
'Group naming attribute',
|
676
|
'text',
|
677
|
$pconfig['ldap_attr_group']
|
678
|
));
|
679
|
|
680
|
$section->addInput(new Form_Input(
|
681
|
'ldap_attr_member',
|
682
|
'Group member attribute',
|
683
|
'text',
|
684
|
$pconfig['ldap_attr_member']
|
685
|
));
|
686
|
|
687
|
$section->addInput(new Form_Checkbox(
|
688
|
'ldap_rfc2307',
|
689
|
'RFC 2307 Groups',
|
690
|
'LDAP Server uses RFC 2307 style group membership',
|
691
|
$pconfig['ldap_rfc2307']
|
692
|
))->setHelp('RFC 2307 style group membership has members listed on the group '.
|
693
|
'object rather than using groups listed on user object. Leave unchecked '.
|
694
|
'for Active Directory style group membership (RFC 2307bis).');
|
695
|
|
696
|
$section->addInput(new Form_Input(
|
697
|
'ldap_attr_groupobj',
|
698
|
'Group Object Class',
|
699
|
'text',
|
700
|
$pconfig['ldap_attr_groupobj'],
|
701
|
['placeholder' => 'posixGroup']
|
702
|
))->setHelp('Object class used for groups in RFC2307 mode. '.
|
703
|
'Typically "posixGroup" or "group".');
|
704
|
|
705
|
$section->addInput(new Form_Checkbox(
|
706
|
'ldap_utf8',
|
707
|
'UTF8 Encode',
|
708
|
'UTF8 encode LDAP parameters before sending them to the server.',
|
709
|
$pconfig['ldap_utf8']
|
710
|
))->setHelp('Required to support international characters, but may not be '.
|
711
|
'supported by every LDAP server.');
|
712
|
|
713
|
$section->addInput(new Form_Checkbox(
|
714
|
'ldap_nostrip_at',
|
715
|
'Username Alterations',
|
716
|
'Do not strip away parts of the username after the @ symbol',
|
717
|
$pconfig['ldap_nostrip_at']
|
718
|
))->setHelp('e.g. user@host becomes user when unchecked.');
|
719
|
|
720
|
$form->add($section);
|
721
|
|
722
|
// ==== RADIUS section ========================================================
|
723
|
$section = new Form_Section('RADIUS Server Settings');
|
724
|
$section->addClass('toggle-radius collapse');
|
725
|
|
726
|
$section->addInput(new Form_Input(
|
727
|
'radius_host',
|
728
|
'Hostname or IP address',
|
729
|
'text',
|
730
|
$pconfig['radius_host']
|
731
|
));
|
732
|
|
733
|
$section->addInput(new Form_Input(
|
734
|
'radius_secret',
|
735
|
'Shared Secret',
|
736
|
'text',
|
737
|
$pconfig['radius_secret']
|
738
|
));
|
739
|
|
740
|
$section->addInput(new Form_Select(
|
741
|
'radius_srvcs',
|
742
|
'Services offered',
|
743
|
$pconfig['radius_srvcs'],
|
744
|
$radius_srvcs
|
745
|
));
|
746
|
|
747
|
$section->addInput(new Form_Input(
|
748
|
'radius_auth_port',
|
749
|
'Authentication port',
|
750
|
'number',
|
751
|
$pconfig['radius_auth_port']
|
752
|
));
|
753
|
|
754
|
$section->addInput(new Form_Input(
|
755
|
'radius_acct_port',
|
756
|
'Accounting port',
|
757
|
'number',
|
758
|
$pconfig['radius_acct_port']
|
759
|
));
|
760
|
|
761
|
$section->addInput(new Form_Input(
|
762
|
'radius_timeout',
|
763
|
'Authentication Timeout',
|
764
|
'number',
|
765
|
$pconfig['radius_timeout']
|
766
|
))->setHelp('This value controls how long, in seconds, that the RADIUS '.
|
767
|
'server may take to respond to an authentication request. If left blank, the '.
|
768
|
'default value is 5 seconds. NOTE: If using an interactive two-factor '.
|
769
|
'authentication system, increase this timeout to account for how long it will '.
|
770
|
'take the user to receive and enter a token.');
|
771
|
|
772
|
if (isset($id) && $a_server[$id])
|
773
|
{
|
774
|
$section->addInput(new Form_Input(
|
775
|
'id',
|
776
|
null,
|
777
|
'hidden',
|
778
|
$id
|
779
|
));
|
780
|
}
|
781
|
|
782
|
$form->add($section);
|
783
|
|
784
|
// Create a largely empty modal to show the available containers. We will populate it via AJAX later
|
785
|
$modal = new Modal("LDAP containers", "containers", true);
|
786
|
|
787
|
$form->add($modal);
|
788
|
|
789
|
print $form;
|
790
|
?>
|
791
|
<script type="text/javascript">
|
792
|
//<![CDATA[
|
793
|
events.push(function() {
|
794
|
|
795
|
// Create an AJAX request (to this page) to get the container list and controls
|
796
|
function select_clicked() {
|
797
|
if (document.getElementById("ldap_port").value == '' ||
|
798
|
document.getElementById("ldap_host").value == '' ||
|
799
|
document.getElementById("ldap_scope").value == '' ||
|
800
|
document.getElementById("ldap_basedn").value == '' ||
|
801
|
document.getElementById("ldapauthcontainers").value == '') {
|
802
|
alert("<?=gettext("Please fill the required values.");?>");
|
803
|
return;
|
804
|
}
|
805
|
|
806
|
if (!document.getElementById("ldap_anon").checked) {
|
807
|
if (document.getElementById("ldap_binddn").value == '' ||
|
808
|
document.getElementById("ldap_bindpw").value == '') {
|
809
|
alert("<?=gettext("Please fill the bind username/password.");?>");
|
810
|
return;
|
811
|
}
|
812
|
}
|
813
|
|
814
|
var ajaxRequest;
|
815
|
var authserver = $('#authmode').val();
|
816
|
var cert;
|
817
|
|
818
|
<?php if (count($a_ca) > 0): ?>
|
819
|
cert = $('#ldap_caref').val();
|
820
|
<?php else: ?>
|
821
|
cert = '';
|
822
|
<?php endif; ?>
|
823
|
/*
|
824
|
$('#containers').modal('show');
|
825
|
$('#serverlist').parent('div').prev('label').remove();
|
826
|
$('#serverlist').parent('div').removeClass("col-sm-10");
|
827
|
$('#serverlist').parent('div').addClass("col-sm-12");
|
828
|
*/
|
829
|
ajaxRequest = $.ajax(
|
830
|
{
|
831
|
url: "/system_authservers.php",
|
832
|
type: "post",
|
833
|
data: {
|
834
|
ajax: "ajax",
|
835
|
port: $('#ldap_port').val(),
|
836
|
host: $('#ldap_host').val(),
|
837
|
scope: $('#ldap_scope').val(),
|
838
|
basedn: $('#ldap_basedn').val(),
|
839
|
binddn: $('#ldap_binddn').val(),
|
840
|
bindpw: $('#ldap_bindpw').val(),
|
841
|
urltype:$('#ldap_urltype').val(),
|
842
|
proto: $('#ldap_protver').val(),
|
843
|
authcn: $('#ldapauthcontainers').val(),
|
844
|
cert: cert
|
845
|
}
|
846
|
}
|
847
|
);
|
848
|
|
849
|
// Deal with the results of the above ajax call
|
850
|
ajaxRequest.done(function (response, textStatus, jqXHR) {
|
851
|
$('#containers').replaceWith(response);
|
852
|
|
853
|
$('#containers').modal('show');
|
854
|
|
855
|
// The button handler needs to be here because until the modal has been populated
|
856
|
// the controls we need to attach handlers to do not exist
|
857
|
$('#svcontbtn').prop("type", "button");
|
858
|
$('#svcontbtn').removeAttr("href");
|
859
|
|
860
|
$('#svcontbtn').click(function () {
|
861
|
var ous = $('[id^=ou]').length;
|
862
|
var i;
|
863
|
|
864
|
$('#ldapauthcontainers').val("");
|
865
|
|
866
|
for (i = 0; i < ous; i++) {
|
867
|
if ($('#ou' + i).prop("checked")) {
|
868
|
if ($('#ldapauthcontainers').val() != "") {
|
869
|
$('#ldapauthcontainers').val($('#ldapauthcontainers').val() +";");
|
870
|
}
|
871
|
|
872
|
$('#ldapauthcontainers').val($('#ldapauthcontainers').val() + $('#ou' + i).val());
|
873
|
}
|
874
|
}
|
875
|
|
876
|
$('#containers').modal('hide');
|
877
|
});
|
878
|
});
|
879
|
|
880
|
}
|
881
|
|
882
|
function set_ldap_port() {
|
883
|
if ($('#ldap_urltype').find(":selected").index() == 0)
|
884
|
$('#ldap_port').val('389');
|
885
|
else
|
886
|
$('#ldap_port').val('636');
|
887
|
}
|
888
|
|
889
|
// Hides all elements of the specified class. This will usually be a section
|
890
|
function hideClass(s_class, hide) {
|
891
|
if (hide)
|
892
|
$('.' + s_class).hide();
|
893
|
else
|
894
|
$('.' + s_class).show();
|
895
|
}
|
896
|
|
897
|
function ldap_tmplchange() {
|
898
|
switch ($('#ldap_tmpltype').find(":selected").index()) {
|
899
|
<?php
|
900
|
$index = 0;
|
901
|
foreach ($ldap_templates as $tmpldata):
|
902
|
?>
|
903
|
case <?=$index;?>:
|
904
|
$('#ldap_attr_user').val("<?=$tmpldata['attr_user'];?>");
|
905
|
$('#ldap_attr_group').val("<?=$tmpldata['attr_group'];?>");
|
906
|
$('#ldap_attr_member').val("<?=$tmpldata['attr_member'];?>");
|
907
|
break;
|
908
|
<?php
|
909
|
$index++;
|
910
|
endforeach;
|
911
|
?>
|
912
|
}
|
913
|
}
|
914
|
|
915
|
// ---------- On initial page load ------------------------------------------------------------
|
916
|
|
917
|
<?php if ($act != 'edit') : ?>
|
918
|
ldap_tmplchange();
|
919
|
<?php endif; ?>
|
920
|
|
921
|
hideClass('ldapanon', $('#ldap_anon').prop('checked'));
|
922
|
hideClass('extended', !$('#ldap_extended_enabled').prop('checked'));
|
923
|
|
924
|
if ($('#ldap_port').val() == "")
|
925
|
set_ldap_port();
|
926
|
|
927
|
<?php
|
928
|
if ($act == 'edit') {
|
929
|
?>
|
930
|
$('#type option:not(:selected)').each(function(){
|
931
|
$(this).attr('disabled', 'disabled');
|
932
|
});
|
933
|
|
934
|
<?php
|
935
|
if (!$input_errors) {
|
936
|
?>
|
937
|
$('#name').prop("readonly", true);
|
938
|
<?php
|
939
|
}
|
940
|
}
|
941
|
?>
|
942
|
// ---------- Click checkbox handlers ---------------------------------------------------------
|
943
|
|
944
|
$('#ldap_tmpltype').on('change', function() {
|
945
|
ldap_tmplchange();
|
946
|
});
|
947
|
|
948
|
$('#ldap_anon').click(function () {
|
949
|
hideClass('ldapanon', this.checked);
|
950
|
});
|
951
|
|
952
|
$('#ldap_urltype').on('change', function() {
|
953
|
set_ldap_port();
|
954
|
});
|
955
|
|
956
|
$('#Select').click(function () {
|
957
|
select_clicked();
|
958
|
});
|
959
|
|
960
|
$('#ldap_extended_enabled').click(function () {
|
961
|
hideClass('extended', !this.checked);
|
962
|
});
|
963
|
|
964
|
});
|
965
|
//]]>
|
966
|
</script>
|
967
|
<?php
|
968
|
include("foot.inc");
|