How can I combine two queries from LDAP and MYSQL?
Posted: Wed Apr 16, 2008 3:53 pm
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
Sorry for the PHP Newb Questions.
The first php code chunk below grabs a list of computers from our mysql database based on the system_os_name, contains 'server'.
The second is just a basic ldap search lookup by OU.
What I would like to do is combine to the two, and be able to get a list of all servers in a particular OU.
So it would have to take the list from the mysql database (b/c some servers might not be in the active directory), and then cross reference that to the ldap database ou lookup. Is this possible in php, or am I even looking at this the wrong way (possibly and easier way)?
PS I know the second code is pretty basic, and I'd probably be better off storing the host,port,user information elsewhere..
Thanks for any help, I want to do this so bad... but I'm too new to php to figure out even where to start.
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
Sorry for the PHP Newb Questions.
The first php code chunk below grabs a list of computers from our mysql database based on the system_os_name, contains 'server'.
Code: Select all
<?php
$query_array=array("headline"=>__("List all Windows Servers"),
"sql"=>"SELECT * FROM `system` WHERE (system_os_name LIKE '%Server%')",
"sort"=>"system_name",
"dir"=>"ASC",
"get"=>array("file"=>"system.php",
"title"=>__("Go to System"),
"var"=>array("pc"=>"%system_uuid",
"view"=>"summary",
),
),
"fields"=>array("10"=>array("name"=>"system_uuid",
"head"=>__("UUID"),
"show"=>"n",
),
"20"=>array("name"=>"net_ip_address",
"head"=>__("IP"),
"show"=>"y",
"link"=>"y",
),
"30"=>array("name"=>"system_name",
"head"=>__("Hostname"),
"show"=>"y",
"link"=>"y",
),
"40"=>array("name"=>"net_domain",
"head"=>"Domain",
"show"=>$show_domain,
),
"50"=>array("name"=>"system_os_name",
"head"=>__("OS"),
"show"=>$show_os,
),
"60"=>array("name"=>"system_service_pack",
"head"=>"Servicepack",
"show"=>$show_service_pack,
),
"70"=>array("name"=>"system_timestamp",
"head"=>__("Date Audited"),
"show"=>$show_date_audited,
),
"80"=>array("name"=>"system_system_type",
"head"=>__("System Type"),
"show"=>$show_type,
"align"=>"center",
),
"90"=>array("name"=>"system_description",
"head"=>"Description",
"show"=>$show_description,
),
),
);
?>
Code: Select all
<?php
$host = "lab.constoso.com";
$port = "389";
$dn = "CN=Computers,DC=lab,DC=contoso,DC=com";
$connection = ldap_connect($host)
or die("Can't establish LDAP connection");
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connection, LDAP_OPT_REFERRALS,0);
ldap_bind($connection,"user","password")
or die("Can't bind to the server.");
$results = ldap_search($connection, $dn, "objectcategory=computer");
$entries = ldap_get_entries($connection, $results);
$count = $entries["count"];
for($x=0; $x < $count; $x++) {
printf("%s ", $entries[$x]["cn"][0]);
echo "<br>";
}
?>
So it would have to take the list from the mysql database (b/c some servers might not be in the active directory), and then cross reference that to the ldap database ou lookup. Is this possible in php, or am I even looking at this the wrong way (possibly and easier way)?
PS I know the second code is pretty basic, and I'd probably be better off storing the host,port,user information elsewhere..
Thanks for any help, I want to do this so bad... but I'm too new to php to figure out even where to start.
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.