douzao2992 2019-06-11 19:41
浏览 98

如何检查是否可以从Ubuntu / Apache / PHP Web服务器访问Active Directory服务器?

How can i check if my webserver wich have Ubuntu/Apache/PHP is inside a windows active diretory ?

I have php-ldap and openssl php extensions enabled, but i still can not login using ldap.

the ldap bind returns false.

The code is the same that works on my local machine.

There is some network command line i can use from ubuntu to check it ?

Or even a php function instead of ldap_connect and ldap_bind ?

Thank´s in advance

EDIT:

this is the code i use to test the connection it works on my local machine and not in the webserver :

<?php
        $useremail      = 'myuser'; 
        $data['password'] = 'mypassword';
        $adServer = "ldap://my.veryowndomain.com";

        $ldap = ldap_connect($adServer);
        var_dump($useremail);

        $ldaprdn = 'myveryowndomain' . "\\" . $useremail;

        ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
        ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);

        $bind = @ldap_bind($ldap, $ldaprdn, $data['password']);
        var_dump($bind);

        echo "1 ldap_error: " . var_dump(ldap_error($conn))."<hr>";
        ldap_get_option($conn, LDAP_OPT_DIAGNOSTIC_MESSAGE, $err);
        echo "2 ldap_get_option: ". $err."<hr>";

        echo  ' >> 3 '. var_dump( ldap_errno() )."<hr>";
        echo  ' >> 4 '.var_dump( ldap_err2str( ldap_errno() ) )."<hr>";

        if ($bind) {

            $filter="(sAMAccountName=" . $useremail . ")";
            $result = ldap_search($ldap,"DC=myveryowndomain,DC=com,DC=br",$filter);

            echo '<hr> 5 result'."<hr>";
            var_dump($result);

            ldap_sort($ldap,$result,"sn");
            $info = ldap_get_entries($ldap, $result);

            echo '<hr> 6 result'."<hr>";
            var_dump($info);

            if ( $info['count'] >= 1 ) {
                $success = true;
                $usernome        = $info[0]['cn'][0];
                $usernetworkUser = $info[0]['samaccountname'][0];
                $useremail       = $info[0]['mail'][0];
                $userimage       = base64_encode($info[0]['thumbnailphoto'][0]);
                echo ($ret);
            } else {

                $success = false;
                echo '7 not authorized'."<hr>";
            }
        } else {
            echo  ' >> 8 '. var_dump( ldap_errno() )."<hr>";
            echo  ' >> 9 '.var_dump( ldap_err2str( ldap_errno() ) )."<hr>";
            $success = false;
            echo '10 Fail to connect to'."<hr>";            
        }

        if (ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) {
            echo "Using LDAPv3<br>";
        } else {
            echo "Failed to set protocol version to 3";
        }

        @ldap_close($ldap);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算