[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-internet/sources/sbin/ -> install-ldap-internet.sh (source)

   1  #!/bin/bash
   2  ##### migration ldap des champs description en destinationlocator  #####
   3  # licence GPL
   4  # auteur : denis bonnenfant 6/02/2008
   5  ##
   6  # $Id: install-ldap-internet.sh 3275 2008-10-12 18:10:44Z dbo $ ##
   7  if [ "$1" == "--help" -o "$1" == "-h" ]
   8  then
   9  echo "Script d'initialisation des enregistrements ldap cn=machine "
  10  echo "normalement exécuté à l'installation de se3-internet"
  11  echo "Usage : install-ldap-internet.sh [utilisateur|machine]"
  12  echo "--help cette aide"
  13  exit
  14  fi
  15  # réinitialisation des droits d'accès à internet : doit être executé la nuit 
  16  # argument optionnel : un nom  (login ou nom machine)
  17  
  18  if [ -z "$1" ]; then
  19          nom="*"
  20  else
  21          nom="$1"
  22  fi
  23  
  24  if [ -e /var/www/se3/includes/config.inc.php ]; then
  25          dbhost=`cat /var/www/se3/includes/config.inc.php | grep "dbhost=" | cut -d = -f 2 |cut -d \" -f 2`
  26          dbname=`cat /var/www/se3/includes/config.inc.php | grep "dbname=" | cut -d = -f 2 |cut -d \" -f 2`
  27          dbuser=`cat /var/www/se3/includes/config.inc.php | grep "dbuser=" | cut -d = -f 2 |cut -d \" -f 2`
  28          dbpass=`cat /var/www/se3/includes/config.inc.php | grep "dbpass=" | cut -d = -f 2 |cut -d \" -f 2`
  29  else
  30          echo "Fichier de conf inaccessible" >> $SE3LOG
  31          exit 1
  32  fi
  33  
  34  #
  35  # Recuperation des params LDAP
  36  #
  37  
  38  BASEDN=`echo "SELECT value FROM params WHERE name='ldap_base_dn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  39  if [ -z "$BASEDN" ]; then
  40          echo "Impossible d'accéder au paramètre BASEDN"
  41          exit 1
  42  fi
  43  COMPUTERSRDN=`echo "SELECT value FROM params WHERE name='computersRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  44  if [ -z "$COMPUTERSRDN" ]; then
  45          echo "Impossible d'accéder au paramètre COMPUTERSRDN"
  46          exit 1
  47  fi
  48  PEOPLERDN=`echo "SELECT value FROM params WHERE name='peopleRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  49  if [ -z "$PEOPLERDN" ]; then
  50          echo "Impossible d'accéder au paramètre PEOPLERDN"
  51          exit 1
  52  fi
  53  PARCSRDN=`echo "SELECT value FROM params WHERE name='parcsRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  54  if [ -z "$PARCSRDN" ]; then
  55          echo "Impossible d'accéder au paramètre PARCSRDN"
  56          exit 1
  57  fi
  58  ADMINRDN=`echo "SELECT value FROM params WHERE name='adminRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  59  if [ -z "$ADMINRDN" ]; then
  60          echo "Impossible d'accéder au paramètre ADMINRDN"
  61          exit 1
  62  fi
  63  ADMINPW=`echo "SELECT value FROM params WHERE name='adminPw'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  64  if [ -z "$ADMINPW" ]; then
  65          echo "Impossible d'accéder au paramètre ADMINPW"
  66          exit 1
  67  fi
  68  
  69  
  70  # On cherche les machines 
  71  echo "raz machines"
  72  for machine in $(ldapsearch -xLLL -D $ADMINRDN,$BASEDN -w $ADMINPW -b $COMPUTERSRDN,$BASEDN "(&(objectClass=ipHost)(cn=$nom))" cn | grep "cn:" | cut -d ' ' -f2) ; do
  73      droit_m=$(ldapsearch -xLLL -D $ADMINRDN,$BASEDN -w $ADMINPW -b $COMPUTERSRDN,$BASEDN "(&(objectClass=ipHost)(cn=$machine))" destinationIndicator | grep -i "destinationIndicator:" | cut -d " " -f2)
  74      if [ -z "$droit_m" ]; then
  75          droit_m=$(ldapsearch -xLLL -D $ADMINRDN,$BASEDN -w $ADMINPW -b $COMPUTERSRDN,$BASEDN "(&(objectClass=ipHost)(cn=$machine))" description | grep -i "description:" | cut -d " " -f2)
  76          if [ -n "$(echo $droit_m | grep ".*:.*:.*")" ]; then
  77              (echo "dn: cn=$machine,$COMPUTERSRDN,$BASEDN"
  78              echo "changetype: modify"
  79              echo "delete: description"
  80              echo "-"
  81              echo "add: destinationIndicator"
  82              echo "destinationIndicator: $droit_m"
  83              echo "-"  
  84              )| ldapmodify  -x  -D $ADMINRDN,$BASEDN -w $ADMINPW > /dev/null
  85          fi
  86          echo -n "."
  87      fi
  88  done
  89  
  90  # on cherche les utilisateurs et on réinitialise leurs droits 
  91  echo "raz utilisateurs"
  92  for user in $(ldapsearch -xLLL -D $ADMINRDN,$BASEDN -w $ADMINPW -b $PEOPLERDN,$BASEDN "(uid=$nom)" uid | grep "uid:" | cut -d " " -f2) ; do
  93      droit_u1=$(ldapsearch -xLLL -D $ADMINRDN,$BASEDN -w $ADMINPW -b $PEOPLERDN,$BASEDN "(uid=$user)" destinationIndicator | grep -i "destinationIndicator:" | cut -d " " -f2)
  94      if [ -z "$(echo $droit_u1 | grep ".*:.*:.*")" ]; then
  95          droit_u=$(ldapsearch -xLLL -D $ADMINRDN,$BASEDN -w $ADMINPW -b $PEOPLERDN,$BASEDN "(uid=$user)" description | grep -i "description" | cut -d " " -f2)
  96          if [ -n "$(echo $droit_u | grep ".*:.*:.*")" ]; then
  97              (echo "dn: uid=$user,$PEOPLERDN,$BASEDN"
  98              echo "changetype: modify"
  99              echo "delete: description"
 100              echo "-"
 101              if [ -n "$droit_u1" ]; then
 102                                  echo "delete: destinationIndicator"
 103                           echo "-"
 104                          fi
 105              echo "add: destinationIndicator"
 106              echo "destinationIndicator: $droit_u"
 107              echo "-"  
 108              )| ldapmodify  -x  -D $ADMINRDN,$BASEDN -w $ADMINPW > /dev/null
 109          fi
 110          echo -n "."
 111      fi
 112  done


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