Project

General

Profile

Download (25.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * system_authservers.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
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&amp;id=<?=$i?>"></a>
450
							<a class="fa fa-trash"  title="<?=gettext("Delete server")?>" href="system_authservers.php?act=del&amp;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 or STARTTLS, 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 &gt; 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\' '.
548
		'or \'TCP - STARTTLS\' options are chosen. '.
549
		'It must match with the CA in the AD otherwise problems will arise.');
550
}
551

    
552
$section->addInput(new Form_Select(
553
	'ldap_protver',
554
	'Protocol version',
555
	$pconfig['ldap_protver'],
556
	array_combine($ldap_protvers, $ldap_protvers)
557
));
558

    
559
$section->addInput(new Form_Input(
560
	'ldap_timeout',
561
	'Server Timeout',
562
	'number',
563
	$pconfig['ldap_timeout'],
564
	['placeholder' => 25]
565
))->setHelp('Timeout for LDAP operations (seconds)');
566

    
567
$group = new Form_Group('Search scope');
568

    
569
$SSF = new Form_Select(
570
	'ldap_scope',
571
	'Level',
572
	$pconfig['ldap_scope'],
573
	$ldap_scopes
574
);
575

    
576
$SSB = new Form_Input(
577
	'ldap_basedn',
578
	'Base DN',
579
	'text',
580
	$pconfig['ldap_basedn']
581
);
582

    
583

    
584
$section->addInput(new Form_StaticText(
585
	'Search scope',
586
	'Level ' . $SSF . '<br />' . 'Base DN' . $SSB
587
));
588

    
589
$group = new Form_Group('Authentication containers');
590
$group->add(new Form_Input(
591
	'ldapauthcontainers',
592
	'Containers',
593
	'text',
594
	$pconfig['ldap_authcn']
595
))->setHelp('Note: Semi-Colon separated. This will be prepended to the search '.
596
	'base dn above or the full container path can be specified containing a dc= '.
597
	'component.<br/>Example: CN=Users;DC=example,DC=com or OU=Staff;OU=Freelancers');
598

    
599
$group->add(new Form_Button(
600
	'Select',
601
	'Select a container',
602
	null,
603
	'fa-search'
604
))->setAttribute('type','button')->addClass('btn-info');
605

    
606
$section->add($group);
607

    
608
$section->addInput(new Form_Checkbox(
609
	'ldap_extended_enabled',
610
	'Extended query',
611
	'Enable extended query',
612
	$pconfig['ldap_extended_enabled']
613
));
614

    
615
$group = new Form_Group('Query');
616
$group->addClass('extended');
617

    
618
$group->add(new Form_Input(
619
	'ldap_extended_query',
620
	'Query',
621
	'text',
622
	$pconfig['ldap_extended_query']
623
))->setHelp('Example: &amp;(objectClass=inetOrgPerson)(mail=*@example.com)');
624

    
625
$section->add($group);
626

    
627
$section->addInput(new Form_Checkbox(
628
	'ldap_anon',
629
	'Bind anonymous',
630
	'Use anonymous binds to resolve distinguished names',
631
	$pconfig['ldap_anon']
632
));
633

    
634
$group = new Form_Group('Bind credentials');
635
$group->addClass('ldapanon');
636

    
637
$group->add(new Form_Input(
638
	'ldap_binddn',
639
	'User DN:',
640
	'text',
641
	$pconfig['ldap_binddn']
642
));
643

    
644
$group->add(new Form_Input(
645
	'ldap_bindpw',
646
	'Password',
647
	'password',
648
	$pconfig['ldap_bindpw']
649
));
650
$section->add($group);
651

    
652
if (!isset($id)) {
653
	$template_list = array();
654

    
655
	foreach ($ldap_templates as $option => $template) {
656
		$template_list[$option] = $template['desc'];
657
	}
658

    
659
	$section->addInput(new Form_Select(
660
		'ldap_tmpltype',
661
		'Initial Template',
662
		$pconfig['ldap_template'],
663
		$template_list
664
	));
665
}
666

    
667
$section->addInput(new Form_Input(
668
	'ldap_attr_user',
669
	'User naming attribute',
670
	'text',
671
	$pconfig['ldap_attr_user']
672
));
673

    
674
$section->addInput(new Form_Input(
675
	'ldap_attr_group',
676
	'Group naming attribute',
677
	'text',
678
	$pconfig['ldap_attr_group']
679
));
680

    
681
$section->addInput(new Form_Input(
682
	'ldap_attr_member',
683
	'Group member attribute',
684
	'text',
685
	$pconfig['ldap_attr_member']
686
));
687

    
688
$section->addInput(new Form_Checkbox(
689
	'ldap_rfc2307',
690
	'RFC 2307 Groups',
691
	'LDAP Server uses RFC 2307 style group membership',
692
	$pconfig['ldap_rfc2307']
693
))->setHelp('RFC 2307 style group membership has members listed on the group '.
694
	'object rather than using groups listed on user object. Leave unchecked '.
695
	'for Active Directory style group membership (RFC 2307bis).');
696

    
697
$section->addInput(new Form_Input(
698
	'ldap_attr_groupobj',
699
	'Group Object Class',
700
	'text',
701
	$pconfig['ldap_attr_groupobj'],
702
	['placeholder' => 'posixGroup']
703
))->setHelp('Object class used for groups in RFC2307 mode. '.
704
	'Typically "posixGroup" or "group".');
705

    
706
$section->addInput(new Form_Checkbox(
707
	'ldap_utf8',
708
	'UTF8 Encode',
709
	'UTF8 encode LDAP parameters before sending them to the server.',
710
	$pconfig['ldap_utf8']
711
))->setHelp('Required to support international characters, but may not be '.
712
	'supported by every LDAP server.');
713

    
714
$section->addInput(new Form_Checkbox(
715
	'ldap_nostrip_at',
716
	'Username Alterations',
717
	'Do not strip away parts of the username after the @ symbol',
718
	$pconfig['ldap_nostrip_at']
719
))->setHelp('e.g. user@host becomes user when unchecked.');
720

    
721
$form->add($section);
722

    
723
// ==== RADIUS section ========================================================
724
$section = new Form_Section('RADIUS Server Settings');
725
$section->addClass('toggle-radius collapse');
726

    
727
$section->addInput(new Form_Input(
728
	'radius_host',
729
	'Hostname or IP address',
730
	'text',
731
	$pconfig['radius_host']
732
));
733

    
734
$section->addInput(new Form_Input(
735
	'radius_secret',
736
	'Shared Secret',
737
	'password',
738
	$pconfig['radius_secret']
739
));
740

    
741
$section->addInput(new Form_Select(
742
	'radius_srvcs',
743
	'Services offered',
744
	$pconfig['radius_srvcs'],
745
	$radius_srvcs
746
));
747

    
748
$section->addInput(new Form_Input(
749
	'radius_auth_port',
750
	'Authentication port',
751
	'number',
752
	$pconfig['radius_auth_port']
753
));
754

    
755
$section->addInput(new Form_Input(
756
	'radius_acct_port',
757
	'Accounting port',
758
	'number',
759
	$pconfig['radius_acct_port']
760
));
761

    
762
$section->addInput(new Form_Input(
763
	'radius_timeout',
764
	'Authentication Timeout',
765
	'number',
766
	$pconfig['radius_timeout']
767
))->setHelp('This value controls how long, in seconds, that the RADIUS '.
768
	'server may take to respond to an authentication request. If left blank, the '.
769
	'default value is 5 seconds. NOTE: If using an interactive two-factor '.
770
	'authentication system, increase this timeout to account for how long it will '.
771
	'take the user to receive and enter a token.');
