Communication with Active Directory
Posted: Thu Oct 31, 2013 6:17 pm
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
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];
}
?>