[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3master/usr/share/se3/sbin/ -> variables_admin_ldap.sh (source)

   1  #!/bin/bash
   2  
   3  # $Id: variables_admin_ldap.sh 7745 2013-03-31 23:53:39Z keyser $
   4  # Script destine à disposer de variable d'acces au LDAP pour simplifier l'ecriture de commandes ldpasearch, ldapadd, ldapdelete, ldapmodify
   5  # Auteur: Stephane Boireau
   6  # Derniere modification: 13/05/2009
   7  
   8  temoin=0
   9  if [ "$0" != "-bash" -a "$0" != "/bin/bash" -a "$1" != "lib" ]; then
  10          temoin=1
  11  fi
  12  
  13  if [ "$temoin" = "1" -o "$1" = "-h" -o "$1" = "--help" ]; then
  14  #if [ "$0" != "-bash" -o "$1" = "-h" -o "$1" = "--help" ]; then
  15      echo "Ce script permet d'initialiser des variables BASEDN, ROOTDN et PASSDN"
  16      echo "pour pouvoir ensuite effectuer des requètes sur le ldap."
  17      #echo "   ldapsearch -xLLL -D \$ROOTDN -w \$PASSDN uid=toto"
  18      #echo "   ldapdelete -xLLL -D \$ROOTDN -w \$PASSDN uid=toto,ou=People,\$BASEDN"
  19      #echo "   ..."
  20      echo ""
  21      echo "USAGE: Il faut appeler ce script par 'source $0'"
  22      echo "       Ou"
  23      echo "       dans un script:"
  24      echo "            . /usr/share/se3/sbin/variables_admin_ldap.sh lib > /dev/null"
  25      echo "       On dispose des variables BASEDN, ROOTDN et PASSDN pour le script dans"
  26      echo "       lequel on a fait cet appel."
  27  else
  28      echo "Initialisation des variables BASEDN, ROOTDN et PASSDN"
  29  
  30      t=$(ps aux|grep mysqld|grep "^mysql")
  31      #echo "t=$t"
  32      if [ -n "$t" ]; then
  33          WWWPATH="/var/www"
  34  
  35          if [ -e $WWWPATH/se3/includes/config.inc.php ]; then
  36              dbhost=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbhost=" | cut -d = -f 2 |cut -d \" -f 2`
  37              dbname=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbname=" | cut -d = -f 2 |cut -d \" -f 2`
  38              dbuser=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbuser=" | cut -d = -f 2 |cut -d \" -f 2`
  39              dbpass=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbpass=" | cut -d = -f 2 |cut -d \" -f 2`
  40          else
  41              echo "Fichier de conf inaccessible"
  42              exit 1
  43          fi
  44  
  45          BASE_DN=`echo "SELECT value FROM params WHERE name='ldap_base_dn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  46          if [ -z "$BASE_DN" ]; then
  47                  echo "Impossible d'acceder au parametre BASE_DN"
  48                  exit 1
  49          fi
  50          BASEDN=$BASE_DN
  51          ADMINRDN=`echo "SELECT value FROM params WHERE name='adminRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  52          if [ -z "$ADMINRDN" ]; then
  53              echo "Impossible d'acceder au parametre ADMINRDN"
  54              exit 1
  55          fi
  56          #ROOTDN=$ADMINRDN
  57          ROOTDN=$ADMINRDN,$BASEDN
  58          ADMINPW=`echo "SELECT value FROM params WHERE name='adminPw'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  59          if [ -z "$ADMINPW" ]; then
  60              echo "Impossible d'acceder au parametre ADMINPW"
  61              exit 1
  62          fi
  63          PASSDN=$ADMINPW
  64          PEOPLERDN=`echo "SELECT value FROM params WHERE name='peopleRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  65          if [ -z "$PEOPLERDN" ]; then
  66              echo "Impossible d'acceder au parametre PEOPLERDN"
  67              exit 1
  68          fi
  69          GROUPSRDN=`echo "SELECT value FROM params WHERE name='groupsRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  70          if [ -z "$GROUPSRDN" ]; then
  71              echo "Impossible d'acceder au parametre GROUPSRDN"
  72              exit 1
  73          fi
  74          RIGHTSRDN=`echo "SELECT value FROM params WHERE name='rightsRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  75          if [ -z "$RIGHTSRDN" ]; then
  76              echo "Impossible d'acceder au parametre RIGHTSRDN"
  77              exit 1
  78          fi
  79      else
  80          echo "Le service MySQL ne semble pas accessible."
  81          echo "Utilisation des parametres locaux."
  82          echo "Ils ne sont valides que si le service LDAP tourne sur le SE3 lui-meme."
  83  
  84          BASEDN=$(cat /etc/ldap/ldap.conf | grep "^BASE" | tr "\t" " " | sed -e "s/ \{2,\}/ /g" | cut -d" " -f2)
  85          ROOTDN=$(cat /etc/ldap/slapd.conf | grep "^rootdn" | tr "\t" " " | cut -d'"' -f2)
  86          PASSDN=$(cat /etc/ldap.secret)
  87          PEOPLERDN="ou=People"
  88          GROUPSRDN="ou=Groups"
  89          RIGHTSRDN="ou=People"
  90      fi
  91  fi
  92  
  93  echo "Exemples d'usages: "
  94  echo "   ldapsearch -xLLL -D \$ROOTDN -w \$PASSDN uid=toto"
  95  echo "   ldapadd -x -D \$ROOTDN -w \$PASSDN -f fichier.ldif"
  96  echo "   ldapmodify -x -D \$ROOTDN -w \$PASSDN -f fichier.ldif"
  97  echo "   ldapdelete -x -D \$ROOTDN -w \$PASSDN uid=truc,\$PEOPLERDN,\$BASEDN"


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1