Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the possibility for users to modify their attributes #105

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions conf/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
$ldap_base = "dc=example,dc=com";
$ldap_user_base = "ou=users,".$ldap_base;
$ldap_user_filter = "(objectClass=inetOrgPerson)";
#$ldap_user_regex = "/,ou=users,/i";
$ldap_user_regex = "/,ou=users,/i";
$ldap_group_base = "ou=groups,".$ldap_base;
$ldap_group_filter = "(|(objectClass=groupOfNames)(objectClass=groupOfUniqueNames))";
$ldap_size_limit = 100;
#$ldap_network_timeout = 10;

# How display attributes
$attributes_map = array(
Expand All @@ -54,7 +53,6 @@
'l' => array( 'attribute' => 'l', 'faclass' => 'globe', 'type' => 'text' ),
'lastname' => array( 'attribute' => 'sn', 'faclass' => 'user-o', 'type' => 'text' ),
'mail' => array( 'attribute' => 'mail', 'faclass' => 'envelope-o', 'type' => 'mailto' ),
'mailquota' => array( 'attribute' => 'gosamailquota', 'faclass' => 'pie-chart', 'type' => 'bytes' ),
'manager' => array( 'attribute' => 'manager', 'faclass' => 'user-circle-o', 'type' => 'dn_link' ),
'member' => array( 'attribute' => 'member', 'faclass' => 'user', 'type' => 'usergroup_dn_link' ),
'memberof' => array( 'attribute' => 'memberof', 'faclass' => 'users', 'type' => 'group_dn_link' ),
Expand Down Expand Up @@ -85,6 +83,9 @@
$advanced_search_criteria = array('firstname', 'lastname', 'mail', 'title', 'businesscategory', 'employeetype', 'created', 'modified');
$advanded_search_display_search_objects = true;

# Authentification Ajout de l'authentification dans la barre de navigation
$use_authentification = true;

# Results display
$results_display_mode = "boxes"; // boxes or table
$search_result_items = array('mail', 'phone', 'mobile');
Expand All @@ -104,11 +105,11 @@
$datatables_auto_print = true;

# Full display
$display_items = array('firstname', 'lastname', 'title', 'businesscategory', 'employeenumber', 'employeetype', 'mail', 'mailquota', 'phone', 'mobile', 'fax', 'postaladdress', 'street', 'postalcode', 'l', 'state', 'manager', 'secretary', 'organizationalunit', 'organization', 'description', 'memberof');
$display_items = array('firstname', 'lastname', 'title', 'businesscategory', 'employeenumber', 'employeetype', 'mail', 'phone', 'mobile', 'fax', 'postaladdress', 'street', 'postalcode', 'l', 'state', 'manager', 'secretary', 'organizationalunit', 'organization', 'description', 'memberof');
$display_title = "fullname";
$display_show_undefined = false;
$display_group_items = array('fullname', 'description', 'member', 'uniquemember', 'memberof');
#$display_edit_link = "http://ldapadmin.example.com/?dn={dn}";
#$display_edit_link = "http://ldapadmin.example.com/?dn={dn}

# Gallery
$use_gallery = true;
Expand Down Expand Up @@ -140,11 +141,9 @@
$vcard_file_extension = "vcf";
$vcard_file_identifier = "identifier";
$vcard_version = "4.0";
$vcard_user_map = array('FN' => 'fullname', 'N' => 'fullname', 'EMAIL' => 'mail', 'CATEGORIES' => 'businesscategory', 'ORG' => 'organization', 'ROLE' => 'employeetype', 'TEL;TYPE=work,voice;VALUE=uri:tel' => 'phone', 'TEL;TYPE=cell,voice;VALUE=uri:tel' => 'mobile', 'UID' => 'identifier');
$vcard_group_map = array('FN' => 'fullname', 'N' => 'fullname', 'EMAIL' => 'mail', 'CATEGORIES' => 'businesscategory', 'MEMBER' => 'member', 'ORG' => 'organization', 'ROLE' => 'employeetype', 'TEL;TYPE=work,voice;VALUE=uri:tel' => 'phone', 'TEL;TYPE=cell,voice;VALUE=uri:tel' => 'mobile', 'UID' => 'identifier');
$vcard_map = array('FN' => 'fullname', 'N' => 'fullname', 'EMAIL' => 'mail', 'CATEGORIES' => 'businesscategory', 'ORG' => 'organization', 'ROLE' => 'employeetype', 'TEL;TYPE=work,voice;VALUE=uri:tel' => 'phone', 'TEL;TYPE=cell,voice;VALUE=uri:tel' => 'mobile', 'UID' => 'identifier');

# Photo
$use_gravatar = false;
$default_photo = "images/240px-PICA.jpg";
$photo_ldap_attribute = "jpegPhoto";
$photo_fixed_width = 240;
Expand All @@ -169,14 +168,12 @@
# Debug mode
$debug = false;

# Smarty
define("SMARTY", "/usr/share/php/smarty3/Smarty.class.php");

# Allow to override current settings with local configuration
if (file_exists (dirname (__FILE__) . '/config.inc.local.php')) {
include dirname (__FILE__) . '/config.inc.local.php';
}

# Smarty
if (!defined("SMARTY")) {
define("SMARTY", "/usr/share/php/smarty3/Smarty.class.php");
}

?>
10 changes: 2 additions & 8 deletions htdocs/advancedsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
require_once("../lib/ldap.inc.php");

# Connect to LDAP
$ldap_connection = wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw, $ldap_network_timeout);
$ldap_connection = wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw);

$ldap = $ldap_connection[0];
$result = $ldap_connection[1];
Expand Down Expand Up @@ -61,7 +61,7 @@
require_once("../lib/date.inc.php");

# Connect to LDAP
$ldap_connection = wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw, $ldap_network_timeout);
$ldap_connection = wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw);

$ldap = $ldap_connection[0];
$result = $ldap_connection[1];
Expand Down Expand Up @@ -100,13 +100,7 @@
} else {
$value = '*' . ldap_escape($value, "", LDAP_ESCAPE_FILTER) . '*';
}
if (isset($_POST[$item."negates"]) and ($_POST[$item."negates"] == 'true')) {
$ldap_filter .= "(!";
}
$ldap_filter .= "($attribute=$value)";
if (isset($_POST[$item."negates"]) and ($_POST[$item."negates"] == 'true')) {
$ldap_filter .= ")";
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
require_once("../lib/ldap.inc.php");

# Connect to LDAP
$ldap_connection = wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw, $ldap_network_timeout);
$ldap_connection = wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw);

$ldap = $ldap_connection[0];
$result = $ldap_connection[1];
Expand Down
47 changes: 5 additions & 42 deletions htdocs/display.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
require_once("../lib/ldap.inc.php");

# Connect to LDAP
$ldap_connection = wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw, $ldap_network_timeout);
$ldap_connection = wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw);

$ldap = $ldap_connection[0];
$result = $ldap_connection[1];
Expand Down Expand Up @@ -60,7 +60,7 @@

if ($use_vcard and $_GET["vcard"] and $vcard_file_identifier) {
$attributes[] = $attributes_map[$vcard_file_identifier]['attribute'];
}
}

# Search entry
$ldap_filter = $ldap_user_filter;
Expand All @@ -80,10 +80,10 @@

# Sort attributes values
foreach ($entry[0] as $attr => $values) {
if ( $values['count'] > 1 ) {
asort($values);
}
if ( isset($values['count']) ) {
if ( $values['count'] > 1 ) {
asort($values);
}
unset($values['count']);
}
$entry[0][$attr] = $values;
Expand All @@ -93,43 +93,6 @@
require_once("../lib/vcard.inc.php");
$vcard_file = $entry[0][$attributes_map[$vcard_file_identifier]['attribute']][0].".".$vcard_file_extension;
download_vcard_send_headers($vcard_file);
if ($type == "group") {
$vcard_map = $vcard_group_map;
$attributes = array();
$attributes[] = $attributes_map['mail']['attribute'];
$attributes[] = $attributes_map['phone']['attribute'];
$ldap_filter = "(".$attributes_map['memberof']['attribute']."=".$entry[0]['dn'].")";
$search = ldap_search($ldap, $ldap_user_base, $ldap_filter, $attributes, 0, $ldap_size_limit);
$errno = ldap_errno($ldap);
if ( $errno == 4 ) {
error_log("LDAP - VCard download hit page size limit");
}
if ( $errno != 0 and $errno != 4 ) {
error_log("LDAP - Search error $errno (".ldap_error($ldap).")");
} else {
# Get search results
$nb_entries = ldap_count_entries($ldap, $search);
$members = array();
if ($nb_entries > 0) {
$entries = ldap_get_entries($ldap, $search);
foreach ($entries as $item) {
foreach ($item as $a => $v) {
if ( $v['count'] > 1 ) { asort($v); }
if ( isset($v['count']) ) { unset($v['count']); }
$item[$a] = $v;
}
if (isset($item[$attributes_map['mail']['attribute']])) {
$members[] = 'mailto:'.$item[$attributes_map['mail']['attribute']][0];
} else if (isset($item[$attributes_map['phone']['attribute']])) {
$members[] = 'tel:'.$item[$attributes_map['phone']['attribute']][0];
}
}
}
$entry[0]['member_mailto'] = $members;
}
} else {
$vcard_map = $vcard_user_map;
}
echo print_vcard($entry[0], $attributes_map, $vcard_map, $vcard_version);
die;
}
Expand Down
140 changes: 140 additions & 0 deletions htdocs/editentry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

session_start();

/*
* Allow edition of an entry
*/

$entry_attributes = array (

"title" => "",

"telephonenumber" => "",
"telephoneassistant" => "",
"mobile" => "",

"physicaldeliveryofficename" => "",
"description" => ""
);

$psswrd = "";

$errProfilePicture = "";
$profilePicture = NULL;

$thumbnailPhoto_state = "";
$modify_state = "";
$submit_state = "";
$readonly = "";

// Checking photo
if($_FILES['thumbnailPhoto']['size'] != 0) {

if($_FILES["thumbnailPhoto"]['size'] > 100000){ // Size
$errProfilePicture = "L'image est trop volumineuse, elle ne doit pas dépasser 100ko. ";
}

$allowed = array('jpeg', 'jpg');
$ext = pathinfo($_FILES['thumbnailPhoto']['name'], PATHINFO_EXTENSION);

if (!in_array($ext, $allowed)) { // Extension
$errProfilePicture += "Mauvais format utilisé, l'image doit être au format jpg ou jpeg.";
}

if($errProfilePicture === ""){ // If no error get the photo

$profilePicture = file_get_contents($_FILES['thumbnailPhoto']['tmp_name']);
}
}



if(isset($_POST["submitedit"])) { // Saving datas

$distname = $_SESSION['distname']; // Get infos
$psswrd = $_SESSION['password'];
$sn = $_POST["sn"];
$givenname = $_POST["givenname"];
$mail = $_POST["mail"];

$ldap_connection = wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw);

$ldap = $ldap_connection[0];

if ($ldap) {

$errors = array();

$errors[] = ldap_bind($ldap, $distname, $psswrd);

foreach($entry_attributes as $attribute => $value){

$entry_attributes[$attribute] = $_POST[$attribute];

if($entry_attributes[$attribute] === ""){
$entry_attributes[$attribute] = array();
}
}

if($profilePicture != NULL){
$entry_attributes['thumbnailphoto'] = $profilePicture;
}

$errors[] = ldap_modify($ldap, $distname, $entry_attributes); // Modify data

$modify_state = "visibility:block;"; // Checking mode
$submit_state = "visibility:hidden;";
$readonly = "readonly";
$thumbnailPhoto_state = "disabled";


}
}
else{

$_SESSION['password'] = $password; // Get infos after authentication
$_SESSION['distname'] = $dn;
$distname = $dn;
$sn = $entry[0]["sn"][0];
$givenname = $entry[0]["givenname"][0];
$mail = $entry[0]["mail"][0];

foreach($entry_attributes as $attribute => $value){

$entry_attributes[$attribute] = $entry[0][$attribute][0];

}

$modify_state = "visibility:hidden;";
$submit_state = "visibility:block;";
$readonly = "";

}



$smarty->assign("errProfilePicture", $errProfilePicture);

$smarty->assign("modify_state", $modify_state);
$smarty->assign("submit_state", $submit_state);
$smarty->assign("readonly", $readonly);

$smarty->assign("distname", $distname);

$smarty->assign("thumbnailPhoto_state", $thumbnailPhoto_state);

$smarty->assign("sn", $sn);
$smarty->assign("givenname", $givenname);
$smarty->assign("title", $entry_attributes["title"]);

$smarty->assign("mail", $mail);

$smarty->assign("telephoneassistant", $entry_attributes["telephoneassistant"]);
$smarty->assign("telephonenumber", $entry_attributes["telephonenumber"]);

$smarty->assign("mobile", $entry_attributes["mobile"]);

$smarty->assign("physicaldeliveryofficename", $entry_attributes["physicaldeliveryofficename"]);
$smarty->assign("description", $entry_attributes["description"]);
?>
7 changes: 1 addition & 6 deletions htdocs/gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
require_once("../lib/ldap.inc.php");

# Connect to LDAP
$ldap_connection = wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw, $ldap_network_timeout);
$ldap_connection = wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw);

$ldap = $ldap_connection[0];
$result = $ldap_connection[1];
Expand All @@ -28,11 +28,6 @@
if (isset($gallery_user_filter) ) {
$gallery_filter = $gallery_user_filter;
}
# Search for users in group
if (isset($_GET['groupdn'])) {
$gallery_filter = "(&".$gallery_filter."(memberOf=".$_GET['groupdn']."))";
}

$search = ldap_search($ldap, $ldap_user_base, $gallery_filter, $attributes, 0, $ldap_size_limit);

$errno = ldap_errno($ldap);
Expand Down
Loading