[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 #!/bin/bash 2 # SambaEdu 3 # 4 # $Id: mail-ldap.sh 341 2005-07-13 15:06:30Z plouf $ 5 # 6 7 WWWPATH="/var/www" 8 9 if [ -e $WWWPATH/se3/includes/config.inc.php ]; then 10 dbhost=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbhost=" | cut -d = -f 2 |cut -d \" -f 2` 11 dbname=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbname=" | cut -d = -f 2 |cut -d \" -f 2` 12 dbuser=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbuser=" | cut -d = -f 2 |cut -d \" -f 2` 13 dbpass=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbpass=" | cut -d = -f 2 |cut -d \" -f 2` 14 else 15 echo "Fichier de conf inaccessible" 16 exit 1 17 fi 18 BASEDN=`echo "SELECT value FROM params WHERE name='ldap_base_dn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` 19 if [ -z "$BASEDN" ]; then 20 echo "Impossible d'accéder au paramètre BASEDN" 21 exit 1 22 fi 23 24 COMPUTERSRDN=`echo "SELECT value FROM params WHERE name='ComputersRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` 25 if [ -z "$COMPUTERSRDN" ]; then 26 echo "Impossible d'accéder au paramètre COMPUTERSRDN" 27 exit 1 28 fi 29 30 PARCSRDN=`echo "SELECT value FROM params WHERE name='parcsRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` 31 if [ -z "$PARCSRDN" ]; then 32 echo "Impossible d'accéder au paramètre PARCSDN" 33 exit 1 34 fi 35 PASSADM=`echo "SELECT value FROM params WHERE name='xppass'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` 36 if [ -z "$PASSADM" ]; then 37 echo "Impossible d'accéder au paramètre PASSADM" 38 exit 1 39 fi 40 41 if [ "$2" = "" -a "$1" != "_" ] 42 then 43 echo "USAGE: Vous devez indiquer un parc existant et une action valide parmi wol, reboot, stop:" 44 echo " Exemple: $0 salle_profs wol" 45 # echo "Les parcs existants sont :" 46 # ldapsearch -x -b $PARCSRDN,$BASEDN '(objectclass=*)' | grep cn | grep -v requesting | grep -i -v Rights | grep -i -v member 47 else 48 if [ "$1" = "_" ]; then 49 tmp=/tmp/liste_parcs_$(date +%Y%m%d%H%M%S)_$RANDOM} 50 touch $tmp 51 chmod 700 $tmp 52 parc="" 53 while [ -z "$parc" ] 54 do 55 echo "Sur quel parc souhaitez-vous agir?" 56 ldapsearch -xLLL -b $PARCSRDN,$BASEDN cn | grep "^cn: " | sed -e "s|^cn: ||" | sort > $tmp 57 cpt=0 58 while read A 59 do 60 tab_parcs[$cpt]=$A 61 echo " $cpt : $A" 62 cpt=$(($cpt+1)) 63 done < $tmp 64 echo -e "Parc: \c" 65 read num_parc 66 67 if [ -n "$tab_parcs[$num_parc]}" ]; then 68 parc=$tab_parcs[$num_parc]} 69 fi 70 done 71 rm -f $tmp 72 73 action="" 74 echo "Quelle action souhaitez-vous appliquer au parc $parc?" 75 while [ -z "$action" ] 76 do 77 echo " 1 : wol (eveil)" 78 echo " 2 : stop ou shutdown (extinction)" 79 echo " 3 : reboot (reboot)" 80 echo -e "Action: \c" 81 read num_action 82 83 case $num_action in 84 1) 85 action='wol' 86 ;; 87 2) 88 action='stop' 89 ;; 90 3) 91 action='reboot' 92 ;; 93 esac 94 done 95 else 96 parc=$1 97 action=$2 98 99 if [ "$action" != "wol" -a "$action" != "shutdown" -a "$action" != "stop" -a "$action" != "reboot" ]; then 100 echo "Action invalide pour le parc $parc} : $action}" 101 exit 102 fi 103 fi 104 105 echo "<h1>Action sur le parc $parc} : $action}</h1><br>" 106 107 ldapsearch -xLLL -b cn=$parc},$PARCSRDN,$BASEDN '(objectclass=groupOfNames)' member | grep member | while read A 108 do 109 #echo "pour la machine $A" 110 echo "$A" | cut -d= -f2 | cut -d, -f1 | while read B 111 do 112 #echo "ldapsearch -x -b cn=$B,$COMPUTERSRDN,$BASEDN '(objectclass=*)' macAddress | grep macAddress | grep -v requesting" 113 114 ldapsearch -xLLL -b cn=$B,$COMPUTERSRDN,$BASEDN '(objectclass=*)' macAddress | grep macAddress | while read C 115 do 116 echo "$C" | cut -d: -f 2-7 | while read D 117 do 118 getent passwd $B$>/dev/null && TYPE="XP" 119 if [ "$TYPE" = "XP" ]; then 120 echo "<br><h3>Action sur : $B</h3>" 121 #============================================ 122 if [ "$action}" = "shutdown" -o "$action}" = "stop" ]; then 123 echo "Tentative d'arret de la machine XP/2000<b> $B</b> correspondant a l'adresse mac <b>$D</b><br>" 124 /usr/bin/net rpc shutdown -C "Shutdown" -S $B -U "$B\adminse3%$PASSADM" 125 fi 126 127 if [ "$action}" = "reboot" ]; then 128 echo "Tentative de reboot de la machine XP/2000<b> $B</b> correspondant a l'adresse mac <b>$D</b><br>" 129 /usr/bin/net rpc shutdown -r -C "Reboot" -S $B -U "$B\adminse3%$PASSADM" 130 fi 131 132 if [ "$action}" = "wol" ]; then 133 ldapsearch -xLLL -b cn=$B,$COMPUTERSRDN,$BASEDN '(objectclass=ipHost)' ipHostNumber | grep ipHostNumber: | sed "s/ipHostNumber: //g;s/\.[0-9]*$/.255/g" | while read I do 134 do 135 echo "Tentative d'eveil pour la machine correspondant a l'adresse mac $D et au broadcast $I<br>" 136 /usr/bin/wakeonlan -i $I $D > /dev/null 137 /usr/bin/wakeonlan $D > /dev/null 138 done 139 fi 140 else 141 # On teste si on a un windows ou un linux 142 ldapsearch -xLLL -b uid=$B$,$COMPUTERSRDN,$BASEDN '(objectclass=*)' uidNumber | grep uid 143 # On peut penser que l'on a un linux, mais cela peut aussi être un win 9X 144 # A affiner 145 if [ $? = "1" ] 146 then 147 echo "<br><h3>Action sur : $B</h3>" 148 if [ "$action}" = "wol" ]; then 149 ldapsearch -xLLL -b cn=$B,$COMPUTERSRDN,$BASEDN '(objectclass=ipHost)' ipHostNumber | grep ipHostNumber: | sed "s/ipHostNumber: //g;s/\.[0-9]*$/.255/g" | while read I do 150 do 151 echo "Tentative d'eveil pour la machine Win9x/Linux <b>$B</b> correspondant a l'adresse mac <b>$D</b><br>" 152 /usr/bin/wakeonlan -i $I $D > /dev/null 153 /usr/bin/wakeonlan $D > /dev/null 154 done 155 fi 156 if [ "$action}" = "shutdown" -o "$action}" = "stop" ]; then 157 echo "Tentative d'arret de la machineWin9x/Linux <b>$B</b> correspondant a l'adresse mac <b>$D</b><br>" 158 # Prevoir de recup l'adresse IP car $B correspond au nom mais sous linux pour le moment cela est son IP :( 159 /usr/bin/ssh -o StrictHostKeyChecking=no $B halt 160 fi 161 if [ "$action}" = "reboot" ]; then 162 echo "Tentative de reboot de la machineWin9x/Linux <b>$B</b> correspondant a l'adresse mac <b>$D</b><br>" 163 # Prevoir de recup l'adresse IP car $B correspond au nom mais sous linux pour le moment cela est son IP :( 164 /usr/bin/ssh -o StrictHostKeyChecking=no $B reboot 165 fi 166 fi 167 fi 168 done 169 done 170 done 171 done 172 fi
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |