Project

General

Profile

Download (25.6 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
 * Licensed under the Apache License, Version 2.0 (the "License");
11
 * you may not use this file except in compliance with the License.
12
 * You may obtain a copy of the License at
13
 *
14
 * http://www.apache.org/licenses/LICENSE-2.0
15
 *
16
 * Unless required by applicable law or agreed to in writing, software
17
 * distributed under the License is distributed on an "AS IS" BASIS,
18
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
 * See the License for the specific language governing permissions and
20
 * limitations under the License.
21
 */
22

    
23
##|+PRIV
24
##|*IDENT=page-system-authservers
25
##|*NAME=System: Authentication Servers
26
##|*DESCR=Allow access to the 'System: Authentication Servers' page.
27
##|*MATCH=system_authservers.php*
28
##|-PRIV
29

    
30
require_once("guiconfig.inc");
31
require_once("auth.inc");
32

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

    
36
	$ous = array();
37
	$authcfg = array();
38

    
39
	$authcfg['ldap_port'] = $_REQUEST['port'];
40
	$authcfg['ldap_basedn'] = $_REQUEST['basedn'];
41
	$authcfg['host'] = $_REQUEST['host'];
42
	$authcfg['ldap_scope'] = $_REQUEST['scope'];
43
	$authcfg['ldap_binddn'] = $_REQUEST['binddn'];
44
	$authcfg['ldap_bindpw'] = $_REQUEST['bindpw'];
45
	$authcfg['ldap_urltype'] = $_REQUEST['urltype'];
46
	$authcfg['ldap_protver'] = $_REQUEST['proto'];
47
	$authcfg['ldap_authcn'] = explode(";", $_REQUEST['authcn']);
48
	$authcfg['ldap_caref'] = $_REQUEST['cert'];
49

    
50
	$ous = ldap_get_user_ous(true, $authcfg);
51

    
52
	if (empty($ous)) {
53
		print('<span class="text-danger">Could not connect to the LDAP server. Please check the LDAP configuration.</span>');
54
	} else {
55
		$modal = new Modal("Select LDAP containers for authentication", "containers", true);
56
		$group = new Form_MultiCheckboxGroup('Containers');
57

    
58
		if (is_array($ous)) {
59
			$idx = 0;
60

    
61
			foreach ($ous as $ou) {
62
				$group->add(new Form_MultiCheckbox(
63
					'ou' . $idx,
64
					'',
65
					$ou,
66
					in_array($ou, $authcfg['ldap_authcn']),
67
					$ou
68
				));
69

    
70
				$idx++;
71
			}
72
		}
73

    
74
		$modal->add($group);
75

    
76
		// Create a "Save button"
77

    
78
		$btnsv = new Form_Button(
79
			'svcontbtn',
80
			'Save',
81
			null,
82
			'fa-save'
83
		);
84

    
85
		$btnsv->removeClass("btn-default)")->addClass("btn-primary");
86

    
87
		$modal->addInput(new Form_StaticText(
88
			'',
89
			$btnsv
90
		));
91

    
92
		print($modal);
93
	}
94

    
95
	exit;
96
}
97

    
98
if (is_numericint($_GET['id'])) {
99
	$id = $_GET['id'];
100
}
101

    
102
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
103
	$id = $_POST['id'];
104
}
105

    
106
if (!is_array($config['system']['authserver'])) {
107
	$config['system']['authserver'] = array();
108
}
109

    
110
$a_servers = auth_get_authserver_list();
111
foreach ($a_servers as $servers) {
112
	$a_server[] = $servers;
113
}
114

    
115
if (!is_array($config['ca'])) {
116
	$config['ca'] = array();
117
}
118
$a_ca =& $config['ca'];
119

    
120
$act = $_GET['act'];
121
if ($_POST['act']) {
122
	$act = $_POST['act'];
123
}
124

    
125
if ($act == "del") {
126

    
127
	if (!$a_server[$_GET['id']]) {
128
		pfSenseHeader("system_authservers.php");
129
		exit;
130
	}
131

    
132
	/* Remove server from main list. */
133
	$serverdeleted = $a_server[$_GET['id']]['name'];
134
	foreach ($config['system']['authserver'] as $k => $as) {
135
		if ($config['system']['authserver'][$k]['name'] == $serverdeleted) {
136
			unset($config['system']['authserver'][$k]);
137
		}
138
	}
139

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

    
143
	$savemsg = sprintf(gettext("Authentication Server %s deleted."), htmlspecialchars($serverdeleted));
144
	write_config($savemsg);
145
}
146

    
147
if ($act == "edit") {
148
	if (isset($id) && $a_server[$id]) {
149

    
150
		$pconfig['type'] = $a_server[$id]['type'];
151
		$pconfig['name'] = $a_server[$id]['name'];
152

    
153
		if ($pconfig['type'] == "ldap") {
154
			$pconfig['ldap_caref'] = $a_server[$id]['ldap_caref'];
155
			$pconfig['ldap_host'] = $a_server[$id]['host'];
156
			$pconfig['ldap_port'] = $a_server[$id]['ldap_port'];
157
			$pconfig['ldap_timeout'] = $a_server[$id]['ldap_timeout'];
158
			$pconfig['ldap_urltype'] = $a_server[$id]['ldap_urltype'];
159
			$pconfig['ldap_protver'] = $a_server[$id]['ldap_protver'];
160
			$pconfig['ldap_scope'] = $a_server[$id]['ldap_scope'];
161
			$pconfig['ldap_basedn'] = $a_server[$id]['ldap_basedn'];
162
			$pconfig['ldap_authcn'] = $a_server[$id]['ldap_authcn'];
163
			$pconfig['ldap_extended_enabled'] = $a_server[$id]['ldap_extended_enabled'];
164
			$pconfig['ldap_extended_query'] = $a_server[$id]['ldap_extended_query'];
165
			$pconfig['ldap_binddn'] = $a_server[$id]['ldap_binddn'];
166
			$pconfig['ldap_bindpw'] = $a_server[$id]['ldap_bindpw'];
167
			$pconfig['ldap_attr_user'] = $a_server[$id]['ldap_attr_user'];
168
			$pconfig['ldap_attr_group'] = $a_server[$id]['ldap_attr_group'];
169
			$pconfig['ldap_attr_member'] = $a_server[$id]['ldap_attr_member'];
170
			$pconfig['ldap_attr_groupobj'] = $a_server[$id]['ldap_attr_groupobj'];
171
			$pconfig['ldap_utf8'] = isset($a_server[$id]['ldap_utf8']);
172
			$pconfig['ldap_nostrip_at'] = isset($a_server[$id]['ldap_nostrip_at']);
173
			$pconfig['ldap_rfc2307'] = isset($a_server[$id]['ldap_rfc2307']);
174

    
175
			if (!$pconfig['ldap_binddn'] || !$pconfig['ldap_bindpw']) {
176
				$pconfig['ldap_anon'] = true;
177
			}
178
		}
179

    
180
		if ($pconfig['type'] == "radius") {
181
			$pconfig['radius_protocol'] = $a_server[$id]['radius_protocol'];
182
			$pconfig['radius_host'] = $a_server[$id]['host'];
183
			$pconfig['radius_auth_port'] = $a_server[$id]['radius_auth_port'];
184
			$pconfig['radius_acct_port'] = $a_server[$id]['radius_acct_port'];
185
			$pconfig['radius_secret'] = $a_server[$id]['radius_secret'];
186
			$pconfig['radius_timeout'] = $a_server[$id]['radius_timeout'];
187

    
188
			if ($pconfig['radius_auth_port'] &&
189
				$pconfig['radius_acct_port']) {
190
				$pconfig['radius_srvcs'] = "both";
191
			}
192

    
193
			if ($pconfig['radius_auth_port'] &&
194
				!$pconfig['radius_acct_port']) {
195
				$pconfig['radius_srvcs'] = "auth";
196
				$pconfig['radius_acct_port'] = 1813;
197
			}
198

    
199
			if (!$pconfig['radius_auth_port'] &&
200
				$pconfig['radius_acct_port']) {
201
				$pconfig['radius_srvcs'] = "acct";
202
				$pconfig['radius_auth_port'] = 1812;
203
			}
204

    
205
		}
206
	}
207
}
208

    
209
if ($act == "new") {
210
	$pconfig['ldap_protver'] = 3;
211
	$pconfig['ldap_anon'] = true;
212
	$pconfig['radius_protocol'] = "MSCHAPv2";
213
	$pconfig['radius_srvcs'] = "both";
214
	$pconfig['radius_auth_port'] = "1812";
215
	$pconfig['radius_acct_port'] = "1813";
216
}
217

    
218
if ($_POST) {
219
	unset($input_errors);
220
	$pconfig = $_POST;
221

    
222
	/* input validation */
223

    
224
	if ($pconfig['type'] == "ldap") {
225
		$reqdfields = explode(" ",
226
			"name type ldap_host ldap_port " .
227
			"ldap_urltype ldap_protver ldap_scope " .
228
			"ldap_attr_user ldap_attr_group ldap_attr_member ldapauthcontainers");
229

    
230
		$reqdfieldsn = array(
231
			gettext("Descriptive name"),
232
			gettext("Type"),
233
			gettext("Hostname or IP"),
234
			gettext("Port value"),
235
			gettext("Transport"),
236
			gettext("Protocol version"),
237
			gettext("Search level"),
238
			gettext("User naming Attribute"),
239
			gettext("Group naming Attribute"),
240
			gettext("Group member attribute"),
241
			gettext("Authentication container"));
242

    
243
		if (!$pconfig['ldap_anon']) {
244
			$reqdfields[] = "ldap_binddn";
245
			$reqdfields[] = "ldap_bindpw";
246
			$reqdfieldsn[] = gettext("Bind user DN");
247
			$reqdfieldsn[] = gettext("Bind Password");
248
		}
249
	}
250

    
251
	if ($pconfig['type'] == "radius") {
252
		$reqdfields = explode(" ", "name type radius_protocol radius_host radius_srvcs");
253
		$reqdfieldsn = array(
254
			gettext("Descriptive name"),
255
			gettext("Type"),
256
			gettext("Radius Protocol"),
257
			gettext("Hostname or IP"),
258
			gettext("Services"));
259

    
260
		if ($pconfig['radius_srvcs'] == "both" ||
261
			$pconfig['radius_srvcs'] == "auth") {
262
			$reqdfields[] = "radius_auth_port";
263
			$reqdfieldsn[] = gettext("Authentication port");
264
		}
265

    
266
		if ($pconfig['radius_srvcs'] == "both" ||
267
			$pconfig['radius_srvcs'] == "acct") {
268
			$reqdfields[] = "radius_acct_port";
269
			$reqdfieldsn[] = gettext("Accounting port");
270
		}
271

    
272
		if (!isset($id)) {
273
			$reqdfields[] = "radius_secret";
274
			$reqdfieldsn[] = gettext("Shared Secret");
275
		}
276
	}
277

    
278
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
279

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

    
284
	if (auth_get_authserver($pconfig['name']) && !isset($id)) {
285
		$input_errors[] = gettext("An authentication server with the same name already exists.");
286
	}
287

    
288
	if (($pconfig['type'] == "ldap") || ($pconfig['type'] == "radius")) {
289
		$to_field = "{$pconfig['type']}_timeout";
290
		if (isset($_POST[$to_field]) && !empty($_POST[$to_field]) && (!is_numeric($_POST[$to_field]) || (is_numeric($_POST[$to_field]) && ($_POST[$to_field] <= 0)))) {
291
			$input_errors[] = sprintf(gettext("%s Timeout value must be numeric and positive."), strtoupper($pconfig['type']));
292
		}
293
	}
294

    
295
	if (!$input_errors) {
296
		$server = array();
297
		$server['refid'] = uniqid();
298
		if (isset($id) && $a_server[$id]) {
299
			$server = $a_server[$id];
300
		}
301

    
302
		$server['type'] = $pconfig['type'];
303
		$server['name'] = $pconfig['name'];
304

    
305
		if ($server['type'] == "ldap") {
306

    
307
			if (!empty($pconfig['ldap_caref'])) {
308
				$server['ldap_caref'] = $pconfig['ldap_caref'];
309
			}
310
			$server['host'] = $pconfig['ldap_host'];
311
			$server['ldap_port'] = $pconfig['ldap_port'];
312
			$server['ldap_urltype'] = $pconfig['ldap_urltype'];
313
			$server['ldap_protver'] = $pconfig['ldap_protver'];
314
			$server['ldap_scope'] = $pconfig['ldap_scope'];
315
			$server['ldap_basedn'] = $pconfig['ldap_basedn'];
316
			$server['ldap_authcn'] = $pconfig['ldapauthcontainers'];
317
			$server['ldap_extended_enabled'] = $pconfig['ldap_extended_enabled'];
318
			$server['ldap_extended_query'] = $pconfig['ldap_extended_query'];
319
			$server['ldap_attr_user'] = $pconfig['ldap_attr_user'];
320
			$server['ldap_attr_group'] = $pconfig['ldap_attr_group'];
321
			$server['ldap_attr_member'] = $pconfig['ldap_attr_member'];
322

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

    
325
			if ($pconfig['ldap_utf8'] == "yes") {
326
				$server['ldap_utf8'] = true;
327
			} else {
328
				unset($server['ldap_utf8']);
329
			}
330
			if ($pconfig['ldap_nostrip_at'] == "yes") {
331
				$server['ldap_nostrip_at'] = true;
332
			} else {
333
				unset($server['ldap_nostrip_at']);
334
			}
335
			if ($pconfig['ldap_rfc2307'] == "yes") {
336
				$server['ldap_rfc2307'] = true;
337
			} else {
338
				unset($server['ldap_rfc2307']);
339
			}
340

    
341

    
342
			if (!$pconfig['ldap_anon']) {
343
				$server['ldap_binddn'] = $pconfig['ldap_binddn'];
344
				$server['ldap_bindpw'] = $pconfig['ldap_bindpw'];
345
			} else {
346
				unset($server['ldap_binddn']);
347
				unset($server['ldap_bindpw']);
348
			}
349

    
350
			if ($pconfig['ldap_timeout']) {
351
				$server['ldap_timeout'] = $pconfig['ldap_timeout'];
352
			} else {
353
				$server['ldap_timeout'] = 25;
354
			}
355
		}
356

    
357
		if ($server['type'] == "radius") {
358

    
359
			$server['radius_protocol'] = $pconfig['radius_protocol'];
360
			$server['host'] = $pconfig['radius_host'];
361

    
362
			if ($pconfig['radius_secret']) {
363
				$server['radius_secret'] = $pconfig['radius_secret'];
364
			}
365

    
366
			if ($pconfig['radius_timeout']) {
367
				$server['radius_timeout'] = $pconfig['radius_timeout'];
368
			} else {
369
				$server['radius_timeout'] = 5;
370
			}
371

    
372
			if ($pconfig['radius_srvcs'] == "both") {
373
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
374
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
375
			}
376

    
377
			if ($pconfig['radius_srvcs'] == "auth") {
378
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
379
				unset($server['radius_acct_port']);
380
			}
381

    
382
			if ($pconfig['radius_srvcs'] == "acct") {
383
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
384
				unset($server['radius_auth_port']);
385
			}
386
		}
387

    
388
		if (isset($id) && $config['system']['authserver'][$id]) {
389
			$config['system']['authserver'][$id] = $server;
390
		} else {
391
			$config['system']['authserver'][] = $server;
392
		}
393

    
394
		write_config();
395

    
396
		pfSenseHeader("system_authservers.php");
397
	}
398
}
399

    
400
// On error, restore the form contents so the user doesn't have to re-enter too much
401
if ($_POST && $input_errors) {
402
	$pconfig = $_POST;
403
	$pconfig['ldap_authcn'] = $_POST['ldapauthcontainers'];
404
	$pconfig['ldap_template'] = $_POST['ldap_tmpltype'];
405
}
406

    
407
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Authentication Servers"));
408

    
409
if ($act == "new" || $act == "edit" || $input_errors) {
410
	$pgtitle[] = gettext('Edit');
411
}
412
$shortcut_section = "authentication";
413
include("head.inc");
414

    
415
if ($input_errors) {
416
	print_input_errors($input_errors);
417
}
418

    
419
if ($savemsg) {
420
	print_info_box($savemsg, 'success');
421
}
422

    
423
$tab_array = array();
424
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
425
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
426
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
427
$tab_array[] = array(gettext("Authentication Servers"), true, "system_authservers.php");
428
display_top_tabs($tab_array);
429

    
430
if (!($act == "new" || $act == "edit" || $input_errors)) {
431
?>
432
<div class="panel panel-default">
433
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Authentication Servers')?></h2></div>
434
	<div class="panel-body">
435
		<div class="table-responsive">
436
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
437
				<thead>
438
					<tr>
439
						<th><?=gettext("Server Name")?></th>
440
						<th><?=gettext("Type")?></th>
441
						<th><?=gettext("Host Name")?></th>
442
						<th><?=gettext("Actions")?></th>
443
					</tr>
444
				</thead>
445
				<tbody>
446
			<?php foreach ($a_server as $i => $server): ?>
447
					<tr>
448
						<td><?=htmlspecialchars($server['name'])?></td>
449
						<td><?=htmlspecialchars($auth_server_types[$server['type']])?></td>
450
						<td><?=htmlspecialchars($server['host'])?></td>
451
						<td>
452
						<?php if ($i < (count($a_server) - 1)): ?>
453
							<a class="fa fa-pencil" title="<?=gettext("Edit server"); ?>" href="system_authservers.php?act=edit&amp;id=<?=$i?>"></a>
454
							<a class="fa fa-trash"  title="<?=gettext("Delete server")?>" href="system_authservers.php?act=del&amp;id=<?=$i?>"></a>
455
						<?php endif?>
456
						</td>
457
					</tr>
458
			<?php endforeach; ?>
459
				</tbody>
460
			</table>
461
		</div>
462
	</div>
463
</div>
464

    
465
<nav class="action-buttons">
466
	<a href="?act=new" class="btn btn-success btn-sm">
467
		<i class="fa fa-plus icon-embed-btn"></i>
468
		<?=gettext("Add")?>
469
	</a>
470
</nav>
471
<?php
472
	include("foot.inc");
473
	exit;
474
}
475

    
476
$form = new Form;
477
$form->setAction('system_authservers.php?act=edit');
478

    
479
$form->addGlobal(new Form_Input(
480
	'userid',
481
	null,
482
	'hidden',
483
	$id
484
));
485

    
486
$section = new Form_Section('Server Settings');
487

    
488
$section->addInput($input = new Form_Input(
489
	'name',
490
	'Descriptive name',
491
	'text',
492
	$pconfig['name']
493
));
494

    
495
$section->addInput($input = new Form_Select(
496
	'type',
497
	'Type',
498
	$pconfig['type'],
499
	$auth_server_types
500
))->toggles();
501

    
502
$form->add($section);
503

    
504
// ==== LDAP settings =========================================================
505
$section = new Form_Section('LDAP Server Settings');
506
$section->addClass('toggle-ldap collapse');
507

    
508
if (!isset($pconfig['type']) || $pconfig['type'] == 'ldap')
509
	$section->addClass('in');
510

    
511
$section->addInput(new Form_Input(
512
	'ldap_host',
513
	'Hostname or IP address',
514
	'text',
515
	$pconfig['ldap_host']
516
))->setHelp('NOTE: When using SSL or STARTTLS, this hostname MUST match the Common Name '.
517
	'(CN) of the LDAP server\'s SSL Certificate.');
518

    
519
$section->addInput(new Form_Input(
520
	'ldap_port',
521
	'Port value',
522
	'number',
523
	$pconfig['ldap_port']
524
));
525

    
526
$section->addInput(new Form_Select(
527
	'ldap_urltype',
528
	'Transport',
529
	$pconfig['ldap_urltype'],
530
	array_combine(array_keys($ldap_urltypes), array_keys($ldap_urltypes))
531
));
532

    
533
if (empty($a_ca))
534
{
535
	$section->addInput(new Form_StaticText(
536
		'Peer Certificate Authority',
537
		'No Certificate Authorities defined.<br/>Create one under <a href="system_camanager.php">System &gt; Cert. Manager</a>.'
538
	));
539
}
540
else
541
{
542
	$ldapCaRef = [];
543
	foreach ($a_ca as $ca)
544
		$ldapCaRef[ $ca['refid'] ] = $ca['descr'];
545

    
546
	$section->addInput(new Form_Select(
547
		'ldap_caref',
548
		'Peer Certificate Authority',
549
		$pconfig['ldap_caref'],
550
		$ldapCaRef
551
	))->setHelp('This option is used if \'SSL Encrypted\' '.
552
		'or \'TCP - STARTTLS\' options are chosen. '.
553
		'It must match with the CA in the AD otherwise problems will arise.');
554
}
555

    
556
$section->addInput(new Form_Select(
557
	'ldap_protver',
558
	'Protocol version',
559
	$pconfig['ldap_protver'],
560
	array_combine($ldap_protvers, $ldap_protvers)
561
));
562

    
563
$section->addInput(new Form_Input(
564
	'ldap_timeout',
565
	'Server Timeout',
566
	'number',
567
	$pconfig['ldap_timeout'],
568
	['placeholder' => 25]
569
))->setHelp('Timeout for LDAP operations (seconds)');
570

    
571
$group = new Form_Group('Search scope');
572

    
573
$SSF = new Form_Select(
574
	'ldap_scope',
575
	'Level',
576
	$pconfig['ldap_scope'],
577
	$ldap_scopes
578
);
579

    
580
$SSB = new Form_Input(
581
	'ldap_basedn',
582
	'Base DN',
583
	'text',
584
	$pconfig['ldap_basedn']
585
);
586

    
587

    
588
$section->addInput(new Form_StaticText(
589
	'Search scope',
590
	'Level ' . $SSF . '<br />' . 'Base DN' . $SSB
591
));
592

    
593
$group = new Form_Group('Authentication containers');
594
$group->add(new Form_Input(
595
	'ldapauthcontainers',
596
	'Containers',
597
	'text',
598
	$pconfig['ldap_authcn']
599
))->setHelp('Note: Semi-Colon separated. This will be prepended to the search '.
600
	'base dn above or the full container path can be specified containing a dc= '.
601
	'component.<br/>Example: CN=Users;DC=example,DC=com or OU=Staff;OU=Freelancers');
602

    
603
$group->add(new Form_Button(
604
	'Select',
605
	'Select a container',
606
	null,
607
	'fa-search'
608
))->setAttribute('type','button')->addClass('btn-info');
609

    
610
$section->add($group);
611

    
612
$section->addInput(new Form_Checkbox(
613
	'ldap_extended_enabled',
614
	'Extended query',
615
	'Enable extended query',
616
	$pconfig['ldap_extended_enabled']
617
));
618

    
619
$group = new Form_Group('Query');
620
$group->addClass('extended');
621

    
622
$group->add(new Form_Input(
623
	'ldap_extended_query',
624
	'Query',
625
	'text',
626
	$pconfig['ldap_extended_query']
627
))->setHelp('Example: &amp;(objectClass=inetOrgPerson)(mail=*@example.com)');
628

    
629
$section->add($group);
630

    
631
$section->addInput(new Form_Checkbox(
632
	'ldap_anon',
633
	'Bind anonymous',
634
	'Use anonymous binds to resolve distinguished names',
635
	$pconfig['ldap_anon']
636
));
637

    
638
$group = new Form_Group('Bind credentials');
639
$group->addClass('ldapanon');
640

    
641
$group->add(new Form_Input(
642
	'ldap_binddn',
643
	'User DN:',
644
	'text',
645
	$pconfig['ldap_binddn']
646
));
647

    
648
$group->add(new Form_Input(
649
	'ldap_bindpw',
650
	'Password',
651
	'password',
652
	$pconfig['ldap_bindpw']
653
));
654
$section->add($group);
655

    
656
if (!isset($id)) {
657
	$template_list = array();
658

    
659
	foreach ($ldap_templates as $option => $template) {
660
		$template_list[$option] = $template['desc'];
661
	}
662

    
663
	$section->addInput(new Form_Select(
664
		'ldap_tmpltype',
665
		'Initial Template',
666
		$pconfig['ldap_template'],
667
		$template_list
668
	));
669
}
670

    
671
$section->addInput(new Form_Input(
672
	'ldap_attr_user',
673
	'User naming attribute',
674
	'text',
675
	$pconfig['ldap_attr_user']
676
));
677

    
678
$section->addInput(new Form_Input(
679
	'ldap_attr_group',
680
	'Group naming attribute',
681
	'text',
682
	$pconfig['ldap_attr_group']
683
));
684

    
685
$section->addInput(new Form_Input(
686
	'ldap_attr_member',
687
	'Group member attribute',
688
	'text',
689
	$pconfig['ldap_attr_member']
690
));
691

    
692
$section->addInput(new Form_Checkbox(
693
	'ldap_rfc2307',
694
	'RFC 2307 Groups',
695
	'LDAP Server uses RFC 2307 style group membership',
696
	$pconfig['ldap_rfc2307']
697
))->setHelp('RFC 2307 style group membership has members listed on the group '.
698
	'object rather than using groups listed on user object. Leave unchecked '.
699
	'for Active Directory style group membership (RFC 2307bis).');
