Select Git revision

David Beniamine authored
index.php 12.73 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/>.
-->
<?php
$school_name = shell_exec('CreoleGet libelle_etab');
$title = "$school_name — Interface de gestion";
?>
<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>
<title><?echo "$title"; ?></title>
</head>
<body>
<div id="box" class="container" style="font-size:large">
<div id="content">
<h1> <? echo "$title"; ?> </h1>
<p>
Bienvenue sur l'interface de gestion de l'école : <code><? echo "$school_name"; ?></code>.
</p>
<?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 le serveur";
}else{
echo "$n postes sont enregistrés sur le serveur";
}
?>
</p>
<h2> Actions globales </h2>
<p>
Les actions de cette sectiode cette sectionappliquées sur la totalité des postes du parc.<br />
Vous avez la possibilité de lancer les mêmes actions invididuellement sur les différents postes dans la section suivante.
</p>
<ul>
<li> Mettre à jour les configurations des postes (scripts d'adaptation de Primtux pour Grenoble) :
<form action="index.php" method="post">
<input type="hidden" name="action" value="upgradeAll">
<input type="submit" value="Mise à jour config" title="Mettre à jour tous les postes (config)" >
</form>
</li>
<li> Mettre à jour les configuration et les paquets <code>apt</code> :
<form action="index.php" method="post">
<input type="hidden" name="action" value="upgradeAllApt">
<input type="submit" value="Mise à jour config + APT" title="Mettre à jour tous les postes (config + APT)">
</form>
</li>
<li> Voir le dernier log de mise à jour des postes depuis le serveur :
<form action="index.php" method="post">
<input type="hidden" name="action" value="getLogAll">
<input type="submit" value="Log de mise à jour" title="Voir le dernier log de mise à jour">
</form>
</li>
</ul>
<h2> Actions ciblées </h2>
<p>
Vous pouvez trier la table ci dessous en cliquant sur la colonne que vous voulez. <br />
Cliquer une deuxième fois pour inverser l'ordre de tri. <br />
Il est aussi possible de filtrer la table pour ne voir qu'une partie des postes (par exemple pour trouver un poste par IP ou non d'hôte).<br />
Veuillez noter que la table est paginée, la totalité des resultats n'est pas forcément affichée.
</p>
<div class="col-sm-12">
<table class="table 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);
if($nb_infos < 2){
continue;
}
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 > 5){
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>".preg_replace('/(\d{4})(\d{2})(\d{2})/', '$1/$2/$3', $entry[0])."</td>";
echo "<td>";
# Actions
?>
<form action="index.php" method="post">
<input type="hidden" name="action" value="wake">
<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="name" value="<?php echo $entry[1]; ?>">
<input type="submit" value="Redémarrer" title="redé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:25,
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": ",",
"scrollX": true,
"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{
if(!isset($name)){
$name="";
}
echo "<h2> Action demandée : $action $name</h2>";
$allowedActions = [
'upgradeAll',
'upgradeAllApt',
'getLogAll',
'upgradeApt',
'upgrade',
'getLog',
'reboot',
];
if($action == "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
}else{
if(in_array($action, $allowedActions)){
$lines = array();
exec("../scripts/actions.sh ".escapeshellarg($action)." "
.escapeshellarg($name), $lines, $code);
echo "<p>Action '$action' effectuée, code : $code</p>";
// Retrieve logs
if(preg_match('/^upgrade/', $action) && $code == 0 ){
echo "<p>Les logs ne se rafraichissent pas tous seuls, vous pouvez utiliser le bouton prévu à cet effet</p>";
exec("../scripts/actions.sh getLog "
.escapeshellarg($name), $lines, $code);
}
if(!empty($lines)){
echo "<pre>";
foreach($lines as $line){
echo "$line\n";
}
echo "</pre>";
}else{
echo "<p>Erreur : pas de réponse</p>";
}
?>
<form action="index.php" method="post">
<input type="hidden" name="action" value="getLog">
<input type="hidden" name="name" value="<?php echo $name; ?>">
<input type="submit" value="Rafraichir les logs" title="Rafraichir les logs">
</form>
<?
}else{
echo "<p><strong>Action '$action' interdite !</strong></p>";
}
}
?>
<form action="index.php" method="post">
<input type="submit" value="Retour à l'accueil" title="Retour à l'accueil">
</form>
<?php
}
?>
</div>
</div>
</body>