system_authservers.php 37.6 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4
    Copyright (C) 2014-2015 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
    Copyright (C) 2010 Ermal Luçi
    Copyright (C) 2008 Shrew Soft Inc.
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice,
       this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.
*/

31
require_once("guiconfig.inc");
Ad Schellevis's avatar
Ad Schellevis committed
32 33
require_once("auth.inc");

34
$ldap_urltypes = array(
35 36 37
    'TCP - Standard' => 389,
    'SSL - Encrypted' => 636
);
38 39

$auth_server_types = array(
40 41 42
    'ldap' => "LDAP",
    'radius' => "Radius"
);
43 44

$ldap_scopes = array(
45 46 47
    'one' => "One Level",
    'subtree' => "Entire Subtree"
);
48

49
$ldap_protvers = array(2, 3);
50 51

$ldap_templates = array(
52 53 54 55 56 57 58 59 60 61 62 63 64
    'open' => array(
        'desc' => "OpenLDAP",
        'attr_user' => "cn"
    ),
    'msad' => array(
        'desc' => "Microsoft AD",
        'attr_user' => "samAccountName"
    ),
    'edir' => array(
        'desc' => "Novell eDirectory",
        'attr_user' => "cn"
    )
);
65 66

$radius_srvcs = array(
67 68 69 70
    'both' => "Authentication and Accounting",
    'auth' => "Authentication",
    'acct' => "Accounting"
);
71 72 73



Ad Schellevis's avatar
Ad Schellevis committed
74 75 76
$pgtitle = array(gettext("System"), gettext("Authentication Servers"));
$shortcut_section = "authentication";

77
if (isset($_GET['id']) && is_numericint($_GET['id'])) {
78 79
    $id = $_GET['id'];
}
80 81 82 83
if (isset($_GET['act'])) {
    $act = $_GET['act'];
} else {
    $act = null;
84
}
Ad Schellevis's avatar
Ad Schellevis committed
85

86
if (!isset($config['system']['authserver'])) {
87 88
    $config['system']['authserver'] = array();
}
Ad Schellevis's avatar
Ad Schellevis committed
89 90

$a_servers = auth_get_authserver_list();
91 92 93
foreach ($a_servers as $servers) {
    $a_server[] = $servers;
}
Ad Schellevis's avatar
Ad Schellevis committed
94

95
if (!is_array($config['ca'])) {
Ad Schellevis's avatar
Ad Schellevis committed
96
        $config['ca'] = array();
97
}
Ad Schellevis's avatar
Ad Schellevis committed
98 99
$a_ca =& $config['ca'];

100

Ad Schellevis's avatar
Ad Schellevis committed
101 102

if ($act == "del") {
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    if (!$a_server[$_GET['id']]) {
        redirectHeader("system_authservers.php");
        exit;
    }

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

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

    $savemsg = gettext("Authentication Server")." {$serverdeleted} ".
                gettext("deleted")."<br />";
    write_config($savemsg);
Ad Schellevis's avatar
Ad Schellevis committed
122 123 124
}

if ($act == "edit") {
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    if (isset($id) && $a_server[$id]) {
        $pconfig['type'] = $a_server[$id]['type'];
        $pconfig['name'] = $a_server[$id]['name'];

        if ($pconfig['type'] == "ldap") {
            $pconfig['ldap_caref'] = $a_server[$id]['ldap_caref'];
            $pconfig['ldap_host'] = $a_server[$id]['host'];
            $pconfig['ldap_port'] = $a_server[$id]['ldap_port'];
            $pconfig['ldap_urltype'] = $a_server[$id]['ldap_urltype'];
            $pconfig['ldap_protver'] = $a_server[$id]['ldap_protver'];
            $pconfig['ldap_scope'] = $a_server[$id]['ldap_scope'];
            $pconfig['ldap_basedn'] = $a_server[$id]['ldap_basedn'];
            $pconfig['ldap_authcn'] = $a_server[$id]['ldap_authcn'];
            $pconfig['ldap_extended_query'] = $a_server[$id]['ldap_extended_query'];
            $pconfig['ldap_binddn'] = $a_server[$id]['ldap_binddn'];
            $pconfig['ldap_bindpw'] = $a_server[$id]['ldap_bindpw'];
            $pconfig['ldap_attr_user'] = $a_server[$id]['ldap_attr_user'];
142
            if (empty($pconfig['ldap_binddn']) || empty($pconfig['ldap_bindpw'])) {
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
                $pconfig['ldap_anon'] = true;
            }
        }

        if ($pconfig['type'] == "radius") {
            $pconfig['radius_host'] = $a_server[$id]['host'];
            $pconfig['radius_auth_port'] = $a_server[$id]['radius_auth_port'];
            $pconfig['radius_acct_port'] = $a_server[$id]['radius_acct_port'];
            $pconfig['radius_secret'] = $a_server[$id]['radius_secret'];
            $pconfig['radius_timeout'] = $a_server[$id]['radius_timeout'];

            if ($pconfig['radius_auth_port'] &&
                $pconfig['radius_acct_port'] ) {
                $pconfig['radius_srvcs'] = "both";
            }

            if ($pconfig['radius_auth_port'] &&
                !$pconfig['radius_acct_port'] ) {
                $pconfig['radius_srvcs'] = "auth";
                $pconfig['radius_acct_port'] = 1813;
            }

            if (!$pconfig['radius_auth_port'] &&
                 $pconfig['radius_acct_port'] ) {
                $pconfig['radius_srvcs'] = "acct";
                $pconfig['radius_auth_port'] = 1812;
            }

        }
    }
Ad Schellevis's avatar
Ad Schellevis committed
173 174 175
}