772

    
773
if (isset($id) && $a_server[$id])
774
{
775
	$section->addInput(new Form_Input(
776
		'id',
777
		null,
778
		'hidden',
779
		$id
780
	));
781
}
782

    
783
$form->add($section);
784

    
785
// Create a largely empty modal to show the available containers. We will populate it via AJAX later
786
$modal = new Modal("LDAP containers", "containers", true);
787

    
788
$form->add($modal);
789

    
790
print $form;
791
?>
792
<script type="text/javascript">
793
//<![CDATA[
794
events.push(function() {
795

    
796
	// Create an AJAX request (to this page) to get the container list and controls
797
	function select_clicked() {
798
		if (document.getElementById("ldap_port").value == '' ||
799
			document.getElementById("ldap_host").value == '' ||
800
			document.getElementById("ldap_scope").value == '' ||
801
			document.getElementById("ldap_basedn").value == '' ||
802
			document.getElementById("ldapauthcontainers").value == '') {
803
			alert("<?=gettext("Please fill the required values.");?>");
804
			return;
805
		}
806

    
807
		if (!document.getElementById("ldap_anon").checked) {
808
			if (document.getElementById("ldap_binddn").value == '' ||
809
				document.getElementById("ldap_bindpw").value == '') {
810
				alert("<?=gettext("Please fill the bind username/password.");?>");
811
				return;
812
			}
813
		}
814

    
815
		var ajaxRequest;
816
		var authserver = $('#authmode').val();
817
		var cert;
818

    
819
<?php if (count($a_ca) > 0): ?>
820
			cert = $('#ldap_caref').val();
821
<?php else: ?>
822
			cert = '';
823
<?php endif; ?>
824
/*
825
		$('#containers').modal('show');
826
		$('#serverlist').parent('div').prev('label').remove();
827
		$('#serverlist').parent('div').removeClass("col-sm-10");
828
		$('#serverlist').parent('div').addClass("col-sm-12");
829
*/
830
		ajaxRequest = $.ajax(
831
			{
832
				url: "/system_authservers.php",
833
				type: "post",
834
				data: {
835
					ajax: 	"ajax",
836
					port: 	$('#ldap_port').val(),
837
					host: 	$('#ldap_host').val(),
838
					scope: 	$('#ldap_scope').val(),
839
					basedn: $('#ldap_basedn').val(),
840
					binddn: $('#ldap_binddn').val(),
841
					bindpw: $('#ldap_bindpw').val(),
842
					urltype:$('#ldap_urltype').val(),
843
					proto:  $('#ldap_protver').val(),
844
					authcn: $('#ldapauthcontainers').val(),
845
					cert:   cert
846
				}
847
			}
848
		);
849

    
850
		// Deal with the results of the above ajax call
851
		ajaxRequest.done(function (response, textStatus, jqXHR) {
852
			$('#containers').replaceWith(response);
853

    
854
			$('#containers').modal('show');
855

    
856
			// The button handler needs to be here because until the modal has been populated
857
			// the controls we need to attach handlers to do not exist
858
			$('#svcontbtn').prop("type", "button");
859
			$('#svcontbtn').removeAttr("href");
860

    
861
			$('#svcontbtn').click(function () {
862
				var ous = $('[id^=ou]').length;
863
				var i;
864

    
865
				$('#ldapauthcontainers').val("");
866

    
867
				for (i = 0; i < ous; i++) {
868
					if ($('#ou' + i).prop("checked")) {
869
						if ($('#ldapauthcontainers').val() != "") {
870
							$('#ldapauthcontainers').val($('#ldapauthcontainers').val() +";");
871
						}
872

    
873
						$('#ldapauthcontainers').val($('#ldapauthcontainers').val() + $('#ou' + i).val());
874
					}
875
				}
876

    
877
				$('#containers').modal('hide');
878
			});
879
		});
880

    
881
	}
882

    
883
	function set_ldap_port() {
884
		if ($('#ldap_urltype').find(":selected").index() == 2)
885
			$('#ldap_port').val('636');
886
		else
887
			$('#ldap_port').val('389');
888
	}
889

    
890
	// Hides all elements of the specified class. This will usually be a section
891
	function hideClass(s_class, hide) {
892
		if (hide)
893
			$('.' + s_class).hide();
894
		else
895
			$('.' + s_class).show();
896
	}
897

    
898
	function ldap_tmplchange() {
899
		switch ($('#ldap_tmpltype').find(":selected").index()) {
900
<?php
901
		$index = 0;
902
		foreach ($ldap_templates as $tmpldata):
903
?>
904
			case <?=$index;?>:
905
				$('#ldap_attr_user').val("<?=$tmpldata['attr_user'];?>");
906
				$('#ldap_attr_group').val("<?=$tmpldata['attr_group'];?>");
907
				$('#ldap_attr_member').val("<?=$tmpldata['attr_member'];?>");
908
				break;
909
<?php
910
			$index++;
911
		endforeach;
912
?>
913
		}
914
	}
915

    
916
	// ---------- On initial page load ------------------------------------------------------------
917

    
918
<?php if ($act != 'edit') : ?>
919
	ldap_tmplchange();
920
<?php endif; ?>
921

    
922
	hideClass('ldapanon', $('#ldap_anon').prop('checked'));
923
	hideClass('extended', !$('#ldap_extended_enabled').prop('checked'));
924

    
925
	if ($('#ldap_port').val() == "")
926
		set_ldap_port();
927

    
928
<?php
929
	if ($act == 'edit') {
930
?>
931
		$('#type option:not(:selected)').each(function(){
932
			$(this).attr('disabled', 'disabled');
933
		});
934

    
935
<?php
936
		if (!$input_errors) {
937
?>
938
		$('#name').prop("readonly", true);
939
<?php
940
		}
941
	}
942
?>
943
	// ---------- Click checkbox handlers ---------------------------------------------------------
944

    
945
	$('#ldap_tmpltype').on('change', function() {
946
		ldap_tmplchange();
947
	});
948

    
949
	$('#ldap_anon').click(function () {
950
		hideClass('ldapanon', this.checked);
951
	});
952

    
953
	$('#ldap_urltype').on('change', function() {
954
		set_ldap_port();
955
	});
956

    
957
	$('#Select').click(function () {
958
		select_clicked();
959
	});
960

    
961
	$('#ldap_extended_enabled').click(function () {
962
		hideClass('extended', !this.checked);
963
	});
964

    
965
});
966
//]]>
967
</script>
968
<?php
969
include("foot.inc");
(191-191/225)