From 44542a926a68c9657204a656d528f6d4146a2370 Mon Sep 17 00:00:00 2001
From: David Beniamine <david.beniamine@tetras-libre.fr>
Date: Mon, 5 Aug 2019 14:59:40 +0200
Subject: [PATCH] Get ip on partage side

---
 wol/scripts/get_ips.sh          |  3 ---
 wol/scripts/wakeonlanservice.sh | 10 +++++++++-
 wol/www/index.php               | 13 ++++++-------
 3 files changed, 15 insertions(+), 11 deletions(-)
 delete mode 100755 wol/scripts/get_ips.sh

diff --git a/wol/scripts/get_ips.sh b/wol/scripts/get_ips.sh
deleted file mode 100755
index d37fdb3..0000000
--- a/wol/scripts/get_ips.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-awk '/^lease/{IP=$2} /hardware ethernet/{gsub(";","",$3);if($3 == "'$1'"){print IP}}' \
-        < /var/lib/dhcp/dhcpd.leases | sort -u
diff --git a/wol/scripts/wakeonlanservice.sh b/wol/scripts/wakeonlanservice.sh
index 5823e5c..62828a4 100755
--- a/wol/scripts/wakeonlanservice.sh
+++ b/wol/scripts/wakeonlanservice.sh
@@ -47,6 +47,14 @@ do
         done
     elif [ $MAC == "get_registry" ]
     then
-        stdbuf -oL cat /etc/registry/hosts | netcat $host $port
+        hostfile="/etc/registry/hosts"
+        while read line
+        do
+            mac=$(echo $line | cut -d ' ' -f 2)
+            IPS=$(getip $mac | sed -e 's/ /,/g')
+            echo "$line $IPS" >> $hostfile-$$
+        done < $hostfile
+        stdbuf -oL cat $hostfile-$$ | netcat $host $port
+        rm $hostfile-$$
     fi
 done
diff --git a/wol/www/index.php b/wol/www/index.php
index ed2e009..8555270 100644
--- a/wol/www/index.php
+++ b/wol/www/index.php
@@ -41,20 +41,19 @@ $lines=shell_exec("../scripts/get_registry.sh");
 $registry = array();
 foreach(explode(PHP_EOL, $lines) as $line){
     if($line != ""){
-        $IPS=shell_exec("../script/get_ips.sh ".escapeshellarg($entry[1]));
         $entry=explode(' ', $line);
         array_push($registry, $entry);
-        # Format date mac name [num_apt_upgrade deb_version pt_version git_branch git_update]
+        # Format date mac name ip [num_apt_upgrade deb_version pt_version git_branch git_update]
         echo "<tr>";
         echo "<td>".$entry[2]."</td>";
-        echo "<td> ".$IPS."</td>";
+        echo "<td> ".$entry[3]."</td>";
         echo "<td>".$entry[1]."</td>";
         #echo "<td>".$entry[0]."</td>";
-        if(count($entry) > 3){
-            echo "<td>".$entry[4]."</td>";
+        if(count($entry) > 4){
             echo "<td>".$entry[5]."</td>";
-            echo "<td>".$entry[3]." mises à jour en attente</td>";
-            echo "<td> branch ".$entry[6]." ".$entry[7]." commits en retard</td>";
+            echo "<td>".$entry[6]."</td>";
+            echo "<td>".$entry[4]." mises à jour en attente</td>";
+            echo "<td> branch ".$entry[7]." ".$entry[8]." commits en retard</td>";
         }else{
             echo "<td>NA</td>";
             echo "<td>NA</td>";
-- 
GitLab