if ($act == "new") {
176 177 178 179 180
    $pconfig['ldap_protver'] = 3;
    $pconfig['ldap_anon'] = true;
    $pconfig['radius_srvcs'] = "both";
    $pconfig['radius_auth_port'] = "1812";
    $pconfig['radius_acct_port'] = "1813";
Ad Schellevis's avatar
Ad Schellevis committed
181 182
}

183 184
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $input_errors = array();
185
    $pconfig = $_POST;
186 187 188 189 190
    if (isset($_POST['id']) && is_numericint($_POST['id'])) {
        $id = $_POST['id'];
    } else {
        $id = null;
    }
191 192 193 194 195 196

    /* input validation */

    if ($pconfig['type'] == "ldap") {
        $reqdfields = explode(" ", "name type ldap_host ldap_port ".
                        "ldap_urltype ldap_protver ldap_scope ".
197
                        "ldap_attr_user ldapauthcontainers");
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
        $reqdfieldsn = array(
            gettext("Descriptive name"),
            gettext("Type"),
            gettext("Hostname or IP"),
            gettext("Port value"),
            gettext("Transport"),
            gettext("Protocol version"),
            gettext("Search level"),
            gettext("User naming Attribute"),
            gettext("Authentication container"));

        if (!$pconfig['ldap_anon']) {
            $reqdfields[] = "ldap_binddn";
            $reqdfields[] = "ldap_bindpw";
            $reqdfieldsn[] = gettext("Bind user DN");
            $reqdfieldsn[] = gettext("Bind Password");
        }
    }

    if ($pconfig['type'] == "radius") {
        $reqdfields = explode(" ", "name type radius_host radius_srvcs");
        $reqdfieldsn = array(
            gettext("Descriptive name"),
            gettext("Type"),
            gettext("Hostname or IP"),
            gettext("Services"));

        if ($pconfig['radisu_srvcs'] == "both" ||
            $pconfig['radisu_srvcs'] == "auth") {
            $reqdfields[] = "radius_auth_port";
            $reqdfieldsn[] = gettext("Authentication port value");
        }

        if ($pconfig['radisu_srvcs'] == "both" ||
            $pconfig['radisu_srvcs'] == "acct") {
            $reqdfields[] = "radius_acct_port";
            $reqdfieldsn[] = gettext("Accounting port value");
        }

237
        if ($id == null) {
238 239 240 241 242 243 244 245 246 247 248
            $reqdfields[] = "radius_secret";
            $reqdfieldsn[] = gettext("Shared Secret");
        }
    }

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

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

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

    if (($pconfig['type'] == "radius") && isset($_POST['radius_timeout']) && !empty($_POST['radius_timeout']) && (!is_numeric($_POST['radius_timeout']) || (is_numeric($_POST['radius_timeout']) && ($_POST['radius_timeout'] <= 0)))) {
        $input_errors[] = gettext("RADIUS Timeout value must be numeric and positive.");
    }

257
    if (count($input_errors) == 0) {
258 259
        $server = array();
        $server['refid'] = uniqid();
260
        if ($id != null && isset($a_server[$id])) {
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
            $server = $a_server[$id];
        }

        $server['type'] = $pconfig['type'];
        $server['name'] = $pconfig['name'];

        if ($server['type'] == "ldap") {
            if (!empty($pconfig['ldap_caref'])) {
                $server['ldap_caref'] = $pconfig['ldap_caref'];
            }
            $server['host'] = $pconfig['ldap_host'];
            $server['ldap_port'] = $pconfig['ldap_port'];
            $server['ldap_urltype'] = $pconfig['ldap_urltype'];
            $server['ldap_protver'] = $pconfig['ldap_protver'];
            $server['ldap_scope'] = $pconfig['ldap_scope'];
            $server['ldap_basedn'] = $pconfig['ldap_basedn'];
            $server['ldap_authcn'] = $pconfig['ldapauthcontainers'];
            $server['ldap_extended_query'] = $pconfig['ldap_extended_query'];
            $server['ldap_attr_user'] = $pconfig['ldap_attr_user'];
            if (!$pconfig['ldap_anon']) {
                $server['ldap_binddn'] = $pconfig['ldap_binddn'];
                $server['ldap_bindpw'] = $pconfig['ldap_bindpw'];
            } else {
                unset($server['ldap_binddn']);
                unset($server['ldap_bindpw']);
            }
287
        } elseif ($server['type'] == "radius") {
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
            $server['host'] = $pconfig['radius_host'];

            if ($pconfig['radius_secret']) {
                $server['radius_secret'] = $pconfig['radius_secret'];
            }

            if ($pconfig['radius_timeout']) {
                $server['radius_timeout'] = $pconfig['radius_timeout'];
            } else {
                $server['radius_timeout'] = 5;
            }

            if ($pconfig['radius_srvcs'] == "both") {
                $server['radius_auth_port'] = $pconfig['radius_auth_port'];
                $server['radius_acct_port'] = $pconfig['radius_acct_port'];
            }

            if ($pconfig['radius_srvcs'] == "auth") {
                $server['radius_auth_port'] = $pconfig['radius_auth_port'];
                unset($server['radius_acct_port']);
            }

            if ($pconfig['radius_srvcs'] == "acct") {
                $server['radius_acct_port'] = $pconfig['radius_acct_port'];
                unset($server['radius_auth_port']);
            }
        }

316
        if ($id != null && isset($config['system']['authserver'][$id])) {
317 318 319 320 321 322 323 324
            $config['system']['authserver'][$id] = $server;
        } else {
            $config['system']['authserver'][] = $server;
        }

        write_config();

        redirectHeader("system_authservers.php");
325 326
    } else {
        $act = "edit";
327
    }
