Project

General

Profile

Download (24.7 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
if (is_numericint($_GET['id'])) {
68
	$id = $_GET['id'];
69
}
70
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
71
	$id = $_POST['id'];
72
}
73

    
74
if (!is_array($config['system']['authserver'])) {
75
	$config['system']['authserver'] = array();
76
}
77

    
78
$a_servers = auth_get_authserver_list();
79
foreach ($a_servers as $servers) {
80
	$a_server[] = $servers;
81
}
82

    
83
if (!is_array($config['ca'])) {
84
	$config['ca'] = array();
85
}
86
$a_ca =& $config['ca'];
87

    
88
$act = $_GET['act'];
89
if ($_POST['act']) {
90
	$act = $_POST['act'];
91
}
92

    
93
if ($act == "del") {
94

    
95
	if (!$a_server[$_GET['id']]) {
96
		pfSenseHeader("system_authservers.php");
97
		exit;
98
	}
99

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

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

    
111
	$savemsg = sprintf(gettext("Authentication Server %s deleted."), htmlspecialchars($serverdeleted));
112
	write_config($savemsg);
113
}
114

    
115
if ($act == "edit") {
116
	if (isset($id) && $a_server[$id]) {
117

    
118
		$pconfig['type'] = $a_server[$id]['type'];
119
		$pconfig['name'] = $a_server[$id]['name'];
120

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

    
143
			if (!$pconfig['ldap_binddn'] || !$pconfig['ldap_bindpw']) {
144
				$pconfig['ldap_anon'] = true;
145
			}
146
		}
147

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

    
155
			if ($pconfig['radius_auth_port'] &&
156
				$pconfig['radius_acct_port']) {
157
				$pconfig['radius_srvcs'] = "both";
158
			}
159

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

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

    
172
		}
173
	}
174
}
175

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

    
184
if ($_POST) {
185
	unset($input_errors);
186
	$pconfig = $_POST;
187

    
188
	/* input validation */
189

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

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

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

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

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

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

    
237
		if (!isset($id)) {
238
			$reqdfields[] = "radius_secret";
239
			$reqdfieldsn[] = gettext("Shared Secret");
240
		}
241
	}
242

    
243
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
244

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

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

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

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

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

    
273
		$server['type'] = $pconfig['type'];
274
		$server['name'] = $pconfig['name'];
275

    
276
		if ($server['type'] == "ldap") {
277

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

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

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

    
312

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

    
321
			if ($pconfig['ldap_timeout']) {
322
				$server['ldap_timeout'] = $pconfig['ldap_timeout'];
323
			} else {
324
				$server['ldap_timeout'] = 25;
325
			}
326
		}
327

    
328
		if ($server['type'] == "radius") {
329

    
330
			$server['host'] = $pconfig['radius_host'];
331

    
332
			if ($pconfig['radius_secret']) {
333
				$server['radius_secret'] = $pconfig['radius_secret'];
334
			}
335

    
336
			if ($pconfig['radius_timeout']) {
337
				$server['radius_timeout'] = $pconfig['radius_timeout'];
338
			} else {
339
				$server['radius_timeout'] = 5;
340
			}
341

    
342
			if ($pconfig['radius_srvcs'] == "both") {
343
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
344
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
345
			}
346

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

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

    
358
		if (isset($id) && $config['system']['authserver'][$id]) {
359
			$config['system']['authserver'][$id] = $server;
360
		} else {
361
			$config['system']['authserver'][] = $server;
362
		}
363

    
364
		write_config();
365

    
366
		pfSenseHeader("system_authservers.php");
367
	}
368
}
369

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

    
377
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Authentication Servers"));
378

    
379
if ($act == "new" || $act == "edit" || $input_errors) {
380
	$pgtitle[] = gettext('Edit');
381
}
382
$shortcut_section = "authentication";
383
include("head.inc");
384

    
385
if ($input_errors) {
386
	print_input_errors($input_errors);
387
}
388

    
389
if ($savemsg) {
390
	print_info_box($savemsg, 'success');
391
}
392

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

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

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

    
446
$form = new Form;
447
$form->setAction('system_authservers.php?act=edit');
448

    
449
$form->addGlobal(new Form_Input(
450
	'userid',
451
	null,
452
	'hidden',
453
	$id
454
));
455

    
456
$section = new Form_Section('Server Settings');
457

    
458
$section->addInput($input = new Form_Input(
459
	'name',
460
	'Descriptive name',
461
	'text',
462
	$pconfig['name']
463
));
464

    
465
$section->addInput($input = new Form_Select(
466
	'type',
467
	'Type',
468
	$pconfig['type'],
469
	$auth_server_types
470
))->toggles();
471

    
472
$form->add($section);
473

    
474
// ==== LDAP settings =========================================================
475
$section = new Form_Section('LDAP Server Settings');
476
$section->addClass('toggle-ldap collapse');
477

    
478
if (!isset($pconfig['type']) || $pconfig['type'] == 'ldap')
479
	$section->addClass('in');
