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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP