ldap.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. /* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006-2017 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. $rowid = GETPOST('id', 'int');
  32. $action = GETPOST('action', 'aZ09');
  33. // Protection
  34. $socid=0;
  35. if ($user->societe_id > 0)
  36. {
  37. $socid = $user->societe_id;
  38. }
  39. $object = new Adherent($db);
  40. $result=$object->fetch($rowid);
  41. if (! $result)
  42. {
  43. dol_print_error($db, "Failed to get adherent: ".$object->error);
  44. exit;
  45. }
  46. /*
  47. * Actions
  48. */
  49. if ($action == 'dolibarr2ldap')
  50. {
  51. $ldap=new Ldap();
  52. $result=$ldap->connect_bind();
  53. if ($result > 0)
  54. {
  55. $info=$object->_load_ldap_info();
  56. $dn=$object->_load_ldap_dn($info);
  57. $olddn=$dn; // We can say that old dn = dn as we force synchro
  58. $result=$ldap->update($dn, $info, $user, $olddn);
  59. }
  60. if ($result >= 0) {
  61. setEventMessages($langs->trans("MemberSynchronized"), null, 'mesgs');
  62. }
  63. else {
  64. setEventMessages($ldap->error, $ldap->errors, 'errors');
  65. }
  66. }
  67. /*
  68. * View
  69. */
  70. $form = new Form($db);
  71. llxHeader('', $langs->trans("Member"), 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
  72. $head = member_prepare_head($object);
  73. dol_fiche_head($head, 'ldap', $langs->trans("Member"), 0, 'user');
  74. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  75. dol_banner_tab($object, 'rowid', $linkback);
  76. print '<div class="fichecenter">';
  77. print '<div class="underbanner clearboth"></div>';
  78. print '<table class="border centpercent tableforfield">';
  79. // Login
  80. print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
  81. // 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
  82. if (! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD))
  83. {
  84. print '<tr><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td>';
  85. print '<td class="valeur">'.$object->pass.'</td>';
  86. print "</tr>\n";
  87. }
  88. $adht = new AdherentType($db);
  89. $adht->fetch($object->typeid);
  90. // Type
  91. print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
  92. // LDAP DN
  93. print '<tr><td>LDAP '.$langs->trans("LDAPMemberDn").'</td><td class="valeur">'.$conf->global->LDAP_MEMBER_DN."</td></tr>\n";
  94. // LDAP Cle
  95. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_MEMBERS."</td></tr>\n";
  96. // LDAP Server
  97. print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
  98. print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
  99. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
  100. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
  101. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
  102. print '</table>';
  103. print '</div>';
  104. dol_fiche_end();
  105. /*
  106. * Barre d'actions
  107. */
  108. print '<div class="tabsAction">';
  109. if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && $conf->global->LDAP_MEMBER_ACTIVE != 'ldap2dolibarr')
  110. {
  111. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a></div>';
  112. }
  113. print "</div>\n";
  114. if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && $conf->global->LDAP_MEMBER_ACTIVE != 'ldap2dolibarr') print "<br>\n";
  115. // Affichage attributs LDAP
  116. print load_fiche_titre($langs->trans("LDAPInformationsForThisMember"));
  117. print '<table width="100%" class="noborder">';
  118. print '<tr class="liste_titre">';
  119. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  120. print '<td>'.$langs->trans("Value").'</td>';
  121. print '</tr>';
  122. // Lecture LDAP
  123. $ldap=new Ldap();
  124. $result=$ldap->connect_bind();
  125. if ($result > 0)
  126. {
  127. $info=$object->_load_ldap_info();
  128. $dn=$object->_load_ldap_dn($info, 1);
  129. $search = "(".$object->_load_ldap_dn($info, 2).")";
  130. if (empty($dn))
  131. {
  132. $langs->load("errors");
  133. print '<tr class="oddeven"><td colspan="2"><font class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Member")).'</font></td></tr>';
  134. }
  135. else
  136. {
  137. $records = $ldap->getAttribute($dn, $search);
  138. //print_r($records);
  139. // Show tree
  140. if (((! is_numeric($records)) || $records != 0) && (! isset($records['count']) || $records['count'] > 0))
  141. {
  142. if (! is_array($records))
  143. {
  144. print '<tr class="oddeven"><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
  145. }
  146. else
  147. {
  148. $result=show_ldap_content($records, 0, $records['count'], true);
  149. }
  150. }
  151. else
  152. {
  153. print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
  154. }
  155. }
  156. $ldap->unbind();
  157. $ldap->close();
  158. }
  159. else
  160. {
  161. setEventMessages($ldap->error, $ldap->errors, 'errors');
  162. }
  163. print '</table>';
  164. // End of page
  165. llxFooter();
  166. $db->close();