Skip to content

Instantly share code, notes, and snippets.

@Rambou
Created April 11, 2016 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rambou/01f8b4430faf4ace44ba069b32341a2a to your computer and use it in GitHub Desktop.
Save Rambou/01f8b4430faf4ace44ba069b32341a2a to your computer and use it in GitHub Desktop.
A php script to make questions against LDAP Aegean University server and authenticating users.
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<body>
<?php
$ldap_server = "ldap://zeus.aegean.gr";
$ldap_dn = "dc=aegean,dc=gr"; // dn for your organization
$ldap_domain = "aegean";
$ldap_username = 'ACADEMIC_USERNAME';
$ldap_pwd = 'ACADEMIC_PASSWORD';
$user_to_get = 'icsd10124';
$ldapconn = ldap_connect($ldap_server) or die("Could not connect to LDAP server.");
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
if ($ldapconn)
@ldap_bind($ldapconn) or die("Πρόβλημα σύνδεσης με την κεντρική αυθεντικοποίηση του Πανεπιστημίου Αιγαίου. Δοκιμάστε αργότερα ή επικοινωνήστε με το διαχειριστή στο {$conf_admin_email}.");
// binding to ldap server using user's given credentials
$ldapbind = @ldap_bind($ldapconn, "$ldap_domain\\$ldap_username", "$ldap_pwd");
if ($ldapbind) {
###########################
## succesfull LDAP login ##
###########################
// Search LDAP for personal details
$filter = "(samaccountname=$user_to_get)"; // this command requires some filter
$justthese = array("cn", "givenname", "sn", "mail", "edupersonaffiliation", "title","department","description","userPrincipalName","url","telephoneNumber","sAMAccountType","samaccountname"); //the attributes to pull, which is much more efficient than pulling all attributes if you don't do this
//List of attributes
//edupersonaffiliation
//extensionattribute13
//department
//$sr = ldap_search($ldapconn, $ldap_dn, $filter, $justthese);
$sr = ldap_search($ldapconn, $ldap_dn, $filter); // for all attributes
$entry = ldap_get_entries($ldapconn, $sr);
/*$full_name = $entry[0]["cn"][0];
$ldap_firstName = $entry[0]["givenname"][0];
$ldap_lastName = $entry[0]["sn"][0];
$ldap_email = $entry[0]["mail"][0];
$ldap_edupersonaffiliation = trim($entry[0]["edupersonaffiliation"][0]);
$ldap_extensionattribute13 = trim($entry[0]["extensionattribute13"][0]);
$ldap_department = trim($entry[0]["department"][0]);
$ldap_title = trim($entry[0]["title"][0]);*/
// kept for testing purposes on LDAP entries
echo "<pre>";
print_r($entry);
echo "</pre>";
exit();
//Check if already exists in local DB
/*$link = mysql_connect("localhost", "mysql_user", "mysql_password");
$sql = "SELECT id_user, username, fname_en, lname_en, email, disabled \n"
. "FROM user WHERE username = '$ldap_username'";
$result = mysql_query($link, $sql) or die(mysql_errno($link) . ": " . mysql_error($link) . "\n");
$row = mysqli_fetch_assoc($result);*/
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment