Project

General

Profile

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

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

    
62
require_once("guiconfig.inc");
63
require_once("auth.inc");
64

    
65
// Have we been called to populate the "Select a container" modal?
66
if ($_REQUEST['ajax']) {
67

    
68
	$ous = array();
69
	$authcfg = array();
70

    
71
	$authcfg['ldap_port'] = $_REQUEST['port'];
72
	$authcfg['ldap_basedn'] = $_REQUEST['basedn'];
73
	$authcfg['host'] = $_REQUEST['host'];
74
	$authcfg['ldap_scope'] = $_REQUEST['scope'];
75
	$authcfg['ldap_binddn'] = $_REQUEST['binddn'];
76
	$authcfg['ldap_bindpw'] = $_REQUEST['bindpw'];
77
	$authcfg['ldap_urltype'] = $_REQUEST['urltype'];
78
	$authcfg['ldap_protver'] = $_REQUEST['proto'];
79
	$authcfg['ldap_authcn'] = explode(";", $_REQUEST['authcn']);
80
	$authcfg['ldap_caref'] = $_REQUEST['cert'];
81

    
82
	$ous = ldap_get_user_ous(true, $authcfg);
83

    
84
	if (empty($ous)) {
85
		print('<span class="text-danger">Could not connect to the LDAP server. Please check the LDAP configuration.</span>');
86
	} else {
87
		$modal = new Modal("Select LDAP containers for authentication", "containers", true);
88
		$group = new Form_MultiCheckboxGroup('Containers');
89

    
90
		if (is_array($ous)) {
91
			$idx = 0;
92

    
93
			foreach ($ous as $ou) {
94
				$group->add(new Form_MultiCheckbox(
95
					'ou' . $idx,
96
					'',
97
					$ou,
98
					in_array($ou, $authcfg['ldap_authcn']),
99
					$ou
100
				));
101

    
102
				$idx++;
103
			}
104
		}
105

    
106
		$modal->add($group);
107

    
108
		// Create a "Save button"
109

    
110
		$btnsv = new Form_Button(
111
			'svcontbtn',
112
			'Save',
113
			null,
114
			'fa-save'
115
		);
116

    
117
		$btnsv->removeClass("btn-default)")->addClass("btn-primary");
118

    
119
		$modal->addInput(new Form_StaticText(
120
			'',
121
			$btnsv
122
		));
123

    
124
		print($modal);
125
	}
126

    
127
	exit;
128
}
129

    
130
if (is_numericint($_GET['id'])) {
131
	$id = $_GET['id'];
132
}
133

    
134
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
135
	$id = $_POST['id'];
136
}
137

    
138
if (!is_array($config['system']['authserver'])) {
139
	$config['system']['authserver'] = array();
140
}
141

    
142
$a_servers = auth_get_authserver_list();
143
foreach ($a_servers as $servers) {
144
	$a_server[] = $servers;
145
}
146

    
147
if (!is_array($config['ca'])) {
148
	$config['ca'] = array();
149
}
150
$a_ca =& $config['ca'];
151

    
152
$act = $_GET['act'];
153
if ($_POST['act']) {
154
	$act = $_POST['act'];
155
}
156

    
157
if ($act == "del") {
158

    
159
	if (!$a_server[$_GET['id']]) {
160
		pfSenseHeader("system_authservers.php");
161
		exit;
162
	}
163

    
164
	/* Remove server from main list. */
165
	$serverdeleted = $a_server[$_GET['id']]['name'];
166
	foreach ($config['system']['authserver'] as $k => $as) {
167
		if ($config['system']['authserver'][$k]['name'] == $serverdeleted) {
168
			unset($config['system']['authserver'][$k]);
169
		}
170
	}
171

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

    
175
	$savemsg = sprintf(gettext("Authentication Server %s deleted."), htmlspecialchars($serverdeleted));
176
	write_config($savemsg);
177
}
178

    
179
if ($act == "edit") {
180
	if (isset($id) && $a_server[$id]) {
181

    
182
		$pconfig['type'] = $a_server[$id]['type'];
183
		$pconfig['name'] = $a_server[$id]['name'];
184

    
185
		if ($pconfig['type'] == "ldap") {
186
			$pconfig['ldap_caref'] = $a_server[$id]['ldap_caref'];
187
			$pconfig['ldap_host'] = $a_server[$id]['host'];
188
			$pconfig['ldap_port'] = $a_server[$id]['ldap_port'];
189
			$pconfig['ldap_timeout'] = $a_server[$id]['ldap_timeout'];
190
			$pconfig['ldap_urltype'] = $a_server[$id]['ldap_urltype'];
191
			$pconfig['ldap_protver'] = $a_server[$id]['ldap_protver'];
192
			$pconfig['ldap_scope'] = $a_server[$id]['ldap_scope'];
193
			$pconfig['ldap_basedn'] = $a_server[$id]['ldap_basedn'];
194
			$pconfig['ldap_authcn'] = $a_server[$id]['ldap_authcn'];
195
			$pconfig['ldap_extended_enabled'] = $a_server[$id]['ldap_extended_enabled'];
196
			$pconfig['ldap_extended_query'] = $a_server[$id]['ldap_extended_query'];
197
			$pconfig['ldap_binddn'] = $a_server[$id]['ldap_binddn'];
198
			$pconfig['ldap_bindpw'] = $a_server[$id]['ldap_bindpw'];
199
			$pconfig['ldap_attr_user'] = $a_server[$id]['ldap_attr_user'];
200
			$pconfig['ldap_attr_group'] = $a_server[$id]['ldap_attr_group'];
201
			$pconfig['ldap_attr_member'] = $a_server[$id]['ldap_attr_member'];
202
			$pconfig['ldap_attr_groupobj'] = $a_server[$id]['ldap_attr_groupobj'];
203
			$pconfig['ldap_utf8'] = isset($a_server[$id]['ldap_utf8']);
204
			$pconfig['ldap_nostrip_at'] = isset($a_server[$id]['ldap_nostrip_at']);
205
			$pconfig['ldap_rfc2307'] = isset($a_server[$id]['ldap_rfc2307']);
206

    
207
			if (!$pconfig['ldap_binddn'] || !$pconfig['ldap_bindpw']) {
208
				$pconfig['ldap_anon'] = true;
209
			}
210
		}
211

    
212
		if ($pconfig['type'] == "radius") {
213
			$pconfig['radius_host'] = $a_server[$id]['host'];
214
			$pconfig['radius_auth_port'] = $a_server[$id]['radius_auth_port'];
215
			$pconfig['radius_acct_port'] = $a_server[$id]['radius_acct_port'];
216
			$pconfig['radius_secret'] = $a_server[$id]['radius_secret'];
217
			$pconfig['radius_timeout'] = $a_server[$id]['radius_timeout'];
218

    
219
			if ($pconfig['radius_auth_port'] &&
220
				$pconfig['radius_acct_port']) {
221
				$pconfig['radius_srvcs'] = "both";
222
			}
223

    
224
			if ($pconfig['radius_auth_port'] &&
225
				!$pconfig['radius_acct_port']) {
226
				$pconfig['radius_srvcs'] = "auth";
227
				$pconfig['radius_acct_port'] = 1813;
228
			}
229

    
230
			if (!$pconfig['radius_auth_port'] &&
231
				$pconfig['radius_acct_port']) {
232
				$pconfig['radius_srvcs'] = "acct";
233
				$pconfig['radius_auth_port'] = 1812;
234
			}
235

    
236
		}
237
	}
238
}
239

    
240
if ($act == "new") {
241
	$pconfig['ldap_protver'] = 3;
242
	$pconfig['ldap_anon'] = true;
243
	$pconfig['radius_srvcs'] = "both";
244
	$pconfig['radius_auth_port'] = "1812";
245
	$pconfig['radius_acct_port'] = "1813";
246
}
247

    
248
if ($_POST) {
249
	unset($input_errors);
250
	$pconfig = $_POST;
251

    
252
	/* input validation */
253

    
254
	if ($pconfig['type'] == "ldap") {
255
		$reqdfields = explode(" ",
256
			"name type ldap_host ldap_port " .
257
			"ldap_urltype ldap_protver ldap_scope " .
258
			"ldap_attr_user ldap_attr_group ldap_attr_member ldapauthcontainers");
259

    
260
		$reqdfieldsn = array(
261
			gettext("Descriptive name"),
262
			gettext("Type"),
263
			gettext("Hostname or IP"),
264
			gettext("Port value"),
265
			gettext("Transport"),
266
			gettext("Protocol version"),
267
			gettext("Search level"),
268
			gettext("User naming Attribute"),
269
			gettext("Group naming Attribute"),
270
			gettext("Group member attribute"),
271
			gettext("Authentication container"));
272

    
273
		if (!$pconfig['ldap_anon']) {
274
			$reqdfields[] = "ldap_binddn";
275
			$reqdfields[] = "ldap_bindpw";
276
			$reqdfieldsn[] = gettext("Bind user DN");
277
			$reqdfieldsn[] = gettext("Bind Password");
278
		}
279
	}
280

    
281
	if ($pconfig['type'] == "radius") {
282
		$reqdfields = explode(" ", "name type radius_host radius_srvcs");
283
		$reqdfieldsn = array(
284
			gettext("Descriptive name"),
285
			gettext("Type"),
286
			gettext("Hostname or IP"),
287
			gettext("Services"));
288

    
289
		if ($pconfig['radisu_srvcs'] == "both" ||
290
			$pconfig['radisu_srvcs'] == "auth") {
291
			$reqdfields[] = "radius_auth_port";
292
			$reqdfieldsn[] = gettext("Authentication port");
293
		}
294

    
295
		if ($pconfig['radisu_srvcs'] == "both" ||
296
			$pconfig['radisu_srvcs'] == "acct") {
297
			$reqdfields[] = "radius_acct_port";
298
			$reqdfieldsn[] = gettext("Accounting port");
299
		}
300

    
301
		if (!isset($id)) {
302
			$reqdfields[] = "radius_secret";
303
			$reqdfieldsn[] = gettext("Shared Secret");
304
		}
305
	}
306

    
307
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
308

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

    
313
	if (auth_get_authserver($pconfig['name']) && !isset($id)) {
314
		$input_errors[] = gettext("An authentication server with the same name already exists.");
315
	}
316

    
317
	if (($pconfig['type'] == "ldap") || ($pconfig['type'] == "radius")) {
318
		$to_field = "{$pconfig['type']}_timeout";
319
		if (isset($_POST[$to_field]) && !empty($_POST[$to_field]) && (!is_numeric($_POST[$to_field]) || (is_numeric($_POST[$to_field]) && ($_POST[$to_field] <= 0)))) {
320
			$input_errors[] = sprintf(gettext("%s Timeout value must be numeric and positive."), strtoupper($pconfig['type']));
321
		}
322
	}
323

    
324
	/* if this is an AJAX caller then handle via JSON */
325
	if (isAjax() && is_array($input_errors)) {
326
		input_errors2Ajax($input_errors);
327
		exit;
328
	}
329

    
330
	if (!$input_errors) {
331
		$server = array();
332
		$server['refid'] = uniqid();
333
		if (isset($id) && $a_server[$id]) {
334
			$server = $a_server[$id];
335
		}
336

    
337
		$server['type'] = $pconfig['type'];
338
		$server['name'] = $pconfig['name'];
339

    
340
		if ($server['type'] == "ldap") {
341

    
342
			if (!empty($pconfig['ldap_caref'])) {
343
				$server['ldap_caref'] = $pconfig['ldap_caref'];
344
			}
345
			$server['host'] = $pconfig['ldap_host'];
346
			$server['ldap_port'] = $pconfig['ldap_port'];
347
			$server['ldap_urltype'] = $pconfig['ldap_urltype'];
348
			$server['ldap_protver'] = $pconfig['ldap_protver'];
349
			$server['ldap_scope'] = $pconfig['ldap_scope'];
350
			$server['ldap_basedn'] = $pconfig['ldap_basedn'];
351
			$server['ldap_authcn'] = $pconfig['ldapauthcontainers'];
352
			$server['ldap_extended_enabled'] = $pconfig['ldap_extended_enabled'];
353
			$server['ldap_extended_query'] = $pconfig['ldap_extended_query'];
354
			$server['ldap_attr_user'] = $pconfig['ldap_attr_user'];
355
			$server['ldap_attr_group'] = $pconfig['ldap_attr_group'];
356
			$server['ldap_attr_member'] = $pconfig['ldap_attr_member'];
357

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

    
360
			if ($pconfig['ldap_utf8'] == "yes") {
361
				$server['ldap_utf8'] = true;
362
			} else {
363
				unset($server['ldap_utf8']);
364
			}
365
			if ($pconfig['ldap_nostrip_at'] == "yes") {
366
				$server['ldap_nostrip_at'] = true;
367
			} else {
368
				unset($server['ldap_nostrip_at']);
369
			}
370
			if ($pconfig['ldap_rfc2307'] == "yes") {
371
				$server['ldap_rfc2307'] = true;
372
			} else {
373
				unset($server['ldap_rfc2307']);
374
			}
375

    
376

    
377
			if (!$pconfig['ldap_anon']) {
378
				$server['ldap_binddn'] = $pconfig['ldap_binddn'];
379
				$server['ldap_bindpw'] = $pconfig['ldap_bindpw'];
380
			} else {
381
				unset($server['ldap_binddn']);
382
				unset($server['ldap_bindpw']);
383
			}
384

    
385
			if ($pconfig['ldap_timeout']) {
386
				$server['ldap_timeout'] = $pconfig['ldap_timeout'];
387
			} else {
388
				$server['ldap_timeout'] = 25;
389
			}
390
		}
391

    
392
		if ($server['type'] == "radius") {
393

    
394
			$server['host'] = $pconfig['radius_host'];
395

    
396
			if ($pconfig['radius_secret']) {
397
				$server['radius_secret'] = $pconfig['radius_secret'];
398
			}
399

    
400
			if ($pconfig['radius_timeout']) {
401
				$server['radius_timeout'] = $pconfig['radius_timeout'];
402
			} else {
403
				$server['radius_timeout'] = 5;
404
			}
405

    
406
			if ($pconfig['radius_srvcs'] == "both") {
407
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
408
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
409
			}
410

    
411
			if ($pconfig['radius_srvcs'] == "auth") {
412
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
413
				unset($server['radius_acct_port']);
414
			}
415

    
416
			if ($pconfig['radius_srvcs'] == "acct") {
417
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
418
				unset($server['radius_auth_port']);
419
			}
420
		}
421

    
422
		if (isset($id) && $config['system']['authserver'][$id]) {
423
			$config['system']['authserver'][$id] = $server;
424
		} else {
425
			$config['system']['authserver'][] = $server;
426
		}
427

    
428
		write_config();
429

    
430
		pfSenseHeader("system_authservers.php");
431
	}
432
}
433

    
434
// On error, restore the form contents so the user doesn't have to re-enter too much
435
if($_POST && $input_errors) {
436
	$pconfig = $_POST;
437
	$pconfig['ldap_authcn'] = $_POST['ldapauthcontainers'];
438
	$pconfig['ldap_template'] = $_POST['ldap_tmpltype'];
439
}
440

    
441
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Authentication Servers"));
442

    
443
if ($act == "new" || $act == "edit" || $input_errors) {
444
	$pgtitle[] = gettext('Edit');
445
}
446
$shortcut_section = "authentication";
447
include("head.inc");
448

    
449
if ($input_errors) {
450
	print_input_errors($input_errors);
451
}
452

    
453
if ($savemsg) {
454
	print_info_box($savemsg, 'success');
455
}
456

    
457
$tab_array = array();
458
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
459
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
460
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
461
$tab_array[] = array(gettext("Authentication Servers"), true, "system_authservers.php");
462
display_top_tabs($tab_array);
463

    
464
if (!($act == "new" || $act == "edit" || $input_errors)) {
465
?>
466
<div class="panel panel-default">
467
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Authentication Servers')?></h2></div>
468
	<div class="panel-body">
469
		<div class="table-responsive">
470
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
471
				<thead>
472
					<tr>
473
						<th><?=gettext("Server Name")?></th>
474
						<th><?=gettext("Type")?></th>
475
						<th><?=gettext("Host Name")?></th>
476
						<th><?=gettext("Actions")?></th>
477
					</tr>
478
				</thead>
479
				<tbody>
480
			<?php foreach($a_server as $i => $server): ?>
481
					<tr>
482
						<td><?=htmlspecialchars($server['name'])?></td>
483
						<td><?=htmlspecialchars($auth_server_types[$server['type']])?></td>
484
						<td><?=htmlspecialchars($server['host'])?></td>
485
						<td>
486
						<?php if ($i < (count($a_server) - 1)): ?>
487
							<a class="fa fa-pencil" title="<?=gettext("Edit server"); ?>" href="system_authservers.php?act=edit&amp;id=<?=$i?>"></a>
488
							<a class="fa fa-trash"  title="<?=gettext("Delete server")?>" href="system_authservers.php?act=del&amp;id=<?=$i?>"></a>
489
						<?php endif?>
490
						</td>
491
					</tr>
492
			<?php endforeach; ?>
493
				</tbody>
494
			</table>
495
		</div>
496
	</div>
497
</div>
498

    
499
<nav class="action-buttons">
500
	<a href="?act=new" class="btn btn-success btn-sm">
501
		<i class="fa fa-plus icon-embed-btn"></i>
502
		<?=gettext("Add")?>
503
	</a>
504
</nav>
505
<?php
506
	include("foot.inc");
507
	exit;
508
}
509

    
510
$form = new Form;
511
$form->setAction('system_authservers.php?act=edit');
512

    
513
$form->addGlobal(new Form_Input(
514
	'userid',
515
	null,
516
	'hidden',
517
	$id
518
));
519

    
520
$section = new Form_Section('Server Settings');
521

    
522
$section->addInput($input = new Form_Input(
523
	'name',
524
	'Descriptive name',
525
	'text',
526
	$pconfig['name']
527
));
528

    
529
$section->addInput($input = new Form_Select(
530
	'type',
531
	'Type',
532
	$pconfig['type'],
533
	$auth_server_types
534
))->toggles();
535

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

    
538
// ==== LDAP settings =========================================================
539
$section = new Form_Section('LDAP Server Settings');
540
$section->addClass('toggle-ldap collapse');
541

    
542
if (!isset($pconfig['type']) || $pconfig['type'] == 'ldap')
543
	$section->addClass('in');
