Project

General

Profile

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

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

    
69
require("guiconfig.inc");
70
require_once("auth.inc");
71

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

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

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

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

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

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

    
101
if ($act == "del") {
102

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

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

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

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

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

    
126
		$pconfig['type'] = $a_server[$id]['type'];
127
		$pconfig['name'] = $a_server[$id]['name'];
128

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

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

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

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

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

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

    
177
		}
178
	}
179
}
180

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

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

    
193
	/* input validation */
194

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

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

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

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

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

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

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

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

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

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

    
258
	if (($pconfig['type'] == "radius") && isset($_POST['radius_timeout']) && !empty($_POST['radius_timeout']) && (!is_numeric($_POST['radius_timeout']) || (is_numeric($_POST['radius_timeout']) && ($_POST['radius_timeout'] <= 0)))) {
259
		$input_errors[] = gettext("RADIUS Timeout value must be numeric and positive.");
260
	}
261

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

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

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

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

    
280
			if (!empty($pconfig['ldap_caref'])) {
281
				$server['ldap_caref'] = $pconfig['ldap_caref'];
282
			}
283
			$server['host'] = $pconfig['ldap_host'];
284
			$server['ldap_port'] = $pconfig['ldap_port'];
285
			$server['ldap_urltype'] = $pconfig['ldap_urltype'];
286
			$server['ldap_protver'] = $pconfig['ldap_protver'];
287
			$server['ldap_scope'] = $pconfig['ldap_scope'];
288
			$server['ldap_basedn'] = $pconfig['ldap_basedn'];
289
			$server['ldap_authcn'] = $pconfig['ldapauthcontainers'];
290
			$server['ldap_extended_enabled'] = $pconfig['ldap_extended_enabled'];
291
			$server['ldap_extended_query'] = $pconfig['ldap_extended_query'];
292
			$server['ldap_attr_user'] = $pconfig['ldap_attr_user'];
293
			$server['ldap_attr_group'] = $pconfig['ldap_attr_group'];
294
			$server['ldap_attr_member'] = $pconfig['ldap_attr_member'];
295
			if ($pconfig['ldap_utf8'] == "yes") {
296
				$server['ldap_utf8'] = true;
297
			} else {
298
				unset($server['ldap_utf8']);
299
			}
300
			if ($pconfig['ldap_nostrip_at'] == "yes") {
301
				$server['ldap_nostrip_at'] = true;
302
			} else {
303
				unset($server['ldap_nostrip_at']);
304
			}
305

    
306

    
307
			if (!$pconfig['ldap_anon']) {
308
				$server['ldap_binddn'] = $pconfig['ldap_binddn'];
309
				$server['ldap_bindpw'] = $pconfig['ldap_bindpw'];
310
			} else {
311
				unset($server['ldap_binddn']);
312
				unset($server['ldap_bindpw']);
313
			}
314
		}
315

    
316
		if ($server['type'] == "radius") {
317

    
318
			$server['host'] = $pconfig['radius_host'];
319

    
320
			if ($pconfig['radius_secret']) {
321
				$server['radius_secret'] = $pconfig['radius_secret'];
322
			}
323

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

    
330
			if ($pconfig['radius_srvcs'] == "both") {
331
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
332
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
333
			}
334

    
335
			if ($pconfig['radius_srvcs'] == "auth") {
336
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
337
				unset($server['radius_acct_port']);
338
			}
339

    
340
			if ($pconfig['radius_srvcs'] == "acct") {
341
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
342
				unset($server['radius_auth_port']);
343
			}
344
		}
345

    
346
		if (isset($id) && $config['system']['authserver'][$id]) {
347
			$config['system']['authserver'][$id] = $server;
348
		} else {
349
			$config['system']['authserver'][] = $server;
350
		}
351

    
352
		write_config();
353

    
354
		pfSenseHeader("system_authservers.php");
355
	}
356
	else {
357
		$pconfig = $_POST;	// Restore the form contents so the user doesn't have to re-eneter it
358
	}
