ldap.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("companies", "members", "ldap", "admin"));
  32. $id = GETPOST('id', 'int');
  33. $ref = GETPOST('ref', 'alphanohtml');
  34. $action = GETPOST('action', 'aZ09');
  35. // Protection
  36. $socid = 0;
  37. if ($user->socid > 0) {
  38. $socid = $user->socid;
  39. }
  40. $object = new Adherent($db);
  41. // Fetch object
  42. if ($id > 0 || !empty($ref)) {
  43. // Load member
  44. $result = $object->fetch($id, $ref);
  45. // Define variables to know what current user can do on users
  46. $canadduser = (!empty($user->admin) || $user->hasRight('user', 'user', 'creer'));
  47. // Define variables to know what current user can do on properties of user linked to edited member
  48. if ($object->user_id) {
  49. // $User is the user who edits, $object->user_id is the id of the related user in the edited member
  50. $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'creer'))
  51. || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'creer')));
  52. $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'password'))
  53. || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'password')));
  54. }
  55. }
  56. // Define variables to determine what the current user can do on the members
  57. $canaddmember = $user->hasRight('adherent', 'creer');
  58. // Define variables to determine what the current user can do on the properties of a member
  59. if ($id) {
  60. $caneditfieldmember = $user->hasRight('adherent', 'creer');
  61. }
  62. // Security check
  63. $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
  64. /*
  65. * Actions
  66. */
  67. if ($action == 'dolibarr2ldap') {
  68. $ldap = new Ldap();
  69. $result = $ldap->connect_bind();
  70. if ($result > 0) {
  71. $info = $object->_load_ldap_info();
  72. $dn = $object->_load_ldap_dn($info);
  73. $olddn = $dn; // We can say that old dn = dn as we force synchro
  74. $result = $ldap->update($dn, $info, $user, $olddn);
  75. }
  76. if ($result >= 0) {
  77. setEventMessages($langs->trans("MemberSynchronized"), null, 'mesgs');
  78. } else {
  79. setEventMessages($ldap->error, $ldap->errors, 'errors');
  80. }
  81. }
  82. /*
  83. * View
  84. */
  85. $form = new Form($db);
  86. llxHeader('', $langs->trans("Member"), 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder');
  87. $head = member_prepare_head($object);
  88. print dol_get_fiche_head($head, 'ldap', $langs->trans("Member"), 0, 'user');
  89. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  90. dol_banner_tab($object, 'rowid', $linkback);
  91. print '<div class="fichecenter">';
  92. print '<div class="underbanner clearboth"></div>';
  93. print '<table class="border centpercent tableforfield">';
  94. // Login
  95. print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
  96. // 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
  97. if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
  98. print '<tr><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td>';
  99. print '<td class="valeur">'.$object->pass.'</td>';
  100. print "</tr>\n";
  101. }
  102. $adht = new AdherentType($db);
  103. $adht->fetch($object->typeid);
  104. // Type
  105. print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
  106. // LDAP DN
  107. print '<tr><td>LDAP '.$langs->trans("LDAPMemberDn").'</td><td class="valeur">'.getDolGlobalString('LDAP_MEMBER_DN')."</td></tr>\n";
  108. // LDAP Cle
  109. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.getDolGlobalString('LDAP_KEY_MEMBERS')."</td></tr>\n";
  110. // LDAP Server
  111. print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_TYPE')."</td></tr>\n";
  112. print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION')."</td></tr>\n";
  113. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
  114. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
  115. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
  116. print '</table>';
  117. print '</div>';
  118. print dol_get_fiche_end();
  119. /*
  120. * Action bar
  121. */
  122. print '<div class="tabsAction">';
  123. if (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalString('LDAP_MEMBER_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
  124. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a></div>';
  125. }
  126. print "</div>\n";
  127. if (getDolGlobalString('LDAP_MEMBER_ACTIVE') && getDolGlobalString('LDAP_MEMBER_ACTIVE') != Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
  128. print "<br>\n";
  129. }
  130. // Affichage attributs LDAP
  131. print load_fiche_titre($langs->trans("LDAPInformationsForThisMember"));
  132. print '<table width="100%" class="noborder">';
  133. print '<tr class="liste_titre">';
  134. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  135. print '<td>'.$langs->trans("Value").'</td>';
  136. print '</tr>';
  137. // Lecture LDAP
  138. $ldap = new Ldap();
  139. $result = $ldap->connect_bind();
  140. if ($result > 0) {
  141. $info = $object->_load_ldap_info();
  142. $dn = $object->_load_ldap_dn($info, 1);
  143. $search = "(".$object->_load_ldap_dn($info, 2).")";
  144. if (empty($dn)) {
  145. $langs->load("errors");
  146. print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Member")).'</span></td></tr>';
  147. } else {
  148. $records = $ldap->getAttribute($dn, $search);
  149. //print_r($records);
  150. // Show tree
  151. if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
  152. if (!is_array($records)) {
  153. print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
  154. } else {
  155. $result = show_ldap_content($records, 0, $records['count'], true);
  156. }
  157. } else {
  158. print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
  159. }
  160. }
  161. $ldap->unbind();
  162. } else {
  163. setEventMessages($ldap->error, $ldap->errors, 'errors');
  164. }
  165. print '</table>';
  166. // End of page
  167. llxFooter();
  168. $db->close();