Project

General

Profile

Download (22.5 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
		$reqdfieldsn = array(
201
			gettext("Descriptive name"),
202
			gettext("Type"),
203
			gettext("Hostname or IP"),
204
			gettext("Port value"),
205
			gettext("Transport"),
206
			gettext("Protocol version"),
207
			gettext("Search level"),
208
			gettext("User naming Attribute"),
209
			gettext("Group naming Attribute"),
210
			gettext("Group member attribute"),
211
			gettext("Authentication container"));
212

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

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

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

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

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

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

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

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

    
257
	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)))) {
258
		$input_errors[] = gettext("RADIUS Timeout value must be numeric and positive.");
259
	}
260

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

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

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

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

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

    
305

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

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

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

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

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

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

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

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

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

    
351
		write_config();
352

    
353
		pfSenseHeader("system_authservers.php");
354
	}
355
}
356

    
357
include("head.inc");
358

    
359
if ($input_errors)
360
	print_input_errors($input_errors);
361
	
362
if ($savemsg)
363
	print_info_box($savemsg, 'success');
364

    
365
$tab_array = array();
366
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
367
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
368
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
369
$tab_array[] = array(gettext("Servers"), true, "system_authservers.php");
370
display_top_tabs($tab_array);
371

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

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

    
411
require_once('classes/Form.class.php');
412
$form = new Form;
413
$form->setAction('system_authservers.php?act=edit');
414

    
415
$form->addGlobal(new Form_Input(
416
	'userid',
417
	null,
418
	'hidden',
419
	$id
420
));
421

    
422
$section = new Form_Section('Server settings');
423

    
424
$section->addInput($input = new Form_Input(
425
	'name',
426
	'Descriptive name',
427
	'text',
428
	$pconfig['name']
429
));
430

    
431
$section->addInput($input = new Form_Select(
432
	'type',
433
	'Type',
434
	$pconfig['type'],
435
	$auth_server_types
436
))->toggles();
437

    
438
$form->add($section);
439

    
440
// ==== LDAP settings =========================================================
441
$section = new Form_Section('LDAP Server Settings');
442
$section->addClass('toggle-ldap collapse');
443

    
444
if (!isset($pconfig['type']) || $pconfig['type'] == 'ldap')
445
	$section->addClass('in');
446

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

    
455
$section->addInput(new Form_Input(
456
	'ldap_port',
457
	'Port value',
458
	'number',
459
	$pconfig['ldap_port']
460
));
461

    
462
$section->addInput(new Form_Select(
463
	'ldap_urltype',
464
	'Transport',
465
	$pconfig['ldap_urltype'],
466
	array_combine(array_keys($ldap_urltypes), array_keys($ldap_urltypes))
467
));
468

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

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

    
491
$section->addInput(new Form_Select(
492
	'ldap_protver',
493
	'Protocol version',
494
	$pconfig['ldap_protver'],
495
	array_combine($ldap_protvers, $ldap_protvers)
496
));
497

    
498
$group = new Form_Group('Search scope');
499

    
500
$SSF = new Form_Select(
501
	'ldap_scope',
502
	'Level',
503
	$pconfig['ldap_scope'],
504
	$ldap_scopes
505
);
506

    
507
$SSB = new Form_Input(
508
	'ldap_basedn',
509
	'Base DN',
510
	'text',
511
	$pconfig['ldap_basedn']
512
);
513

    
514

    
515
$section->addInput(new Form_StaticText(
516
	'Search scope',
517
	'Level ' . $SSF . '<br />' . 'Base DN' . $SSB
518
));
519

    
520
$group = new Form_Group('Authentication containers');
521
$group->add(new Form_Input(
522
	'ldapauthcontainers',
523
	'Containers',
524
	'text',
525
	$pconfig['ldap_authcn']
526
))->setHelp('Note: Semi-Colon separated. This will be prepended to the search '.
527
	'base dn above or you can specify full container path containing a dc= '.
528
	'component.<br/>Example: CN=Users;DC=example,DC=com or OU=Staff;OU=Freelancers');
529
#FIXME
530
$group->add(new Form_Button(
531
	'Select',
532
	'Select a container'
533
//	'/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='
534
))->removeClass('btn-primary')->addClass('btn-default');
535

    
536
$section->add($group);
537

    
538
$section->addInput(new Form_Checkbox(
539
	'ldap_extended_enabled',
540
	'Extended query',
541
	'Enable extended query',
542
	$pconfig['ldap_extended_enabled']
543
))->toggles('.toggle-extended');
544

    
545
$group = new Form_Group('Query');
546
$group->addClass('toggle-extended collapse');
547
$group->add(new Form_Input(
548
	'ldap_extended_query',
549
	'Query',
550
	'text',
551
	$pconfig['ldap_extended_query']
552
))->setHelp('Example: &amp;(objectClass=inetOrgPerson)(mail=*@example.com)');
553

    
554
$section->add($group);
555

    
556
$section->addInput(new Form_Checkbox(
557
	'ldap_anon',
558
	'Bind anonymous',
559
	'Use anonymous binds to resolve distinguished names',
560
	$pconfig['ldap_anon']
561
));
562

    
563
$group = new Form_Group('Bind credentials');
564
$group->addClass('ldapanon');
565

    
566
$group->add(new Form_Input(
567
	'ldap_binddn',
568
	'User DN:',
569
	'text',
570
	$pconfig['ldap_binddn']
571
));
572

    
573
$group->add(new Form_Input(
574
	'ldap_bindpw',
575
	'Password',
576
	'text',
577
	$pconfig['ldap_bindpw']
578
));
579
$section->add($group);
580

    
581
if (!isset($id)) {
582
	$template_list = array();
583

    
584
	foreach($ldap_templates as $option => $template) {
585
		$template_list[$option] = $template['desc'];
586
	}
587

    
588
	$section->addInput(new Form_Select(
589
		'ldap_tmpltype',
590
		'Initial Template',
591
		$pconfig['ldap_template'],
592
		$template_list
593
	));
594
}
595

    
596
$section->addInput(new Form_Input(
597
	'ldap_attr_user',
598
	'User naming attribute',
599
	'text',
600
	$pconfig['ldap_attr_user']
601
));
602

    
603
$section->addInput(new Form_Input(
604
	'ldap_attr_group',
605
	'Group naming attribute',
606
	'text',
607
	$pconfig['ldap_attr_group']
608
));
609

    
610
$section->addInput(new Form_Input(
611
	'ldap_attr_member',
612
	'Group member attribute',
613
	'text',
614
	$pconfig['ldap_attr_member']
615
));
616

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

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

    
632
$form->add($section);
633

    
634
// ==== RADIUS section ========================================================
635
$section = new Form_Section('Radius Server Settings');
636
$section->addClass('toggle-radius collapse');
637

    
638
$section->addInput(new Form_Input(
639
	'radius_host',
640
	'Hostname or IP address',
641
	'text',
642
	$pconfig['radius_host']
643
));
644

    
645
$section->addInput(new Form_Input(
646
	'radius_secret',
647
	'Shared Secret',
648
	'text',
649
	$pconfig['radius_secret']
650
));
651

    
652
$section->addInput(new Form_Select(
653
	'radius_srvcs',
654
	'Services offered',
655
	$pconfig['radius_srvcs'],
656
	$radius_srvcs
657
));
658

    
659
$section->addInput(new Form_Input(
660
	'radius_auth_port',
661
	'Authentication port',
662
	'number',
663
	$pconfig['radius_auth_port']
664
));
665

    
666
$section->addInput(new Form_Input(
667
	'radius_acct_port',
668
	'Accounting port',
669
	'number',
670
	$pconfig['radius_acct_port']
671
));
672

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

    
684
if (isset($id) && $a_server[$id])
685
{
686
	$section->addInput(new Form_Input(
687
		'id',
688
		null,
689
		'hidden',
690
		$id
691
	));
692
}
693

    
694
$form->add($section);
695
print $form;
696
?>
697
<script>
698
//<![CDATA[
699
events.push(function(){
700
	function select_clicked() {
701
		if (document.getElementById("ldap_port").value == '' ||
702
		    document.getElementById("ldap_host").value == '' ||
703
		    document.getElementById("ldap_scope").value == '' ||
704
		    document.getElementById("ldap_basedn").value == '' ||
705
		    document.getElementById("ldapauthcontainers").value == '') {
706
			alert("<?=gettext("Please fill the required values.");?>");
707
			return;
708
		}
709
		
710
		if (!document.getElementById("ldap_anon").checked) {
711
			if (document.getElementById("ldap_binddn").value == '' ||
712
			    document.getElementById("ldap_bindpw").value == '') {
713
				alert("<?=gettext("Please fill the bind username/password.");?>");
714
				return;
715
			}
716
		}
717
		var url = 'system_usermanager_settings_ldapacpicker.php?';
718
		url += 'port=' + document.getElementById("ldap_port").value;
719
		url += '&host=' + document.getElementById("ldap_host").value;
720
		url += '&scope=' + document.getElementById("ldap_scope").value;
721
		url += '&basedn=' + document.getElementById("ldap_basedn").value;
722
		url += '&binddn=' + document.getElementById("ldap_binddn").value;
723
		url += '&bindpw=' + document.getElementById("ldap_bindpw").value;
724
		url += '&urltype=' + document.getElementById("ldap_urltype").value;
725
		url += '&proto=' + document.getElementById("ldap_protver").value;
726
		url += '&authcn=' + document.getElementById("ldapauthcontainers").value;
727
		<?php if (count($a_ca) > 0): ?>
728
			url += '&cert=' + document.getElementById("ldap_caref").value;
729
		<?php else: ?>
730
			url += '&cert=';
731
		<?php endif; ?>
732
	
733
		var oWin = window.open(url, "pfSensePop", "width=620,height=400,top=150,left=150");
734
		if (oWin == null || typeof(oWin) == "undefined") {
735
			alert("<?=gettext('Popup blocker detected.  Action aborted.');?>");
736
		}
737
	}
738
	
739
	function set_ldap_port() {
740
        if($('#ldap_urltype').find(":selected").index() == 0)
741
			$('#ldap_port').val('389');
742
		else
743
			$('#ldap_port').val('636');		
744
	}
745
	
746
    // Hides all elements of the specified class. This will usually be a section
747
    function hideClass(s_class, hide) {
748
        if(hide)
749
            $('.' + s_class).hide();
750
        else
751
            $('.' + s_class).show();
752
    }
753
    
754
	function ldap_tmplchange() {
755
		switch ($('#ldap_tmpltype').find(":selected").index()) {
756
<?php
757
		$index = 0;
758
		foreach ($ldap_templates as $tmpldata):
759
?>
760
			case <?=$index;?>:
761
				$('#ldap_attr_user').val("<?=$tmpldata['attr_user'];?>");
762
				$('#ldap_attr_group').val("<?=$tmpldata['attr_group'];?>");
763
				$('#ldap_attr_member').val("<?=$tmpldata['attr_member'];?>");
764
				break;
765
<?php
766
			$index++;
767
		endforeach;
768
?>
769
		}
770
	}
771

    
772
	// On page load . .
773
	ldap_tmplchange();
774
	hideClass('ldapanon', $('#ldap_anon').prop('checked'));
775
	$("#Select").prop('type','button');
776

    
777
		
778
	if($('#ldap_port').val() == "")
779
		set_ldap_port();
780

    
781
<?php
782
	if($act == 'edit') {
783
?>
784
		$('#type option:not(:selected)').each(function(){
785
 			$(this).attr('disabled', 'disabled');
786
		});
787
		
788
<?php
789
		if(!$input_errors) {
790
?>	
791
		$('#name').prop("readonly", true);
792
<?php
793
		}
794
	}
795
?>
796
	// On click . .
797
	$('#ldap_tmpltype').on('change', function() {
798
		ldap_tmplchange();
799
	});
800

    
801
    $('#ldap_anon').click(function () {
802
        hideClass('ldapanon', this.checked);
803
    });
804
    
805
	$('#ldap_urltype').on('change', function() {
806
		set_ldap_port();
807
    }); 
808
    
809
    $('#Select').click(function () {
810
        select_clicked();
811
    });   
812
});
813
//]]>
814
</script>
815
<?php
816
include("foot.inc");
(194-194/238)