From 15b57d24d4bcff44ef1aaa924445a86603872e39 Mon Sep 17 00:00:00 2001
From: David Beniamine <david.beniamine@tetras-libre.fr>
Date: Mon, 30 Sep 2019 14:28:18 +0200
Subject: [PATCH] Fix reboot action

---
 wol/scripts/wakeonlanservice.sh | 8 ++++----
 wol/www/index.php               | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/wol/scripts/wakeonlanservice.sh b/wol/scripts/wakeonlanservice.sh
index d3aa387..48fdc1f 100755
--- a/wol/scripts/wakeonlanservice.sh
+++ b/wol/scripts/wakeonlanservice.sh
@@ -18,7 +18,7 @@
 
 getip(){
     awk '/^lease/{IP=$2} /hardware ethernet/{gsub(";","",$3);if($3 == "'$1'"){print IP}}' \
-        < /var/lib/dhcp/dhcpd.leases
+        | sort -u < /var/lib/dhcp/dhcpd.leases
 }
 
 # $1 : file|stdin
@@ -101,12 +101,12 @@ do
         echo "Started 'upgrade_all.sh $subactions' in background on $(date)" | answer
     elif [[ "$LINE" =~ "reboot" ]]
     then
-        mac=$(echo $line | cut -d ' ' -f 2)
+        mac=$(echo $LINE | cut -d ' ' -f 2)
         IPS=$(getip $mac | sed -e 's/ /,/g')
-        for $ip in $IPS
+        for ip in $IPS
         do
             ssh $ip "reboot"
         done
-        answer "Redémarrage demandé, attendez une à deux minutes avant d'essayer de vous connecter"
+        echo "Redémarrage demandé, attendez une à deux minutes avant d'essayer de vous connecter" | answer
     fi
 done
diff --git a/wol/www/index.php b/wol/www/index.php
index 8f03bfc..82c29f4 100644
--- a/wol/www/index.php
+++ b/wol/www/index.php
@@ -140,12 +140,12 @@ if(!isset($action)){
     ?>
     <form action="index.php" method="post">
         <input type="hidden" name="action" value="wake">
-        <input type="hidden"   name="mac" value="<?php echo $entry[1]; ?>">
+        <input type="hidden"   name="name" value="<?php echo $entry[1]; ?>">
         <input type="submit" value="Démarrer" title="Démarrer la machine">
     </form>
     <form action="index.php" method="post" onsubmit='return confirm("Êtes-vous sûr de vouloir redémarrer la machine <? echo $entry[2]; ?>");'>
         <input type="hidden" name="action" value="reboot">
-        <input type="hidden"   name="mac" value="<?php echo $entry[1]; ?>">
+        <input type="hidden"   name="name" value="<?php echo $entry[1]; ?>">
         <input type="submit" value="Redémarrer" title="redémarrer la machine">
     </form>
     <form action="index.php" method="post">
-- 
GitLab