#!/bin/bash # SambaEdu # # $Id: mail-ldap.sh 341 2005-07-13 15:06:30Z plouf $ # WWWPATH="/var/www" if [ -e $WWWPATH/se3/includes/config.inc.php ]; then dbhost=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbhost=" | cut -d = -f 2 |cut -d \" -f 2` dbname=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbname=" | cut -d = -f 2 |cut -d \" -f 2` dbuser=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbuser=" | cut -d = -f 2 |cut -d \" -f 2` dbpass=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbpass=" | cut -d = -f 2 |cut -d \" -f 2` else echo "Fichier de conf inaccessible" exit 1 fi BASEDN=`echo "SELECT value FROM params WHERE name='ldap_base_dn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` if [ -z "$BASEDN" ]; then echo "Impossible d'accéder au paramètre BASEDN" exit 1 fi COMPUTERSRDN=`echo "SELECT value FROM params WHERE name='ComputersRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` if [ -z "$COMPUTERSRDN" ]; then echo "Impossible d'accéder au paramètre COMPUTERSRDN" exit 1 fi PARCSRDN=`echo "SELECT value FROM params WHERE name='parcsRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` if [ -z "$PARCSRDN" ]; then echo "Impossible d'accéder au paramètre PARCSDN" exit 1 fi PASSADM=`echo "SELECT value FROM params WHERE name='xppass'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` if [ -z "$PASSADM" ]; then echo "Impossible d'accéder au paramètre PASSADM" exit 1 fi if [ "$2" = "" -a "$1" != "_" ] then echo "USAGE: Vous devez indiquer un parc existant et une action valide parmi wol, reboot, stop:" echo " Exemple: $0 salle_profs wol" # echo "Les parcs existants sont :" # ldapsearch -x -b $PARCSRDN,$BASEDN '(objectclass=*)' | grep cn | grep -v requesting | grep -i -v Rights | grep -i -v member else if [ "$1" = "_" ]; then tmp=/tmp/liste_parcs_$(date +%Y%m%d%H%M%S)_${RANDOM} touch $tmp chmod 700 $tmp parc="" while [ -z "$parc" ] do echo "Sur quel parc souhaitez-vous agir?" ldapsearch -xLLL -b $PARCSRDN,$BASEDN cn | grep "^cn: " | sed -e "s|^cn: ||" | sort > $tmp cpt=0 while read A do tab_parcs[$cpt]=$A echo " $cpt : $A" cpt=$(($cpt+1)) done < $tmp echo -e "Parc: \c" read num_parc if [ -n "${tab_parcs[$num_parc]}" ]; then parc=${tab_parcs[$num_parc]} fi done rm -f $tmp action="" echo "Quelle action souhaitez-vous appliquer au parc $parc?" while [ -z "$action" ] do echo " 1 : wol (eveil)" echo " 2 : stop ou shutdown (extinction)" echo " 3 : reboot (reboot)" echo -e "Action: \c" read num_action case $num_action in 1) action='wol' ;; 2) action='stop' ;; 3) action='reboot' ;; esac done else parc=$1 action=$2 if [ "$action" != "wol" -a "$action" != "shutdown" -a "$action" != "stop" -a "$action" != "reboot" ]; then echo "Action invalide pour le parc ${parc} : ${action}" exit fi fi echo "