ldap.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. // Load Dolibarr environment
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
  31. // Load translation files required by page
  32. $langs->loadLangs(array('companies', 'ldap', 'users', 'admin'));
  33. $id = GETPOST('id', 'int');
  34. $action = GETPOST('action', 'aZ09');
  35. $socid = 0;
  36. if ($user->socid > 0) {
  37. $socid = $user->socid;
  38. }
  39. $object = new UserGroup($db);
  40. $object->fetch($id, '', true);
  41. $object->getrights();
  42. // Users/Groups management only in master entity if transverse mode
  43. if (isModEnabled('multicompany') && $conf->entity > 1 && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
  44. accessforbidden();
  45. }
  46. $canreadperms = true;
  47. if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
  48. $canreadperms = (!empty($user->admin) || !empty($user->rights->user->group_advance->read));
  49. }
  50. /*
  51. * Actions
  52. */
  53. if ($action == 'dolibarr2ldap') {
  54. $ldap = new Ldap();
  55. $result = $ldap->connect_bind();
  56. if ($result > 0) {
  57. $info = $object->_load_ldap_info();
  58. // Get a gid number for objectclass PosixGroup if none was provided
  59. if (empty($info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')]) && in_array('posixGroup', $info['objectclass'])) {
  60. $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS');
  61. }
  62. $dn = $object->_load_ldap_dn($info);
  63. $olddn = $dn; // We can say that old dn = dn as we force synchro
  64. $result = $ldap->update($dn, $info, $user, $olddn);
  65. }
  66. if ($result >= 0) {
  67. setEventMessages($langs->trans("GroupSynchronized"), null, 'mesgs');
  68. } else {
  69. setEventMessages($ldap->error, $ldap->errors, 'errors');
  70. }
  71. }
  72. /*
  73. * View
  74. */
  75. $form = new Form($db);
  76. $title = $object->name." - ".$langs->trans('LDAP');
  77. $help_url = '';
  78. llxHeader('', $title, $help_url);
  79. $head = group_prepare_head($object);
  80. print dol_get_fiche_head($head, 'ldap', $langs->trans("Group"), -1, 'group');
  81. $linkback = '<a href="'.DOL_URL_ROOT.'/user/group/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  82. dol_banner_tab($object, 'id', $linkback, ($user->hasRight('user', 'user', 'lire') || !empty($user->admin)));
  83. print '<div class="fichecenter">';
  84. print '<div class="underbanner clearboth"></div>';
  85. print '<table class="border centpercent tableforfield">';
  86. // Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner)
  87. if (!empty($conf->mutlicompany->enabled)) {
  88. print '<tr><td class="titlefield">'.$langs->trans("Name").'</td>';
  89. print '<td class="valeur">'.$object->name;
  90. if (!$object->entity) {
  91. print img_picto($langs->trans("GlobalGroup"), 'redstar');
  92. }
  93. print "</td></tr>\n";
  94. }
  95. // Note
  96. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  97. print '<td class="valeur sensiblehtmlcontent">';
  98. print dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note));
  99. print '</td>';
  100. print "</tr>\n";
  101. // LDAP DN
  102. print '<tr><td>LDAP '.$langs->trans("LDAPGroupDn").'</td><td class="valeur">'.getDolGlobalString('LDAP_GROUP_DN')."</td></tr>\n";
  103. // LDAP Cle
  104. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.getDolGlobalString('LDAP_KEY_GROUPS')."</td></tr>\n";
  105. // LDAP Server
  106. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
  107. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
  108. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
  109. print "</table>\n";
  110. print '</div>';
  111. print dol_get_fiche_end();
  112. /*
  113. * Action bar
  114. */
  115. print '<div class="tabsAction">';
  116. if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
  117. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
  118. }
  119. print "</div>\n";
  120. if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
  121. print "<br>\n";
  122. }
  123. // Affichage attributs LDAP
  124. print load_fiche_titre($langs->trans("LDAPInformationsForThisGroup"));
  125. print '<table class="noborder centpercent">';
  126. print '<tr class="liste_titre">';
  127. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  128. print '<td>'.$langs->trans("Value").'</td>';
  129. print '</tr>';
  130. // Lecture LDAP
  131. $ldap = new Ldap();
  132. $result = $ldap->connect_bind();
  133. if ($result > 0) {
  134. $info = $object->_load_ldap_info();
  135. $dn = $object->_load_ldap_dn($info, 1);
  136. $search = "(".$object->_load_ldap_dn($info, 2).")";
  137. $records = $ldap->getAttribute($dn, $search);
  138. //var_dump($records);
  139. // Show tree
  140. if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
  141. if (!is_array($records)) {
  142. print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
  143. } else {
  144. $result = show_ldap_content($records, 0, $records['count'], true);
  145. }
  146. } else {
  147. print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
  148. }
  149. $ldap->unbind();
  150. } else {
  151. setEventMessages($ldap->error, $ldap->errors, 'errors');
  152. }
  153. print '</table>';
  154. // End of page
  155. llxFooter();
  156. $db->close();