359
}
360

    
361
include("head.inc");
362

    
363
if ($input_errors)
364
	print_input_errors($input_errors);
365

    
366
if ($savemsg)
367
	print_info_box($savemsg, 'success');
368

    
369
$tab_array = array();
370
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
371
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
372
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
373
$tab_array[] = array(gettext("Servers"), true, "system_authservers.php");
374
display_top_tabs($tab_array);
375

    
376
if (!($act == "new" || $act == "edit" || $input_errors))
377
{
378
	?>
379
	<div class="table-responsive">
380
		<table class="table table-striped table-hover">
381
			<thead>
382
				<tr>
383
					<th><?=gettext("Server Name")?></th>
384
					<th><?=gettext("Type")?></th>
385
					<th><?=gettext("Host Name")?></th>
386
					<th></th>
387
				</tr>
388
			</thead>
389
			<tbody>
390
		<?php foreach($a_server as $i => $server): ?>
391
				<tr>
392
					<td><?=htmlspecialchars($server['name'])?></td>
393
					<td><?=htmlspecialchars($auth_server_types[$server['type']])?></td>
394
					<td><?=htmlspecialchars($server['host'])?></td>
395
					<td>
396
					<?php if ($i < (count($a_server) - 1)): ?>
397
						<a href="system_authservers.php?act=edit&amp;id=<?=$i?>" class="btn btn-xs btn-primary">edit</a>
398
						<a href="system_authservers.php?act=del&amp;id=<?=$i?>" class="btn btn-xs btn-danger">delete</a>
399
					<?php endif?>
400
					</td>
401
				</tr>
402
		<?php endforeach; ?>
403
			</tbody>
404
		</table>
405
	</div>
406

    
407
	<nav class="action-buttons">
408
		<a href="?act=new" class="btn btn-success">add new</a>
409
	</nav>
410
<?php
411
	include("foot.inc");
412
	exit;
413
}
414

    
415
require_once('classes/Form.class.php');
416
$form = new Form;
417
$form->setAction('system_authservers.php?act=edit');
418

    
419
$form->addGlobal(new Form_Input(
420
	'userid',
421
	null,
422
	'hidden',
423
	$id
424
));
425

    
426
$section = new Form_Section('Server settings');
427

    
428
$section->addInput($input = new Form_Input(
429
	'name',
430
	'Descriptive name',
431
	'text',
432
	$pconfig['name']
433
));
434

    
435
$section->addInput($input = new Form_Select(
436
	'type',
437
	'Type',
438
	$pconfig['type'],
439
	$auth_server_types
440
))->toggles();
441

    
442
$form->add($section);
443

    
444
// ==== LDAP settings =========================================================
445
$section = new Form_Section('LDAP Server Settings');
446
$section->addClass('toggle-ldap collapse');
447

    
448
if (!isset($pconfig['type']) || $pconfig['type'] == 'ldap')
449
	$section->addClass('in');
450

    
451
$section->addInput(new Form_Input(
452
	'ldap_host',
453
	'Hostname or IP address',
454
	'text',
455
	$pconfig['ldap_host']
456
))->setHelp('NOTE: When using SSL, this hostname MUST match the Common Name '.
457
	'(CN) of the LDAP server\'s SSL Certificate.');
458

    
459
$section->addInput(new Form_Input(
460
	'ldap_port',
461
	'Port value',
462
	'number',
463
	$pconfig['ldap_port']
464
));
465

    
466
$section->addInput(new Form_Select(
467
	'ldap_urltype',
468
	'Transport',
469
	$pconfig['ldap_urltype'],
470
	array_combine(array_keys($ldap_urltypes), array_keys($ldap_urltypes))
471
));
472

    
473
if (empty($a_ca))
474
{
475
	$section->addInput(new Form_StaticText(
476
		'Peer Certificate Authority',
477
		'No Certificate Authorities defined.<br/>Create one under <a href="system_camanager.php">System &gt; Cert Manager</a>.'
478
	));
479
}
480
else
481
{
482
	$ldapCaRef = [];
483
	foreach ($a_ca as $ca)
484
		$ldapCaRef[ $ca['refid'] ] = $ca['descr'];
485

    
486
	$section->addInput(new Form_Select(
487
		'ldap_caref',
488
		'Peer Certificate Authority',
489
		$pconfig['ldap_caref'],
490
		$ldapCaRef
491
	))->setHelp('This option is used if \'SSL Encrypted\' option is choosen. '.
492
		'It must match with the CA in the AD otherwise problems will arise.');
493
}
494

    
495
$section->addInput(new Form_Select(
496
	'ldap_protver',
497
	'Protocol version',
498
	$pconfig['ldap_protver'],
499
	array_combine($ldap_protvers, $ldap_protvers)
500
));
501

    
502
$group = new Form_Group('Search scope');
503

    
504
$SSF = new Form_Select(
505
	'ldap_scope',
506
	'Level',
507
	$pconfig['ldap_scope'],
508
	$ldap_scopes
509
);
510

    
511
$SSB = new Form_Input(
512
	'ldap_basedn',
513
	'Base DN',
514
	'text',
515
	$pconfig['ldap_basedn']
516
);
517

    
518

    
519
$section->addInput(new Form_StaticText(
520
	'Search scope',
521
	'Level ' . $SSF . '<br />' . 'Base DN' . $SSB
522
));
523

    
524
$group = new Form_Group('Authentication containers');
525
$group->add(new Form_Input(
526
	'ldapauthcontainers',
527
	'Containers',
528
	'text',
529
	$pconfig['ldap_authcn']
530
))->setHelp('Note: Semi-Colon separated. This will be prepended to the search '.
531
	'base dn above or you can specify full container path containing a dc= '.
532
	'component.<br/>Example: CN=Users;DC=example,DC=com or OU=Staff;OU=Freelancers');
533
#FIXME
534
$group->add(new Form_Button(
535
	'Select',
536
	'Select a container'
537
//	'/system_usermanager_settings_ldapacpicker.php?port=389&host=192.168.1.1&scope=one&basedn=CN=pfsense&binddn=&bindpw=&urltype=TCP%20-%20Standard&proto=3&authcn=OU=Staff&cert='
538
))->removeClass('btn-primary')->addClass('btn-default');
539

    
540
$section->add($group);
541

    
542
$section->addInput(new Form_Checkbox(
543
	'ldap_extended_enabled',
544
	'Extended query',
545
	'Enable extended query',
546
	$pconfig['ldap_extended_enabled']
547
));
548

    
549
$group = new Form_Group('Query');
550
$group->addClass('extended');
551

    
552
$group->add(new Form_Input(
553
	'ldap_extended_query',
554
	'Query',
555
	'text',
556
	$pconfig['ldap_extended_query']
557
))->setHelp('Example: &amp;(objectClass=inetOrgPerson)(mail=*@example.com)');
558

    
559
$section->add($group);
560

    
561
$section->addInput(new Form_Checkbox(
562
	'ldap_anon',
563
	'Bind anonymous',
564
	'Use anonymous binds to resolve distinguished names',
565
	$pconfig['ldap_anon']
566
));
567

    
568
$group = new Form_Group('Bind credentials');
569
$group->addClass('ldapanon');
570

    
571
$group->add(new Form_Input(
572
	'ldap_binddn',
573
	'User DN:',
574
	'text',
575
	$pconfig['ldap_binddn']
576
));
577

    
578
$group->add(new Form_Input(
579
	'ldap_bindpw',
580
	'Password',
581
	'text',
582
	$pconfig['ldap_bindpw']
583
));
584
$section->add($group);
585

    
586
if (!isset($id)) {
587
	$template_list = array();
588

    
589
	foreach($ldap_templates as $option => $template) {
590
		$template_list[$option] = $template['desc'];
591
	}
592

    
593
	$section->addInput(new Form_Select(
594
		'ldap_tmpltype',
595
		'Initial Template',
596
		$pconfig['ldap_template'],
597
		$template_list
598
	));
599
}
600

    
601
$section->addInput(new Form_Input(
602
	'ldap_attr_user',
603
	'User naming attribute',
604
	'text',
605
	$pconfig['ldap_attr_user']
606
));
607

    
608
$section->addInput(new Form_Input(
609
	'ldap_attr_group',
610
	'Group naming attribute',
611
	'text',
612
	$pconfig['ldap_attr_group']
613
));
614

    
615
$section->addInput(new Form_Input(
616
	'ldap_attr_member',
617
	'Group member attribute',
618
	'text',
619
	$pconfig['ldap_attr_member']
620
));
621

    
622
$section->addInput(new Form_Checkbox(
623
	'ldap_utf8',
624
	'UTF8 Encode',
625
	'UTF8 encode LDAP parameters before sending them to the server.',
626
	$pconfig['ldap_utf8']
627
))->setHelp('Required to support international characters, but may not be '.
628
	'supported by every LDAP server.');
