system_usermanager_settings_test.php 3.35 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1 2
<?php
/*
3
	Copyright (C) 2014-2015 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
	Copyright (C) 2007 Scott Ullrich <sullrich@gmail.com>
	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.
*/

29
require_once("guiconfig.inc");
Ad Schellevis's avatar
Ad Schellevis committed
30
require_once("auth.inc");
31
include('head.inc');
Ad Schellevis's avatar
Ad Schellevis committed
32

33

34 35 36 37
if (isset($config['system']['authserver'][0]['host'])) {
    $auth_server = $config['system']['authserver'][0]['host'];
    $authserver = $_GET['authserver'];
    $authcfg = auth_get_authserver($authserver);
38

39
    $ldap_auth = new OPNsense\Auth\LDAP($authcfg['ldap_basedn'],  $authcfg['ldap_protver']);
40 41
    ldap_setup_caenv($authcfg);
    $ldap_is_connected = $ldap_auth->connect($authcfg['ldap_full_url'], $authcfg['ldap_binddn'], $authcfg['ldap_bindpw']);
42
}
Ad Schellevis's avatar
Ad Schellevis committed
43

44

Ad Schellevis's avatar
Ad Schellevis committed
45 46
?>

47 48
<body>
	<form method="post" name="iform" id="iform">
49

Ad Schellevis's avatar
Ad Schellevis committed
50 51 52
<?php

if (!$authcfg) {
53
    printf(gettext("Could not find settings for %s%s"), htmlspecialchars($authserver), "<p/>");
Ad Schellevis's avatar
Ad Schellevis committed
54
} else {
55 56 57 58
    echo "<table class='table table-striped'>";

    echo "<tr><th colspan='2'>".sprintf(gettext("Testing %s LDAP settings... One moment please..."), $g['product_name'])."</th></tr>";
    echo "<tr><td>" . gettext("Attempting connection to") . " " . $authserver . "</td>";
59
    if ($ldap_is_connected) {
60 61
        echo "<td><font color='green'>OK</font></td></tr>";
            echo "<tr><td>" . gettext("Attempting to fetch Organizational Units from") . " " . $authserver . "</td>";
62
            $ous = $ldap_auth->listOUs();
63 64
            if (count($ous)>1) {
                echo "<td><font color=green>OK</font></td></tr>";
65 66 67
                echo "<tr><td>".gettext("Organization units found") . "</td><td><font color=green>".count($ous)."</font></td></tr>";
                foreach ($ous as $ou) {
                    echo "<tr><td colspan='2'>" . $ou . "</td></tr>";
68 69 70 71 72 73 74
                }
            } else {
                echo "<td><font color='red'>" . gettext("failed") . "</font></td></tr>";
            }
        } else {
            echo "<td><font color='red'>" . gettext("failed") . "</font></td></tr>";
        }
Ad Schellevis's avatar
Ad Schellevis committed
75 76 77
}

?>
78 79 80 81 82 83
	<tr>
		<td colspan="2" align="right">
			<input type="Button" value="<?=gettext("Close"); ?>" class="btn btn-default" onClick='Javascript:window.close();'>
		</td>
	</tr>
	</table>
Ad Schellevis's avatar
Ad Schellevis committed
84 85 86
	</form>
</body>
</html>