Project

General

Profile

Download (24.4 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
	pfSense_MODULE: auth
58
*/
59

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

    
67
require("guiconfig.inc");
68
require_once("auth.inc");
69

    
70
$pgtitle = array(gettext("System"), gettext("Authentication Servers"));
71
$shortcut_section = "authentication";
72

    
73
if (is_numericint($_GET['id'])) {
74
	$id = $_GET['id'];
75
}
76
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
77
	$id = $_POST['id'];
78
}
79

    
80
if (!is_array($config['system']['authserver'])) {
81
	$config['system']['authserver'] = array();
82
}
83

    
84
$a_servers = auth_get_authserver_list();
85
foreach ($a_servers as $servers) {
86
	$a_server[] = $servers;
87
}
88

    
89
if (!is_array($config['ca'])) {
90
	$config['ca'] = array();
91
}
92
$a_ca =& $config['ca'];
93

    
94
$act = $_GET['act'];
95
if ($_POST['act']) {
96
	$act = $_POST['act'];
97
}
98

    
99
if ($act == "del") {
100

    
101
	if (!$a_server[$_GET['id']]) {
102
		pfSenseHeader("system_authservers.php");
103
		exit;
104
	}
105

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

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

    
117
	$savemsg = gettext("Authentication Server") . " " . htmlspecialchars($serverdeleted) . " " . gettext("deleted") . "<br />";
118
	write_config($savemsg);
119
}
120

    
121
if ($act == "edit") {
122
	if (isset($id) && $a_server[$id]) {
123

    
124
		$pconfig['type'] = $a_server[$id]['type'];
125
		$pconfig['name'] = $a_server[$id]['name'];
126

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

    
149
			if (!$pconfig['ldap_binddn'] || !$pconfig['ldap_bindpw']) {
150
				$pconfig['ldap_anon'] = true;
151
			}
152
		}
153

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

    
161
			if ($pconfig['radius_auth_port'] &&
162
				$pconfig['radius_acct_port']) {
163
				$pconfig['radius_srvcs'] = "both";
164
			}
165

    
166
			if ($pconfig['radius_auth_port'] &&
167
				!$pconfig['radius_acct_port']) {
168
				$pconfig['radius_srvcs'] = "auth";
169
				$pconfig['radius_acct_port'] = 1813;
170
			}
171

    
172
			if (!$pconfig['radius_auth_port'] &&
173
				$pconfig['radius_acct_port']) {
174
				$pconfig['radius_srvcs'] = "acct";
175
				$pconfig['radius_auth_port'] = 1812;
176
			}
177

    
178
		}
179
	}
180
}
181

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

    
190
if ($_POST) {
191
	unset($input_errors);
192
	$pconfig = $_POST;
193

    
194
	/* input validation */
195

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

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

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

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

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

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

    
243
		if (!isset($id)) {
244
			$reqdfields[] = "radius_secret";
245
			$reqdfieldsn[] = gettext("Shared Secret");
246
		}
247
	}
248

    
249
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
250

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

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

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

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

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

    
279
		$server['type'] = $pconfig['type'];
280
		$server['name'] = $pconfig['name'];
281

    
282
		if ($server['type'] == "ldap") {
283

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

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

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

    
318

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

    
327
			if ($pconfig['ldap_timeout']) {
328
				$server['ldap_timeout'] = $pconfig['ldap_timeout'];
329
			} else {
330
				$server['ldap_timeout'] = 25;
331
			}
332
		}
333

    
334
		if ($server['type'] == "radius") {
335

    
336
			$server['host'] = $pconfig['radius_host'];
337

    
338
			if ($pconfig['radius_secret']) {
339
				$server['radius_secret'] = $pconfig['radius_secret'];
340
			}
341

    
342
			if ($pconfig['radius_timeout']) {
343
				$server['radius_timeout'] = $pconfig['radius_timeout'];
344
			} else {
345
				$server['radius_timeout'] = 5;
346
			}
347

    
348
			if ($pconfig['radius_srvcs'] == "both") {
349
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
350
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
351
			}
352

    
353
			if ($pconfig['radius_srvcs'] == "auth") {
354
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
355
				unset($server['radius_acct_port']);
356
			}
357

    
358
			if ($pconfig['radius_srvcs'] == "acct") {
359
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
360
				unset($server['radius_auth_port']);
361
			}
362
		}
363

    
364
		if (isset($id) && $config['system']['authserver'][$id]) {
365
			$config['system']['authserver'][$id] = $server;
366
		} else {
367
			$config['system']['authserver'][] = $server;
368
		}
369

    
370
		write_config();
371

    
372
		pfSenseHeader("system_authservers.php");
373
	}
374
}
375

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

    
383
include("head.inc");
384

    
385
if ($input_errors)
386
	print_input_errors($input_errors);
387

    
388
if ($savemsg)
389
	print_info_box($savemsg, 'success');
390

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

    
398
if (!($act == "new" || $act == "edit" || $input_errors))
399
{
400
	?>
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

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

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

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

    
450
$section = new Form_Section('Server settings');
451

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

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

    
466
$form->add($section);
467

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

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

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

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

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

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

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

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

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

    
534
$group = new Form_Group('Search scope');
535

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

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

    
550

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

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

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

    
571
$section->add($group);
572

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

    
580
$group = new Form_Group('Query');
581
$group->addClass('extended');
582

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

    
590
$section->add($group);
591

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

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

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

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

    
617
if (!isset($id)) {
618
	$template_list = array();
619

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

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

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

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

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

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

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

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

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

    
686
$form->add($section);
687

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
826
	// ---------- On initial page load ------------------------------------------------------------
827

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

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

    
836
	if($('#ldap_port').val() == "")
837
		set_ldap_port();
838

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

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

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

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

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

    
868
	$('#Select').click(function () {
869
		select_clicked();
870
	});
871

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

    
876
});
877
//]]>
878
</script>
879
<?php
880
include("foot.inc");
(191-191/228)