480

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

    
489
$section->addInput(new Form_Input(
490
	'ldap_port',
491
	'Port value',
492
	'number',
493
	$pconfig['ldap_port']
494
));
495

    
496
$section->addInput(new Form_Select(
497
	'ldap_urltype',
498
	'Transport',
499
	$pconfig['ldap_urltype'],
500
	array_combine(array_keys($ldap_urltypes), array_keys($ldap_urltypes))
501
));
502

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

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

    
525
$section->addInput(new Form_Select(
526
	'ldap_protver',
527
	'Protocol version',
528
	$pconfig['ldap_protver'],
529
	array_combine($ldap_protvers, $ldap_protvers)
530
));
531

    
532
$section->addInput(new Form_Input(
533
	'ldap_timeout',
534
	'Server Timeout',
535
	'number',
536
	$pconfig['ldap_timeout'],
537
	['placeholder' => 25]
538
))->setHelp('Timeout for LDAP operations (seconds)');
539

    
540
$group = new Form_Group('Search scope');
541

    
542
$SSF = new Form_Select(
543
	'ldap_scope',
544
	'Level',
545
	$pconfig['ldap_scope'],
546
	$ldap_scopes
547
);
548

    
549
$SSB = new Form_Input(
550
	'ldap_basedn',
551
	'Base DN',
552
	'text',
553
	$pconfig['ldap_basedn']
554
);
555

    
556

    
557
$section->addInput(new Form_StaticText(
558
	'Search scope',
559
	'Level ' . $SSF . '<br />' . 'Base DN' . $SSB
560
));
561

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

    
572
$group->add(new Form_Button(
573
	'Select',
574
	'Select a container',
575
	null,
576
	'fa-search'
577
))->addClass('btn-info');
578

    
579
$section->add($group);
580

    
581
$section->addInput(new Form_Checkbox(
582
	'ldap_extended_enabled',
583
	'Extended query',
584
	'Enable extended query',
585
	$pconfig['ldap_extended_enabled']
586
));
587

    
588
$group = new Form_Group('Query');
589
$group->addClass('extended');
590

    
591
$group->add(new Form_Input(
592
	'ldap_extended_query',
593
	'Query',
594
	'text',
595
	$pconfig['ldap_extended_query']
596
))->setHelp('Example: &amp;(objectClass=inetOrgPerson)(mail=*@example.com)');
597

    
598
$section->add($group);
599

    
600
$section->addInput(new Form_Checkbox(
601
	'ldap_anon',
602
	'Bind anonymous',
603
	'Use anonymous binds to resolve distinguished names',
604
	$pconfig['ldap_anon']
605
));
606

    
607
$group = new Form_Group('Bind credentials');
608
$group->addClass('ldapanon');
609

    
610
$group->add(new Form_Input(
611
	'ldap_binddn',
612
	'User DN:',
613
	'text',
614
	$pconfig['ldap_binddn']
615
));
616

    
617
$group->add(new Form_Input(
618
	'ldap_bindpw',
619
	'Password',
620
	'text',
621
	$pconfig['ldap_bindpw']
622
));
623
$section->add($group);
624

    
625
if (!isset($id)) {
626
	$template_list = array();
627

    
628
	foreach($ldap_templates as $option => $template) {
629
		$template_list[$option] = $template['desc'];
630
	}
631

    
632
	$section->addInput(new Form_Select(
633
		'ldap_tmpltype',
634
		'Initial Template',
635
		$pconfig['ldap_template'],
636
		$template_list
637
	));
638
}
639

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

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

    
654
$section->addInput(new Form_Input(
655
	'ldap_attr_member',
656
	'Group member attribute',
657
	'text',
658
	$pconfig['ldap_attr_member']
659
));
660

    
661
$section->addInput(new Form_Checkbox(
662
	'ldap_rfc2307',
663
	'RFC 2307 Groups',
664
	'LDAP Server uses RFC 2307 style group membership',
665
	$pconfig['ldap_rfc2307']
666
))->setHelp('RFC 2307 style group membership has members listed on the group '.
667
	'object rather than using groups listed on user object. Leave unchecked '.
668
	'for Active Directory style group membership (RFC 2307bis).');
