Communication with Active Directory

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
vladsn07
Posts: 12
Joined: Wed Oct 16, 2013 12:33 pm

Communication with Active Directory

Post by vladsn07 »

Script URL:
Version of script: 2.5.2
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution:

Write your message below: There is a code of index.php from the home page. http://www.hesk.com/demo/index.php?a=add.
You must collect all the necessary information for the user and the computer automatically when you open this page insert in the form.
The script is receiving data and it is fully working. That is, I've found that you can get the Ip address, Ip address is already having to get the computer name via dns, get the computer name who is now logged in on this computer (taken from the database mssql) and get all the necessary infu about the user (name, mail, etc. .) also want to add custom fields to a form

Code: Select all

  <?php
    include ("mssql_config.php");
    function getRealIpAddr()
            {
                    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
                    {
                            $ip=$_SERVER['HTTP_CLIENT_IP'];
                    }
                    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
                    {
                            $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
                    }
                    else
                    {
                            $ip=$_SERVER['REMOTE_ADDR'];
                    }
                    return $ip;
            }
       $ip_address = getRealIpAddr();
       $hostname = gethostbyaddr ($ip_address);
       
    $sql= "select u.employeeid , replace(u.username,'***\','') as username, p.name as compname, l.date, p.inventarynumber as invnumber from userlog l, userid u, pc p where l.id in (select MAX(id) from userlog group by pc_id) and l.user_id = u.id and l.pc_id = p.id and l.status = '0' and p.name=replace('".$hostname."','.***.local','') order by l.date desc";
    $sql2 = mssql_query($sql);
      $sql1=mssql_fetch_array($sql2);
       
    $ldapServer = '192.168.0.1';
    $ldapUserToAuth = 'Test01@*.local'; 
    $ldapUserPasswd = '***';
    $ldapBase = 'dc=***, dc=local'; / / How to start your search (here in an entire domain)
    $ldapFilter_user = '(&(objectclass=user)(objectcategory=Person)(samaccountname='. $sql1[1].'))';
    $justthese_user = array('samaccountname','displayname','mail', 'department',  'employeeid', 'telephonenumber'); 
    $ldapFilter_comp = '(&(objectclass=computer)(cn='. $sql1[2].'))';
    $justthese_comp = array('cn','description');

    // Connecting to LDAP
    $ldapconn = ldap_connect($ldapServer)
    or die("Could not connect to $ldapServer");

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

    // Авторизация
    $ldapbind = ldap_bind($ldapconn, $ldapUserToAuth, $ldapUserPasswd);

    $sr_user=ldap_search($ldapconn, $ldapBase, $ldapFilter_user, $justthese_user);
    $info_user = ldap_get_entries($ldapconn, $sr_user);

    $sr_comp=ldap_search($ldapconn, $ldapBase, $ldapFilter_comp, $justthese_comp);
    $info_comp = ldap_get_entries($ldapconn, $sr_comp);


       
    for ($i=0, $c=$info_user['count']; $i<$c; $i++)
       {
       echo $i. ' ----> ' . $info_user[$i]['displayname'][0] . ' ----> ' . $info_user[$i]['samaccountname'][0];
       if (isset($info_user[$i]['mail'][0]))
          echo ' ----> '.$info_user[$i]['mail'][0];
       if (isset($info_user[$i]['telephonenumber'][0]))
          echo ' ----> '.$info_user[$i]['telephonenumber'][0];
       if (isset($info_user[$i]['department'][0]))
          echo ' ----> '.$info_user[$i]['department'][0];
       echo  ' </br>' ;
       }
    //for ($i=0, $c=count($sql1); $i<$c; $i++)
    //echo $sql1[2];
    for ($i=0, $c=$info_comp['count']; $i<$c; $i++)
    {
       echo $i. ' ----> ' .$info_comp[$i]['cn'][0] . ' ----> ';
       if (isset($info_comp[$i]['description'][0]))
          echo ' ----> '.$info_comp[$i]['description'][0];
    }
    ?>
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: Communication with Active Directory

Post by Klemen »

Thanks for sharing!
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
vladsn07
Posts: 12
Joined: Wed Oct 16, 2013 12:33 pm

Re: Communication with Active Directory

Post by vladsn07 »

Klemen
How can I combine these two scripts?
Post Reply