Select Git revision
postinstall_partage.sh
Forked from
primtux-eole / Grenoble / eole-wol
Source project has a limited visibility.
index.php 6.39 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">
</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)){
$lines=explode(PHP_EOL, shell_exec("../scripts/get_registry.sh"));
?>
<p> <?php echo count($lines); ?> postes sont inscrits 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">
</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 avec mises à jour APT">
</form>
<h2> Gestion des postes </h2>
<table class="table-striped table-bordered table-hover">
<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
$registry = array();
foreach($lines as $line){
if($line != ""){
$entry=explode(' ', $line);
array_push($registry, $entry);
# 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> ".$entry[3]."</td>";
echo "<td>".$entry[1]."</td>";
#echo "<td>".$entry[0]."</td>";
if(count($entry) > 4){
echo "<td>".$entry[5]."</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>";
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="mac" value="<?php echo $entry[1]; ?>">
<input type="submit" value="Mettre à jour" title="Mettre à jour">
</form>
<form action="index.php" method="post">
<input type="hidden" name="action" value="upgradeAPT">
<input type="hidden" name="mac" value="<?php echo $entry[1]?>;">
<input type="submit" value="Mettre à jour + Apt" title="Mettre à jour + apt">
</form>
<?php
echo "</td></tr>";
}
}
?>
</table>
<pre>
<?php json_encode($registry); ?>
</pre>
<?php
}else{
echo "<h2> Action en cours </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 "upgradeAll" :
echo "I should upgradeAll machines, not implemented yet";
breaK;
case "upgradeAllApt" :
echo "I should upgradeAllApt machines, not implemented yet";
breaK;
case "upgrade" :
echo "I should upgrade $mac, not implemented yet";
break;
case "upgradeAPT" :
echo "I should upgrade $mac with apt, not implemented yet";
break;
}
}
?>
</div>
</div>