700

    
701
$section->addInput(new Form_Input(
702
	'ldap_attr_groupobj',
703
	'Group Object Class',
704
	'text',
705
	$pconfig['ldap_attr_groupobj'],
706
	['placeholder' => 'posixGroup']
707
))->setHelp('Object class used for groups in RFC2307 mode. '.
708
	'Typically "posixGroup" or "group".');
709

    
710
$section->addInput(new Form_Checkbox(
711
	'ldap_utf8',
712
	'UTF8 Encode',
713
	'UTF8 encode LDAP parameters before sending them to the server.',
714
	$pconfig['ldap_utf8']
715
))->setHelp('Required to support international characters, but may not be '.
716
	'supported by every LDAP server.');
717

    
718
$section->addInput(new Form_Checkbox(
719
	'ldap_nostrip_at',
720
	'Username Alterations',
721
	'Do not strip away parts of the username after the @ symbol',
722
	$pconfig['ldap_nostrip_at']
723
))->setHelp('e.g. user@host becomes user when unchecked.');
724

    
725
$form->add($section);
726

    
727
// ==== RADIUS section ========================================================
728
$section = new Form_Section('RADIUS Server Settings');
729
$section->addClass('toggle-radius collapse');
730

    
731
$section->addInput(new Form_Select(
732
	'radius_protocol',
733
	'Protocol',
734
	$pconfig['radius_protocol'],
735
	$radius_protocol
736
));
737

    
738
$section->addInput(new Form_Input(
739
	'radius_host',
740
	'Hostname or IP address',
741
	'text',
742
	$pconfig['radius_host']
743
));
744

    
745
$section->addInput(new Form_Input(
746
	'radius_secret',
747
	'Shared Secret',
748
	'password',
749
	$pconfig['radius_secret']
750
));
751

    
752
$section->addInput(new Form_Select(
753
	'radius_srvcs',
754
	'Services offered',
755
	$pconfig['radius_srvcs'],
756
	$radius_srvcs
757
));
758

    
759
$section->addInput(new Form_Input(
760
	'radius_auth_port',
761
	'Authentication port',
762
	'number',
763
	$pconfig['radius_auth_port']
764
));
765

    
766
$section->addInput(new Form_Input(
767
	'radius_acct_port',
768
	'Accounting port',
769
	'number',
770
	$pconfig['radius_acct_port']
771
));
772

    
773
$section->addInput(new Form_Input(
774
	'radius_timeout',
775
	'Authentication Timeout',
776
	'number',
777
	$pconfig['radius_timeout']
778
))->setHelp('This value controls how long, in seconds, that the RADIUS '.
779
	'server may take to respond to an authentication request. If left blank, the '.
780
	'default value is 5 seconds. NOTE: If using an interactive two-factor '.
781
	'authentication system, increase this timeout to account for how long it will '.
782
	'take the user to receive and enter a token.');
