[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/admin/ -> ldap.php (source)

   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@cap-networks.com>
   6   *
   7   * This program is free software; you can redistribute it and/or modify
   8   * it under the terms of the GNU General Public License as published by
   9   * the Free Software Foundation; either version 2 of the License, or
  10   * (at your option) any later version.
  11   *
  12   * This program is distributed in the hope that it will be useful,
  13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15   * GNU General Public License for more details.
  16   *
  17   * You should have received a copy of the GNU General Public License
  18   * along with this program; if not, write to the Free Software
  19   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20   *
  21   * $Id: ldap.php,v 1.39 2005/10/18 14:03:05 eldy Exp $
  22   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/admin/ldap.php,v $
  23   */
  24   
  25  /**
  26          \file       htdocs/admin/ldap.php
  27          \ingroup    ldap
  28          \brief      Page d'administration/configuration du module Ldap
  29          \version    $Revision: 1.39 $
  30          \remarks    Exemple configuration :
  31                      LDAP_SERVER_HOST    Serveur LDAP              192.168.1.50
  32                      LDAP_SERVER_PORT    Port LDAP             389
  33                      LDAP_ADMIN_DN       Administrateur LDAP      cn=adminldap,dc=societe,dc=com    
  34                      LDAP_ADMIN_PASS     Mot de passe              xxxxxxxx
  35                      LDAP_USER_DN        DN des utilisateurs      ou=users,dc=societe,dc=com
  36                      LDAP_GROUP_DN       DN des groupes            ou=groups,dc=societe,dc=com    
  37                      LDAP_CONTACT_DN     DN des contacts            ou=contacts,dc=societe,dc=com
  38                      LDAP_SERVER_TYPE    Type                          Openldap
  39  */
  40  
  41  require ("./pre.inc.php");
  42  require_once(DOL_DOCUMENT_ROOT."/lib/ldap.lib.php");
  43  
  44  $langs->load("admin");
  45  
  46  if (!$user->admin)
  47    accessforbidden();
  48  
  49  /*
  50   * Actions
  51   */
  52   
  53  if ($_GET["action"] == 'setvalue' && $user->admin)
  54  {
  55    $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'LDAP_SERVER_HOST';";
  56    $db->query($sql);
  57  
  58    $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES
  59      ('LDAP_SERVER_HOST','".$_POST["host"]."',0);";
  60      $db->query($sql);
  61      
  62      $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'LDAP_SERVER_PORT';";
  63    $db->query($sql);
  64  
  65    $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES
  66      ('LDAP_SERVER_PORT','".$_POST["port"]."',0);";
  67      $db->query($sql);
  68    
  69    //suppression pour compatibilité divers config ldap
  70    //
  71    //$sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'LDAP_SUFFIX_DN';";
  72    //$db->query($sql);
  73  
  74    //$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES
  75      //('LDAP_SUFFIX_DN','".$_POST["suffix"]."',0);";
  76    //$db->query($sql);
  77    
  78    $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'LDAP_ADMIN_DN';";
  79    $db->query($sql);
  80    
  81    $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES
  82      ('LDAP_ADMIN_DN','".$_POST["admin"]."',0);";
  83    $db->query($sql);
  84  
  85    $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'LDAP_ADMIN_PASS';";
  86    $db->query($sql);
  87    
  88    $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES
  89      ('LDAP_ADMIN_PASS','".$_POST["pass"]."',0);";
  90    $db->query($sql);
  91    
  92    $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'LDAP_USER_DN';";
  93    $db->query($sql);
  94  
  95    $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES
  96      ('LDAP_USER_DN','".$_POST["user"]."',0);";
  97    $db->query($sql);
  98    
  99    $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'LDAP_GROUP_DN';";
 100    $db->query($sql);
 101  
 102    $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES
 103      ('LDAP_GROUP_DN','".$_POST["group"]."',0);";
 104    $db->query($sql);
 105    
 106    $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'LDAP_CONTACT_ACTIVE';";
 107    $db->query($sql);
 108  
 109    $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES
 110      ('LDAP_CONTACT_ACTIVE','".$_POST["activecontact"]."',0);";
 111    $db->query($sql);
 112    
 113    $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'LDAP_CONTACT_DN';";
 114    $db->query($sql);
 115  
 116    $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES
 117      ('LDAP_CONTACT_DN','".$_POST["contact"]."',0);";
 118    $db->query($sql);
 119  
 120    $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'LDAP_SERVER_PROTOCOLVERSION';";
 121    $db->query($sql);
 122  
 123    $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES
 124      ('LDAP_SERVER_PROTOCOLVERSION','".$_POST["version"]."',0);";
 125    $db->query($sql);
 126  
 127  
 128    $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'LDAP_SERVER_TYPE';";
 129    $db->query($sql);
 130  
 131    $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES
 132      ('LDAP_SERVER_TYPE','".$_POST["type"]."',0);";
 133  
 134    if ($db->query($sql))
 135      {
 136        Header("Location: ldap.php");
 137      }
 138  }
 139  
 140  /*
 141   * Visu
 142   */
 143  
 144  llxHeader();
 145  
 146  print_titre($langs->trans("LDAPSetup"));
 147  
 148  print '<br>';
 149  print '<table class="noborder" width="100%">';
 150  print '<tr>';
 151  print '<td width="50%" valign="top">';
 152  
 153  print '<table class="border" width="100%">';
 154  print '<tr class="liste_titre">';
 155  print '<td>'.$langs->trans("Parameter").'</td>';
 156  print '<td>'.$langs->trans("Value").'</td><td colspan="2">&nbsp;</td>';
 157  print "</tr>\n";
 158      
 159  if (defined("LDAP_SERVER_HOST") && LDAP_SERVER_HOST)
 160  {
 161    print '<tr><td>'.$langs->trans("LDAPServer").'</td><td>'.LDAP_SERVER_HOST.'</td></tr>';
 162  }
 163  else
 164  {
 165    print '<tr><td>'.$langs->trans("LDAPServer").'</td><td>'.$langs->trans("LDAPServerExample").'</td></tr>';
 166  }
 167  if (defined("LDAP_SERVER_PORT") && LDAP_SERVER_PORT)
 168  {
 169    print '<tr><td>'.$langs->trans("LDAPServerPort").'</td><td>'.LDAP_SERVER_PORT.'</td></tr>';
 170  }
 171  else
 172  {
 173    print '<tr><td>'.$langs->trans("LDAPServerPort").'</td><td>'.$langs->trans("LDAPServerPortExample").'</td></tr>';
 174  }
 175  
 176  //suppression pour compatibilité divers config ldap
 177  //
 178  //if (defined("LDAP_SUFFIX_DN") && LDAP_SUFFIX_DN)
 179  //{
 180  //    print '<tr><td>'.$langs->trans("LDAPSuffix").'</td><td>'.LDAP_SUFFIX_DN.'</td></tr>';
 181  //}
 182  //else
 183  //{
 184  //      print '<tr><td>'.$langs->trans("LDAPSuffix").'</td><td>'.$langs->trans("LDAPSuffixExample").'</td></tr>';
 185  //}
 186  
 187  if (defined("LDAP_ADMIN_DN") && LDAP_ADMIN_DN)
 188  {
 189    print '<tr><td>'.$langs->trans("DNAdmin").'</td><td>'.LDAP_ADMIN_DN.'</td></tr>';
 190  }
 191  else
 192  {
 193    print '<tr><td>'.$langs->trans("DNAdmin").'</td><td>'.$langs->trans("DNAdminExample").'</td></tr>';
 194  }
 195  if (defined("LDAP_ADMIN_PASS") && LDAP_ADMIN_PASS)
 196  {
 197    print '<tr><td>'.$langs->trans("LDAPPassword").'</td><td>********</td></tr>';
 198  }
 199  else
 200  {
 201    print '<tr><td>'.$langs->trans("LDAPPassword").'</td><td>'.$langs->trans("LDAPPasswordExample").'</td></tr>';
 202  }
 203  if (defined("LDAP_USER_DN") && LDAP_USER_DN)
 204  {
 205    print '<tr><td>'.$langs->trans("DNUser").'</td><td>'.LDAP_USER_DN.'</td></tr>';
 206  }
 207  else
 208  {
 209    print '<tr><td>'.$langs->trans("DNUser").'</td><td>'.$langs->trans("DNUserExample").'</td></tr>';
 210  }
 211  if (defined("LDAP_GROUP_DN") && LDAP_GROUP_DN)
 212  {
 213    print '<tr><td>'.$langs->trans("DNGroup").'</td><td>'.LDAP_GROUP_DN.'</td></tr>';
 214  }
 215  else
 216  {
 217    print '<tr><td>'.$langs->trans("DNGroup").'</td><td>'.$langs->trans("DNGroupExample").'</td></tr>';
 218  }
 219  if (defined("LDAP_CONTACT_ACTIVE") && LDAP_CONTACT_ACTIVE)
 220  {
 221    print '<tr><td>'.$langs->trans("DNContactActive").'</td><td>'.$langs->trans("DNContactActiveYes").'</td></tr>';
 222  }
 223  else
 224  {
 225    print '<tr><td>'.$langs->trans("DNContactActive").'</td><td>'.$langs->trans("DNContactActiveExample").'</td></tr>';
 226  }
 227  if (defined("LDAP_CONTACT_DN") && LDAP_CONTACT_DN)
 228  {
 229    print '<tr><td>'.$langs->trans("DNContact").'</td><td>'.LDAP_CONTACT_DN.'</td></tr>';
 230  }
 231  else
 232  {
 233    print '<tr><td>'.$langs->trans("DNContact").'</td><td>'.$langs->trans("DNContactExample").'</td></tr>';
 234  }
 235  if (defined("LDAP_SERVER_TYPE") && LDAP_SERVER_TYPE)
 236  {
 237    print '<tr><td>'.$langs->trans("Type").'</td><td>'.LDAP_SERVER_TYPE.'</td></tr>';
 238  }
 239      else
 240  {
 241    print '<tr><td>'.$langs->trans("Type").'</td><td>'.$langs->trans("TypeExample").'</td></tr>';
 242  }
 243  
 244  print '<tr><td>'.$langs->trans("Version").'</td><td>'.LDAP_SERVER_PROTOCOLVERSION.'</td></tr>';
 245  
 246  print '</table>';
 247  
 248  print '</td><td width="50%">';
 249  
 250  /*
 251   * Modification
 252   */
 253  
 254  print '<form method="post" action="ldap.php?action=setvalue">';
 255  
 256  print '<table class="border" width="100%">';
 257  print '<tr class="liste_titre">';
 258  print '<td>'.$langs->trans("Parameter").'</td>';
 259  print '<td>'.$langs->trans("Value").'</td><td colspan="2">&nbsp;</td>';
 260  print "</tr>\n";
 261  print '<tr><td>';
 262  print $langs->trans("LDAPServer").'</td><td>';
 263  print '<input size="25" type="text" name="host" value="'.LDAP_SERVER_HOST.'">';
 264  print '</td></tr>';
 265  print '<tr><td>'.$langs->trans("LDAPServerPort").'</td><td>';
 266  if (defined("LDAP_SERVER_PORT") && LDAP_SERVER_PORT)
 267  {
 268    print '<input size="25" type="text" name="port" value="'.LDAP_SERVER_PORT.'">';
 269  }
 270  else
 271  {
 272    print '<input size="25" type="text" name="port" value="389">';
 273  }
 274  print '</td></tr>';
 275  
 276  //suppression pour compatibilité divers config ldap
 277  //
 278  //print '<tr><td>'.$langs->trans("LDAPSuffix").'</td><td>';
 279  //print '<input size="25" type="text" name="suffix" value="'.LDAP_SUFFIX_DN.'">';
 280  //print '</td></tr>';
 281  
 282  print '<tr><td>'.$langs->trans("DNAdmin").'</td><td>';
 283  print '<input size="25" type="text" name="admin" value="'.LDAP_ADMIN_DN.'">';
 284  print '</td></tr>';
 285  print '<tr><td>'.$langs->trans("LDAPPassword").'</td><td>';
 286  if (defined("LDAP_ADMIN_PASS") && LDAP_ADMIN_PASS)
 287  {
 288    print '<input size="25" type="password" name="pass" value="'.LDAP_ADMIN_PASS.'">';
 289  }
 290  else
 291  {
 292    print '<input size="25" type="text" name="pass" value="'.LDAP_ADMIN_PASS.'">';
 293  }
 294  print '</td></tr>';
 295  print '<tr><td>'.$langs->trans("DNUser").'</td><td>';
 296  print '<input size="25" type="text" name="user" value="'.LDAP_USER_DN.'">';
 297  print '</td></tr>';
 298  print '<tr><td>'.$langs->trans("DNGroup").'</td><td>';
 299  print '<input size="25" type="text" name="group" value="'.LDAP_GROUP_DN.'">';
 300  print '</td></tr>';
 301  print '<tr><td>'.$langs->trans("DNContactActive").'</td><td><select name="activecontact">';
 302  if (defined("LDAP_CONTACT_ACTIVE") && LDAP_CONTACT_ACTIVE == 1)
 303  {
 304    print '<option value="1" selected="true">'.$langs->trans("Yes");
 305  }
 306  else
 307  {
 308      print '<option value="0" selected="true">'.$langs->trans("No");
 309  }
 310  print '<option value="LDAP_CONTACT_ACTIVE">--------';
 311  print '<option value="0">'.$langs->trans("No");
 312  print '<option value="1">'.$langs->trans("Yes");
 313  print '</select>';
 314  print '</td></tr>';
 315  print '<tr><td>'.$langs->trans("DNContact").'</td><td>';
 316  print '<input size="25" type="text" name="contact" value="'.LDAP_CONTACT_DN.'">';
 317  print '</td></tr>';
 318  
 319  print '<tr><td>'.$langs->trans("Type").'</td><td><select name="type">';
 320  if (defined("LDAP_SERVER_TYPE") && LDAP_SERVER_TYPE == activedirectory)
 321  {
 322    print '<option value="activedirectory" selected="true">Active Directory';
 323  }
 324  else
 325  {
 326    if (defined("LDAP_SERVER_TYPE") && LDAP_SERVER_TYPE == egroupware)
 327      {
 328        print '<option value="egroupware" selected="true">Egroupware';
 329      }
 330    else
 331      {
 332        print '<option value="openldap" selected="true">OpenLdap';
 333      }
 334  }
 335  print '<option value="LDAP_SERVER_TYPE">------------------------';
 336  print '<option value="openldap">OpenLdap';
 337  print '<option value="egroupware">Egroupware';
 338  print '<option value="activedirectory">Active Directory';
 339  print '</select>';
 340  print '</td></tr>';
 341  
 342  print '<tr><td>'.$langs->trans("Version").'</td><td><select name="version">';
 343  
 344  if (defined("LDAP_SERVER_PROTOCOLVERSION") && LDAP_SERVER_PROTOCOLVERSION == 3)
 345  {
 346    print '<option value="3" selected="true">Version 3';
 347  }
 348  else
 349  {
 350    print '<option value="2" selected="true">Version 2';
 351  }
 352  print '<option value="LDAP_SERVER_PROTOCOLVERSION">------------------------';
 353  print '<option value="3">Version 3';
 354  print '<option value="2">Version 2';
 355  print '</select>';
 356  print '</td></tr>';
 357  
 358  print '<tr><td colspan="2" align="center"><input type="submit" value="'.$langs->trans("Modify").'"></td></tr>';
 359  print '</table></form>';
 360  
 361  print '</td></tr></table>';
 362  
 363  /*
 364   * test de la connexion
 365   */
 366   
 367   
 368  if (defined("LDAP_SERVER_HOST") && LDAP_SERVER_HOST) {
 369      print '<a class="tabAction" href="ldap.php?action=test">'.$langs->trans("TestConnectLdap").'</a><br><br>';
 370  }
 371  
 372  
 373  if (defined("LDAP_SERVER_HOST") && LDAP_SERVER_HOST && LDAP_ADMIN_DN && LDAP_ADMIN_PASS && $_GET["action"] == 'test')
 374  {
 375    $ds = dolibarr_ldap_connect();
 376    
 377    if ($ds)
 378      {
 379        print img_picto('','info');
 380        print "connexion au serveur ldap réussie<br>";
 381      }
 382    else
 383      {
 384        print img_picto('','alerte');
 385    
 386        print "connexion au serveur ldap échouée";
 387        print "<br>";
 388        print ldap_error($ds);
 389        print "<br>";
 390      }
 391    if ((dolibarr_ldap_getversion($ds) == 3))
 392      {
 393        print img_picto('','info');
 394        print "Serveur ldap configuré en version 3<br>";
 395      }
 396    else
 397      {
 398        print img_picto('','info');
 399        print "Serveur ldap configuré en version 2<br>";
 400      }
 401    
 402    $bind = @dolibarr_ldap_bind($ds);
 403    
 404    if ($bind)
 405      {
 406        print img_picto('','info');
 407        print "connexion au dn $dn réussi<br>";
 408      }
 409    else
 410      {
 411        print img_picto('','alerte');
 412  
 413        print "connexion au dn $dn raté : ";
 414        print ldap_error($ds);
 415        print "<br>";
 416      }
 417    
 418    $unbind = @dolibarr_ldap_unbind($ds);
 419    
 420    if ($bind)
 421      {
 422        print img_picto('','info');
 423        print "déconnection du dn $dn réussi<br>";
 424      }
 425    else
 426      {
 427        print img_picto('','alerte');
 428  
 429        print "déconnection du dn $dn raté";
 430        print "<br>";
 431      }
 432  }
 433  
 434  $db->close();
 435  
 436  llxFooter();
 437  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics