Project

General

Profile

Download (24.7 KB) Statistics
| Branch: | Tag: | Revision:
1 fbf672cb Matthew Grooms
<?php
2
/*
3 ce77a9c4 Phil Davis
	system_authservers.php
4 fbf672cb Matthew Grooms
*/
5 ac9d8bed Stephen Beaver
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 df8fca9d Stephen Beaver
 *	Copyright (c)  2008 Shrew Soft Inc.
8 ac9d8bed Stephen Beaver
 *
9
 *	Redistribution and use in source and binary forms, with or without modification,
10
 *	are permitted provided that the following conditions are met:
11
 *
12
 *	1. Redistributions of source code must retain the above copyright notice,
13
 *		this list of conditions and the following disclaimer.
14
 *
15
 *	2. Redistributions in binary form must reproduce the above copyright
16
 *		notice, this list of conditions and the following disclaimer in
17
 *		the documentation and/or other materials provided with the
18
 *		distribution.
19
 *
20
 *	3. All advertising materials mentioning features or use of this software
21
 *		must display the following acknowledgment:
22
 *		"This product includes software developed by the pfSense Project
23
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
24
 *
25
 *	4. The names "pfSense" and "pfSense Project" must not be used to
26
 *		 endorse or promote products derived from this software without
27
 *		 prior written permission. For written permission, please contact
28
 *		 coreteam@pfsense.org.
29
 *
30
 *	5. Products derived from this software may not be called "pfSense"
31
 *		nor may "pfSense" appear in their names without prior written
32
 *		permission of the Electric Sheep Fencing, LLC.
33
 *
34
 *	6. Redistributions of any form whatsoever must retain the following
35
 *		acknowledgment:
36
 *
37
 *	"This product includes software developed by the pfSense Project
38
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
52
 *
53
 *	====================================================================
54
 *
55
 */
56 fbf672cb Matthew Grooms
57
##|+PRIV
58
##|*IDENT=page-system-authservers
59
##|*NAME=System: Authentication Servers
60
##|*DESCR=Allow access to the 'System: Authentication Servers' page.
61
##|*MATCH=system_authservers.php*
62
##|-PRIV
63
64
require("guiconfig.inc");
65 acee624f Ermal Lu?i
require_once("auth.inc");
66 fbf672cb Matthew Grooms
67 2ee8dea1 Phil Davis
if (is_numericint($_GET['id'])) {
68 e41ec584 Renato Botelho
	$id = $_GET['id'];
69 2ee8dea1 Phil Davis
}
70
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
71 fbf672cb Matthew Grooms
	$id = $_POST['id'];
72 2ee8dea1 Phil Davis
}
73 fbf672cb Matthew Grooms
74 2ee8dea1 Phil Davis
if (!is_array($config['system']['authserver'])) {
75 fbf672cb Matthew Grooms
	$config['system']['authserver'] = array();
76 2ee8dea1 Phil Davis
}
77 fbf672cb Matthew Grooms
78 6306b5dd Ermal Lu?i
$a_servers = auth_get_authserver_list();
79 2ee8dea1 Phil Davis
foreach ($a_servers as $servers) {
80 6306b5dd Ermal Lu?i
	$a_server[] = $servers;
81 2ee8dea1 Phil Davis
}
82 fbf672cb Matthew Grooms
83 2ee8dea1 Phil Davis
if (!is_array($config['ca'])) {
84 a0165602 Sjon Hortensius
	$config['ca'] = array();
85 2ee8dea1 Phil Davis
}
86 fe2031ab Ermal
$a_ca =& $config['ca'];
87
88 fbf672cb Matthew Grooms
$act = $_GET['act'];
89 2ee8dea1 Phil Davis
if ($_POST['act']) {
90 fbf672cb Matthew Grooms
	$act = $_POST['act'];
91 2ee8dea1 Phil Davis
}
92 fbf672cb Matthew Grooms
93
if ($act == "del") {
94
95
	if (!$a_server[$_GET['id']]) {
96
		pfSenseHeader("system_authservers.php");
97
		exit;
98
	}
99
100 9db6993f jim-p
	/* Remove server from main list. */
101 fbf672cb Matthew Grooms
	$serverdeleted = $a_server[$_GET['id']]['name'];
102 9db6993f jim-p
	foreach ($config['system']['authserver'] as $k => $as) {
103 2ee8dea1 Phil Davis
		if ($config['system']['authserver'][$k]['name'] == $serverdeleted) {
104 9db6993f jim-p
			unset($config['system']['authserver'][$k]);
105 2ee8dea1 Phil Davis
		}
106 9db6993f jim-p
	}
107
108
	/* Remove server from temp list used later on this page. */
109 fbf672cb Matthew Grooms
	unset($a_server[$_GET['id']]);
110 9db6993f jim-p
111 8545adde k-paulius
	$savemsg = sprintf(gettext("Authentication Server %s deleted."), htmlspecialchars($serverdeleted));
112 9db6993f jim-p
	write_config($savemsg);
113 fbf672cb Matthew Grooms
}
114
115
if ($act == "edit") {
116
	if (isset($id) && $a_server[$id]) {
117
118
		$pconfig['type'] = $a_server[$id]['type'];
119
		$pconfig['name'] = $a_server[$id]['name'];
120
121
		if ($pconfig['type'] == "ldap") {
122 fe2031ab Ermal
			$pconfig['ldap_caref'] = $a_server[$id]['ldap_caref'];
123 fbf672cb Matthew Grooms
			$pconfig['ldap_host'] = $a_server[$id]['host'];
124
			$pconfig['ldap_port'] = $a_server[$id]['ldap_port'];
125 d6b4dfe3 jim-p
			$pconfig['ldap_timeout'] = $a_server[$id]['ldap_timeout'];
126 fbf672cb Matthew Grooms
			$pconfig['ldap_urltype'] = $a_server[$id]['ldap_urltype'];
127
			$pconfig['ldap_protver'] = $a_server[$id]['ldap_protver'];
128
			$pconfig['ldap_scope'] = $a_server[$id]['ldap_scope'];
129
			$pconfig['ldap_basedn'] = $a_server[$id]['ldap_basedn'];
130 c61e4626 Ermal Lu?i
			$pconfig['ldap_authcn'] = $a_server[$id]['ldap_authcn'];
131 c7073ebf namezero111111
			$pconfig['ldap_extended_enabled'] = $a_server[$id]['ldap_extended_enabled'];
132
			$pconfig['ldap_extended_query'] = $a_server[$id]['ldap_extended_query'];
133 fbf672cb Matthew Grooms
			$pconfig['ldap_binddn'] = $a_server[$id]['ldap_binddn'];
134
			$pconfig['ldap_bindpw'] = $a_server[$id]['ldap_bindpw'];
135
			$pconfig['ldap_attr_user'] = $a_server[$id]['ldap_attr_user'];
136
			$pconfig['ldap_attr_group'] = $a_server[$id]['ldap_attr_group'];
137
			$pconfig['ldap_attr_member'] = $a_server[$id]['ldap_attr_member'];
138 149efbea jim-p
			$pconfig['ldap_attr_groupobj'] = $a_server[$id]['ldap_attr_groupobj'];
139 a5cd1c5a jim-p
			$pconfig['ldap_utf8'] = isset($a_server[$id]['ldap_utf8']);
140
			$pconfig['ldap_nostrip_at'] = isset($a_server[$id]['ldap_nostrip_at']);
141 149efbea jim-p
			$pconfig['ldap_rfc2307'] = isset($a_server[$id]['ldap_rfc2307']);
142 fbf672cb Matthew Grooms
143 2ee8dea1 Phil Davis
			if (!$pconfig['ldap_binddn'] || !$pconfig['ldap_bindpw']) {
144 fbf672cb Matthew Grooms
				$pconfig['ldap_anon'] = true;
145 2ee8dea1 Phil Davis
			}
146 fbf672cb Matthew Grooms
		}
147
148
		if ($pconfig['type'] == "radius") {
149
			$pconfig['radius_host'] = $a_server[$id]['host'];
150
			$pconfig['radius_auth_port'] = $a_server[$id]['radius_auth_port'];
151
			$pconfig['radius_acct_port'] = $a_server[$id]['radius_acct_port'];
152 e8a58de4 Ermal Lu?i
			$pconfig['radius_secret'] = $a_server[$id]['radius_secret'];
153 bddd2be8 jim-p
			$pconfig['radius_timeout'] = $a_server[$id]['radius_timeout'];
154 fbf672cb Matthew Grooms
155
			if ($pconfig['radius_auth_port'] &&
156 ac9d8bed Stephen Beaver
				$pconfig['radius_acct_port']) {
157 fbf672cb Matthew Grooms
				$pconfig['radius_srvcs'] = "both";
158
			}
159
160 2ee8dea1 Phil Davis
			if ($pconfig['radius_auth_port'] &&
161 ac9d8bed Stephen Beaver
				!$pconfig['radius_acct_port']) {
162 fbf672cb Matthew Grooms
				$pconfig['radius_srvcs'] = "auth";
163 acee624f Ermal Lu?i
				$pconfig['radius_acct_port'] = 1813;
164 fbf672cb Matthew Grooms
			}
165
166
			if (!$pconfig['radius_auth_port'] &&
167 ac9d8bed Stephen Beaver
				$pconfig['radius_acct_port']) {
168 fbf672cb Matthew Grooms
				$pconfig['radius_srvcs'] = "acct";
169 acee624f Ermal Lu?i
				$pconfig['radius_auth_port'] = 1812;
170 fbf672cb Matthew Grooms
			}
171
172
		}
173
	}
174
}
175
176
if ($act == "new") {
177
	$pconfig['ldap_protver'] = 3;
178
	$pconfig['ldap_anon'] = true;
179
	$pconfig['radius_srvcs'] = "both";
180 acee624f Ermal Lu?i
	$pconfig['radius_auth_port'] = "1812";
181
	$pconfig['radius_acct_port'] = "1813";
182 fbf672cb Matthew Grooms
}
183
184
if ($_POST) {
185
	unset($input_errors);
186
	$pconfig = $_POST;
187
188
	/* input validation */
189
190
	if ($pconfig['type'] == "ldap") {
191 2ee8dea1 Phil Davis
		$reqdfields = explode(" ",
192
			"name type ldap_host ldap_port " .
193
			"ldap_urltype ldap_protver ldap_scope " .
194
			"ldap_attr_user ldap_attr_group ldap_attr_member ldapauthcontainers");
195 7b4b0ad3 Stephen Beaver
196 257705ca Renato Botelho
		$reqdfieldsn = array(
197
			gettext("Descriptive name"),
198
			gettext("Type"),
199
			gettext("Hostname or IP"),
200
			gettext("Port value"),
201
			gettext("Transport"),
202
			gettext("Protocol version"),
203
			gettext("Search level"),
204
			gettext("User naming Attribute"),
205
			gettext("Group naming Attribute"),
206
			gettext("Group member attribute"),
207
			gettext("Authentication container"));
208 fbf672cb Matthew Grooms
209
		if (!$pconfig['ldap_anon']) {
210
			$reqdfields[] = "ldap_binddn";
211
			$reqdfields[] = "ldap_bindpw";
212 257705ca Renato Botelho
			$reqdfieldsn[] = gettext("Bind user DN");
213
			$reqdfieldsn[] = gettext("Bind Password");
214 fbf672cb Matthew Grooms
		}
215
	}
216
217
	if ($pconfig['type'] == "radius") {
218
		$reqdfields = explode(" ", "name type radius_host radius_srvcs");
219 257705ca Renato Botelho
		$reqdfieldsn = array(
220
			gettext("Descriptive name"),
221
			gettext("Type"),
222
			gettext("Hostname or IP"),
223
			gettext("Services"));
224 fbf672cb Matthew Grooms
225
		if ($pconfig['radisu_srvcs'] == "both" ||
226 ac9d8bed Stephen Beaver
			$pconfig['radisu_srvcs'] == "auth") {
227 fbf672cb Matthew Grooms
			$reqdfields[] = "radius_auth_port";
228 81ec3187 Chris Buechler
			$reqdfieldsn[] = gettext("Authentication port");
229 fbf672cb Matthew Grooms
		}
230
231
		if ($pconfig['radisu_srvcs'] == "both" ||
232 ac9d8bed Stephen Beaver
			$pconfig['radisu_srvcs'] == "acct") {
233 fbf672cb Matthew Grooms
			$reqdfields[] = "radius_acct_port";
234 81ec3187 Chris Buechler
			$reqdfieldsn[] = gettext("Accounting port");
235 fbf672cb Matthew Grooms
		}
236
237
		if (!isset($id)) {
238
			$reqdfields[] = "radius_secret";
239 257705ca Renato Botelho
			$reqdfieldsn[] = gettext("Shared Secret");
240 fbf672cb Matthew Grooms
		}
241
	}
242
243 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
244 fbf672cb Matthew Grooms
245 2ee8dea1 Phil Davis
	if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['host'])) {
246 fbf672cb Matthew Grooms
		$input_errors[] = gettext("The host name contains invalid characters.");
247 2ee8dea1 Phil Davis
	}
248 fbf672cb Matthew Grooms
249 2ee8dea1 Phil Davis
	if (auth_get_authserver($pconfig['name']) && !isset($id)) {
250 257705ca Renato Botelho
		$input_errors[] = gettext("An authentication server with the same name already exists.");
251 2ee8dea1 Phil Davis
	}
252 acee624f Ermal Lu?i
253 d6b4dfe3 jim-p
	if (($pconfig['type'] == "ldap") || ($pconfig['type'] == "radius")) {
254
		$to_field = "{$pconfig['type']}_timeout";
255
		if (isset($_POST[$to_field]) && !empty($_POST[$to_field]) && (!is_numeric($_POST[$to_field]) || (is_numeric($_POST[$to_field]) && ($_POST[$to_field] <= 0)))) {
256
			$input_errors[] = sprintf(gettext("%s Timeout value must be numeric and positive."), strtoupper($pconfig['type']));
257
		}
258 2ee8dea1 Phil Davis
	}
259 bddd2be8 jim-p
260 fbf672cb Matthew Grooms
	/* if this is an AJAX caller then handle via JSON */
261
	if (isAjax() && is_array($input_errors)) {
262
		input_errors2Ajax($input_errors);
263
		exit;
264
	}
265
266
	if (!$input_errors) {
267
		$server = array();
268
		$server['refid'] = uniqid();
269 2ee8dea1 Phil Davis
		if (isset($id) && $a_server[$id]) {
270 fbf672cb Matthew Grooms
			$server = $a_server[$id];
271 2ee8dea1 Phil Davis
		}
272 fbf672cb Matthew Grooms
273
		$server['type'] = $pconfig['type'];
274
		$server['name'] = $pconfig['name'];
275
276
		if ($server['type'] == "ldap") {
277
278 2ee8dea1 Phil Davis
			if (!empty($pconfig['ldap_caref'])) {
279 fe2031ab Ermal
				$server['ldap_caref'] = $pconfig['ldap_caref'];
280 2ee8dea1 Phil Davis
			}
281 fbf672cb Matthew Grooms
			$server['host'] = $pconfig['ldap_host'];
282
			$server['ldap_port'] = $pconfig['ldap_port'];
283
			$server['ldap_urltype'] = $pconfig['ldap_urltype'];
284
			$server['ldap_protver'] = $pconfig['ldap_protver'];
285
			$server['ldap_scope'] = $pconfig['ldap_scope'];
286
			$server['ldap_basedn'] = $pconfig['ldap_basedn'];
287 c61e4626 Ermal Lu?i
			$server['ldap_authcn'] = $pconfig['ldapauthcontainers'];
288 c7073ebf namezero111111
			$server['ldap_extended_enabled'] = $pconfig['ldap_extended_enabled'];
289
			$server['ldap_extended_query'] = $pconfig['ldap_extended_query'];
290 fbf672cb Matthew Grooms
			$server['ldap_attr_user'] = $pconfig['ldap_attr_user'];
291
			$server['ldap_attr_group'] = $pconfig['ldap_attr_group'];
292
			$server['ldap_attr_member'] = $pconfig['ldap_attr_member'];
293 149efbea jim-p
294
			$server['ldap_attr_groupobj'] = empty($pconfig['ldap_attr_groupobj']) ? "posixGroup" : $pconfig['ldap_attr_groupobj'];
295
296 2ee8dea1 Phil Davis
			if ($pconfig['ldap_utf8'] == "yes") {
297 a5cd1c5a jim-p
				$server['ldap_utf8'] = true;
298 2ee8dea1 Phil Davis
			} else {
299 a5cd1c5a jim-p
				unset($server['ldap_utf8']);
300 2ee8dea1 Phil Davis
			}
301
			if ($pconfig['ldap_nostrip_at'] == "yes") {
302 a5cd1c5a jim-p
				$server['ldap_nostrip_at'] = true;
303 2ee8dea1 Phil Davis
			} else {
304 a5cd1c5a jim-p
				unset($server['ldap_nostrip_at']);
305 2ee8dea1 Phil Davis
			}
306 149efbea jim-p
			if ($pconfig['ldap_rfc2307'] == "yes") {
307
				$server['ldap_rfc2307'] = true;
308
			} else {
309
				unset($server['ldap_rfc2307']);
310
			}
311 a5cd1c5a jim-p
312 fbf672cb Matthew Grooms
313
			if (!$pconfig['ldap_anon']) {
314
				$server['ldap_binddn'] = $pconfig['ldap_binddn'];
315
				$server['ldap_bindpw'] = $pconfig['ldap_bindpw'];
316
			} else {
317
				unset($server['ldap_binddn']);
318
				unset($server['ldap_bindpw']);
319
			}
320 d6b4dfe3 jim-p
321
			if ($pconfig['ldap_timeout']) {
322
				$server['ldap_timeout'] = $pconfig['ldap_timeout'];
323
			} else {
324
				$server['ldap_timeout'] = 25;
325
			}
326 fbf672cb Matthew Grooms
		}
327
328
		if ($server['type'] == "radius") {
329
330
			$server['host'] = $pconfig['radius_host'];
331
332 2ee8dea1 Phil Davis
			if ($pconfig['radius_secret']) {
333 fbf672cb Matthew Grooms
				$server['radius_secret'] = $pconfig['radius_secret'];
334 2ee8dea1 Phil Davis
			}
335 fbf672cb Matthew Grooms
336 2ee8dea1 Phil Davis
			if ($pconfig['radius_timeout']) {
337 bddd2be8 jim-p
				$server['radius_timeout'] = $pconfig['radius_timeout'];
338 2ee8dea1 Phil Davis
			} else {
339 afdf29d3 jim-p
				$server['radius_timeout'] = 5;
340 2ee8dea1 Phil Davis
			}
341 bddd2be8 jim-p
342 fbf672cb Matthew Grooms
			if ($pconfig['radius_srvcs'] == "both") {
343
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
344
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
345
			}
346
347
			if ($pconfig['radius_srvcs'] == "auth") {
348
				$server['radius_auth_port'] = $pconfig['radius_auth_port'];
349
				unset($server['radius_acct_port']);
350
			}
351
352
			if ($pconfig['radius_srvcs'] == "acct") {
353
				$server['radius_acct_port'] = $pconfig['radius_acct_port'];
354
				unset($server['radius_auth_port']);
355
			}
356
		}
357
358 2ee8dea1 Phil Davis
		if (isset($id) && $config['system']['authserver'][$id]) {
359 6306b5dd Ermal Lu?i
			$config['system']['authserver'][$id] = $server;
360 2ee8dea1 Phil Davis
		} else {
361 6306b5dd Ermal Lu?i
			$config['system']['authserver'][] = $server;
362 2ee8dea1 Phil Davis
		}
363 fbf672cb Matthew Grooms
364
		write_config();
365
366
		pfSenseHeader("system_authservers.php");
367
	}
368
}
369
370 1d3259b5 Stephen Beaver
// On error, restore the form contents so the user doesn't have to re-enter too much
371 504bd882 Stephen Beaver
if($_POST && $input_errors) {
372
	$pconfig = $_POST;
373
	$pconfig['ldap_authcn'] = $_POST['ldapauthcontainers'];
374 b1f0f7e1 Stephen Beaver
	$pconfig['ldap_template'] = $_POST['ldap_tmpltype'];
375 504bd882 Stephen Beaver
}
376
377 8f1ab2a4 k-paulius
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Authentication Servers"));
378
379
if ($act == "new" || $act == "edit" || $input_errors) {
380
	$pgtitle[] = gettext('Edit');
381
}
382
$shortcut_section = "authentication";
383 fbf672cb Matthew Grooms
include("head.inc");
384
385 762faef5 Phil Davis
if ($input_errors) {
386 a0165602 Sjon Hortensius
	print_input_errors($input_errors);
387 762faef5 Phil Davis
}
388 7b4b0ad3 Stephen Beaver
389 762faef5 Phil Davis
if ($savemsg) {
390 ea342b0f Stephen Beaver
	print_info_box($savemsg, 'success');
391 762faef5 Phil Davis
}
392 a0165602 Sjon Hortensius
393
$tab_array = array();
394
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
395
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
396
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
397 2d1f33d9 k-paulius
$tab_array[] = array(gettext("Authentication Servers"), true, "system_authservers.php");
398 a0165602 Sjon Hortensius
display_top_tabs($tab_array);
399
400 762faef5 Phil Davis
if (!($act == "new" || $act == "edit" || $input_errors)) {
401 060ed238 Stephen Beaver
?>
402
<div class="panel panel-default">
403 70dc5cd6 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Authentication Servers')?></h2></div>
404 060ed238 Stephen Beaver
	<div class="panel-body">
405
		<div class="table-responsive">
406
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
407
				<thead>
408
					<tr>
409
						<th><?=gettext("Server Name")?></th>
410
						<th><?=gettext("Type")?></th>
411
						<th><?=gettext("Host Name")?></th>
412
						<th><?=gettext("Actions")?></th>
413
					</tr>
414
				</thead>
415
				<tbody>
416
			<?php foreach($a_server as $i => $server): ?>
417
					<tr>
418
						<td><?=htmlspecialchars($server['name'])?></td>
419
						<td><?=htmlspecialchars($auth_server_types[$server['type']])?></td>
420
						<td><?=htmlspecialchars($server['host'])?></td>
421
						<td>
422
						<?php if ($i < (count($a_server) - 1)): ?>
423
							<a class="fa fa-pencil" title="<?=gettext("Edit server"); ?>" href="system_authservers.php?act=edit&amp;id=<?=$i?>"></a>
424
							<a class="fa fa-trash"  title="<?=gettext("Delete server")?>" href="system_authservers.php?act=del&amp;id=<?=$i?>"></a>
425
						<?php endif?>
426
						</td>
427
					</tr>
428
			<?php endforeach; ?>
429
				</tbody>
430
			</table>
431
		</div>
432 94404d94 Sander van Leeuwen
	</div>
433 060ed238 Stephen Beaver
</div>
434
435
<nav class="action-buttons">
436
	<a href="?act=new" class="btn btn-success btn-sm">
437
		<i class="fa fa-plus icon-embed-btn"></i>
438
		<?=gettext("Add")?>
439
	</a>
440
</nav>
441 fbf672cb Matthew Grooms
<?php
442 a0165602 Sjon Hortensius
	include("foot.inc");
443
	exit;
444 fbf672cb Matthew Grooms
}
445
446 a0165602 Sjon Hortensius
$form = new Form;
447
$form->setAction('system_authservers.php?act=edit');
448 ea342b0f Stephen Beaver
449 a0165602 Sjon Hortensius
$form->addGlobal(new Form_Input(
450
	'userid',
451
	null,
452
	'hidden',
453
	$id
454
));
455
456 5f88f964 k-paulius
$section = new Form_Section('Server Settings');
457 a0165602 Sjon Hortensius
458
$section->addInput($input = new Form_Input(
459
	'name',
460
	'Descriptive name',
461
	'text',
462
	$pconfig['name']
463
));
464
465
$section->addInput($input = new Form_Select(
466
	'type',
467
	'Type',
468
	$pconfig['type'],
469
	$auth_server_types
470 44d906ca Sjon Hortensius
))->toggles();
471 a0165602 Sjon Hortensius
472
$form->add($section);
473 6157f724 Stephen Beaver
474
// ==== LDAP settings =========================================================
475 a0165602 Sjon Hortensius
$section = new Form_Section('LDAP Server Settings');
476 44d906ca Sjon Hortensius
$section->addClass('toggle-ldap collapse');
477 a0165602 Sjon Hortensius
478
if (!isset($pconfig['type']) || $pconfig['type'] == 'ldap')
479
	$section->addClass('in');
480
481
$section->addInput(new Form_Input(
482
	'ldap_host',
483
	'Hostname or IP address',
484
	'text',
485
	$pconfig['ldap_host']
486
))->setHelp('NOTE: When using SSL, this hostname MUST match the Common Name '.
487 5585e65d Chris Buechler
	'(CN) of the LDAP server\'s SSL Certificate.');
488 a0165602 Sjon Hortensius
489
$section->addInput(new Form_Input(
490
	'ldap_port',
491
	'Port value',
492
	'number',
493
	$pconfig['ldap_port']
494
));
495
496
$section->addInput(new Form_Select(
497
	'ldap_urltype',
498
	'Transport',
499
	$pconfig['ldap_urltype'],
500
	array_combine(array_keys($ldap_urltypes), array_keys($ldap_urltypes))
501
));
502
503
if (empty($a_ca))
504
{
505
	$section->addInput(new Form_StaticText(
506
		'Peer Certificate Authority',
507 d4a744b2 k-paulius
		'No Certificate Authorities defined.<br/>Create one under <a href="system_camanager.php">System &gt; Cert. Manager</a>.'
508 a0165602 Sjon Hortensius
	));
509 fbf672cb Matthew Grooms
}
510 a0165602 Sjon Hortensius
else
511
{
512
	$ldapCaRef = [];
513
	foreach ($a_ca as $ca)
514
		$ldapCaRef[ $ca['refid'] ] = $ca['descr'];
515
516
	$section->addInput(new Form_Select(
517
		'ldap_caref',
518
		'Peer Certificate Authority',
519
		$pconfig['ldap_caref'],
520
		$ldapCaRef
521
	))->setHelp('This option is used if \'SSL Encrypted\' option is choosen. '.
522
		'It must match with the CA in the AD otherwise problems will arise.');
523 fbf672cb Matthew Grooms
}
524
525 a0165602 Sjon Hortensius
$section->addInput(new Form_Select(
526
	'ldap_protver',
527
	'Protocol version',
528
	$pconfig['ldap_protver'],
529
	array_combine($ldap_protvers, $ldap_protvers)
530
));
531
532 d6b4dfe3 jim-p
$section->addInput(new Form_Input(
533
	'ldap_timeout',
534
	'Server Timeout',
535
	'number',
536
	$pconfig['ldap_timeout'],
537
	['placeholder' => 25]
538
))->setHelp('Timeout for LDAP operations (seconds)');
539
540 905f6119 Stephen Beaver
$group = new Form_Group('Search scope');
541
542 c84db5bb Stephen Beaver
$SSF = new Form_Select(
543 a0165602 Sjon Hortensius
	'ldap_scope',
544 c84db5bb Stephen Beaver
	'Level',
545 a0165602 Sjon Hortensius
	$pconfig['ldap_scope'],
546
	$ldap_scopes
547 c84db5bb Stephen Beaver
);
548 df8fca9d Stephen Beaver
549 c84db5bb Stephen Beaver
$SSB = new Form_Input(
550 a0165602 Sjon Hortensius
	'ldap_basedn',
551
	'Base DN',
552
	'text',
553
	$pconfig['ldap_basedn']
554 c84db5bb Stephen Beaver
);
555 905f6119 Stephen Beaver
556 c84db5bb Stephen Beaver
557
$section->addInput(new Form_StaticText(
558
	'Search scope',
559
	'Level ' . $SSF . '<br />' . 'Base DN' . $SSB
560
));
561 a0165602 Sjon Hortensius
562
$group = new Form_Group('Authentication containers');
563
$group->add(new Form_Input(
564
	'ldapauthcontainers',
565
	'Containers',
566
	'text',
567
	$pconfig['ldap_authcn']
568
))->setHelp('Note: Semi-Colon separated. This will be prepended to the search '.
569
	'base dn above or you can specify full container path containing a dc= '.
570
	'component.<br/>Example: CN=Users;DC=example,DC=com or OU=Staff;OU=Freelancers');
