ldap.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. /* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006-2021 Regis Houssin <regis.houssin@inodbox.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/adherents/ldap.php
  20. * \ingroup ldap member
  21. * \brief Page fiche LDAP adherent
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("companies", "members", "ldap", "admin"));
  31. $id = GETPOST('id', 'int');
  32. $ref = GETPOST('ref', 'alphanohtml');
  33. $action = GETPOST('action', 'aZ09');
  34. // Protection
  35. $socid = 0;
  36. if ($user->socid > 0) {
  37. $socid = $user->socid;
  38. }
  39. $object = new Adherent($db);
  40. // Fetch object
  41. if ($id > 0 || !empty($ref)) {
  42. // Load member
  43. $result = $object->fetch($id, $ref);
  44. // Define variables to know what current user can do on users
  45. $canadduser = (!empty($user->admin) || !empty($user->rights->user->user->creer));
  46. // Define variables to know what current user can do on properties of user linked to edited member
  47. if ($object->user_id) {
  48. // $User is the user who edits, $object->user_id is the id of the related user in the edited member
  49. $caneditfielduser = ((($user->id == $object->user_id) && !empty($user->rights->user->self->creer))
  50. || (($user->id != $object->user_id) && !empty($user->rights->user->user->creer)));
  51. $caneditpassworduser = ((($user->id == $object->user_id) && $user->rights->user->self->password)
  52. || (($user->id != $object->user_id) && !empty($user->rights->user->user->password)));
  53. }
  54. }
  55. // Define variables to determine what the current user can do on the members
  56. $canaddmember = $user->rights->adherent->creer;
  57. // Define variables to determine what the current user can do on the properties of a member
  58. if ($id) {
  59. $caneditfieldmember = $user->rights->adherent->creer;
  60. }
  61. // Security check
  62. $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
  63. /*
  64. * Actions
  65. */
  66. if ($action == 'dolibarr2ldap') {
  67. $ldap = new Ldap();
  68. $result = $ldap->connect_bind();
  69. if ($result > 0) {
  70. $info = $object->_load_ldap_info();
  71. $dn = $object->_load_ldap_dn($info);
  72. $olddn = $dn; // We can say that old dn = dn as we force synchro
  73. $result = $ldap->update($dn, $info, $user, $olddn);
  74. }
  75. if ($result >= 0) {
  76. setEventMessages($langs->trans("MemberSynchronized"), null, 'mesgs');
  77. } else {
  78. setEventMessages($ldap->error, $ldap->errors, 'errors');
  79. }
  80. }
  81. /*
  82. * View
  83. */
  84. $form = new Form($db);
  85. llxHeader('', $langs->trans("Member"), 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
  86. $head = member_prepare_head($object);
  87. print dol_get_fiche_head($head, 'ldap', $langs->trans("Member"), 0, 'user');
  88. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  89. dol_banner_tab($object, 'rowid', $linkback);
  90. print '<div class="fichecenter">';
  91. print '<div class="underbanner clearboth"></div>';
  92. print '<table class="border centpercent tableforfield">';
  93. // Login
  94. print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
  95. // If there is a link to password not crypted, we show value in database here so we can compare because it is shown nowhere else
  96. if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
  97. print '<tr><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td>';
  98. print '<td class="valeur">'.$object->pass.'</td>';
  99. print "</tr>\n";
  100. }
  101. $adht = new AdherentType($db);
  102. $adht->fetch($object->typeid);
  103. // Type
  104. print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
  105. // LDAP DN
  106. print '<tr><td>LDAP '.$langs->trans("LDAPMemberDn").'</td><td class="valeur">'.getDolGlobalString('LDAP_MEMBER_DN')."</td></tr>\n";
  107. // LDAP Cle
  108. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.getDolGlobalString('LDAP_KEY_MEMBERS')."</td></tr>\n";
  109. // LDAP Server
  110. print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_TYPE')."</td></tr>\n";
  111. print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION')."</td></tr>\n";
  112. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
  113. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
  114. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
  115. print '</table>';
  116. print '</div>';
  117. print dol_get_fiche_end();
  118. /*
  119. * Action bar
  120. */
  121. print '<div class="tabsAction">';
  122. if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && getDolGlobalString('LDAP_MEMBER_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
  123. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a></div>';
  124. }
  125. print "</div>\n";
  126. if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && getDolGlobalString('LDAP_MEMBER_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
  127. print "<br>\n";
  128. }
  129. // Affichage attributs LDAP
  130. print load_fiche_titre($langs->trans("LDAPInformationsForThisMember"));
  131. print '<table width="100%" class="noborder">';
  132. print '<tr class="liste_titre">';
  133. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  134. print '<td>'.$langs->trans("Value").'</td>';
  135. print '</tr>';
  136. // Lecture LDAP
  137. $ldap = new Ldap();
  138. $result = $ldap->connect_bind();
  139. if ($result > 0) {
  140. $info = $object->_load_ldap_info();
  141. $dn = $object->_load_ldap_dn($info, 1);
  142. $search = "(".$object->_load_ldap_dn($info, 2).")";
  143. if (empty($dn)) {
  144. $langs->load("errors");
  145. print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Member")).'</span></td></tr>';
  146. } else {
  147. $records = $ldap->getAttribute($dn, $search);
  148. //print_r($records);
  149. // Show tree
  150. if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
  151. if (!is_array($records)) {
  152. print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
  153. } else {
  154. $result = show_ldap_content($records, 0, $records['count'], true);
  155. }
  156. } else {
  157. print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
  158. }
  159. }
  160. $ldap->unbind();
  161. } else {
  162. setEventMessages($ldap->error, $ldap->errors, 'errors');
  163. }
  164. print '</table>';
  165. // End of page
  166. llxFooter();
  167. $db->close();