Project

General

Profile

Download (24.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	system_authservers.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *	Copyright (c)  2008 Shrew Soft Inc.
8
 *
9
 *	Redistribution and use in source and binary forms, with or without modification,
10
 *	are permitted provided that the following conditions are met:
11
 *
12
 *	1. Redistributions of source code must retain the above copyright notice,
13
 *		this list of conditions and the following disclaimer.
14
 *
15
 *	2. Redistributions in binary form must reproduce the above copyright
16
 *		notice, this list of conditions and the following disclaimer in
17
 *		the documentation and/or other materials provided with the
18
 *		distribution.
19
 *
20
 *	3. All advertising materials mentioning features or use of this software
21
 *		must display the following acknowledgment:
22
 *		"This product includes software developed by the pfSense Project
23
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
24
 *
25
 *	4. The names "pfSense" and "pfSense Project" must not be used to
26
 *		 endorse or promote products derived from this software without
27
 *		 prior written permission. For written permission, please contact
28
 *		 coreteam@pfsense.org.
29
 *
30
 *	5. Products derived from this software may not be called "pfSense"
31
 *		nor may "pfSense" appear in their names without prior written
32
 *		permission of the Electric Sheep Fencing, LLC.
33
 *
34
 *	6. Redistributions of any form whatsoever must retain the following
35
 *		acknowledgment:
36
 *
37
 *	"This product includes software developed by the pfSense Project
38
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
52
 *
53
 *	====================================================================
54
 *
55
 */
56

    
57
##|+PRIV
58
##|*IDENT=page-system-authservers
59
##|*NAME=System: Authentication Servers
60
##|*DESCR=Allow access to the 'System: Authentication Servers' page.
61
##|*MATCH=system_authservers.php*
62
##|-PRIV
63

    
64
require("guiconfig.inc");
65
require_once("auth.inc");
66

    
67
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Authentication Servers"));
68
$shortcut_section = "authentication";
69

    
70
if (is_numericint($_GET['id'])) {
71
	$id = $_GET['id'];
72
}
73
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
74
	$id = $_POST['id'];
75
}
76

    
77
if (!is_array($config['system']['authserver'])) {
78
	$config['system']['authserver'] = array();
79
}
80

    
81
$a_servers = auth_get_authserver_list();
82
foreach ($a_servers as $servers) {
83
	$a_server[] = $servers;
84
}
85

    
86
if (!is_array($config['ca'])) {
87
	$config['ca'] = array();
88
}
89
$a_ca =& $config['ca'];
90

    
91
$act = $_GET['act'];
92
if ($_POST['act']) {
93
	$act = $_POST['act'];
94
}
95

    
96
if ($act == "del") {
97

    
98
	if (!$a_server[$_GET['id']]) {
99
		pfSenseHeader("system_authservers.php");
100
		exit;
101
	}
102

    
103
	/* Remove server from main list. */
104
	$serverdeleted = $a_server[$_GET['id']]['name'];
105
	foreach ($config['system']['authserver'] as $k => $as) {
106
		if ($config['system']['authserver'][$k]['name'] == $serverdeleted) {
107
			unset($config['system']['authserver'][$k]);
108
		}
109
	}
110

    
111
	/* Remove server from temp list used later on this page. */
112
	unset($a_server[$_GET['id']]);
113

    
114
	$savemsg = gettext("Authentication Server") . " " . htmlspecialchars($serverdeleted) . " " . gettext("deleted") . "<br />";
115
	write_config($savemsg);
116
}
117

    
118
if ($act == "edit") {
119
	if (isset($id) && $a_server[$id]) {
120

    
121
		$pconfig['type'] = $a_server[$id]['type'];
122
		$pconfig['name'] = $a_server[$id]['name'];
123

    
124
		if ($pconfig['type'] == "ldap") {
125
			$pconfig['ldap_caref'] = $a_server[$id]['ldap_caref'];
126
			$pconfig['ldap_host'] = $a_server[$id]['host'];
127
			$pconfig['ldap_port'] = $a_server[$id]['ldap_port'];
128
			$pconfig['ldap_timeout'] = $a_server[$id]['ldap_timeout'];
129
			$pconfig['ldap_urltype'] = $a_server[$id]['ldap_urltype'];
130
			$pconfig['ldap_protver'] = $a_server[$id]['ldap_protver'];
131
			$pconfig['ldap_scope'] = $a_server[$id]['ldap_scope'];
132
			$pconfig['ldap_basedn'] = $a_server[$id]['ldap_basedn'];
133
			$pconfig['ldap_authcn'] = $a_server[$id]['ldap_authcn'];
134
			$pconfig['ldap_extended_enabled'] = $a_server[$id]['ldap_extended_enabled'];
135
			$pconfig['ldap_extended_query'] = $a_server[$id]['ldap_extended_query'];
136
			$pconfig['ldap_binddn'] = $a_server[$id]['ldap_binddn'];
137
			$pconfig['ldap_bindpw'] = $a_server[$id]['ldap_bindpw'];
138
			$pconfig['ldap_attr_user'] = $a_server[$id]['ldap_attr_user'];
139
			$pconfig['ldap_attr_group'] = $a_server[$id]['ldap_attr_group'];
140
			$pconfig['ldap_attr_member'] = $a_server[$id]['ldap_attr_member'];
141
			$pconfig['ldap_attr_groupobj'] = $a_server[$id]['ldap_attr_groupobj'];
142
			$pconfig['ldap_utf8'] = isset($a_server[$id]['ldap_utf8']);
143
			$pconfig['ldap_nostrip_at'] = isset($a_server[$id]['ldap_nostrip_at']);
144
			$pconfig['ldap_rfc2307'] = isset($a_server[$id]['ldap_rfc2307']);
145

    
146
			if (!$pconfig['ldap_binddn'] || !$pconfig['ldap_bindpw']) {
147
				$pconfig['ldap_anon'] = true;
148
			}
149
		}
150

    
151
		if ($pconfig['type'] == "radius") {
152
			$pconfig['radius_host'] = $a_server[$id]['host'];
153
			$pconfig['radius_auth_port'] = $a_server[$id]['radius_auth_port'];
154
			$pconfig['radius_acct_port'] = $a_server[$id]['radius_acct_port'];
155
			$pconfig['radius_secret'] = $a_server[$id]['radius_secret'];
156
			$pconfig['radius_timeout'] = $a_server[$id]['radius_timeout'];
157

    
158
			if ($pconfig['radius_auth_port'] &&
159
				$pconfig['radius_acct_port']) {
160
				$pconfig['radius_srvcs'] = "both";
161
			}
162

    
163
			if ($pconfig['radius_auth_port'] &&
164
				!$pconfig['radius_acct_port']) {
165
				$pconfig['radius_srvcs'] = "auth";
166
				$pconfig['radius_acct_port'] = 1813;
167
			}
168

    
169
			if (!$pconfig['radius_auth_port'] &&
170
				$pconfig['radius_acct_port']) {
171
				$pconfig['radius_srvcs'] = "acct";
172
				$pconfig['radius_auth_port'] = 1812;
173
			}
174

    
175
		}
176
	}
177
}
178

    
179
if ($act == "new") {
180
	$pconfig['ldap_protver'] = 3;
181
	$pconfig['ldap_anon'] = true;
182
	$pconfig['radius_srvcs'] = "both";
183
	$pconfig['radius_auth_port'] = "1812";
184
	$pconfig['radius_acct_port'] = "1813";
185
}
186

    
187
if ($_POST) {
188
	unset($input_errors);
189
	$pconfig = $_POST;
190

    
191
	/* input validation */
192

    
193
	if ($pconfig['type'] == "ldap") {
194
		$reqdfields = explode(" ",
195
			"name type ldap_host ldap_port " .
196
			"ldap_urltype ldap_protver ldap_scope " .
197
			"ldap_attr_user ldap_attr_group ldap_attr_member ldapauthcontainers");
198

    
199
		$reqdfieldsn = array(
200
			gettext("Descriptive name"),
201
			gettext("Type"),
202
			gettext("Hostname or IP"),
203
			gettext("Port value"),
204
			gettext("Transport"),
205
			gettext("Protocol version"),
206
			gettext("Search level"),
207
			gettext("User naming Attribute"),
208
			gettext("Group naming Attribute"),
209
			gettext("Group member attribute"),
210
			gettext("Authentication container"));
211

    
212
		if (!$pconfig['ldap_anon']) {
213
			$reqdfields[] = "ldap_binddn";
214
			$reqdfields[] = "ldap_bindpw";
215
			$reqdfieldsn[] = gettext("Bind user DN");
216
			$reqdfieldsn[] = gettext("Bind Password");
217
		}
218
	}
219

    
220
	if ($pconfig['type'] == "radius") {
221
		$reqdfields = explode(" ", "name type radius_host radius_srvcs");
222
		$reqdfieldsn = array(
223
			gettext("Descriptive name"),
224
			gettext("Type"),
225
			gettext("Hostname or IP"),
226
			gettext("Services"));
227

    
228
		if ($pconfig['radisu_srvcs'] == "both" ||
229
			$pconfig['radisu_srvcs'] == "auth") {
230
			$reqdfields[] = "radius_auth_port";
231
			$reqdfieldsn[] = gettext("Authentication port");
232
		}
233

    
234
		if ($pconfig['radisu_srvcs'] == "both" ||
235
			$pconfig['radisu_srvcs'] == "acct") {
236
			$reqdfields[] = "radius_acct_port";
237
			$reqdfieldsn[] = gettext("Accounting port");
238
		}
239

    
240
		if (!isset($id)) {
241
			$reqdfields[] = "radius_secret";
242
			$reqdfieldsn[] = gettext("Shared Secret");
243
		}
244
	}
245

    
246
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
247

    
248
	if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['host'])) {
249
		$input_errors[] = gettext("The host name contains invalid characters.");
250
	}
251

    
252
	if (auth_get_authserver($pconfig['name']) && !isset($id)) {
253
		$input_errors[] = gettext("An authentication server with the same name already exists.");
254
	}
255

    
256
	if (($pconfig['type'] == "ldap") || ($pconfig['type'] == "radius")) {
257
		$to_field = "{$pconfig['type']}_timeout";
258
		if (isset($_POST[$to_field]) && !empty($_POST[$to_field]) && (!is_numeric($_POST[$to_field]) || (is_numeric($_POST[$to_field]) && ($_POST[$to_field] <= 0)))) {
259
			$input_errors[] = sprintf(gettext("%s Timeout value must be numeric and positive."), strtoupper($pconfig['type']));
260
		}
261
	}
262

    
263
	/* if this is an AJAX caller then handle via JSON */
264
	if (isAjax() && is_array($input_errors)) {
265
		input_errors2Ajax($input_errors);
266
		exit;
267
	}
268

    
269
	if (!$input_errors) {
270
		$server = array();
271
		$server['refid'] = uniqid();
272
		if (isset($id) && $a_server[$id]) {
273
			$server = $a_server[$id];
274
		}
275

    
276
		$server['type'] = $pconfig['type'];
277
		$server['name'] = $pconfig['name'];
278

    
279
		if ($server['type'] == "ldap") {
280

    
281
			if (!empty($pconfig['ldap_caref'])) {
282
				$server['ldap_caref'] = $pconfig['ldap_caref'];
283
			}
284
			$server['host'] = $pconfig['ldap_host'];
285
			$server['ldap_port'] = $pconfig['ldap_port'];
286
			$server['ldap_urltype'] = $pconfig['ldap_urltype'];
287
			$server['ldap_protver'] = $pconfig['ldap_protver'];
288
			$server['ldap_scope'] = $pconfig['ldap_scope'];
289
			$server['ldap_basedn'] = $pconfig['ldap_basedn'];
290
			$server['ldap_authcn'] = $pconfig['ldapauthcontainers'];
291
			$server['ldap_extended_enabled'] = $pconfig['ldap_extended_enabled'];
292
			$server['ldap_extended_query'] = $pconfig['ldap_extended_query'];
293
			$server['ldap_attr_user'] = $pconfig['ldap_attr_user'];
294
			$server['ldap_attr_group'] = $pconfig['ldap_attr_group'];
295
			$server['ldap_attr_member'] = $pconfig['ldap_attr_member'];
296

    
297
			$server['ldap_attr_groupobj'] = empty($pconfig['ldap_attr_groupobj']) ? "posixGroup" : $pconfig['ldap_attr_groupobj'];
298

    
299
			if ($pconfig['ldap_utf8'] == "yes") {
300
				$server['ldap_utf8'] = true;
301
			} else {
302
				unset($server['ldap_utf8']);
303
			}
304
			if ($pconfig['ldap_nostrip_at'] == "yes") {
305
				$server['ldap_nostrip_at'] = true;
306
			} else {
307
				unset($server['ldap_nostrip_at']);
308
			}
309
			if ($pconfig['ldap_rfc2307'] == "yes") {
310
				$server['ldap_rfc2307'] = true;
311
			} else {
312
				unset($server['ldap_rfc2307']);
313
			}
314

    
315

    
316
			if (!$pconfig['ldap_anon']) {
317
				$server['ldap_binddn'] = $pconfig['ldap_binddn'];
318
				$server['ldap_bindpw'] = $pconfig['ldap_bindpw'];
319
			} else {
320
				unset($server['ldap_binddn']);
321
				unset($server['ldap_bindpw']);
322
			}
323

    
324
			if ($pconfig['ldap_timeout']) {
325
				$server['ldap_timeout'] = $pconfig['ldap_timeout'];
326
			} else {
327
				$server['ldap_timeout'] = 25;
328
			}
329
		}
330

    
331
		if ($server['type'] == "radius") {
332

    
333
			$server['host'] = $pconfig['radius_host'];
334

    
335
			if ($pconfig['radius_secret']) {
336
				$server['radius_secret'] = $pconfig['radius_secret'];
337
			}
338

    
339
			if ($pconfig['radius_timeout']) {
340
				$server['radius_timeout'] = $pconfig['radius_timeout'];
341
			} else {
342
				$server['radius_timeout'] = 5;
343
			}
344

    
345
			if ($pconfig['radius_srvcs'] == "both") {
346
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
347
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
348
			}
349

    
350
			if ($pconfig['radius_srvcs'] == "auth") {
351
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
352
				unset($server['radius_acct_port']);
353
			}
354

    
355
			if ($pconfig['radius_srvcs'] == "acct") {
356
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
357
				unset($server['radius_auth_port']);
358
			}
359
		}
360

    
361
		if (isset($id) && $config['system']['authserver'][$id]) {
362
			$config['system']['authserver'][$id] = $server;
363
		} else {
364
			$config['system']['authserver'][] = $server;
365
		}
366

    
367
		write_config();
368

    
369
		pfSenseHeader("system_authservers.php");
370
	}