629

    
630
$section->addInput(new Form_Checkbox(
631
	'ldap_nostrip_at',
632
	'Username Alterations',
633
	'Do not strip away parts of the username after the @ symbol',
634
	$pconfig['ldap_nostrip_at']
635
))->setHelp('e.g. user@host becomes user when unchecked.');
636

    
637
$form->add($section);
638

    
639
// ==== RADIUS section ========================================================
640
$section = new Form_Section('Radius Server Settings');
641
$section->addClass('toggle-radius collapse');
642

    
643
$section->addInput(new Form_Input(
644
	'radius_host',
645
	'Hostname or IP address',
646
	'text',
647
	$pconfig['radius_host']
648
));
649

    
650
$section->addInput(new Form_Input(
651
	'radius_secret',
652
	'Shared Secret',
653
	'text',
654
	$pconfig['radius_secret']
655
));
656

    
657
$section->addInput(new Form_Select(
658
	'radius_srvcs',
659
	'Services offered',
660
	$pconfig['radius_srvcs'],
661
	$radius_srvcs
662
));
663

    
664
$section->addInput(new Form_Input(
665
	'radius_auth_port',
666
	'Authentication port',
667
	'number',
668
	$pconfig['radius_auth_port']
669
));
670

    
671
$section->addInput(new Form_Input(
672
	'radius_acct_port',
673
	'Accounting port',
674
	'number',
675
	$pconfig['radius_acct_port']
676
));
677

    
678
$section->addInput(new Form_Input(
679
	'radius_timeout',
680
	'Authentication Timeout',
681
	'number',
682
	$pconfig['radius_timeout']
683
))->setHelp('This value controls how long, in seconds, that the RADIUS '.
684
	'server may take to respond to an authentication request. If left blank, the '.
685
	'default value is 5 seconds. NOTE: If you are using an interactive two-factor '.
686
	'authentication system, increase this timeout to account for how long it will '.
687
	'take the user to receive and enter a token.');
