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 Rubicon Communications, LLC (Netgate)
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['radius_srvcs'] == "both" ||
290
			$pconfig['radius_srvcs'] == "auth") {
291
			$reqdfields[] = "radius_auth_port";
292
			$reqdfieldsn[] = gettext("Authentication port");
293
		}
294

    
295
		if ($pconfig['radius_srvcs'] == "both" ||
296
			$pconfig['radius_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 (!$input_errors) {
325
		$server = array();
326
		$server['refid'] = uniqid();
327
		if (isset($id) && $a_server[$id]) {
328
			$server = $a_server[$id];
329
		}
330

    
331
		$server['type'] = $pconfig['type'];
332
		$server['name'] = $pconfig['name'];
333

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

    
336
			if (!empty($pconfig['ldap_caref'])) {
337
				$server['ldap_caref'] = $pconfig['ldap_caref'];
338
			}
339
			$server['host'] = $pconfig['ldap_host'];
340
			$server['ldap_port'] = $pconfig['ldap_port'];
341
			$server['ldap_urltype'] = $pconfig['ldap_urltype'];
342
			$server['ldap_protver'] = $pconfig['ldap_protver'];
343
			$server['ldap_scope'] = $pconfig['ldap_scope'];
344
			$server['ldap_basedn'] = $pconfig['ldap_basedn'];
345
			$server['ldap_authcn'] = $pconfig['ldapauthcontainers'];
346
			$server['ldap_extended_enabled'] = $pconfig['ldap_extended_enabled'];
347
			$server['ldap_extended_query'] = $pconfig['ldap_extended_query'];
348
			$server['ldap_attr_user'] = $pconfig['ldap_attr_user'];
349
			$server['ldap_attr_group'] = $pconfig['ldap_attr_group'];
350
			$server['ldap_attr_member'] = $pconfig['ldap_attr_member'];
351

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

    
354
			if ($pconfig['ldap_utf8'] == "yes") {
355
				$server['ldap_utf8'] = true;
356
			} else {
357
				unset($server['ldap_utf8']);
358
			}
359
			if ($pconfig['ldap_nostrip_at'] == "yes") {
360
				$server['ldap_nostrip_at'] = true;
361
			} else {
362
				unset($server['ldap_nostrip_at']);
363
			}
364
			if ($pconfig['ldap_rfc2307'] == "yes") {
365
				$server['ldap_rfc2307'] = true;
366
			} else {
367
				unset($server['ldap_rfc2307']);
368
			}
369

    
370

    
371
			if (!$pconfig['ldap_anon']) {
372
				$server['ldap_binddn'] = $pconfig['ldap_binddn'];
373
				$server['ldap_bindpw'] = $pconfig['ldap_bindpw'];
374
			} else {
375
				unset($server['ldap_binddn']);
376
				unset($server['ldap_bindpw']);
377
			}
378

    
379
			if ($pconfig['ldap_timeout']) {
380
				$server['ldap_timeout'] = $pconfig['ldap_timeout'];
381
			} else {
382
				$server['ldap_timeout'] = 25;
383
			}
384
		}
385

    
386
		if ($server['type'] == "radius") {
387

    
388
			$server['host'] = $pconfig['radius_host'];
389

    
390
			if ($pconfig['radius_secret']) {
391
				$server['radius_secret'] = $pconfig['radius_secret'];
392
			}
393

    
394
			if ($pconfig['radius_timeout']) {
395
				$server['radius_timeout'] = $pconfig['radius_timeout'];
396
			} else {
397
				$server['radius_timeout'] = 5;
398
			}
399

    
400
			if ($pconfig['radius_srvcs'] == "both") {
401
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
402
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
403
			}
404

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

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

    
416
		if (isset($id) && $config['system']['authserver'][$id]) {
417
			$config['system']['authserver'][$id] = $server;
418
		} else {
419
			$config['system']['authserver'][] = $server;
420
		}
421

    
422
		write_config();
423

    
424
		pfSenseHeader("system_authservers.php");
425
	}
426
}
427

    
428
// On error, restore the form contents so the user doesn't have to re-enter too much
429
if ($_POST && $input_errors) {
430
	$pconfig = $_POST;
431
	$pconfig['ldap_authcn'] = $_POST['ldapauthcontainers'];
432
	$pconfig['ldap_template'] = $_POST['ldap_tmpltype'];
433
}
434

    
435
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Authentication Servers"));
436

    
437
if ($act == "new" || $act == "edit" || $input_errors) {
438
	$pgtitle[] = gettext('Edit');
439
}
440
$shortcut_section = "authentication";
441
include("head.inc");
442

    
443
if ($input_errors) {
444
	print_input_errors($input_errors);
445
}
446

    
447
if ($savemsg) {
448
	print_info_box($savemsg, 'success');
449
}
450

    
451
$tab_array = array();
452
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
453
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
454
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
455
$tab_array[] = array(gettext("Authentication Servers"), true, "system_authservers.php");
456
display_top_tabs($tab_array);
457

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

    
493
<nav class="action-buttons">
494
	<a href="?act=new" class="btn btn-success btn-sm">
495
		<i class="fa fa-plus icon-embed-btn"></i>
496
		<?=gettext("Add")?>
497
	</a>
498
</nav>
499
<?php
500
	include("foot.inc");
501
	exit;
502
}
503

    
504
$form = new Form;
505
$form->setAction('system_authservers.php?act=edit');
506

    
507
$form->addGlobal(new Form_Input(
508
	'userid',
509
	null,
510
	'hidden',
511
	$id
512
));
513

    
514
$section = new Form_Section('Server Settings');
515

    
516
$section->addInput($input = new Form_Input(
517
	'name',
518
	'Descriptive name',
519
	'text',
520
	$pconfig['name']
521
));
522

    
523
$section->addInput($input = new Form_Select(
524
	'type',
525
	'Type',
526
	$pconfig['type'],
527
	$auth_server_types
528
))->toggles();
529

    
530
$form->add($section);
531

    
532
// ==== LDAP settings =========================================================
533
$section = new Form_Section('LDAP Server Settings');
534
$section->addClass('toggle-ldap collapse');
535

    
536
if (!isset($pconfig['type']) || $pconfig['type'] == 'ldap')
537
	$section->addClass('in');
538

    
539
$section->addInput(new Form_Input(
540
	'ldap_host',
541
	'Hostname or IP address',
542
	'text',
543
	$pconfig['ldap_host']
544
))->setHelp('NOTE: When using SSL or STARTTLS, this hostname MUST match the Common Name '.
545
	'(CN) of the LDAP server\'s SSL Certificate.');
546

    
547
$section->addInput(new Form_Input(
548
	'ldap_port',
549
	'Port value',
550
	'number',
551
	$pconfig['ldap_port']
552
));
553

    
554
$section->addInput(new Form_Select(
555
	'ldap_urltype',
556
	'Transport',
557
	$pconfig['ldap_urltype'],
558
	array_combine(array_keys($ldap_urltypes), array_keys($ldap_urltypes))
559
));
560

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

    
574
	$section->addInput(new Form_Select(
575
		'ldap_caref',
576
		'Peer Certificate Authority',
577
		$pconfig['ldap_caref'],
578
		$ldapCaRef
579
	))->setHelp('This option is used if \'SSL Encrypted\' '.
580
		'or \'TCP - STARTTLS\' options are chosen. '.
581
		'It must match with the CA in the AD otherwise problems will arise.');
582
}
583

    
584
$section->addInput(new Form_Select(
585
	'ldap_protver',
586
	'Protocol version',
587
	$pconfig['ldap_protver'],
588
	array_combine($ldap_protvers, $ldap_protvers)
589
));
590

    
591
$section->addInput(new Form_Input(
592
	'ldap_timeout',
593
	'Server Timeout',
594
	'number',
595
	$pconfig['ldap_timeout'],
596
	['placeholder' => 25]
597
))->setHelp('Timeout for LDAP operations (seconds)');
598

    
599
$group = new Form_Group('Search scope');
600

    
601
$SSF = new Form_Select(
602
	'ldap_scope',
603
	'Level',
604
	$pconfig['ldap_scope'],
605
	$ldap_scopes
606
);
607

    
608
$SSB = new Form_Input(
609
	'ldap_basedn',
610
	'Base DN',
611
	'text',
612
	$pconfig['ldap_basedn']
613
);
614

    
615

    
616
$section->addInput(new Form_StaticText(
617
	'Search scope',
618
	'Level ' . $SSF . '<br />' . 'Base DN' . $SSB
619
));
620

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

    
631
$group->add(new Form_Button(
632
	'Select',
633
	'Select a container',
634
	null,
635
	'fa-search'
636
))->setAttribute('type','button')->addClass('btn-info');
637

    
638
$section->add($group);
639

    
640
$section->addInput(new Form_Checkbox(
641
	'ldap_extended_enabled',
642
	'Extended query',
643
	'Enable extended query',
644
	$pconfig['ldap_extended_enabled']
645
));
646

    
647
$group = new Form_Group('Query');
648
$group->addClass('extended');
649

    
650
$group->add(new Form_Input(
651
	'ldap_extended_query',
652
	'Query',
653
	'text',
654
	$pconfig['ldap_extended_query']
655
))->setHelp('Example: &amp;(objectClass=inetOrgPerson)(mail=*@example.com)');
656

    
657
$section->add($group);
658

    
659
$section->addInput(new Form_Checkbox(
660
	'ldap_anon',
661
	'Bind anonymous',
662
	'Use anonymous binds to resolve distinguished names',
663
	$pconfig['ldap_anon']
664
));
665

    
666
$group = new Form_Group('Bind credentials');
667
$group->addClass('ldapanon');
668

    
669
$group->add(new Form_Input(
670
	'ldap_binddn',
671
	'User DN:',
672
	'text',
673
	$pconfig['ldap_binddn']
674
));
675

    
676
$group->add(new Form_Input(
677
	'ldap_bindpw',
678
	'Password',
679
	'password',
680
	$pconfig['ldap_bindpw']
681
));
682
$section->add($group);
683

    
684
if (!isset($id)) {
685
	$template_list = array();
686

    
687
	foreach ($ldap_templates as $option => $template) {
688
		$template_list[$option] = $template['desc'];
689
	}
690

    
691
	$section->addInput(new Form_Select(
692
		'ldap_tmpltype',
693
		'Initial Template',
694
		$pconfig['ldap_template'],
695
		$template_list
696
	));
697
}
698

    
699
$section->addInput(new Form_Input(
700
	'ldap_attr_user',
701
	'User naming attribute',
702
	'text',
703
	$pconfig['ldap_attr_user']
704
));
705

    
706
$section->addInput(new Form_Input(
707
	'ldap_attr_group',
708
	'Group naming attribute',
709
	'text',
710
	$pconfig['ldap_attr_group']
711
));
712

    
713
$section->addInput(new Form_Input(
714
	'ldap_attr_member',
715
	'Group member attribute',
716
	'text',
717
	$pconfig['ldap_attr_member']
718
));
719

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

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

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

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

    
753
$form->add($section);
754

    
755
// ==== RADIUS section ========================================================
756
$section = new Form_Section('RADIUS Server Settings');
757
$section->addClass('toggle-radius collapse');
758

    
759
$section->addInput(new Form_Input(
760
	'radius_host',
761
	'Hostname or IP address',
762
	'text',
763
	$pconfig['radius_host']
764
));
765

    
766
$section->addInput(new Form_Input(
767
	'radius_secret',
768
	'Shared Secret',
769
	'password',
770
	$pconfig['radius_secret']
771
));
772

    
773
$section->addInput(new Form_Select(
774
	'radius_srvcs',
775
	'Services offered',
776
	$pconfig['radius_srvcs'],
777
	$radius_srvcs
778
));
779

    
780
$section->addInput(new Form_Input(
781
	'radius_auth_port',
782
	'Authentication port',
783
	'number',
784
	$pconfig['radius_auth_port']
785
));
786

    
787
$section->addInput(new Form_Input(
788
	'radius_acct_port',
789
	'Accounting port',
790
	'number',
791
	$pconfig['radius_acct_port']
792
));
793

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

    
805
if (isset($id) && $a_server[$id])
806
{
807
	$section->addInput(new Form_Input(
808
		'id',
809
		null,
810
		'hidden',
811
		$id
812
	));
813
}
814

    
815
$form->add($section);
816

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

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

    
822
print $form;
823
?>
824
<script type="text/javascript">
825
//<![CDATA[
826
events.push(function() {
827

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

    
839
		if (!document.getElementById("ldap_anon").checked) {
840
			if (document.getElementById("ldap_binddn").value == '' ||
841
				document.getElementById("ldap_bindpw").value == '') {
842
				alert("<?=gettext("Please fill the bind username/password.");?>");
843
				return;
844
			}
845
		}
846

    
847
		var ajaxRequest;
848
		var authserver = $('#authmode').val();
849
		var cert;
850

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

    
882
		// Deal with the results of the above ajax call
883
		ajaxRequest.done(function (response, textStatus, jqXHR) {
884
			$('#containers').replaceWith(response);
885

    
886
			$('#containers').modal('show');
887

    
888
			// The button handler needs to be here because until the modal has been populated
889
			// the controls we need to attach handlers to do not exist
890
			$('#svcontbtn').prop("type", "button");
891
			$('#svcontbtn').removeAttr("href");
892

    
893
			$('#svcontbtn').click(function () {
894
				var ous = $('[id^=ou]').length;
895
				var i;
896

    
897
				$('#ldapauthcontainers').val("");
898

    
899
				for (i = 0; i < ous; i++) {
900
					if ($('#ou' + i).prop("checked")) {
901
						if ($('#ldapauthcontainers').val() != "") {
902
							$('#ldapauthcontainers').val($('#ldapauthcontainers').val() +";");
903
						}
904

    
905
						$('#ldapauthcontainers').val($('#ldapauthcontainers').val() + $('#ou' + i).val());
906
					}
907
				}
908

    
909
				$('#containers').modal('hide');
910
			});
911
		});
912

    
913
	}
914

    
915
	function set_ldap_port() {
916
		if ($('#ldap_urltype').find(":selected").index() == 2)
917
			$('#ldap_port').val('636');
918
		else
919
			$('#ldap_port').val('389');
920
	}
921

    
922
	// Hides all elements of the specified class. This will usually be a section
923
	function hideClass(s_class, hide) {
924
		if (hide)
925
			$('.' + s_class).hide();
926
		else
927
			$('.' + s_class).show();
928
	}
929

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

    
948
	// ---------- On initial page load ------------------------------------------------------------
949

    
950
<?php if ($act != 'edit') : ?>
951
	ldap_tmplchange();
952
<?php endif; ?>
953

    
954
	hideClass('ldapanon', $('#ldap_anon').prop('checked'));
955
	hideClass('extended', !$('#ldap_extended_enabled').prop('checked'));
956

    
957
	if ($('#ldap_port').val() == "")
958
		set_ldap_port();
959

    
960
<?php
961
	if ($act == 'edit') {
962
?>
963
		$('#type option:not(:selected)').each(function(){
964
			$(this).attr('disabled', 'disabled');
965
		});
966

    
967
<?php
968
		if (!$input_errors) {
969
?>
970
		$('#name').prop("readonly", true);
971
<?php
972
		}
973
	}
974
?>
975
	// ---------- Click checkbox handlers ---------------------------------------------------------
976

    
977
	$('#ldap_tmpltype').on('change', function() {
978
		ldap_tmplchange();
979
	});
980

    
981
	$('#ldap_anon').click(function () {
982
		hideClass('ldapanon', this.checked);
983
	});
984

    
985
	$('#ldap_urltype').on('change', function() {
986
		set_ldap_port();
987
	});
988

    
989
	$('#Select').click(function () {
990
		select_clicked();
991
	});
992

    
993
	$('#ldap_extended_enabled').click(function () {
994
		hideClass('extended', !this.checked);
995
	});
996

    
997
});
998
//]]>
999
</script>
1000
<?php
1001
include("foot.inc");
(193-193/227)