ldap.php 6.6 KB

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