Select Git revision
docker-compose.yml
index.php 10.56 KiB
<!--
- Copyright (C) 2017 Tetras Libre <contact@tetras-libre.fr>
- Author: Beniamine, David <David.Beniamine@tetras-libre.fr>
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>
</head>
<div id="box" class="container" style="font-size:large">
<div id="content">
<h1> Interface de gestion des postes </h1>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
extract($_POST);
if(!isset($action)){
exec("../scripts/actions.sh getRegistry", $lines, $code);
?>
<p>
<?php
$n=count($lines);
if(empty($lines)){
echo "Impossible de récupérer le registre, code $code";
}else if ($n == 1){
echo "$n poste est enregistré sur ce serveur";
}else{
echo "$n postes sont enregistrés sur ce serveur";
}
?>
</p>
<h2> Actions globables </h2>
<form action="index.php" method="post">
<input type="hidden" name="action" value="upgradeAll">
<input type="submit" value="Mettre à jour tous les postes" title="Mettre à jour tous les postes (config)">
</form>
<form action="index.php" method="post">
<input type="hidden" name="action" value="upgradeAllApt">
<input type="submit" value="Mettre à jour tous les postes avec mises à jour APT" title="Mettre à jour tous les postes (config + APT)">
</form>
<form action="index.php" method="post">
<input type="hidden" name="action" value="getLogAll">
<input type="submit" value="Voir le dernier log de mise à jour" title="Voir le dernier log de mise à jour">
</form>
<h2> Gestion des postes </h2>
<p>
Vous pouvez trier la table ci dessous en cliquant sur la colonne que vous voulez.
<br />
Cliquer une deuxième fois inverser l'ordre de tri.
</p>
<div class="table-responsive">
<table class="table-striped table-bordered table-hover" style="text-align:center;">
<thead>
<tr>
<th style="text-align:center;" data-sort="string" data-sort-onload="yes" >Nom</th>
<th style="text-align:center;" data-sort="string" >IP(s)</th>
<th style="text-align:center;" data-sort="string" >MAC</th>
<th style="text-align:center;" data-sort="string" >Version Debian</th>
<th style="text-align:center;" data-sort="string" >Version Primtux</th>
<th style="text-align:center;" data-sort="string" >Mises à jour apt en attente</th>
<th style="text-align:center;" data-sort="string" >État git</th>
<th style="text-align:center;" data-sort="string" >Date dernier contact</th>
<th style="text-align:center;" >Actions</th>
</tr>
</thead>
<tbody>
<?php
$registry = array();
foreach($lines as $line){
if($line != ""){
$entry=explode(' ', $line);
$nb_infos=count($entry);
array_push($registry, $entry);
# Format date mac name [num_apt_upgrade deb_version pt_version git_branch git_update] ip
echo "<tr>";
echo "<td>".$entry[2]."</td>";
echo "<td> ".$entry[$nb_infos-1]."</td>";
echo "<td>".$entry[1]."</td>";
#echo "<td>".$entry[0]."</td>";
if($nb_infos > 4){
echo "<td>".$entry[4]."</td>";
echo "<td>".str_replace('_', ' ', $entry[5])."</td>";
echo "<td>".$entry[3]."</td>";
echo "<td> branche ".$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>";
# Actions
?>
<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="submit" value="Démarrer" title="Démarrer la machine">
</form>
<form action="index.php" method="post">
<input type="hidden" name="action" value="upgrade">
<input type="hidden" name="name" value="<?php echo $entry[2]; ?>">
<input type="submit" value="Mise à jour config" title="Mettre à jour">
</form>
<form action="index.php" method="post">
<input type="hidden" name="action" value="upgradeAPT">
<input type="hidden" name="name" value="<?php echo $entry[2]; ?>">
<input type="submit" value="Mise à jour config + APT" title="Mettre à jour + apt">
</form>
<form action="index.php" method="post">
<input type="hidden" name="action" value="getLog">
<input type="hidden" name="name" value="<?php echo $entry[2]; ?>">
<input type="submit" value="Log de mise à jour" title="Télécharger le dernier log de mise à jour">
</form>
<?php
echo "</td></tr>";
}
}
?>
</tbody>
</table>
<!-- Script to add titles to each td -->
<script language="javascript">
$().ready(function(){
titles=[];
$('th').each(function(e,v){
titles.push($(v).text());
});
$(' td').attr('title', function (index, attr) {
return titles[$(this).index()];
});
// Make table sortable and searchable
$('table').DataTable({
pageLength:5,
language:{
"decimal": "",
"emptyTable": "pas de données dans cette table",
"info": "Affichage des entrées _START_ à _END_ sur _TOTAL_",
"infoEmpty": "0 à 0 de 0 entrées affichées",
"infoFiltered": "(filtré sur _MAX_ entrées)",
"infoPostFix": "",
"thousands": ",",
"lengthMenu": "Montrer _MENU_ entrées",
"loadingRecords": "Chargement...",
"processing": "Traitement encours...",
"search": "Rechercher :",
"zeroRecords": "Pas d'entrées",
"paginate": {
"first": "Premier",
"last": "Dernier",
"next": "Suivant",
"previous": "Précédent"
},
"aria": {
"sortAscending": ": Trier la colonne par ordre croissant",
"sortDescending": ": Trier la colonne par ordre décroissant"
}
},
});
});
</script>
</div>
<?php
}else{
$lines = array();
$run=false;
$emptymsg="<p>Not implemented yet</p><p>Cette action n'affiche pas de message.<br />Vous pouvez demander les logs depuis <a href='/wol/'>la page principale<a></p>";
if(!isset($name)){
$name="";
}
echo "<h2> Action demandée : $action $name</h2>";
switch($action){
case "wake" :
echo "<div id='result'><p>Démarrage demandé pour la machine $mac, veuillez patienter</p></div>";
?>
<script language="javascript">
// the wakeonlan is handled via ajax to show timeout progress
function sendpost(retry){
$.ajax({
type: "POST",
data: '<?php echo "mac=$mac"?>',
url: 'boot.php',
timeout: 30000,
error: function(reponse){
if(retry > 0){
// We probably have not waited long enough, let retry
$("#result").html("Recherche de la machine sur le réseau.<br/>Merci de patienter encore un peu (max "+retry*5+" sec).") ;
sendpost(retry-1);
}else{
// Actual error
$("#result").html('Erreur : machine absente du réseau après 120 secondes.<br />Pensez à vérifier l\'adresse MAC \'<?php echo "$mac"?>\'') ;
}
},
success: function(response) {
// All good !
$("#result").html(response) ;
}
});
}
// Ask for machine boot with timeout 24*5 = 120 seconds
sendpost(24);
</script>
<?php
break;
case "upgradeAllApt" :
$run=true;
break;
case "upgradeAll" :
echo "Todo see log";
$run=true;
break;
case "getLogAll" :
$emptymsg="<p>Pas de log globaux disponibles</p>";
$run=true;
break;
case "upgradeAPT" :
$run=true;
break;
case "upgrade" :
$run=true;
break;
case "getLog" :
$emptymsg="<p>Pas de log disponibles pour $name</p>";
$run=true;
break;
}
if($run){
exec("../scripts/actions.sh .".escapeshellarg($action)." "
.escapeshellarg($name), $lines, $code);
echo "<p>Action effectuée, code : $code</p>";
if(!empty($lines)){
echo "<pre>";
foreach($lines as $line){
echo "$line\n";
}
echo "</pre>";
}else{
echo $emptymsg;
}
}
}
?>
</div>
</div>