From 295bd0860c467506d34f1ad272a1b510ad74abb6 Mon Sep 17 00:00:00 2001
From: David Beniamine <david.beniamine@tetras-libre.fr>
Date: Mon, 5 Aug 2019 14:09:50 +0200
Subject: [PATCH] Wip web page ugly

---
 wol/scripts/get_ips.sh |  3 +++
 wol/www/index.php      | 50 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
 create mode 100755 wol/scripts/get_ips.sh

diff --git a/wol/scripts/get_ips.sh b/wol/scripts/get_ips.sh
new file mode 100755
index 0000000..d37fdb3
--- /dev/null
+++ b/wol/scripts/get_ips.sh
@@ -0,0 +1,3 @@
+#!/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/www/index.php b/wol/www/index.php
index d0f33f5..ed2e009 100644
--- a/wol/www/index.php
+++ b/wol/www/index.php
@@ -23,6 +23,56 @@
 <div id="box" style="font-size:large">
 <div id="content">
 <h1> Interface de gestion des postes </h1>
+<p> test </p>
+<table>
+<tr>
+    <th>Nom</th>
+    <th>IP(s)</th>
+    <th>MAC</th>
+    <th>Version Debian</th>
+    <th>Version Primtux</th>
+    <th>État apt</th>
+    <th>État git</th>
+    <th>Date dernier contact</th>
+    <th>Actions</th>
+</tr>
+<?php
+$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]
+        echo "<tr>";
+        echo "<td>".$entry[2]."</td>";
+        echo "<td> ".$IPS."</td>";
+        echo "<td>".$entry[1]."</td>";
+        #echo "<td>".$entry[0]."</td>";
+        if(count($entry) > 3){
+            echo "<td>".$entry[4]."</td>";
+            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>";
+        }else{
+            echo "<td>NA</td>";
+            echo "<td>NA</td>";
+            echo "<td>NA</td>";
+            echo "<td>NA</td>";
+        }
+        # Last seen
+        echo "<td>".$entry[0]."</td>";
+        echo "<td>Todo</td>";
+        echo "</tr>";
+    }
+}
+?>
+</table>
+<pre>
+<? json_encode($registry); ?>
+</pre>
+
 <p>Merci d'indiquer l'adresse MAC du PC à réveiller</p>
 <form action="index.php" method="post">
     <input type="hidden" name="action" value="wake">
-- 
GitLab