571 504bd882 Stephen Beaver
572 a0165602 Sjon Hortensius
$group->add(new Form_Button(
573
	'Select',
574 501efbd2 Stephen Beaver
	'Select a container'
575
))->removeClass('btn-primary')->addClass('btn-default');
576
577 a0165602 Sjon Hortensius
$section->add($group);
578
579 2e101d89 Sander van Leeuwen
$section->addInput(new Form_Checkbox(
580 a0165602 Sjon Hortensius
	'ldap_extended_enabled',
581 2e101d89 Sander van Leeuwen
	'Extended query',
582
	'Enable extended query',
583 a0165602 Sjon Hortensius
	$pconfig['ldap_extended_enabled']
584 e39a41e9 Stephen Beaver
));
585 a0165602 Sjon Hortensius
586 2e101d89 Sander van Leeuwen
$group = new Form_Group('Query');
587 e39a41e9 Stephen Beaver
$group->addClass('extended');
588
589 a0165602 Sjon Hortensius
$group->add(new Form_Input(
590
	'ldap_extended_query',
591 2e101d89 Sander van Leeuwen
	'Query',
592 a0165602 Sjon Hortensius
	'text',
593
	$pconfig['ldap_extended_query']
594 2e101d89 Sander van Leeuwen
))->setHelp('Example: &amp;(objectClass=inetOrgPerson)(mail=*@example.com)');
595
596 a0165602 Sjon Hortensius
$section->add($group);
597
598
$section->addInput(new Form_Checkbox(
599
	'ldap_anon',
600
	'Bind anonymous',
601
	'Use anonymous binds to resolve distinguished names',
602
	$pconfig['ldap_anon']
603 b0909f2e Stephen Beaver
));
604 a0165602 Sjon Hortensius
605
$group = new Form_Group('Bind credentials');
606 b0909f2e Stephen Beaver
$group->addClass('ldapanon');
607
608 a0165602 Sjon Hortensius
$group->add(new Form_Input(
609
	'ldap_binddn',
610
	'User DN:',
611
	'text',
612
	$pconfig['ldap_binddn']
613
));
614 b0909f2e Stephen Beaver
615 a0165602 Sjon Hortensius
$group->add(new Form_Input(
616
	'ldap_bindpw',
617
	'Password',
618
	'text',
619
	$pconfig['ldap_bindpw']
620
));
621
$section->add($group);
622
623 ac9d8bed Stephen Beaver
if (!isset($id)) {
624
	$template_list = array();
625
626
	foreach($ldap_templates as $option => $template) {
627
		$template_list[$option] = $template['desc'];
628
	}
629 a0165602 Sjon Hortensius
630
	$section->addInput(new Form_Select(
631
		'ldap_tmpltype',
632
		'Initial Template',
633
		$pconfig['ldap_template'],
634 ac9d8bed Stephen Beaver
		$template_list
635 a0165602 Sjon Hortensius
	));
636 fbf672cb Matthew Grooms
}
637
638 a0165602 Sjon Hortensius
$section->addInput(new Form_Input(
639
	'ldap_attr_user',
640
	'User naming attribute',
641
	'text',
642
	$pconfig['ldap_attr_user']
643
));
644
645
$section->addInput(new Form_Input(
646
	'ldap_attr_group',
647
	'Group naming attribute',
648
	'text',
649
	$pconfig['ldap_attr_group']
650
));
651
652
$section->addInput(new Form_Input(
653
	'ldap_attr_member',
654
	'Group member attribute',
655
	'text',
656
	$pconfig['ldap_attr_member']
657
));
658
659 149efbea jim-p
$section->addInput(new Form_Checkbox(
660
	'ldap_rfc2307',
661
	'RFC 2307 Groups',
662
	'LDAP Server uses RFC 2307 style group membership',
663
	$pconfig['ldap_rfc2307']
664
))->setHelp('RFC 2307 style group membership has members listed on the group '.
665
	'object rather than using groups listed on user object. Leave unchecked '.
666
	'for Active Directory style group membership (RFC 2307bis).');