688

    
689
if (isset($id) && $a_server[$id])
690
{
691
	$section->addInput(new Form_Input(
692
		'id',
693
		null,
694
		'hidden',
695
		$id
696
	));
697
}
698

    
699
$form->add($section);
700
print $form;
701
?>
702
<script>
703
//<![CDATA[
704
events.push(function(){
705
	function select_clicked() {
706
		if (document.getElementById("ldap_port").value == '' ||
707
			document.getElementById("ldap_host").value == '' ||
708
			document.getElementById("ldap_scope").value == '' ||
709
			document.getElementById("ldap_basedn").value == '' ||
710
			document.getElementById("ldapauthcontainers").value == '') {
711
			alert("<?=gettext("Please fill the required values.");?>");
712
			return;
713
		}
714

    
715
		if (!document.getElementById("ldap_anon").checked) {
716
			if (document.getElementById("ldap_binddn").value == '' ||
717
				document.getElementById("ldap_bindpw").value == '') {
718
				alert("<?=gettext("Please fill the bind username/password.");?>");
719
				return;
720
			}
721
		}
722
		var url = 'system_usermanager_settings_ldapacpicker.php?';
723
		url += 'port=' + document.getElementById("ldap_port").value;
724
		url += '&host=' + document.getElementById("ldap_host").value;
725
		url += '&scope=' + document.getElementById("ldap_scope").value;
726
		url += '&basedn=' + document.getElementById("ldap_basedn").value;
727
		url += '&binddn=' + document.getElementById("ldap_binddn").value;
728
		url += '&bindpw=' + document.getElementById("ldap_bindpw").value;
729
		url += '&urltype=' + document.getElementById("ldap_urltype").value;
730
		url += '&proto=' + document.getElementById("ldap_protver").value;
731
		url += '&authcn=' + document.getElementById("ldapauthcontainers").value;
732
		<?php if (count($a_ca) > 0): ?>
733
			url += '&cert=' + document.getElementById("ldap_caref").value;
734
		<?php else: ?>
735
			url += '&cert=';
736
		<?php endif; ?>
737

    
738
		var oWin = window.open(url, "pfSensePop", "width=620,height=400,top=150,left=150");
739
		if (oWin == null || typeof(oWin) == "undefined") {
740
			alert("<?=gettext('Popup blocker detected.	Action aborted.');?>");
741
		}
742
	}
743

    
744
	function set_ldap_port() {
745
		if($('#ldap_urltype').find(":selected").index() == 0)
746
			$('#ldap_port').val('389');
747
		else
748
			$('#ldap_port').val('636');
749
	}
750

    
751
	// Hides all elements of the specified class. This will usually be a section
752
	function hideClass(s_class, hide) {
753
		if(hide)
754
			$('.' + s_class).hide();
755
		else
756
			$('.' + s_class).show();
757
	}
758

    
759
	function ldap_tmplchange() {
760
		switch ($('#ldap_tmpltype').find(":selected").index()) {
761
<?php
762
		$index = 0;
763
		foreach ($ldap_templates as $tmpldata):
764
?>
765
			case <?=$index;?>:
766
				$('#ldap_attr_user').val("<?=$tmpldata['attr_user'];?>");
767
				$('#ldap_attr_group').val("<?=$tmpldata['attr_group'];?>");
768
				$('#ldap_attr_member').val("<?=$tmpldata['attr_member'];?>");
769
				break;
770
<?php
771
			$index++;
772
		endforeach;
773
?>
774
		}
775
	}
776

    
777
	// On page load . .
778
	ldap_tmplchange();
779
	hideClass('ldapanon', $('#ldap_anon').prop('checked'));
780
	$("#Select").prop('type','button');
781
	hideClass('extended', !$('#ldap_extended_enabled').prop('checked'));
782

    
783
	if($('#ldap_port').val() == "")
784
		set_ldap_port();
785

    
786
<?php
787
	if($act == 'edit') {
788
?>
789
		$('#type option:not(:selected)').each(function(){
790
			$(this).attr('disabled', 'disabled');
791
		});
792

    
793
<?php
794
		if(!$input_errors) {
795
?>
796
		$('#name').prop("readonly", true);
797
<?php
798
		}
799
	}
800
?>
801
	// On click . .
802
	$('#ldap_tmpltype').on('change', function() {
803
		ldap_tmplchange();
804
	});
805

    
806
	$('#ldap_anon').click(function () {
807
		hideClass('ldapanon', this.checked);
808
	});
809

    
810
	$('#ldap_urltype').on('change', function() {
811
		set_ldap_port();
812
	});
813

    
814
	$('#Select').click(function () {
815
		select_clicked();
816
	});
817
	
818
	$('#ldap_extended_enabled').click(function () {
819
		hideClass('extended', !this.checked);
820
	});
821
	
822
});
823
//]]>
824
</script>
825
<?php
826
include("foot.inc");
(194-194/238)