ldap.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 <https://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->socid > 0) {
  34. $socid = $user->socid;
  35. }
  36. $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user');
  37. $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
  38. $object = new User($db);
  39. $object->fetch($id, '', '', 1);
  40. $object->getrights();
  41. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  42. $hookmanager->initHooks(array('usercard', 'userldap', 'globalcard'));
  43. /*
  44. * Actions
  45. */
  46. $parameters = array('id'=>$socid);
  47. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  48. if ($reshook < 0) {
  49. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  50. }
  51. if (empty($reshook)) {
  52. if ($_GET["action"] == 'dolibarr2ldap') {
  53. $ldap = new Ldap();
  54. $result = $ldap->connect_bind();
  55. if ($result > 0) {
  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. } else {
  64. setEventMessages($ldap->error, $ldap->errors, 'errors');
  65. }
  66. }
  67. }
  68. /*
  69. * View
  70. */
  71. $form = new Form($db);
  72. llxHeader();
  73. $head = user_prepare_head($object);
  74. $title = $langs->trans("User");
  75. print dol_get_fiche_head($head, 'ldap', $title, 0, 'user');
  76. $linkback = '';
  77. if ($user->rights->user->user->lire || $user->admin) {
  78. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  79. }
  80. dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
  81. print '<div class="fichecenter">';
  82. print '<div class="underbanner clearboth"></div>';
  83. print '<table class="border centpercent">';
  84. // Login
  85. print '<tr><td class="titlefield">'.$langs->trans("Login").'</td>';
  86. if ($object->ldap_sid) {
  87. print '<td class="warning">'.$langs->trans("LoginAccountDisableInDolibarr").'</td>';
  88. } else {
  89. print '<td>'.$object->login.'</td>';
  90. }
  91. print '</tr>';
  92. if ($conf->global->LDAP_SERVER_TYPE == "activedirectory") {
  93. $ldap = new Ldap();
  94. $result = $ldap->connect_bind();
  95. if ($result > 0) {
  96. $userSID = $ldap->getObjectSid($object->login);
  97. }
  98. print '<tr><td class="valigntop">'.$langs->trans("SID").'</td>';
  99. print '<td>'.$userSID.'</td>';
  100. print "</tr>\n";
  101. }
  102. // LDAP DN
  103. print '<tr><td>LDAP '.$langs->trans("LDAPUserDn").'</td><td class="valeur">'.$conf->global->LDAP_USER_DN."</td></tr>\n";
  104. // LDAP Cle
  105. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_USERS."</td></tr>\n";
  106. // LDAP Server
  107. print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
  108. print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
  109. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
  110. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
  111. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
  112. print '</table>';
  113. print '</div>';
  114. print dol_get_fiche_end();
  115. /*
  116. * Action bar
  117. */
  118. print '<div class="tabsAction">';
  119. if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') {
  120. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
  121. }
  122. print "</div>\n";
  123. if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') {
  124. print "<br>\n";
  125. }
  126. // Affichage attributs LDAP
  127. print load_fiche_titre($langs->trans("LDAPInformationsForThisUser"));
  128. print '<table class="noborder centpercent">';
  129. print '<tr class="liste_titre">';
  130. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  131. print '<td>'.$langs->trans("Value").'</td>';
  132. print '</tr>';
  133. // Lecture LDAP
  134. $ldap = new Ldap();
  135. $result = $ldap->connect_bind();
  136. if ($result > 0) {
  137. $info = $object->_load_ldap_info();
  138. $dn = $object->_load_ldap_dn($info, 1);
  139. $search = "(".$object->_load_ldap_dn($info, 2).")";
  140. $records = $ldap->getAttribute($dn, $search);
  141. //print_r($records);
  142. // Affichage arbre
  143. if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
  144. if (!is_array($records)) {
  145. print '<tr class="oddeven"><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
  146. } else {
  147. $result = show_ldap_content($records, 0, $records['count'], true);
  148. }
  149. } else {
  150. print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
  151. }
  152. $ldap->unbind();
  153. $ldap->close();
  154. } else {
  155. setEventMessages($ldap->error, $ldap->errors, 'errors');
  156. }
  157. print '</table>';
  158. // End of page
  159. llxFooter();
  160. $db->close();