Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $q = strtolower(preg_replace('/[^0-9a-zA-Z@\.]/i','',$_GET['q']));
- $attribute = strtolower(preg_replace('/[^0-9a-zA-Z]/i','',$_GET['attribute']));
- if (empty($q) || empty($attribute)){ echo "Missing parameter. Format should be index.php?q=XXXXXXX&attribute=YYYYYYY.\n\nq may be a NetID or email address.\nattribute may be any valid LDAP attribute (e.g., ndMail, telephoneNumber, or ndPrimaryAffiliation).\n\nAll values are case insensitive.\n\nSee eds.nd.edu for possible attributes and values."; die;}
- $ds=ldap_connect("ldaps://ldap.nd.edu",636); // must be a valid LDAP server!
- if ($ds) {
- $r=ldap_bind($ds); // this is an "anonymous" bind, typically
- // read-only access
- if (strpos($q, '@')) {
- $filter = "ndmail=".$q;
- }
- else {
- $filter = "uid=".$q;
- }
- $sr=ldap_search($ds, "o=University of Notre Dame,st=Indiana,c=US", $filter);
- $info = ldap_get_entries($ds, $sr);
- echo "{\n \"title\": \"LDAP\",\n \"attributes\": {\n";
- for ($i=0; $i<$info["count"]; $i++) {
- echo " \"netid\": \"" . $info[$i]["uid"][0] . "\",\n";
- echo " \"".$attribute."\": \"" . $info[$i][$attribute][0] . "\"\n";
- }
- ldap_close($ds);
- echo " }\n}";
- } else {
- echo "{ \"Unable to connect to LDAP server\" }";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement