ldap.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. /* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006 Regis Houssin <regis@dolibarr.fr>
  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 2 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 <http://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."/lib/member.lib.php");
  25. require_once(DOL_DOCUMENT_ROOT."/lib/ldap.class.php");
  26. require_once(DOL_DOCUMENT_ROOT."/lib/ldap.lib.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. $langs->load("companies");
  30. $langs->load("members");
  31. $langs->load("ldap");
  32. $langs->load("admin");
  33. // Protection quand utilisateur externe
  34. $rowid = isset($_GET["id"])?$_GET["id"]:'';
  35. $socid=0;
  36. if ($user->societe_id > 0)
  37. {
  38. $socid = $user->societe_id;
  39. }
  40. $adh = new Adherent($db);
  41. $adh->id = $rowid;
  42. $result=$adh->fetch($rowid);
  43. if (! $result)
  44. {
  45. dol_print_error($db,"Failed to get adherent: ".$adh->error);
  46. exit;
  47. }
  48. /*
  49. * Actions
  50. */
  51. if ($_GET["action"] == 'dolibarr2ldap')
  52. {
  53. $message="";
  54. $db->begin();
  55. $ldap=new Ldap();
  56. $result=$ldap->connect_bind();
  57. $info=$adh->_load_ldap_info();
  58. $dn=$adh->_load_ldap_dn($info);
  59. $olddn=$dn; // We can say that old dn = dn as we force synchro
  60. $result=$ldap->update($dn,$info,$user,$olddn);
  61. if ($result >= 0)
  62. {
  63. $message.='<div class="ok">'.$langs->trans("MemberSynchronized").'</div>';
  64. $db->commit();
  65. }
  66. else
  67. {
  68. $message.='<div class="error">'.$ldap->error.'</div>';
  69. $db->rollback();
  70. }
  71. }
  72. /*
  73. * View
  74. */
  75. llxHeader('',$langs->trans("Member"),'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
  76. $html = new Form($db);
  77. $head = member_prepare_head($adh);
  78. dol_fiche_head($head, 'ldap', $langs->trans("Member"), 0, 'user');
  79. print '<table class="border" width="100%">';
  80. // Ref
  81. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  82. print '<td class="valeur">';
  83. print $html->showrefnav($adh,'id');
  84. print '</td></tr>';
  85. // Nom
  86. print '<tr><td>'.$langs->trans("Lastname").'</td><td class="valeur">'.$adh->nom.'&nbsp;</td>';
  87. print '</tr>';
  88. // Prenom
  89. print '<tr><td width="15%">'.$langs->trans("Firstname").'</td><td class="valeur">'.$adh->prenom.'&nbsp;</td>';
  90. print '</tr>';
  91. // Login
  92. print '<tr><td>'.$langs->trans("Login").'</td><td class="valeur">'.$adh->login.'&nbsp;</td></tr>';
  93. // Password not crypted
  94. if ($conf->global->LDAP_MEMBER_FIELD_PASSWORD)
  95. {
  96. print '<tr><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td>';
  97. print '<td class="valeur">'.$fuser->pass.'</td>';
  98. print "</tr>\n";
  99. }
  100. // Password crypted
  101. if ($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)
  102. {
  103. print '<tr><td>'.$langs->trans("LDAPFieldPasswordCrypted").'</td>';
  104. print '<td class="valeur">'.$fuser->pass_crypted.'</td>';
  105. print "</tr>\n";
  106. }
  107. // Type
  108. print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adh->type."</td></tr>\n";
  109. $langs->load("admin");
  110. // LDAP DN
  111. print '<tr><td>LDAP '.$langs->trans("LDAPMemberDn").'</td><td class="valeur">'.$conf->global->LDAP_MEMBER_DN."</td></tr>\n";
  112. // LDAP Cle
  113. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_MEMBERS."</td></tr>\n";
  114. // LDAP Server
  115. print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
  116. print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
  117. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
  118. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
  119. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
  120. print '</table>';
  121. print '</div>';
  122. dol_htmloutput_mesg($message);
  123. /*
  124. * Barre d'actions
  125. */
  126. print '<div class="tabsAction">';
  127. if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && $conf->global->LDAP_MEMBER_ACTIVE != 'ldap2dolibarr')
  128. {
  129. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$adh->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
  130. }
  131. print "</div>\n";
  132. if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && $conf->global->LDAP_MEMBER_ACTIVE != 'ldap2dolibarr') print "<br>\n";
  133. // Affichage attributs LDAP
  134. print_titre($langs->trans("LDAPInformationsForThisMember"));
  135. print '<table width="100%" class="noborder">';
  136. print '<tr class="liste_titre">';
  137. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  138. print '<td>'.$langs->trans("Value").'</td>';
  139. print '</tr>';
  140. // Lecture LDAP
  141. $ldap=new Ldap();
  142. $result=$ldap->connect_bind();
  143. if ($result > 0)
  144. {
  145. $info=$adh->_load_ldap_info();
  146. $dn=$adh->_load_ldap_dn($info,1);
  147. $search = "(".$adh->_load_ldap_dn($info,2).")";
  148. $records=$ldap->getAttribute($dn,$search);
  149. //print_r($records);
  150. // Affichage arbre
  151. if (sizeof($records) && $records != false && (! isset($records['count']) || $records['count'] > 0))
  152. {
  153. if (! is_array($records))
  154. {
  155. print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
  156. }
  157. else
  158. {
  159. $result=show_ldap_content($records,0,$records['count'],true);
  160. }
  161. }
  162. else
  163. {
  164. print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
  165. }
  166. $ldap->unbind();
  167. $ldap->close();
  168. }
  169. else
  170. {
  171. dol_print_error('',$ldap->error);
  172. }
  173. print '</table>';
  174. $db->close();
  175. llxFooter();
  176. ?>