783

    
784
if (isset($id) && $a_server[$id])
785
{
786
	$section->addInput(new Form_Input(
787
		'id',
788
		null,
789
		'hidden',
790
		$id
791
	));
792
}
793

    
794
$form->add($section);
795

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

    
799
$form->add($modal);
800

    
801
print $form;
802
?>
803
<script type="text/javascript">
804
//<![CDATA[
805
events.push(function() {
806

    
807
	// Create an AJAX request (to this page) to get the container list and controls
808
	function select_clicked() {
809
		if (document.getElementById("ldap_port").value == '' ||
810
			document.getElementById("ldap_host").value == '' ||
811
			document.getElementById("ldap_scope").value == '' ||
812
			document.getElementById("ldap_basedn").value == '' ||
813
			document.getElementById("ldapauthcontainers").value == '') {
814
			alert("<?=gettext("Please fill the required values.");?>");
815
			return;
816
		}
817

    
818
		if (!document.getElementById("ldap_anon").checked) {
819
			if (document.getElementById("ldap_binddn").value == '' ||
820
				document.getElementById("ldap_bindpw").value == '') {
821
				alert("<?=gettext("Please fill the bind username/password.");?>");
822
				return;
823
			}
824
		}
825

    
826
		var ajaxRequest;
827
		var authserver = $('#authmode').val();
828
		var cert;
829

    
830
<?php if (count($a_ca) > 0): ?>
831
			cert = $('#ldap_caref').val();
832
<?php else: ?>
833
			cert = '';
834
<?php endif; ?>
835
/*
836
		$('#containers').modal('show');
837
		$('#serverlist').parent('div').prev('label').remove();
838
		$('#serverlist').parent('div').removeClass("col-sm-10");
839
		$('#serverlist').parent('div').addClass("col-sm-12");
840
*/
841
		ajaxRequest = $.ajax(
842
			{
843
				url: "/system_authservers.php",
844
				type: "post",
845
				data: {
846
					ajax: 	"ajax",
847
					port: 	$('#ldap_port').val(),
848
					host: 	$('#ldap_host').val(),
849
					scope: 	$('#ldap_scope').val(),
850
					basedn: $('#ldap_basedn').val(),
851
					binddn: $('#ldap_binddn').val(),
852
					bindpw: $('#ldap_bindpw').val(),
853
					urltype:$('#ldap_urltype').val(),
854
					proto:  $('#ldap_protver').val(),
855
					authcn: $('#ldapauthcontainers').val(),
856
					cert:   cert
857
				}
858
			}
859
		);
860

    
861
		// Deal with the results of the above ajax call
862
		ajaxRequest.done(function (response, textStatus, jqXHR) {
863
			$('#containers').replaceWith(response);
864

    
865
			$('#containers').modal('show');
866

    
867
			// The button handler needs to be here because until the modal has been populated
868
			// the controls we need to attach handlers to do not exist
869
			$('#svcontbtn').prop("type", "button");
870
			$('#svcontbtn').removeAttr("href");
871

    
872
			$('#svcontbtn').click(function () {
873
				var ous = $('[id^=ou]').length;
874
				var i;
875

    
876
				$('#ldapauthcontainers').val("");
877

    
878
				for (i = 0; i < ous; i++) {
879
					if ($('#ou' + i).prop("checked")) {
880
						if ($('#ldapauthcontainers').val() != "") {
881
							$('#ldapauthcontainers').val($('#ldapauthcontainers').val() +";");
882
						}
883

    
884
						$('#ldapauthcontainers').val($('#ldapauthcontainers').val() + $('#ou' + i).val());
885
					}
886
				}
887

    
888
				$('#containers').modal('hide');
889
			});
890
		});
891

    
892
	}
893

    
894
	function set_ldap_port() {
895
		if ($('#ldap_urltype').find(":selected").index() == 2)
896
			$('#ldap_port').val('636');
897
		else
898
			$('#ldap_port').val('389');
899
	}
900

    
901
	// Hides all elements of the specified class. This will usually be a section
902
	function hideClass(s_class, hide) {
903
		if (hide)
904
			$('.' + s_class).hide();
905
		else
906
			$('.' + s_class).show();
907
	}
908

    
909
	function ldap_tmplchange() {
910
		switch ($('#ldap_tmpltype').find(":selected").index()) {
911
<?php
912
		$index = 0;
913
		foreach ($ldap_templates as $tmpldata):
914
?>
915
			case <?=$index;?>:
916
				$('#ldap_attr_user').val("<?=$tmpldata['attr_user'];?>");
917
				$('#ldap_attr_group').val("<?=$tmpldata['attr_group'];?>");
918
				$('#ldap_attr_member').val("<?=$tmpldata['attr_member'];?>");
919
				break;
920
<?php
921
			$index++;
922
		endforeach;
923
?>
924
		}
925
	}
926

    
927
	// ---------- On initial page load ------------------------------------------------------------
928

    
929
<?php if ($act != 'edit') : ?>
930
	ldap_tmplchange();
931
<?php endif; ?>
932

    
933
	hideClass('ldapanon', $('#ldap_anon').prop('checked'));
934
	hideClass('extended', !$('#ldap_extended_enabled').prop('checked'));
935

    
936
	if ($('#ldap_port').val() == "")
937
		set_ldap_port();
938

    
939
<?php
940
	if ($act == 'edit') {
941
?>
942
		$('#type option:not(:selected)').each(function(){
943
			$(this).attr('disabled', 'disabled');
944
		});
945

    
946
<?php
947
		if (!$input_errors) {
948
?>
949
		$('#name').prop("readonly", true);
950
<?php
951
		}
952
	}
953
?>
954
	// ---------- Click checkbox handlers ---------------------------------------------------------
955

    
956
	$('#ldap_tmpltype').on('change', function() {
957
		ldap_tmplchange();
958
	});
959

    
960
	$('#ldap_anon').click(function () {
961
		hideClass('ldapanon', this.checked);
962
	});
963

    
964
	$('#ldap_urltype').on('change', function() {
965
		set_ldap_port();
966
	});
967

    
968
	$('#Select').click(function () {
969
		select_clicked();
970
	});
971

    
972
	$('#ldap_extended_enabled').click(function () {
973
		hideClass('extended', !this.checked);
974
	});
975

    
976
});
977
//]]>
978
</script>
979
<?php
980
include("foot.inc");
(191-191/225)