667
668
$section->addInput(new Form_Input(
669
	'ldap_attr_groupobj',
670
	'Group Object Class',
671
	'text',
672
	$pconfig['ldap_attr_groupobj'],
673
	['placeholder' => 'posixGroup']
674
))->setHelp('Object class used for groups in RFC2307 mode. '.
675
	'Typically "posixGroup" or "group".');
676
677 a0165602 Sjon Hortensius
$section->addInput(new Form_Checkbox(
678
	'ldap_utf8',
679
	'UTF8 Encode',
680
	'UTF8 encode LDAP parameters before sending them to the server.',
681
	$pconfig['ldap_utf8']
682
))->setHelp('Required to support international characters, but may not be '.
683
	'supported by every LDAP server.');
684
685
$section->addInput(new Form_Checkbox(
686
	'ldap_nostrip_at',
687
	'Username Alterations',
688
	'Do not strip away parts of the username after the @ symbol',
689
	$pconfig['ldap_nostrip_at']
690
))->setHelp('e.g. user@host becomes user when unchecked.');
691
692
$form->add($section);
693 6157f724 Stephen Beaver
694
// ==== RADIUS section ========================================================
695 7aaf60a8 k-paulius
$section = new Form_Section('RADIUS Server Settings');
696 44d906ca Sjon Hortensius
$section->addClass('toggle-radius collapse');
697 a0165602 Sjon Hortensius
698
$section->addInput(new Form_Input(
699
	'radius_host',
700
	'Hostname or IP address',
701
	'text',
702
	$pconfig['radius_host']
703
));
704
705
$section->addInput(new Form_Input(
706
	'radius_secret',
707
	'Shared Secret',
708
	'text',
709
	$pconfig['radius_secret']
710
));
711
712
$section->addInput(new Form_Select(
713
	'radius_srvcs',
714
	'Services offered',
715
	$pconfig['radius_srvcs'],
716
	$radius_srvcs
717
));
718
719
$section->addInput(new Form_Input(
720
	'radius_auth_port',
721 81ec3187 Chris Buechler
	'Authentication port',
722 a0165602 Sjon Hortensius
	'number',
723 df5d8616 Stephen Beaver
	$pconfig['radius_auth_port']
724 a0165602 Sjon Hortensius
));
725
726
$section->addInput(new Form_Input(
727
	'radius_acct_port',
728 df5d8616 Stephen Beaver
	'Accounting port',
729 a0165602 Sjon Hortensius
	'number',
730
	$pconfig['radius_acct_port']
731
));
732
733
$section->addInput(new Form_Input(
734
	'radius_timeout',
735
	'Authentication Timeout',
736
	'number',
737
	$pconfig['radius_timeout']
738
))->setHelp('This value controls how long, in seconds, that the RADIUS '.
739
	'server may take to respond to an authentication request. If left blank, the '.
740
	'default value is 5 seconds. NOTE: If you are using an interactive two-factor '.
741
	'authentication system, increase this timeout to account for how long it will '.
742
	'take the user to receive and enter a token.');