371
}
372

    
373
// On error, restore the form contents so the user doesn't have to re-enter too much
374
if($_POST && $input_errors) {
375
	$pconfig = $_POST;
376
	$pconfig['ldap_authcn'] = $_POST['ldapauthcontainers'];
377
	$pconfig['ldap_template'] = $_POST['ldap_tmpltype'];
378
}
379

    
380
include("head.inc");
381

    
382
if ($input_errors)
383
	print_input_errors($input_errors);
384

    
385
if ($savemsg)
386
	print_info_box($savemsg, 'success');
387

    
388
$tab_array = array();
389
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
390
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
391
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
392
$tab_array[] = array(gettext("Servers"), true, "system_authservers.php");
393
display_top_tabs($tab_array);
394

    
395
if (!($act == "new" || $act == "edit" || $input_errors))
396
{
397
?>
398
<div class="panel panel-default">
399
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Authentication Servers')?></h2></div>
400
	<div class="panel-body">
401
		<div class="table-responsive">
402
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
403
				<thead>
404
					<tr>
405
						<th><?=gettext("Server Name")?></th>
406
						<th><?=gettext("Type")?></th>
407
						<th><?=gettext("Host Name")?></th>
408
						<th><?=gettext("Actions")?></th>
409
					</tr>
410
				</thead>
411
				<tbody>
412
			<?php foreach($a_server as $i => $server): ?>
413
					<tr>
414
						<td><?=htmlspecialchars($server['name'])?></td>
415
						<td><?=htmlspecialchars($auth_server_types[$server['type']])?></td>
416
						<td><?=htmlspecialchars($server['host'])?></td>
417
						<td>
418
						<?php if ($i < (count($a_server) - 1)): ?>
419
							<a class="fa fa-pencil" title="<?=gettext("Edit server"); ?>" href="system_authservers.php?act=edit&amp;id=<?=$i?>"></a>
420
							<a class="fa fa-trash"  title="<?=gettext("Delete server")?>" href="system_authservers.php?act=del&amp;id=<?=$i?>"></a>
421
						<?php endif?>
422
						</td>
423
					</tr>
424
			<?php endforeach; ?>
425
				</tbody>
426
			</table>
427
		</div>
428
	</div>
429
</div>
430

    
431
<nav class="action-buttons">
432
	<a href="?act=new" class="btn btn-success btn-sm">
433
		<i class="fa fa-plus icon-embed-btn"></i>
434
		<?=gettext("Add")?>
435
	</a>
436
</nav>
437
<?php
438
	include("foot.inc");
439
	exit;
440
}
441

    
442
$form = new Form;
443
$form->setAction('system_authservers.php?act=edit');
444

    
445
$form->addGlobal(new Form_Input(
446
	'userid',
447
	null,
448
	'hidden',
449
	$id
450
));
451

    
452
$section = new Form_Section('Server settings');
453

    
454
$section->addInput($input = new Form_Input(
455
	'name',
456
	'Descriptive name',
457
	'text',
458
	$pconfig['name']
459
));
460

    
461
$section->addInput($input = new Form_Select(
462
	'type',
463
	'Type',
464
	$pconfig['type'],
465
	$auth_server_types
466
))->toggles();
467

    
468
$form->add($section);
469

    
470
// ==== LDAP settings =========================================================
471
$section = new Form_Section('LDAP Server Settings');
472
$section->addClass('toggle-ldap collapse');
473

    
474
if (!isset($pconfig['type']) || $pconfig['type'] == 'ldap')
475
	$section->addClass('in');
