ldap.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/user/group/ldap.php
  21. * \ingroup ldap
  22. * \brief Page fiche LDAP groupe
  23. */
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
  30. // Load translation files required by page
  31. $langs->loadLangs(array('companies', 'ldap', 'users', 'admin'));
  32. $id = GETPOST('id', 'int');
  33. $action = GETPOST('action', 'aZ09');
  34. $socid = 0;
  35. if ($user->socid > 0) {
  36. $socid = $user->socid;
  37. }
  38. $object = new Usergroup($db);
  39. $object->fetch($id);
  40. $object->getrights();
  41. // Users/Groups management only in master entity if transverse mode
  42. if (!empty($conf->multicompany->enabled) && $conf->entity > 1 && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
  43. accessforbidden();
  44. }
  45. $canreadperms = true;
  46. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  47. $canreadperms = (!empty($user->admin) || !empty($user->rights->user->group_advance->read));
  48. }
  49. /*
  50. * Actions
  51. */
  52. if ($action == 'dolibarr2ldap') {
  53. $ldap = new Ldap();
  54. $result = $ldap->connect_bind();
  55. if ($result > 0) {
  56. $info = $object->_load_ldap_info();
  57. // Get a gid number for objectclass PosixGroup if none was provided
  58. if (empty($info[$conf->global->LDAP_GROUP_FIELD_GROUPID]) && in_array('posixGroup', $info['objectclass'])) {
  59. $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS');
  60. }
  61. $dn = $object->_load_ldap_dn($info);
  62. $olddn = $dn; // We can say that old dn = dn as we force synchro
  63. $result = $ldap->update($dn, $info, $user, $olddn);
  64. }
  65. if ($result >= 0) {
  66. setEventMessages($langs->trans("GroupSynchronized"), null, 'mesgs');
  67. } else {
  68. setEventMessages($ldap->error, $ldap->errors, 'errors');
  69. }
  70. }
  71. /*
  72. * View
  73. */
  74. $form = new Form($db);
  75. llxHeader();
  76. $head = group_prepare_head($object);
  77. print dol_get_fiche_head($head, 'ldap', $langs->trans("Group"), -1, 'group');
  78. $linkback = '<a href="'.DOL_URL_ROOT.'/user/group/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  79. dol_banner_tab($object, 'id', $linkback, (!empty($user->rights->user->user->lire) || !empty($user->admin)));
  80. print '<div class="fichecenter">';
  81. print '<div class="underbanner clearboth"></div>';
  82. print '<table class="border centpercent">';
  83. // Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner)
  84. if (!empty($conf->mutlicompany->enabled)) {
  85. print '<tr><td class="titlefield">'.$langs->trans("Name").'</td>';
  86. print '<td class="valeur">'.$object->name;
  87. if (!$object->entity) {
  88. print img_picto($langs->trans("GlobalGroup"), 'redstar');
  89. }
  90. print "</td></tr>\n";
  91. }
  92. // Note
  93. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  94. print '<td class="valeur sensiblehtmlcontent">';
  95. print dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note));
  96. print '</td>';
  97. print "</tr>\n";
  98. // LDAP DN
  99. print '<tr><td>LDAP '.$langs->trans("LDAPGroupDn").'</td><td class="valeur">'.getDolGlobalString('LDAP_GROUP_DN')."</td></tr>\n";
  100. // LDAP Cle
  101. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.getDolGlobalString('LDAP_KEY_GROUPS')."</td></tr>\n";
  102. // LDAP Server
  103. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
  104. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
  105. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
  106. print "</table>\n";
  107. print '</div>';
  108. print dol_get_fiche_end();
  109. /*
  110. * Action bar
  111. */
  112. print '<div class="tabsAction">';
  113. if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
  114. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
  115. }
  116. print "</div>\n";
  117. if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
  118. print "<br>\n";
  119. }
  120. // Affichage attributs LDAP
  121. print load_fiche_titre($langs->trans("LDAPInformationsForThisGroup"));
  122. print '<table class="noborder centpercent">';
  123. print '<tr class="liste_titre">';
  124. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  125. print '<td>'.$langs->trans("Value").'</td>';
  126. print '</tr>';
  127. // Lecture LDAP
  128. $ldap = new Ldap();
  129. $result = $ldap->connect_bind();
  130. if ($result > 0) {
  131. $info = $object->_load_ldap_info();
  132. $dn = $object->_load_ldap_dn($info, 1);
  133. $search = "(".$object->_load_ldap_dn($info, 2).")";
  134. $records = $ldap->getAttribute($dn, $search);
  135. //var_dump($records);
  136. // Show tree
  137. if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
  138. if (!is_array($records)) {
  139. print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
  140. } else {
  141. $result = show_ldap_content($records, 0, $records['count'], true);
  142. }
  143. } else {
  144. print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
  145. }
  146. $ldap->unbind();
  147. } else {
  148. setEventMessages($ldap->error, $ldap->errors, 'errors');
  149. }
  150. print '</table>';
  151. // End of page
  152. llxFooter();
  153. $db->close();