743
744
if (isset($id) && $a_server[$id])
745
{
746
	$section->addInput(new Form_Input(
747
		'id',
748
		null,
749
		'hidden',
750
		$id
751
	));
752 6306b5dd Ermal Lu?i
}
753 a0165602 Sjon Hortensius
754
$form->add($section);
755
print $form;
756 ac9d8bed Stephen Beaver
?>
757 8fd9052f Colin Fleming
<script type="text/javascript">
758 ac9d8bed Stephen Beaver
//<![CDATA[
759
events.push(function(){
760 501efbd2 Stephen Beaver
	function select_clicked() {
761
		if (document.getElementById("ldap_port").value == '' ||
762 7b4b0ad3 Stephen Beaver
			document.getElementById("ldap_host").value == '' ||
763
			document.getElementById("ldap_scope").value == '' ||
764
			document.getElementById("ldap_basedn").value == '' ||
765
			document.getElementById("ldapauthcontainers").value == '') {
766 501efbd2 Stephen Beaver
			alert("<?=gettext("Please fill the required values.");?>");
767
			return;
768
		}
769 7b4b0ad3 Stephen Beaver
770 501efbd2 Stephen Beaver
		if (!document.getElementById("ldap_anon").checked) {
771
			if (document.getElementById("ldap_binddn").value == '' ||
772 7b4b0ad3 Stephen Beaver
				document.getElementById("ldap_bindpw").value == '') {
773 501efbd2 Stephen Beaver
				alert("<?=gettext("Please fill the bind username/password.");?>");
774
				return;
775
			}
776
		}
777
		var url = 'system_usermanager_settings_ldapacpicker.php?';
778
		url += 'port=' + document.getElementById("ldap_port").value;
779
		url += '&host=' + document.getElementById("ldap_host").value;
780
		url += '&scope=' + document.getElementById("ldap_scope").value;
781
		url += '&basedn=' + document.getElementById("ldap_basedn").value;
782
		url += '&binddn=' + document.getElementById("ldap_binddn").value;
783
		url += '&bindpw=' + document.getElementById("ldap_bindpw").value;
784
		url += '&urltype=' + document.getElementById("ldap_urltype").value;
785
		url += '&proto=' + document.getElementById("ldap_protver").value;
786
		url += '&authcn=' + document.getElementById("ldapauthcontainers").value;
787
		<?php if (count($a_ca) > 0): ?>
788
			url += '&cert=' + document.getElementById("ldap_caref").value;
789
		<?php else: ?>
790
			url += '&cert=';
791
		<?php endif; ?>
792 7b4b0ad3 Stephen Beaver
793 501efbd2 Stephen Beaver
		var oWin = window.open(url, "pfSensePop", "width=620,height=400,top=150,left=150");
794
		if (oWin == null || typeof(oWin) == "undefined") {
795 7b4b0ad3 Stephen Beaver
			alert("<?=gettext('Popup blocker detected.	Action aborted.');?>");
796 501efbd2 Stephen Beaver
		}
797
	}
798 7b4b0ad3 Stephen Beaver
799 f3a43095 Stephen Beaver
	function set_ldap_port() {
800 7b4b0ad3 Stephen Beaver
		if($('#ldap_urltype').find(":selected").index() == 0)
801 f3a43095 Stephen Beaver
			$('#ldap_port').val('389');
802
		else
803 7b4b0ad3 Stephen Beaver
			$('#ldap_port').val('636');
804
	}
805
806
	// Hides all elements of the specified class. This will usually be a section
807
	function hideClass(s_class, hide) {
808
		if(hide)
809
			$('.' + s_class).hide();
810
		else
811
			$('.' + s_class).show();
812 f3a43095 Stephen Beaver
	}
813 7b4b0ad3 Stephen Beaver
814 ac9d8bed Stephen Beaver
	function ldap_tmplchange() {
815
		switch ($('#ldap_tmpltype').find(":selected").index()) {
816
<?php
817
		$index = 0;
818
		foreach ($ldap_templates as $tmpldata):
819
?>
820
			case <?=$index;?>:
821
				$('#ldap_attr_user').val("<?=$tmpldata['attr_user'];?>");
822
				$('#ldap_attr_group').val("<?=$tmpldata['attr_group'];?>");
823
				$('#ldap_attr_member').val("<?=$tmpldata['attr_member'];?>");
824
				break;
825
<?php
826
			$index++;
827
		endforeach;
828
?>
829
		}
830
	}
831 a0165602 Sjon Hortensius
832 eef93144 Jared Dillard
	// ---------- On initial page load ------------------------------------------------------------
833 782922c2 Stephen Beaver
834 c4302457 Stephen Beaver
<?php if ($act != 'edit') : ?>
835 ac9d8bed Stephen Beaver
	ldap_tmplchange();
836 c4302457 Stephen Beaver
<?php endif; ?>
837
838 b0909f2e Stephen Beaver
	hideClass('ldapanon', $('#ldap_anon').prop('checked'));
839 501efbd2 Stephen Beaver
	$("#Select").prop('type','button');
840 e39a41e9 Stephen Beaver
	hideClass('extended', !$('#ldap_extended_enabled').prop('checked'));
841 7b4b0ad3 Stephen Beaver
842 f3a43095 Stephen Beaver
	if($('#ldap_port').val() == "")
843
		set_ldap_port();
844 ac9d8bed Stephen Beaver
845 ea342b0f Stephen Beaver
<?php
846
	if($act == 'edit') {
847
?>
848 6157f724 Stephen Beaver
		$('#type option:not(:selected)').each(function(){
849 7b4b0ad3 Stephen Beaver
			$(this).attr('disabled', 'disabled');
850 6157f724 Stephen Beaver
		});
851 7b4b0ad3 Stephen Beaver
852 2138c41b Stephen Beaver
<?php
853
		if(!$input_errors) {
854 7b4b0ad3 Stephen Beaver
?>
855 6157f724 Stephen Beaver
		$('#name').prop("readonly", true);
856 ea342b0f Stephen Beaver
<?php
857 2138c41b Stephen Beaver
		}
858 ea342b0f Stephen Beaver
	}
859
?>
860 eef93144 Jared Dillard
	// ---------- Click checkbox handlers ---------------------------------------------------------
861 782922c2 Stephen Beaver
862 ac9d8bed Stephen Beaver
	$('#ldap_tmpltype').on('change', function() {
863
		ldap_tmplchange();
864
	});
865 b0909f2e Stephen Beaver
866 7b4b0ad3 Stephen Beaver
	$('#ldap_anon').click(function () {
867
		hideClass('ldapanon', this.checked);
868
	});
869
870 f3a43095 Stephen Beaver
	$('#ldap_urltype').on('change', function() {
871
		set_ldap_port();
872 7b4b0ad3 Stephen Beaver
	});
873
874
	$('#Select').click(function () {
875
		select_clicked();
876
	});
877 504bd882 Stephen Beaver
878 e39a41e9 Stephen Beaver
	$('#ldap_extended_enabled').click(function () {
879
		hideClass('extended', !this.checked);
880
	});
881 504bd882 Stephen Beaver
882 ac9d8bed Stephen Beaver
});
883
//]]>
884
</script>
885
<?php
886 81ec3187 Chris Buechler
include("foot.inc");