Ad Schellevis's avatar
Ad Schellevis committed
328 329 330
}

include("head.inc");
Ad Schellevis's avatar
Ad Schellevis committed
331 332

$main_buttons = array(
333
    array('label'=>'Add server', 'href'=>'system_authservers.php?act=new'),
Ad Schellevis's avatar
Ad Schellevis committed
334 335
);

Ad Schellevis's avatar
Ad Schellevis committed
336 337
?>

Ad Schellevis's avatar
Ad Schellevis committed
338

339
<body>
Ad Schellevis's avatar
Ad Schellevis committed
340

Ad Schellevis's avatar
Ad Schellevis committed
341 342 343 344 345 346 347 348 349 350 351
<script type="text/javascript">
//<![CDATA[

function server_typechange(typ) {

	var idx = 0;
	if (!typ) {
		idx = document.getElementById("type").selectedIndex;
		typ = document.getElementById("type").options[idx].value;
	}

352
	switch (typ) {
Ad Schellevis's avatar
Ad Schellevis committed
353 354 355 356 357 358 359 360 361 362 363 364 365 366
		case "ldap":
			document.getElementById("ldap").style.display="";
			document.getElementById("radius").style.display="none";
			break;
		case "radius":
			document.getElementById("ldap").style.display="none";
			document.getElementById("radius").style.display="";
			break;
	}
}

function ldap_urlchange() {
    switch (document.getElementById("ldap_urltype").selectedIndex) {
<?php
367 368
    $index = 0;
foreach ($ldap_urltypes as $urltype => $urlport) :
Ad Schellevis's avatar
Ad Schellevis committed
369
?>
370 371 372
    case <?=$index;?>:
        document.getElementById("ldap_port").value = "<?=$urlport;?>";
        break;
Ad Schellevis's avatar
Ad Schellevis committed
373
<?php
374 375
    $index++;
endforeach;
Ad Schellevis's avatar
Ad Schellevis committed
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
?>
	}
}

function ldap_bindchange() {

	if (document.getElementById("ldap_anon").checked)
		document.getElementById("ldap_bind").style.display="none";
    else
		document.getElementById("ldap_bind").style.display="";
}

function ldap_tmplchange(){
    switch (document.getElementById("ldap_tmpltype").selectedIndex) {
<?php
391 392
    $index = 0;
foreach ($ldap_templates as $tmpldata) :
Ad Schellevis's avatar
Ad Schellevis committed
393
?>
394 395 396 397 398
    case <?=$index;?>:
        document.getElementById("ldap_attr_user").value = "<?=$tmpldata['attr_user'];?>";
        document.getElementById("ldap_attr_group").value = "<?=$tmpldata['attr_group'];?>";
        document.getElementById("ldap_attr_member").value = "<?=$tmpldata['attr_member'];?>";
        break;
Ad Schellevis's avatar
Ad Schellevis committed
399
<?php
400 401
    $index++;
endforeach;
Ad Schellevis's avatar
Ad Schellevis committed
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
?>
	}
}

function radius_srvcschange(){
    switch (document.getElementById("radius_srvcs").selectedIndex) {
		case 0: // both
			document.getElementById("radius_auth").style.display="";
			document.getElementById("radius_acct").style.display="";
			break;
		case 1: // authentication
			document.getElementById("radius_auth").style.display="";
			document.getElementById("radius_acct").style.display="none";
			break;
		case 2: // accounting
			document.getElementById("radius_auth").style.display="none";
			document.getElementById("radius_acct").style.display="";
			break;
	}
}