544

    
545
$section->addInput(new Form_Input(
546
	'ldap_host',
547
	'Hostname or IP address',
548
	'text',
549
	$pconfig['ldap_host']
550
))->setHelp('NOTE: When using SSL, this hostname MUST match the Common Name '.
551
	'(CN) of the LDAP server\'s SSL Certificate.');
552

    
553
$section->addInput(new Form_Input(
554
	'ldap_port',
555
	'Port value',
556
	'number',
557
	$pconfig['ldap_port']
558
));
559

    
560
$section->addInput(new Form_Select(
561
	'ldap_urltype',
562
	'Transport',
563
	$pconfig['ldap_urltype'],
564
	array_combine(array_keys($ldap_urltypes), array_keys($ldap_urltypes))
565
));
566

    
567
if (empty($a_ca))
568
{
569
	$section->addInput(new Form_StaticText(
570
		'Peer Certificate Authority',
571
		'No Certificate Authorities defined.<br/>Create one under <a href="system_camanager.php">System &gt; Cert. Manager</a>.'
572
	));
573
}
574
else
575
{
576
	$ldapCaRef = [];
577
	foreach ($a_ca as $ca)
578
		$ldapCaRef[ $ca['refid'] ] = $ca['descr'];
579

    
580
	$section->addInput(new Form_Select(
581
		'ldap_caref',
582
		'Peer Certificate Authority',
583
		$pconfig['ldap_caref'],
584
		$ldapCaRef
585
	))->setHelp('This option is used if \'SSL Encrypted\' option is choosen. '.
586
		'It must match with the CA in the AD otherwise problems will arise.');
587
}
588

    
589
$section->addInput(new Form_Select(
590
	'ldap_protver',
591
	'Protocol version',
592
	$pconfig['ldap_protver'],
593
	array_combine($ldap_protvers, $ldap_protvers)
594
));
595

    
596
$section->addInput(new Form_Input(
597
	'ldap_timeout',
598
	'Server Timeout',
599
	'number',
600
	$pconfig['ldap_timeout'],
601
	['placeholder' => 25]
602
))->setHelp('Timeout for LDAP operations (seconds)');
603

    
604
$group = new Form_Group('Search scope');
605

    
606
$SSF = new Form_Select(
607
	'ldap_scope',
608
	'Level',
609
	$pconfig['ldap_scope'],
610
	$ldap_scopes
611
);
612

    
613
$SSB = new Form_Input(
614
	'ldap_basedn',
615
	'Base DN',
616
	'text',
617
	$pconfig['ldap_basedn']
618
);
619

    
620

    
621
$section->addInput(new Form_StaticText(
622
	'Search scope',
623
	'Level ' . $SSF . '<br />' . 'Base DN' . $SSB
624
));
625

    
626
$group = new Form_Group('Authentication containers');
627
$group->add(new Form_Input(
628
	'ldapauthcontainers',
629
	'Containers',
630
	'text',
631
	$pconfig['ldap_authcn']
632
))->setHelp('Note: Semi-Colon separated. This will be prepended to the search '.
633
	'base dn above or the full container path can be specified containing a dc= '.
634
	'component.<br/>Example: CN=Users;DC=example,DC=com or OU=Staff;OU=Freelancers');
