PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/ldap.php

https://bitbucket.org/speedealing/speedealing
PHP | 330 lines | 226 code | 54 blank | 50 comment | 35 complexity | e283ba6460e418bd7f13c767dc012102 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  4. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  5. * Copyright (C) 2005 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  7. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/admin/ldap.php
  24. * \ingroup ldap
  25. * \brief Page d'administration/configuration du module Ldap
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.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. $langs->load("admin");
  32. if (!$user->admin)
  33. accessforbidden();
  34. $action = GETPOST("action");
  35. /*
  36. * Actions
  37. */
  38. if ($action == 'setvalue' && $user->admin)
  39. {
  40. $error=0;
  41. $db->begin();
  42. if (! dolibarr_set_const($db, 'LDAP_SERVER_TYPE',GETPOST("type"),'chaine',0,'',$conf->entity)) $error++;
  43. if (! dolibarr_set_const($db, 'LDAP_SERVER_PROTOCOLVERSION',GETPOST("LDAP_SERVER_PROTOCOLVERSION"),'chaine',0,'',$conf->entity)) $error++;
  44. if (! dolibarr_set_const($db, 'LDAP_SERVER_HOST',GETPOST("host"),'chaine',0,'',$conf->entity)) $error++;
  45. if (! dolibarr_set_const($db, 'LDAP_SERVER_HOST_SLAVE',GETPOST("slave"),'chaine',0,'',$conf->entity)) $error++;
  46. if (! dolibarr_set_const($db, 'LDAP_SERVER_PORT',GETPOST("port"),'chaine',0,'',$conf->entity)) $error++;
  47. if (! dolibarr_set_const($db, 'LDAP_SERVER_DN',GETPOST("dn"),'chaine',0,'',$conf->entity)) $error++;
  48. if (! dolibarr_set_const($db, 'LDAP_ADMIN_DN',GETPOST("admin"),'chaine',0,'',$conf->entity)) $error++;
  49. if (! dolibarr_set_const($db, 'LDAP_ADMIN_PASS',GETPOST("pass"),'chaine',0,'',$conf->entity)) $error++;
  50. if (! dolibarr_set_const($db, 'LDAP_SERVER_USE_TLS',GETPOST("usetls"),'chaine',0,'',$conf->entity)) $error++;
  51. if (! dolibarr_set_const($db, 'LDAP_SYNCHRO_ACTIVE',GETPOST("activesynchro"),'chaine',0,'',$conf->entity)) $error++;
  52. if (! dolibarr_set_const($db, 'LDAP_CONTACT_ACTIVE',GETPOST("activecontact"),'chaine',0,'',$conf->entity)) $error++;
  53. if (! dolibarr_set_const($db, 'LDAP_MEMBER_ACTIVE',GETPOST("activemembers"),'chaine',0,'',$conf->entity)) $error++;
  54. if (! $error)
  55. {
  56. $db->commit();
  57. $mesg='<div class="ok">'.$langs->trans("SetupSaved").'</div>';
  58. }
  59. else
  60. {
  61. $db->rollback();
  62. dol_print_error($db);
  63. }
  64. }
  65. /*
  66. * View
  67. */
  68. llxHeader('',$langs->trans("LDAPSetup"),'EN:Module_LDAP_En|FR:Module_LDAP|ES:M&oacute;dulo_LDAP');
  69. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  70. print_fiche_titre($langs->trans("LDAPSetup"),$linkback,'setup');
  71. $head = ldap_prepare_head();
  72. // Test si fonction LDAP actives
  73. if (! function_exists("ldap_connect"))
  74. {
  75. $mesg.='<div class="error">'.$langs->trans("LDAPFunctionsNotAvailableOnPHP").'</div>'; ;
  76. }
  77. dol_fiche_head($head, 'ldap', $langs->trans("LDAPSetup"));
  78. $var=true;
  79. $form=new Form($db);
  80. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=setvalue">';
  81. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  82. print '<table class="noborder" width="100%">';
  83. // Liste de synchro actives
  84. print '<tr class="liste_titre">';
  85. print '<td colspan="3">'.$langs->trans("LDAPSynchronization").'</td>';
  86. print "</tr>\n";
  87. // Synchro utilisateurs/groupes active
  88. $var=!$var;
  89. print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPDnSynchroActive").'</td><td>';
  90. $arraylist=array();
  91. $arraylist['0']=$langs->trans("No");
  92. $arraylist['ldap2dolibarr']=$langs->trans("LDAPToSpeedealing");
  93. $arraylist['dolibarr2ldap']=$langs->trans("SpeedealingToLDAP");
  94. print $form->selectarray('activesynchro',$arraylist,$conf->global->LDAP_SYNCHRO_ACTIVE);
  95. print '</td><td>'.$langs->trans("LDAPDnSynchroActiveExample");
  96. if ($conf->global->LDAP_SYNCHRO_ACTIVE && ! $conf->global->LDAP_USER_DN)
  97. {
  98. print '<br><font class="error">'.$langs->trans("LDAPSetupNotComplete").'</font>';
  99. }
  100. print '</td></tr>';
  101. // Synchro contact active
  102. if (! empty($conf->societe->enabled))
  103. {
  104. $var=!$var;
  105. print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPDnContactActive").'</td><td>';
  106. $arraylist=array();
  107. $arraylist['0']=$langs->trans("No");
  108. $arraylist['1']=$langs->trans("SpeedealingToLDAP");
  109. print $form->selectarray('activecontact',$arraylist,$conf->global->LDAP_CONTACT_ACTIVE);
  110. print '</td><td>'.$langs->trans("LDAPDnContactActiveExample").'</td></tr>';
  111. }
  112. // Synchro adherentt active
  113. if (! empty($conf->adherent->enabled))
  114. {
  115. $var=!$var;
  116. print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPDnMemberActive").'</td><td>';
  117. $arraylist=array();
  118. $arraylist['0']=$langs->trans("No");
  119. $arraylist['1']=$langs->trans("SpeedealingToLDAP");
  120. print $form->selectarray('activemembers',$arraylist,$conf->global->LDAP_MEMBER_ACTIVE);
  121. print '</td><td>'.$langs->trans("LDAPDnMemberActiveExample").'</td></tr>';
  122. }
  123. print '<tr class="liste_titre">';
  124. print '<td>'.$langs->trans("Parameter").'</td>';
  125. print '<td>'.$langs->trans("Value").'</td>';
  126. print '<td>'.$langs->trans("Example").'</td>';
  127. print "</tr>\n";
  128. // Type
  129. $var=!$var;
  130. print '<tr '.$bc[$var].'><td>'.$langs->trans("Type").'</td><td>';
  131. $arraylist=array();
  132. $arraylist['activedirectory']='Active Directory';
  133. $arraylist['openldap']='OpenLdap';
  134. $arraylist['egroupware']='Egroupware';
  135. print $form->selectarray('type',$arraylist,$conf->global->LDAP_SERVER_TYPE);
  136. print '</td><td>&nbsp;</td></tr>';
  137. // Version
  138. $var=!$var;
  139. print '<tr '.$bc[$var].'><td>'.$langs->trans("Version").'</td><td>';
  140. $arraylist=array();
  141. $arraylist['3']='Version 3';
  142. $arraylist['2']='Version 2';
  143. print $form->selectarray('LDAP_SERVER_PROTOCOLVERSION',$arraylist,$conf->global->LDAP_SERVER_PROTOCOLVERSION);
  144. print '</td><td>'.$langs->trans("LDAPServerProtocolVersion").'</td></tr>';
  145. // Serveur primaire
  146. $var=!$var;
  147. print '<tr '.$bc[$var].'><td>';
  148. print $langs->trans("LDAPPrimaryServer").'</td><td>';
  149. print '<input size="25" type="text" name="host" value="'.$conf->global->LDAP_SERVER_HOST.'">';
  150. print '</td><td>'.$langs->trans("LDAPServerExample").'</td></tr>';
  151. // Serveur secondaire
  152. $var=!$var;
  153. print '<tr '.$bc[$var].'><td>';
  154. print $langs->trans("LDAPSecondaryServer").'</td><td>';
  155. print '<input size="25" type="text" name="slave" value="'.$conf->global->LDAP_SERVER_HOST_SLAVE.'">';
  156. print '</td><td>'.$langs->trans("LDAPServerExample").'</td></tr>';
  157. // Port
  158. $var=!$var;
  159. print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPServerPort").'</td><td>';
  160. if (! empty($conf->global->LDAP_SERVER_PORT))
  161. {
  162. print '<input size="25" type="text" name="port" value="'.$conf->global->LDAP_SERVER_PORT.'">';
  163. }
  164. else
  165. {
  166. print '<input size="25" type="text" name="port" value="389">';
  167. }
  168. print '</td><td>'.$langs->trans("LDAPServerPortExample").'</td></tr>';
  169. // DNserver
  170. $var=!$var;
  171. print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPServerDn").'</td><td>';
  172. print '<input size="25" type="text" name="dn" value="'.$conf->global->LDAP_SERVER_DN.'">';
  173. print '</td><td>'.$langs->trans("LDAPServerDnExample").'</td></tr>';
  174. // Utiliser TLS
  175. $var=!$var;
  176. print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPServerUseTLS").'</td><td>';
  177. $arraylist=array();
  178. $arraylist['0']=$langs->trans("No");
  179. $arraylist['1']=$langs->trans("Yes");
  180. print $form->selectarray('usetls',$arraylist,$conf->global->LDAP_SERVER_USE_TLS);
  181. print '</td><td>'.$langs->trans("LDAPServerUseTLSExample").'</td></tr>';
  182. print '<tr class="liste_titre">';
  183. print '<td colspan="3">'.$langs->trans("ForANonAnonymousAccess").'</td>';
  184. print "</tr>\n";
  185. // DNAdmin
  186. $var=!$var;
  187. print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPAdminDn").'</td><td>';
  188. print '<input size="25" type="text" name="admin" value="'.$conf->global->LDAP_ADMIN_DN.'">';
  189. print '</td><td>'.$langs->trans("LDAPAdminDnExample").'</td></tr>';
  190. // Pass
  191. $var=!$var;
  192. print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPPassword").'</td><td>';
  193. if (! empty($conf->global->LDAP_ADMIN_PASS))
  194. {
  195. print '<input size="25" type="password" name="pass" value="'.$conf->global->LDAP_ADMIN_PASS.'">';// je le met en visible pour test
  196. }
  197. else
  198. {
  199. print '<input size="25" type="text" name="pass" value="'.$conf->global->LDAP_ADMIN_PASS.'">';
  200. }
  201. print '</td><td>secret</td></tr>';
  202. print '</table>';
  203. print '<center><input type="submit" class="button" value="'.$langs->trans("Modify").'"></center>';
  204. print '</form>';
  205. print '</div>';
  206. /*
  207. * Test de la connexion
  208. */
  209. if (function_exists("ldap_connect"))
  210. {
  211. if (! empty($conf->global->LDAP_SERVER_HOST))
  212. {
  213. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test">'.$langs->trans("LDAPTestConnect").'</a><br><br>';
  214. }
  215. if ($_GET["action"] == 'test')
  216. {
  217. $ldap = new Ldap(); // Les parametres sont passes et recuperes via $conf
  218. $result = $ldap->connect_bind();
  219. if ($result)
  220. {
  221. // Test ldap connect and bind
  222. print img_picto('','info').' ';
  223. print '<font class="ok">'.$langs->trans("LDAPTCPConnectOK",$conf->global->LDAP_SERVER_HOST,$conf->global->LDAP_SERVER_PORT).'</font>';
  224. print '<br>';
  225. if ($conf->global->LDAP_ADMIN_DN && ! empty($conf->global->LDAP_ADMIN_PASS))
  226. {
  227. if ($result == 2)
  228. {
  229. print img_picto('','info').' ';
  230. print '<font class="ok">'.$langs->trans("LDAPBindOK",$conf->global->LDAP_SERVER_HOST,$conf->global->LDAP_SERVER_PORT,$conf->global->LDAP_ADMIN_DN,preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)).'</font>';
  231. print '<br>';
  232. }
  233. else
  234. {
  235. print img_picto('','error').' ';
  236. print '<font class="error">'.$langs->trans("LDAPBindKO",$conf->global->LDAP_SERVER_HOST,$conf->global->LDAP_SERVER_PORT,$conf->global->LDAP_ADMIN_DN,preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)).'</font>';
  237. print '<br>';
  238. print $langs->trans("Error").' '.$ldap->error;
  239. print '<br>';
  240. }
  241. }
  242. else
  243. {
  244. print img_picto('','warning').' ';
  245. print '<font class="warning">'.$langs->trans("LDAPNoUserOrPasswordProvidedAccessIsReadOnly").'</font>';
  246. print '<br>';
  247. }
  248. // Test ldap_getversion
  249. if (($ldap->getVersion() == 3))
  250. {
  251. print img_picto('','info').' ';
  252. print '<font class="ok">'.$langs->trans("LDAPSetupForVersion3").'</font>';
  253. print '<br>';
  254. }
  255. else
  256. {
  257. print img_picto('','info').' ';
  258. print '<font class="ok">'.$langs->trans("LDAPSetupForVersion2").'</font>';
  259. print '<br>';
  260. }
  261. $unbind = $ldap->unbind();
  262. }
  263. else
  264. {
  265. print img_picto('','error').' ';
  266. print '<font class="error">'.$langs->trans("LDAPTCPConnectKO",$conf->global->LDAP_SERVER_HOST,$conf->global->LDAP_SERVER_PORT).'</font>';
  267. print '<br>';
  268. print $langs->trans("Error").' '.$ldap->error;
  269. print '<br>';
  270. }
  271. }
  272. }
  273. dol_htmloutput_mesg($mesg);
  274. $db->close();
  275. llxFooter();
  276. ?>