476

    
477
$section->addInput(new Form_Input(
478
	'ldap_host',
479
	'Hostname or IP address',
480
	'text',
481
	$pconfig['ldap_host']
482
))->setHelp('NOTE: When using SSL, this hostname MUST match the Common Name '.
483
	'(CN) of the LDAP server\'s SSL Certificate.');
484

    
485
$section->addInput(new Form_Input(
486
	'ldap_port',
487
	'Port value',
488
	'number',
489
	$pconfig['ldap_port']
490
));
491

    
492
$section->addInput(new Form_Select(
493
	'ldap_urltype',
494
	'Transport',
495
	$pconfig['ldap_urltype'],
496
	array_combine(array_keys($ldap_urltypes), array_keys($ldap_urltypes))
497
));
498

    
499
if (empty($a_ca))
500
{
501
	$section->addInput(new Form_StaticText(
502
		'Peer Certificate Authority',
503
		'No Certificate Authorities defined.<br/>Create one under <a href="system_camanager.php">System &gt; Cert Manager</a>.'
504
	));
505
}
506
else
507
{
508
	$ldapCaRef = [];
509
	foreach ($a_ca as $ca)
510
		$ldapCaRef[ $ca['refid'] ] = $ca['descr'];
511

    
512
	$section->addInput(new Form_Select(
513
		'ldap_caref',
514
		'Peer Certificate Authority',
515
		$pconfig['ldap_caref'],
516
		$ldapCaRef
517
	))->setHelp('This option is used if \'SSL Encrypted\' option is choosen. '.
518
		'It must match with the CA in the AD otherwise problems will arise.');
519
}
520

    
521
$section->addInput(new Form_Select(
522
	'ldap_protver',
523
	'Protocol version',
524
	$pconfig['ldap_protver'],
525
	array_combine($ldap_protvers, $ldap_protvers)
526
));
527

    
528
$section->addInput(new Form_Input(
529
	'ldap_timeout',
530
	'Server Timeout',
531
	'number',
532
	$pconfig['ldap_timeout'],
533
	['placeholder' => 25]
534
))->setHelp('Timeout for LDAP operations (seconds)');
535

    
536
$group = new Form_Group('Search scope');
537

    
538
$SSF = new Form_Select(
539
	'ldap_scope',
540
	'Level',
541
	$pconfig['ldap_scope'],
542
	$ldap_scopes
543
);
544

    
545
$SSB = new Form_Input(
546
	'ldap_basedn',
547
	'Base DN',
548
	'text',
549
	$pconfig['ldap_basedn']
550
);
551

    
552

    
553
$section->addInput(new Form_StaticText(
554
	'Search scope',
555
	'Level ' . $SSF . '<br />' . 'Base DN' . $SSB
556
));
557

    
558
$group = new Form_Group('Authentication containers');
559
$group->add(new Form_Input(
560
	'ldapauthcontainers',
561
	'Containers',
562
	'text',
563
	$pconfig['ldap_authcn']
564
))->setHelp('Note: Semi-Colon separated. This will be prepended to the search '.
565
	'base dn above or you can specify full container path containing a dc= '.
566
	'component.<br/>Example: CN=Users;DC=example,DC=com or OU=Staff;OU=Freelancers');
567

    
568
$group->add(new Form_Button(
569
	'Select',
570
	'Select a container'
571
))->removeClass('btn-primary')->addClass('btn-default');
572

    
573
$section->add($group);
574

    
575
$section->addInput(new Form_Checkbox(
576
	'ldap_extended_enabled',
577
	'Extended query',
578
	'Enable extended query',
579
	$pconfig['ldap_extended_enabled']
580
));
581

    
582
$group = new Form_Group('Query');
583
$group->addClass('extended');
584

    
585
$group->add(new Form_Input(
586
	'ldap_extended_query',
587
	'Query',
588
	'text',
589
	$pconfig['ldap_extended_query']
590
))->setHelp('Example: &amp;(objectClass=inetOrgPerson)(mail=*@example.com)');
591

    
592
$section->add($group);
593

    
594
$section->addInput(new Form_Checkbox(
595
	'ldap_anon',
596
	'Bind anonymous',
597
	'Use anonymous binds to resolve distinguished names',
598
	$pconfig['ldap_anon']
599
));
600

    
601
$group = new Form_Group('Bind credentials');
602
$group->addClass('ldapanon');
603

    
604
$group->add(new Form_Input(
605
	'ldap_binddn',
606
	'User DN:',
607
	'text',
608
	$pconfig['ldap_binddn']
609
));
610

    
611
$group->add(new Form_Input(
612
	'ldap_bindpw',
613
	'Password',
614
	'text',
615
	$pconfig['ldap_bindpw']
616
));
617
$section->add($group);
618

    
619
if (!isset($id)) {
620
	$template_list = array();
621

    
622
	foreach($ldap_templates as $option => $template) {
623
		$template_list[$option] = $template['desc'];
624
	}
625

    
626
	$section->addInput(new Form_Select(
627
		'ldap_tmpltype',
628
		'Initial Template',
629
		$pconfig['ldap_template'],
630
		$template_list
631
	));
632
}
633

    
634
$section->addInput(new Form_Input(
635
	'ldap_attr_user',
636
	'User naming attribute',
637
	'text',
638
	$pconfig['ldap_attr_user']
639
));
640

    
641
$section->addInput(new Form_Input(
642
	'ldap_attr_group',
643
	'Group naming attribute',
644
	'text',
645
	$pconfig['ldap_attr_group']
646
));
647

    
648
$section->addInput(new Form_Input(
649
	'ldap_attr_member',
650
	'Group member attribute',
651
	'text',
652
	$pconfig['ldap_attr_member']
653
));
654

    
655
$section->addInput(new Form_Checkbox(
656
	'ldap_rfc2307',
657
	'RFC 2307 Groups',
658
	'LDAP Server uses RFC 2307 style group membership',
659
	$pconfig['ldap_rfc2307']
660
))->setHelp('RFC 2307 style group membership has members listed on the group '.
661
	'object rather than using groups listed on user object. Leave unchecked '.
662
	'for Active Directory style group membership (RFC 2307bis).');