635

    
636
$group->add(new Form_Button(
637
	'Select',
638
	'Select a container',
639
	null,
640
	'fa-search'
641
))->setAttribute('type','button')->addClass('btn-info');
642

    
643
$section->add($group);
644

    
645
$section->addInput(new Form_Checkbox(
646
	'ldap_extended_enabled',
647
	'Extended query',
648
	'Enable extended query',
649
	$pconfig['ldap_extended_enabled']
650
));
651

    
652
$group = new Form_Group('Query');
653
$group->addClass('extended');
654

    
655
$group->add(new Form_Input(
656
	'ldap_extended_query',
657
	'Query',
658
	'text',
659
	$pconfig['ldap_extended_query']
660
))->setHelp('Example: &amp;(objectClass=inetOrgPerson)(mail=*@example.com)');
661

    
662
$section->add($group);
663

    
664
$section->addInput(new Form_Checkbox(
665
	'ldap_anon',
666
	'Bind anonymous',
667
	'Use anonymous binds to resolve distinguished names',
668
	$pconfig['ldap_anon']
669
));
670

    
671
$group = new Form_Group('Bind credentials');
672
$group->addClass('ldapanon');
673

    
674
$group->add(new Form_Input(
675
	'ldap_binddn',
676
	'User DN:',
677
	'text',
678
	$pconfig['ldap_binddn']
679
));
680

    
681
$group->add(new Form_Input(
682
	'ldap_bindpw',
683
	'Password',
684
	'text',
685
	$pconfig['ldap_bindpw']
686
));
687
$section->add($group);
688

    
689
if (!isset($id)) {
690
	$template_list = array();
691

    
692
	foreach($ldap_templates as $option => $template) {
693
		$template_list[$option] = $template['desc'];
694
	}
695

    
696
	$section->addInput(new Form_Select(
697
		'ldap_tmpltype',
698
		'Initial Template',
699
		$pconfig['ldap_template'],
700
		$template_list
701
	));
702
}
703

    
704
$section->addInput(new Form_Input(
705
	'ldap_attr_user',
706
	'User naming attribute',
707
	'text',
708
	$pconfig['ldap_attr_user']
709
));
710

    
711
$section->addInput(new Form_Input(
712
	'ldap_attr_group',
713
	'Group naming attribute',
714
	'text',
715
	$pconfig['ldap_attr_group']
716
));
717

    
718
$section->addInput(new Form_Input(
719
	'ldap_attr_member',
720
	'Group member attribute',
721
	'text',
722
	$pconfig['ldap_attr_member']
723
));
724

    
725
$section->addInput(new Form_Checkbox(
726
	'ldap_rfc2307',
727
	'RFC 2307 Groups',
728
	'LDAP Server uses RFC 2307 style group membership',
729
	$pconfig['ldap_rfc2307']
730
))->setHelp('RFC 2307 style group membership has members listed on the group '.
731
	'object rather than using groups listed on user object. Leave unchecked '.
732
	'for Active Directory style group membership (RFC 2307bis).');
733

    
734
$section->addInput(new Form_Input(
735
	'ldap_attr_groupobj',
736
	'Group Object Class',
737
	'text',
738
	$pconfig['ldap_attr_groupobj'],
739
	['placeholder' => 'posixGroup']
740
))->setHelp('Object class used for groups in RFC2307 mode. '.
741
	'Typically "posixGroup" or "group".');
742

    
743
$section->addInput(new Form_Checkbox(
744
	'ldap_utf8',
745
	'UTF8 Encode',
746
	'UTF8 encode LDAP parameters before sending them to the server.',
747
	$pconfig['ldap_utf8']
748
))->setHelp('Required to support international characters, but may not be '.
749
	'supported by every LDAP server.');
750

    
751
$section->addInput(new Form_Checkbox(
752
	'ldap_nostrip_at',
753
	'Username Alterations',
754
	'Do not strip away parts of the username after the @ symbol',
755
	$pconfig['ldap_nostrip_at']
756
))->setHelp('e.g. user@host becomes user when unchecked.');
757

    
758
$form->add($section);
759

    
760
// ==== RADIUS section ========================================================
761
$section = new Form_Section('RADIUS Server Settings');
762
$section->addClass('toggle-radius collapse');
763

    
764
$section->addInput(new Form_Input(
765
	'radius_host',
766
	'Hostname or IP address',
767
	'text',
768
	$pconfig['radius_host']
769
));
770

    
771
$section->addInput(new Form_Input(
772
	'radius_secret',
773
	'Shared Secret',
774
	'text',
775
	$pconfig['radius_secret']
776
));
777

    
778
$section->addInput(new Form_Select(
779
	'radius_srvcs',
780
	'Services offered',
781
	$pconfig['radius_srvcs'],
782
	$radius_srvcs
783
));
784

    
785
$section->addInput(new Form_Input(
786
	'radius_auth_port',
787
	'Authentication port',
788
	'number',
789
	$pconfig['radius_auth_port']
790
));
791

    
792
$section->addInput(new Form_Input(
793
	'radius_acct_port',
794
	'Accounting port',
795
	'number',
796
	$pconfig['radius_acct_port']
797
));
798

    
799
$section->addInput(new Form_Input(
800
	'radius_timeout',
801
	'Authentication Timeout',
802
	'number',
803
	$pconfig['radius_timeout']
804
))->setHelp('This value controls how long, in seconds, that the RADIUS '.
805
	'server may take to respond to an authentication request. If left blank, the '.
806
	'default value is 5 seconds. NOTE: If using an interactive two-factor '.
807
	'authentication system, increase this timeout to account for how long it will '.
808
	'take the user to receive and enter a token.');
809

    
810
if (isset($id) && $a_server[$id])
811
{
812
	$section->addInput(new Form_Input(
813
		'id',
814
		null,
815
		'hidden',
816
		$id
817
	));
818
}
819

    
820
$form->add($section);
821

    
822
// Create a largely empty modal to show the available containers. We will populate it via AJAX later
823
$modal = new Modal("LDAP containers", "containers", true);
824

    
825
$form->add($modal);
826

    
827
print $form;
828
?>
829
<script type="text/javascript">
830
//<![CDATA[
831
events.push(function() {
832

    
833
	// Create an AJAX request (to this page) to get the container list and controls
834
	function select_clicked() {
835
		if (document.getElementById("ldap_port").value == '' ||
836
			document.getElementById("ldap_host").value == '' ||
837
			document.getElementById("ldap_scope").value == '' ||
838
			document.getElementById("ldap_basedn").value == '' ||
839
			document.getElementById("ldapauthcontainers").value == '') {
840
			alert("<?=gettext("Please fill the required values.");?>");
841
			return;
842
		}
843

    
844
		if (!document.getElementById("ldap_anon").checked) {
845
			if (document.getElementById("ldap_binddn").value == '' ||
846
				document.getElementById("ldap_bindpw").value == '') {
847
				alert("<?=gettext("Please fill the bind username/password.");?>");
848
				return;
849
			}
850
		}
851

    
852
		var ajaxRequest;
853
		var authserver = $('#authmode').val();
854
		var cert;
855

    
856
<?php if (count($a_ca) > 0): ?>
857
			cert = $('#ldap_caref').val();
858
<?php else: ?>
859
			cert = '';
860
<?php endif; ?>
861
/*
862
		$('#containers').modal('show');
863
		$('#serverlist').parent('div').prev('label').remove();
864
		$('#serverlist').parent('div').removeClass("col-sm-10");
865
		$('#serverlist').parent('div').addClass("col-sm-12");
866
*/
867
		ajaxRequest = $.ajax(
868
			{
869
				url: "/system_authservers.php",
870
				type: "post",
871
				data: {
872
					ajax: 	"ajax",
873
					port: 	$('#ldap_port').val(),
874
					host: 	$('#ldap_host').val(),
875
					scope: 	$('#ldap_scope').val(),
876
					basedn: $('#ldap_basedn').val(),
877
					binddn: $('#ldap_binddn').val(),
878
					bindpw: $('#ldap_bindpw').val(),
879
					urltype:$('#ldap_urltype').val(),
880
					proto:  $('#ldap_protver').val(),
881
					authcn: $('#ldapauthcontainers').val(),
882
					cert:   cert
883
				}
884
			}
885
		);
886

    
887
		// Deal with the results of the above ajax call
888
		ajaxRequest.done(function (response, textStatus, jqXHR) {
889
			$('#containers').replaceWith(response);
890

    
891
			$('#containers').modal('show');
892

    
893
			// The button handler needs to be here because until the modal has been populated
894
			// the controls we need to attach handlers to do not exist
895
			$('#svcontbtn').prop("type", "button");
896
			$('#svcontbtn').removeAttr("href");
897

    
898
			$('#svcontbtn').click(function () {
899
				var ous = $('[id^=ou]').length;
900
				var i;
901

    
902
				$('#ldapauthcontainers').val("");
903

    
904
				for (i = 0; i < ous; i++) {
905
					if ($('#ou' + i).prop("checked")) {
906
						if ($('#ldapauthcontainers').val() != "") {
907
							$('#ldapauthcontainers').val($('#ldapauthcontainers').val() +";");
908
						}
909

    
910
						$('#ldapauthcontainers').val($('#ldapauthcontainers').val() + $('#ou' + i).val());
911
					}
912
				}
913

    
914
				$('#containers').modal('hide');
915
			});
916
		});
917

    
918
	}
919

    
920
	function set_ldap_port() {
921
		if($('#ldap_urltype').find(":selected").index() == 0)
922
			$('#ldap_port').val('389');
923
		else
924
			$('#ldap_port').val('636');
925
	}
926

    
927
	// Hides all elements of the specified class. This will usually be a section
928
	function hideClass(s_class, hide) {
929
		if(hide)
930
			$('.' + s_class).hide();
931
		else
932
			$('.' + s_class).show();
933
	}
934

    
935
	function ldap_tmplchange() {
936
		switch ($('#ldap_tmpltype').find(":selected").index()) {
937
<?php
938
		$index = 0;
939
		foreach ($ldap_templates as $tmpldata):
940
?>
941
			case <?=$index;?>:
942
				$('#ldap_attr_user').val("<?=$tmpldata['attr_user'];?>");
943
				$('#ldap_attr_group').val("<?=$tmpldata['attr_group'];?>");
944
				$('#ldap_attr_member').val("<?=$tmpldata['attr_member'];?>");
945
				break;
946
<?php
947
			$index++;
948
		endforeach;
949
?>
950
		}
951
	}
952

    
953
	// ---------- On initial page load ------------------------------------------------------------
954

    
955
<?php if ($act != 'edit') : ?>
956
	ldap_tmplchange();
957
<?php endif; ?>
958

    
959
	hideClass('ldapanon', $('#ldap_anon').prop('checked'));
960
	hideClass('extended', !$('#ldap_extended_enabled').prop('checked'));
961

    
962
	if($('#ldap_port').val() == "")
963
		set_ldap_port();
964

    
965
<?php
966
	if($act == 'edit') {
967
?>
968
		$('#type option:not(:selected)').each(function(){
969
			$(this).attr('disabled', 'disabled');
970
		});
971

    
972
<?php
973
		if(!$input_errors) {
974
?>
975
		$('#name').prop("readonly", true);
976
<?php
977
		}
978
	}
979
?>
980
	// ---------- Click checkbox handlers ---------------------------------------------------------
981

    
982
	$('#ldap_tmpltype').on('change', function() {
983
		ldap_tmplchange();
984
	});
985

    
986
	$('#ldap_anon').click(function () {
987
		hideClass('ldapanon', this.checked);
988
	});
989

    
990
	$('#ldap_urltype').on('change', function() {
991
		set_ldap_port();
992
	});
993

    
994
	$('#Select').click(function () {
995
		select_clicked();
996
	});
997

    
998
	$('#ldap_extended_enabled').click(function () {
999
		hideClass('extended', !this.checked);
1000
	});
1001

    
1002
});
1003
//]]>
1004
</script>
1005
<?php
1006
include("foot.inc");
(191-191/225)