669

    
670
$section->addInput(new Form_Input(
671
	'ldap_attr_groupobj',
672
	'Group Object Class',
673
	'text',
674
	$pconfig['ldap_attr_groupobj'],
675
	['placeholder' => 'posixGroup']
676
))->setHelp('Object class used for groups in RFC2307 mode. '.
677
	'Typically "posixGroup" or "group".');
678

    
679
$section->addInput(new Form_Checkbox(
680
	'ldap_utf8',
681
	'UTF8 Encode',
682
	'UTF8 encode LDAP parameters before sending them to the server.',
683
	$pconfig['ldap_utf8']
684
))->setHelp('Required to support international characters, but may not be '.
685
	'supported by every LDAP server.');
686

    
687
$section->addInput(new Form_Checkbox(
688
	'ldap_nostrip_at',
689
	'Username Alterations',
690
	'Do not strip away parts of the username after the @ symbol',
691
	$pconfig['ldap_nostrip_at']
692
))->setHelp('e.g. user@host becomes user when unchecked.');
693

    
694
$form->add($section);
695

    
696
// ==== RADIUS section ========================================================
697
$section = new Form_Section('RADIUS Server Settings');
698
$section->addClass('toggle-radius collapse');
699

    
700
$section->addInput(new Form_Input(
701
	'radius_host',
702
	'Hostname or IP address',
703
	'text',
704
	$pconfig['radius_host']
705
));
706

    
707
$section->addInput(new Form_Input(
708
	'radius_secret',
709
	'Shared Secret',
710
	'text',
711
	$pconfig['radius_secret']
712
));
713

    
714
$section->addInput(new Form_Select(
715
	'radius_srvcs',
716
	'Services offered',
717
	$pconfig['radius_srvcs'],
718
	$radius_srvcs
719
));
720

    
721
$section->addInput(new Form_Input(
722
	'radius_auth_port',
723
	'Authentication port',
724
	'number',
725
	$pconfig['radius_auth_port']
726
));
727

    
728
$section->addInput(new Form_Input(
729
	'radius_acct_port',
730
	'Accounting port',
731
	'number',
732
	$pconfig['radius_acct_port']
733
));
734

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

    
746
if (isset($id) && $a_server[$id])
747
{
748
	$section->addInput(new Form_Input(
749
		'id',
750
		null,
751
		'hidden',
752
		$id
753
	));
754
}
755

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

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

    
795
		var oWin = window.open(url, "pfSensePop", "width=620,height=400,top=150,left=150");
796
		if (oWin == null || typeof(oWin) == "undefined") {
797
			alert("<?=gettext('Popup blocker detected.	Action aborted.');?>");
798
		}
799
	}
800

    
801
	function set_ldap_port() {
802
		if($('#ldap_urltype').find(":selected").index() == 0)
803
			$('#ldap_port').val('389');
804
		else
805
			$('#ldap_port').val('636');
806
	}
807

    
808
	// Hides all elements of the specified class. This will usually be a section
809
	function hideClass(s_class, hide) {
810
		if(hide)
811
			$('.' + s_class).hide();
812
		else
813
			$('.' + s_class).show();
814
	}
815

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

    
834
	// ---------- On initial page load ------------------------------------------------------------
835

    
836
<?php if ($act != 'edit') : ?>
837
	ldap_tmplchange();
838
<?php endif; ?>
839

    
840
	hideClass('ldapanon', $('#ldap_anon').prop('checked'));
841
	$("#Select").prop('type','button');
842
	hideClass('extended', !$('#ldap_extended_enabled').prop('checked'));
843

    
844
	if($('#ldap_port').val() == "")
845
		set_ldap_port();
846

    
847
<?php
848
	if($act == 'edit') {
849
?>
850
		$('#type option:not(:selected)').each(function(){
851
			$(this).attr('disabled', 'disabled');
852
		});
853

    
854
<?php
855
		if(!$input_errors) {
856
?>
857
		$('#name').prop("readonly", true);
858
<?php
859
		}
860
	}
861
?>
862
	// ---------- Click checkbox handlers ---------------------------------------------------------
863

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

    
868
	$('#ldap_anon').click(function () {
869
		hideClass('ldapanon', this.checked);
870
	});
871

    
872
	$('#ldap_urltype').on('change', function() {
873
		set_ldap_port();
874
	});
875

    
876
	$('#Select').click(function () {
877
		select_clicked();
878
	});
879

    
880
	$('#ldap_extended_enabled').click(function () {
881
		hideClass('extended', !this.checked);
882
	});
883

    
884
});
885
//]]>
886
</script>
887
<?php
888
include("foot.inc");
(192-192/227)