function select_clicked() {
	if (document.getElementById("ldap_port").value == '' ||
	    document.getElementById("ldap_host").value == '' ||
	    document.getElementById("ldap_scope").value == '' ||
427
	    document.getElementById("ldap_basedn").value == '' ) {
Ad Schellevis's avatar
Ad Schellevis committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
		alert("<?=gettext("Please fill the required values.");?>");
		return;
	}
	if (!document.getElementById("ldap_anon").checked) {
		if (document.getElementById("ldap_binddn").value == '' ||
		    document.getElementById("ldap_bindpw").value == '') {
				alert("<?=gettext("Please fill the bind username/password.");?>");
			return;
		}
	}
        var url = 'system_usermanager_settings_ldapacpicker.php?';
        url += 'port=' + document.getElementById("ldap_port").value;
        url += '&host=' + document.getElementById("ldap_host").value;
        url += '&scope=' + document.getElementById("ldap_scope").value;
        url += '&basedn=' + document.getElementById("ldap_basedn").value;
        url += '&binddn=' + document.getElementById("ldap_binddn").value;
        url += '&bindpw=' + document.getElementById("ldap_bindpw").value;
        url += '&urltype=' + document.getElementById("ldap_urltype").value;
        url += '&proto=' + document.getElementById("ldap_protver").value;
	url += '&authcn=' + document.getElementById("ldapauthcontainers").value;
448 449
	<?php if (count($a_ca) > 0) :
?>
Ad Schellevis's avatar
Ad Schellevis committed
450
		url += '&cert=' + document.getElementById("ldap_caref").value;
451 452 453
	<?php
else :
?>
Ad Schellevis's avatar
Ad Schellevis committed
454
		url += '&cert=';
455 456
	<?php
endif; ?>
Ad Schellevis's avatar
Ad Schellevis committed
457

458
        var oWin = window.open(url,"OPNsense","width=620,height=400,top=150,left=150");
Ad Schellevis's avatar
Ad Schellevis committed
459 460 461 462 463 464
        if (oWin==null || typeof(oWin)=="undefined")
			alert("<?=gettext('Popup blocker detected.  Action aborted.');?>");
}
//]]>
</script>

Ad Schellevis's avatar
Ad Schellevis committed
465 466 467
<?php include("fbegin.inc");?>

	<section class="page-content-main">
468
		<div class="container-fluid">
Ad Schellevis's avatar
Ad Schellevis committed
469
			<div class="row">
470

Ad Schellevis's avatar
Ad Schellevis committed
471
				<?php
472
                if (isset($input_errors) && count($input_errors) > 0) {
473 474
                    print_input_errors($input_errors);
                }
475
                if (isset($savemsg)) {
476 477 478
                    print_info_box($savemsg);
                }
                ?>
479

Ad Schellevis's avatar
Ad Schellevis committed
480
			    <section class="col-xs-12">
481 482

					<?php
483 484 485 486 487 488 489
                            $tab_array = array();
                            $tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
                            $tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
                            $tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
                            $tab_array[] = array(gettext("Servers"), true, "system_authservers.php");
                            display_top_tabs($tab_array);
                        ?>
490

491
						<div class="tab-content content-box col-xs-12 table-responsive">
492

493
								<?php if ($act == "new" || $act == "edit") :
494
?>
495 496
								<form id="iform" name="iform" action="system_authservers.php" method="post">
									<table class="table table-striped table-sort">
Ad Schellevis's avatar
Ad Schellevis committed
497 498 499
											<tr>
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
												<td width="78%" class="vtable">
500 501
												<?php if (!isset($id)) :
?>
Ad Schellevis's avatar
Ad Schellevis committed
502
													<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"/>
503 504 505
												<?php
else :
?>
Ad Schellevis's avatar
Ad Schellevis committed
506 507
					                                                                <strong><?=htmlspecialchars($pconfig['name']);?></strong>
					                                                                <input name='name' type='hidden' id='name' value="<?=htmlspecialchars($pconfig['name']);?>"/>
508 509
					                                                                <?php
endif; ?>
Ad Schellevis's avatar
Ad Schellevis committed
510 511 512 513 514
												</td>
											</tr>
											<tr>
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Type");?></td>
												<td width="78%" class="vtable">
515 516
													<?php if (!isset($id)) :
?>
517
													<select name='type' id='type' class="formselect selectpicker" data-style="btn-default" onchange='server_typechange()'>
Ad Schellevis's avatar
Ad Schellevis committed
518
													<?php
519 520 521 522 523 524 525 526 527 528 529
                                                    foreach ($auth_server_types as $typename => $typedesc) :
                                                        $selected = "";
                                                        if ($pconfig['type'] == $typename) {
                                                            $selected = "selected=\"selected\"";
                                                        }
                                                    ?>
                                                    <option value="<?=$typename;
?>" <?=$selected;
?>><?=$typedesc;?></option>
													<?php
                                                    endforeach; ?>
Ad Schellevis's avatar
Ad Schellevis committed
530
													</select>
531 532 533
													<?php
else :
?>
Ad Schellevis's avatar
Ad Schellevis committed
534 535
													<strong><?=$auth_server_types[$pconfig['type']];?></strong>
													<input name='type' type='hidden' id='type' value="<?=htmlspecialchars($pconfig['type']);?>"/>
536 537
													<?php
endif; ?>
Ad Schellevis's avatar
Ad Schellevis committed
538 539 540
												</td>
											</tr>
										</table>
541

Ad Schellevis's avatar
Ad Schellevis committed
542
										<table class="table table-striped table-sort" id="ldap" style="display:none" summary="">
543

Ad Schellevis's avatar
Ad Schellevis committed
544 545
		                                    <thead>
		                                        <tr>
546
									<th colspan="2" class="listtopic"><?=gettext("LDAP Server Settings");?></th>
Ad Schellevis's avatar
Ad Schellevis committed
547 548
		                                        </tr>
		                                    </thead>
549 550 551

										<tbody>

Ad Schellevis's avatar
Ad Schellevis committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
											<tr>
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Hostname or IP address");?></td>
												<td width="78%" class="vtable">
													<input name="ldap_host" type="text" class="formfld unknown" id="ldap_host" size="20" value="<?=htmlspecialchars($pconfig['ldap_host']);?>"/>
													<br /><?= gettext("NOTE: When using SSL, this hostname MUST match the Common Name (CN) of the LDAP server's SSL Certificate."); ?>
												</td>
											</tr>
											<tr>
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Port value");?></td>
												<td width="78%" class="vtable">
													<input name="ldap_port" type="text" class="formfld unknown" id="ldap_port" size="5" value="<?=htmlspecialchars($pconfig['ldap_port']);?>"/>
												</td>
											</tr>
											<tr>
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Transport");?></td>
												<td width="78%" class="vtable">
568
													<select name='ldap_urltype' id='ldap_urltype' class="formselect selectpicker" data-style="btn-default" onchange='ldap_urlchange()'>
Ad Schellevis's avatar
Ad Schellevis committed
569
													<?php
570 571 572 573 574 575 576 577 578 579 580
                                                    foreach ($ldap_urltypes as $urltype => $urlport) :
                                                        $selected = "";
                                                        if ($pconfig['ldap_urltype'] == $urltype) {
                                                            $selected = "selected=\"selected\"";
                                                        }
                                                    ?>
                                                    <option value="<?=$urltype;
?>" <?=$selected;
?>><?=$urltype;?></option>
													<?php
                                                    endforeach; ?>
Ad Schellevis's avatar
Ad Schellevis committed
581 582 583 584 585 586
													</select>
												</td>
											</tr>
											<tr id="tls_ca">
												<td width="22%" valign="top" class="vncell"><?=gettext("Peer Certificate Authority"); ?></td>
					                                                        <td width="78%" class="vtable">
587 588
					                                                        <?php if (count($a_ca)) :
?>
589
													<select id='ldap_caref' name='ldap_caref' class="formselect selectpicker" data-style="btn-default">
Ad Schellevis's avatar
Ad Schellevis committed
590
					                                                        <?php
591 592 593 594 595 596 597 598 599 600 601
                                                                            foreach ($a_ca as $ca) :
                                                                                    $selected = "";
                                                                                if ($pconfig['ldap_caref'] == $ca['refid']) {
                                                                                        $selected = "selected=\"selected\"";
                                                                                }
                                                                            ?>
														<option value="<?=$ca['refid'];
?>" <?=$selected;
?>><?=$ca['descr'];?></option>
					                                                        <?php
                                                                            endforeach; ?>
Ad Schellevis's avatar
Ad Schellevis committed
602 603 604
													</select>
													<br /><span><?=gettext("This option is used if 'SSL Encrypted' option is choosen.");?> <br />
													<?=gettext("It must match with the CA in the AD otherwise problems will arise.");?></span>
605 606 607
					                                                        <?php
else :
?>
608
					                                                                <b>No Certificate Authorities defined.</b> <br />Create one under <a href="system_camanager.php">System: Certificates</a>.
609 610
					                                                        <?php
endif; ?>
Ad Schellevis's avatar
Ad Schellevis committed
611 612 613 614 615
					                                                        </td>
											</tr>
											<tr>
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol version");?></td>
												<td width="78%" class="vtable">
616
													<select name='ldap_protver' id='ldap_protver' class="formselect selectpicker" data-style="btn-default">
Ad Schellevis's avatar
Ad Schellevis committed
617
													<?php
618 619 620 621 622 623 624 625 626 627 628
                                                    foreach ($ldap_protvers as $version) :
                                                        $selected = "";
                                                        if ($pconfig['ldap_protver'] == $version) {
                                                            $selected = "selected=\"selected\"";
                                                        }
                                                    ?>
                                                    <option value="<?=$version;
?>" <?=$selected;
?>><?=$version;?></option>
													<?php
                                                    endforeach; ?>
Ad Schellevis's avatar
Ad Schellevis committed
629 630 631
													</select>
												</td>
											</tr>
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
											<tr>
												<td width="22%" valign="top" class="vncell"><?=gettext("Bind credentials");?></td>
												<td width="78%" class="vtable">
													<table border="0" cellspacing="0" cellpadding="2" summary="bind credentials">
														<tr>
															<td>
																<input name="ldap_anon" type="checkbox" id="ldap_anon" value="yes" <?php if ($pconfig['ldap_anon']) {
                                                                    echo "checked=\"checked\"";
} ?> onclick="ldap_bindchange()" />
															</td>
															<td>
																<?=gettext("Use anonymous binds to resolve distinguished names");?>
															</td>
														</tr>
													</table>
													<table border="0" cellspacing="0" cellpadding="2" id="ldap_bind" summary="bind">
														<tr>
															<td colspan="2"></td>
														</tr>
														<tr>
															<td><?=gettext("User DN:");?> &nbsp;</td>
															<td>
																<input name="ldap_binddn" type="text" class="formfld unknown" id="ldap_binddn" size="40" value="<?=htmlspecialchars($pconfig['ldap_binddn']);?>"/><br />
															</td>
														</tr>
														<tr>
															<td><?=gettext("Password:");?> &nbsp;</td>
															<td>
																<input name="ldap_bindpw" type="password" class="formfld pwd" id="ldap_bindpw" size="20" value="<?=htmlspecialchars($pconfig['ldap_bindpw']);?>"/><br />
															</td>
														</tr>
													</table>
												</td>
											</tr>
Ad Schellevis's avatar
Ad Schellevis committed
666 667 668 669 670
											<tr>
												<td width="22%" valign="top" class="vncell"><?=gettext("Search scope");?></td>
												<td width="78%" class="vtable">
													<table border="0" cellspacing="0" cellpadding="2" summary="search scope">
														<tr>
671
															<td><?=gettext("Level:");?></td>
Ad Schellevis's avatar
Ad Schellevis committed
672
															<td>
673
																<select name='ldap_scope' id='ldap_scope' class="formselect selectpicker" data-style="btn-default">
Ad Schellevis's avatar
Ad Schellevis committed
674
																<?php
675 676 677 678 679 680 681 682 683 684 685
                                                                foreach ($ldap_scopes as $scopename => $scopedesc) :
                                                                    $selected = "";
                                                                    if ($pconfig['ldap_scope'] == $scopename) {
                                                                        $selected = "selected=\"selected\"";
                                                                    }
                                                                ?>
                                                                <option value="<?=$scopename;
?>" <?=$selected;
?>><?=$scopedesc;?></option>
																<?php
                                                                endforeach; ?>
Ad Schellevis's avatar
Ad Schellevis committed
686 687 688 689
																</select>
															</td>
														</tr>
														<tr>
690
															<td><?=gettext("Base DN:");?></td>
Ad Schellevis's avatar
Ad Schellevis committed
691 692 693 694 695
															<td>
																<input name="ldap_basedn" type="text" class="formfld unknown" id="ldap_basedn" size="40" value="<?=htmlspecialchars($pconfig['ldap_basedn']);?>"/>
															</td>
														</tr>
													</table>
696

Ad Schellevis's avatar
Ad Schellevis committed
697 698 699 700 701 702 703
												</td>
											</tr>
											<tr>
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Authentication containers");?></td>
												<td width="78%" class="vtable">
													<table border="0" cellspacing="0" cellpadding="2" summary="auth containers">
														<tr>
Ad Schellevis's avatar
Ad Schellevis committed
704
															<td valign="top"><?=gettext("Containers:");?> &nbsp;</td>
Ad Schellevis's avatar
Ad Schellevis committed
705
															<td>
Ad Schellevis's avatar
Ad Schellevis committed
706
																<ul class="list-inline">
707 708
																<li><input name="ldapauthcontainers" type="text" class="formfld unknown" id="ldapauthcontainers" size="40" value="<?=htmlspecialchars($pconfig['ldap_authcn']);?>"/></li>
																<li><input type="button" onclick="select_clicked();" class="btn btn-default" value="<?=gettext("Select");?>" /></li>
Ad Schellevis's avatar
Ad Schellevis committed
709 710
																</ul>
															</td>
711

Ad Schellevis's avatar
Ad Schellevis committed
712 713
														</tr>
														<tr>
714
														<td colspan="2">
Ad Schellevis's avatar
Ad Schellevis committed
715 716 717
																<br /><?=gettext("Note: Semi-Colon separated. This will be prepended to the search base dn above or you can specify full container path containing a dc= component.");?>
																<br /><?=gettext("Example:");?> CN=Users;DC=example,DC=com
																<br /><?=gettext("Example:");?> OU=Staff;OU=Freelancers
718
														</td>
Ad Schellevis's avatar
Ad Schellevis committed
719 720 721 722 723 724 725 726 727 728
														</tr>
													</table>
												</td>
											</tr>
											<tr>
												<td width="22%" valign="top" class="vncell"><?=gettext("Extended Query");?></td>
												<td width="78%" class="vtable">
													<table border="0" cellspacing="0" cellpadding="2" summary="query">
														<tr>
															<td>
729

Ad Schellevis's avatar
Ad Schellevis committed
730 731 732 733 734 735 736
																<input name="ldap_extended_query" type="text" class="formfld unknown" id="ldap_extended_query" size="40" value="<?=htmlspecialchars($pconfig['ldap_extended_query']);?>"/>
																<br /><?=gettext("Example:");?> &amp;(objectClass=inetOrgPerson)(mail=*@example.com)
															</td>
														</tr>
													</table>
												</td>
											</tr>
737 738
											<?php if (!isset($id)) :
?>
Ad Schellevis's avatar
Ad Schellevis committed
739 740 741
											<tr>
												<td width="22%" valign="top" class="vncell"><?=gettext("Initial Template");?></td>
												<td width="78%" class="vtable">
742
													<select name='ldap_tmpltype' id='ldap_tmpltype' class="formselect selectpicker" data-style="btn-default" onchange='ldap_tmplchange()'>
Ad Schellevis's avatar
Ad Schellevis committed
743
													<?php
744 745 746 747 748 749 750 751 752 753 754
                                                    foreach ($ldap_templates as $tmplname => $tmpldata) :
                                                        $selected = "";
                                                        if ($pconfig['ldap_template'] == $tmplname) {
                                                            $selected = "selected=\"selected\"";
                                                        }
                                                    ?>
                                                    <option value="<?=$tmplname;
?>" <?=$selected;
?>><?=$tmpldata['desc'];?></option>
													<?php
                                                    endforeach; ?>
Ad Schellevis's avatar
Ad Schellevis committed
755 756 757
													</select>
												</td>
											</tr>
758 759
											<?php
endif; ?>
Ad Schellevis's avatar
Ad Schellevis committed
760 761 762 763 764 765 766
											<tr>
												<td width="22%" valign="top" class="vncell"><?=gettext("User naming attribute");?></td>
												<td width="78%" class="vtable">
													<input name="ldap_attr_user" type="text" class="formfld unknown" id="ldap_attr_user" size="20" value="<?=htmlspecialchars($pconfig['ldap_attr_user']);?>"/>
												</td>
											</tr>
										</table>
767

Ad Schellevis's avatar
Ad Schellevis committed
768 769 770
										<table class="table table-striped table-sort" id="radius" style="display:none" summary="">
											<tr>
												<td colspan="2" class="list" height="12"></td>
771
											</tr>
Ad Schellevis's avatar
Ad Schellevis committed
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
											<tr>
												<td colspan="2" valign="top" class="listtopic"><?=gettext("Radius Server Settings");?></td>
											</tr>
											<tr>
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Hostname or IP address");?></td>
												<td width="78%" class="vtable">
													<input name="radius_host" type="text" class="formfld unknown" id="radius_host" size="20" value="<?=htmlspecialchars($pconfig['radius_host']);?>"/>
												</td>
											</tr>
											<tr>
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Shared Secret");?></td>
												<td width="78%" class="vtable">
													<input name="radius_secret" type="password" class="formfld pwd" id="radius_secret" size="20" value="<?=htmlspecialchars($pconfig['radius_secret']);?>"/>
												</td>
											</tr>
											<tr>
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Services offered");?></td>
												<td width="78%" class="vtable">
790
													<select name='radius_srvcs' id='radius_srvcs' class="formselect selectpicker" data-style="btn-default" onchange='radius_srvcschange()'>
Ad Schellevis's avatar
Ad Schellevis committed
791
													<?php
792 793 794 795 796 797 798 799 800 801 802
                                                    foreach ($radius_srvcs as $srvcname => $srvcdesc) :
                                                        $selected = "";
                                                        if ($pconfig['radius_srvcs'] == $srvcname) {
                                                            $selected = "selected=\"selected\"";
                                                        }
                                                    ?>
                                                    <option value="<?=$srvcname;
?>" <?=$selected;
?>><?=$srvcdesc;?></option>
													<?php
                                                    endforeach; ?>
Ad Schellevis's avatar
Ad Schellevis committed
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
													</select>
												</td>
											</tr>
											<tr id="radius_auth">
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Authentication port value");?></td>
												<td width="78%" class="vtable">
													<input name="radius_auth_port" type="text" class="formfld unknown" id="radius_auth_port" size="5" value="<?=htmlspecialchars($pconfig['radius_auth_port']);?>"/>
												</td>
											</tr>
											<tr id="radius_acct">
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Accounting port value");?></td>
												<td width="78%" class="vtable">
													<input name="radius_acct_port" type="text" class="formfld unknown" id="radius_acct_port" size="5" value="<?=htmlspecialchars($pconfig['radius_acct_port']);?>"/>
												</td>
											</tr>
											<tr>
												<td width="22%" valign="top" class="vncellreq"><?=gettext("Authentication Timeout");?></td>
												<td width="78%" class="vtable">
													<input name="radius_timeout" type="text" class="formfld unknown" id="radius_timeout" size="20" value="<?=htmlspecialchars($pconfig['radius_timeout']);?>"/>
													<br /><?= gettext("This value controls how long, in seconds, that the RADIUS server may take to respond to an authentication request.") ?>
													<br /><?= gettext("If left blank, the default value is 5 seconds.") ?>
													<br /><br /><?= gettext("NOTE: If you are using an interactive two-factor authentication system, increase this timeout to account for how long it will take the user to receive and enter a token.") ?>
												</td>
											</tr>
										</table>

										<table class="table table-striped table-sort">
											<tr>
												<td width="22%" valign="top">&nbsp;</td>
												<td width="78%">
													<input id="submit" name="save" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" />