663

    
664
$section->addInput(new Form_Input(
665
	'ldap_attr_groupobj',
666
	'Group Object Class',
667
	'text',
668
	$pconfig['ldap_attr_groupobj'],
669
	['placeholder' => 'posixGroup']
670
))->setHelp('Object class used for groups in RFC2307 mode. '.
671
	'Typically "posixGroup" or "group".');
672

    
673
$section->addInput(new Form_Checkbox(
674
	'ldap_utf8',
675
	'UTF8 Encode',
676
	'UTF8 encode LDAP parameters before sending them to the server.',
677
	$pconfig['ldap_utf8']
678
))->setHelp('Required to support international characters, but may not be '.
679
	'supported by every LDAP server.');
680

    
681
$section->addInput(new Form_Checkbox(
682
	'ldap_nostrip_at',
683
	'Username Alterations',
684
	'Do not strip away parts of the username after the @ symbol',
685
	$pconfig['ldap_nostrip_at']
686
))->setHelp('e.g. user@host becomes user when unchecked.');
687

    
688
$form->add($section);
689

    
690
// ==== RADIUS section ========================================================
691
$section = new Form_Section('Radius Server Settings');
692
$section->addClass('toggle-radius collapse');
693

    
694
$section->addInput(new Form_Input(
695
	'radius_host',
696
	'Hostname or IP address',
697
	'text',
698
	$pconfig['radius_host']
699
));
700

    
701
$section->addInput(new Form_Input(
702
	'radius_secret',
703
	'Shared Secret',
704
	'text',
705
	$pconfig['radius_secret']
706
));
707

    
708
$section->addInput(new Form_Select(
709
	'radius_srvcs',
710
	'Services offered',
711
	$pconfig['radius_srvcs'],
712
	$radius_srvcs
713
));
714

    
715
$section->addInput(new Form_Input(
716
	'radius_auth_port',
717
	'Authentication port',
718
	'number',
719
	$pconfig['radius_auth_port']
720
));
721

    
722
$section->addInput(new Form_Input(
723
	'radius_acct_port',
724
	'Accounting port',
725
	'number',
726
	$pconfig['radius_acct_port']
727
));
728

    
729
$section->addInput(new Form_Input(
730
	'radius_timeout',
731
	'Authentication Timeout',
732
	'number',
733
	$pconfig['radius_timeout']
734
))->setHelp('This value controls how long, in seconds, that the RADIUS '.
735
	'server may take to respond to an authentication request. If left blank, the '.
736
	'default value is 5 seconds. NOTE: If you are using an interactive two-factor '.
737
	'authentication system, increase this timeout to account for how long it will '.
738
	'take the user to receive and enter a token.');
739

    
740
if (isset($id) && $a_server[$id])
741
{
742
	$section->addInput(new Form_Input(
743
		'id',
744
		null,
745
		'hidden',
746
		$id
747
	));
748
}
749

    
750
$form->add($section);
751
print $form;
752
?>
753
<script type="text/javascript">
754
//<![CDATA[
755
events.push(function(){
756
	function select_clicked() {
757
		if (document.getElementById("ldap_port").value == '' ||
758
			document.getElementById("ldap_host").value == '' ||
759
			document.getElementById("ldap_scope").value == '' ||
760
			document.getElementById("ldap_basedn").value == '' ||
761
			document.getElementById("ldapauthcontainers").value == '') {
762
			alert("<?=gettext("Please fill the required values.");?>");
763
			return;
764
		}
765

    
766
		if (!document.getElementById("ldap_anon").checked) {
767
			if (document.getElementById("ldap_binddn").value == '' ||
768
				document.getElementById("ldap_bindpw").value == '') {
769
				alert("<?=gettext("Please fill the bind username/password.");?>");
770
				return;
771
			}
772
		}
773
		var url = 'system_usermanager_settings_ldapacpicker.php?';
774
		url += 'port=' + document.getElementById("ldap_port").value;
775
		url += '&host=' + document.getElementById("ldap_host").value;
776
		url += '&scope=' + document.getElementById("ldap_scope").value;
777
		url += '&basedn=' + document.getElementById("ldap_basedn").value;
778
		url += '&binddn=' + document.getElementById("ldap_binddn").value;
779
		url += '&bindpw=' + document.getElementById("ldap_bindpw").value;
780
		url += '&urltype=' + document.getElementById("ldap_urltype").value;
781
		url += '&proto=' + document.getElementById("ldap_protver").value;
782
		url += '&authcn=' + document.getElementById("ldapauthcontainers").value;
783
		<?php if (count($a_ca) > 0): ?>
784
			url += '&cert=' + document.getElementById("ldap_caref").value;
785
		<?php else: ?>
786
			url += '&cert=';
787
		<?php endif; ?>
788

    
789
		var oWin = window.open(url, "pfSensePop", "width=620,height=400,top=150,left=150");
790
		if (oWin == null || typeof(oWin) == "undefined") {
791
			alert("<?=gettext('Popup blocker detected.	Action aborted.');?>");
792
		}
793
	}
794

    
795
	function set_ldap_port() {
796
		if($('#ldap_urltype').find(":selected").index() == 0)
797
			$('#ldap_port').val('389');
798
		else
799
			$('#ldap_port').val('636');
800
	}
801

    
802
	// Hides all elements of the specified class. This will usually be a section
803
	function hideClass(s_class, hide) {
804
		if(hide)
805
			$('.' + s_class).hide();
806
		else
807
			$('.' + s_class).show();
808
	}
809

    
810
	function ldap_tmplchange() {
811
		switch ($('#ldap_tmpltype').find(":selected").index()) {
812
<?php
813
		$index = 0;
814
		foreach ($ldap_templates as $tmpldata):
815
?>
816
			case <?=$index;?>:
817
				$('#ldap_attr_user').val("<?=$tmpldata['attr_user'];?>");
818
				$('#ldap_attr_group').val("<?=$tmpldata['attr_group'];?>");
819
				$('#ldap_attr_member').val("<?=$tmpldata['attr_member'];?>");
820
				break;
821
<?php
822
			$index++;
823
		endforeach;
824
?>
825
		}
826
	}
827

    
828
	// ---------- On initial page load ------------------------------------------------------------
829

    
830
<?php if ($act != 'edit') : ?>
831
	ldap_tmplchange();
832
<?php endif; ?>
833

    
834
	hideClass('ldapanon', $('#ldap_anon').prop('checked'));
835
	$("#Select").prop('type','button');
836
	hideClass('extended', !$('#ldap_extended_enabled').prop('checked'));
837

    
838
	if($('#ldap_port').val() == "")
839
		set_ldap_port();
840

    
841
<?php
842
	if($act == 'edit') {
843
?>
844
		$('#type option:not(:selected)').each(function(){
845
			$(this).attr('disabled', 'disabled');
846
		});
847

    
848
<?php
849
		if(!$input_errors) {
850
?>
851
		$('#name').prop("readonly", true);
852
<?php
853
		}
854
	}
855
?>
856
	// ---------- Click checkbox handlers ---------------------------------------------------------
857

    
858
	$('#ldap_tmpltype').on('change', function() {
859
		ldap_tmplchange();
860
	});
861

    
862
	$('#ldap_anon').click(function () {
863
		hideClass('ldapanon', this.checked);
864
	});
865

    
866
	$('#ldap_urltype').on('change', function() {
867
		set_ldap_port();
868
	});
869

    
870
	$('#Select').click(function () {
871
		select_clicked();
872
	});
873

    
874
	$('#ldap_extended_enabled').click(function () {
875
		hideClass('extended', !this.checked);
876
	});
877

    
878
});
879
//]]>
880
</script>
881
<?php
882
include("foot.inc");
(194-194/229)