ldap.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /* Copyright (C) 2006-2012 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 <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/user/ldap.php
  20. * \ingroup ldap
  21. * \brief Page fiche LDAP utilisateur
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
  27. // Load translation files required by page
  28. $langs->loadLangs(array('users', 'admin', 'companies', 'ldap'));
  29. $id = GETPOST('id', 'int');
  30. $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'userldap'; // To manage different context of search
  31. // Security check
  32. $socid=0;
  33. if ($user->societe_id > 0) $socid = $user->societe_id;
  34. $feature2 = (($socid && $user->rights->user->self->creer)?'':'user');
  35. if ($user->id == $id) $feature2=''; // A user can always read its own card
  36. $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
  37. $object = new User($db);
  38. $object->fetch($id, '', '', 1);
  39. $object->getrights();
  40. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  41. $hookmanager->initHooks(array('usercard','userldap','globalcard'));
  42. /*
  43. * Actions
  44. */
  45. $parameters=array('id'=>$socid);
  46. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  47. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  48. if (empty($reshook))
  49. {
  50. if ($_GET["action"] == 'dolibarr2ldap')
  51. {
  52. $ldap = new Ldap();
  53. $result = $ldap->connect_bind();
  54. if ($result > 0)
  55. {
  56. $info = $object->_load_ldap_info();
  57. $dn = $object->_load_ldap_dn($info);
  58. $olddn = $dn; // We can say that old dn = dn as we force synchro
  59. $result = $ldap->update($dn, $info, $user, $olddn);
  60. }
  61. if ($result >= 0) {
  62. setEventMessages($langs->trans("UserSynchronized"), null, 'mesgs');
  63. }
  64. else {
  65. setEventMessages($ldap->error, $ldap->errors, 'errors');
  66. }
  67. }
  68. }
  69. /*
  70. * View
  71. */
  72. llxHeader();
  73. $form = new Form($db);
  74. $head = user_prepare_head($object);
  75. $title = $langs->trans("User");
  76. dol_fiche_head($head, 'ldap', $title, 0, 'user');
  77. $linkback = '';
  78. if ($user->rights->user->user->lire || $user->admin) {
  79. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  80. }
  81. dol_banner_tab($object,'id',$linkback,$user->rights->user->user->lire || $user->admin);
  82. print '<div class="fichecenter">';
  83. print '<div class="underbanner clearboth"></div>';
  84. print '<table class="border" width="100%">';
  85. // Login
  86. print '<tr><td class="titlefield">'.$langs->trans("Login").'</td>';
  87. if ($object->ldap_sid)
  88. {
  89. print '<td class="warning">'.$langs->trans("LoginAccountDisableInDolibarr").'</td>';
  90. }
  91. else
  92. {
  93. print '<td>'.$object->login.'</td>';
  94. }
  95. print '</tr>';
  96. if ($conf->global->LDAP_SERVER_TYPE == "activedirectory")
  97. {
  98. $ldap = new Ldap();
  99. $result = $ldap->connect_bind();
  100. if ($result > 0)
  101. {
  102. $userSID = $ldap->getObjectSid($object->login);
  103. }
  104. print '<tr><td class="valigntop">'.$langs->trans("SID").'</td>';
  105. print '<td>'.$userSID.'</td>';
  106. print "</tr>\n";
  107. }
  108. // LDAP DN
  109. print '<tr><td>LDAP '.$langs->trans("LDAPUserDn").'</td><td class="valeur">'.$conf->global->LDAP_USER_DN."</td></tr>\n";
  110. // LDAP Cle
  111. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_USERS."</td></tr>\n";
  112. // LDAP Server
  113. print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
  114. print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
  115. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
  116. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
  117. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
  118. print '</table>';
  119. print '</div>';
  120. dol_fiche_end();
  121. /*
  122. * Barre d'actions
  123. */
  124. print '<div class="tabsAction">';
  125. if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
  126. {
  127. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
  128. }
  129. print "</div>\n";
  130. if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') print "<br>\n";
  131. // Affichage attributs LDAP
  132. print load_fiche_titre($langs->trans("LDAPInformationsForThisUser"));
  133. print '<table width="100%" class="noborder">';
  134. print '<tr class="liste_titre">';
  135. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  136. print '<td>'.$langs->trans("Value").'</td>';
  137. print '</tr>';
  138. // Lecture LDAP
  139. $ldap=new Ldap();
  140. $result=$ldap->connect_bind();
  141. if ($result > 0)
  142. {
  143. $info=$object->_load_ldap_info();
  144. $dn=$object->_load_ldap_dn($info,1);
  145. $search = "(".$object->_load_ldap_dn($info,2).")";
  146. $records = $ldap->getAttribute($dn,$search);
  147. //print_r($records);
  148. // Affichage arbre
  149. if ((! is_numeric($records) || $records != 0) && (! isset($records['count']) || $records['count'] > 0))
  150. {
  151. if (! is_array($records))
  152. {
  153. print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
  154. }
  155. else
  156. {
  157. $result=show_ldap_content($records,0,$records['count'],true);
  158. }
  159. }
  160. else
  161. {
  162. print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
  163. }
  164. $ldap->unbind();
  165. $ldap->close();
  166. }
  167. else
  168. {
  169. setEventMessages($ldap->error, $ldap->errors, 'errors');
  170. }
  171. print '</table>';
  172. // End of page
  173. llxFooter();
  174. $db->close();