834 835
													<?php if (isset($id) && $a_server[$id]) :
?>
Ad Schellevis's avatar
Ad Schellevis committed
836
													<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
837 838
													<?php
endif;?>
Ad Schellevis's avatar
Ad Schellevis committed
839 840 841 842
												</td>
											</tr>
										</table>
									</form>
Ad Schellevis's avatar
Ad Schellevis committed
843

844 845 846
				<?php
else :
?>
847

848 849
									<table class="table table-striped table-sort">

Ad Schellevis's avatar
Ad Schellevis committed
850 851 852 853 854 855 856 857 858
											<thead>
												<tr>
													<th width="25%" class="listhdrr"><?=gettext("Server Name");?></th>
													<th width="25%" class="listhdrr"><?=gettext("Type");?></th>
													<th width="35%" class="listhdrr"><?=gettext("Host Name");?></th>
													<th width="10%" class="list"></th>
												</tr>
											</thead>
											<tfoot>
859

Ad Schellevis's avatar
Ad Schellevis committed
860
												<tr>
861
													<td colspan="4">
Ad Schellevis's avatar
Ad Schellevis committed
862 863 864 865 866 867 868 869
														<p>
															<?=gettext("Additional authentication servers can be added here.");?>
														</p>
													</td>
												</tr>
											</tfoot>
											<tbody>
												<?php
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
                                                    $i = 0;
                                                foreach ($a_server as $server) :
                                                    $name = htmlspecialchars($server['name']);
                                                    $type = htmlspecialchars($auth_server_types[$server['type']]);
                                                    $host = htmlspecialchars($server['host']);
                                                ?>
												<tr <?php if ($i < (count($a_server) - 1)) :
?> ondblclick="document.location='system_authservers.php?act=edit&amp;id=<?=$i;?>'" <?php
endif; ?>>
                                                <td class="listlr"><?=$name?>&nbsp;</td>
                                                <td class="listr"><?=$type;?>&nbsp;</td>
                                                <td class="listr"><?=$host;?>&nbsp;</td>
                                                <td valign="middle" class="list nowrap">
                                                <?php if ($i < (count($a_server) - 1)) :
?>
Ad Schellevis's avatar
Ad Schellevis committed
885 886 887 888
														<a href="system_authservers.php?act=edit&amp;id=<?=$i;?>" class="btn btn-default btn-xs">
															<span class="glyphicon glyphicon-pencil"></span>
														</a>
														&nbsp;
889 890
														<a href="system_authservers.php?act=del&amp;id=<?=$i;
?>" onclick="return confirm('<?=gettext("Do you really want to delete this Server?");?>')" class="btn btn-default btn-xs">
Ad Schellevis's avatar
Ad Schellevis committed
891 892
															<span class="glyphicon glyphicon-remove"></span>
														</a>
893 894 895
													<?php
endif; ?>
                                                </td>
Ad Schellevis's avatar
Ad Schellevis committed
896 897
												</tr>
												<?php
898 899 900 901
                                                $i++;

                                                endforeach;
                                                ?>
Ad Schellevis's avatar
Ad Schellevis committed
902 903
											</tbody>
										</table>
904

905 906
							<?php
endif; ?>
Ad Schellevis's avatar
Ad Schellevis committed
907 908 909 910 911
							</div>
						</section>
					</div>
				</div>
			</section>
912

Ad Schellevis's avatar
Ad Schellevis committed
913
<script type="text/javascript">
914 915 916 917 918 919
    //<![CDATA[
    $( document ).ready(function() {
        server_typechange('<?=htmlspecialchars($pconfig['type']);?>');
        if (document.getElementById("ldap_port").value == "") ldap_urlchange();
        <?php
        if ($pconfig['type'] == "ldap") {
920 921
            echo "     ldap_bindchange();\n";
            echo "     if (document.getElementById(\"ldap_port\").value == \"\") ldap_urlchange();\n";
922
            if (!isset($id)) {
923
                echo "    ldap_tmplchange();\n";
924 925
            }
        } else {
926
            echo "     radius_srvcschange();\n";
927 928
        }
        ?>
929
    });
930
    //]]>
Ad Schellevis's avatar
Ad Schellevis committed
931
</script>
Ad Schellevis's avatar
Ad Schellevis committed
932

933
<?php include("foot.inc");