Unverified Commit e34c06f7 authored by David Beniamine's avatar David Beniamine
Browse files

Retrieve logs

parent a9e501aa
......@@ -21,6 +21,16 @@ getip(){
< /var/lib/dhcp/dhcpd.leases
}
# $1 : file|stdin
answer(){
if [ -z "$1" ]
then
netcat $host $port
else
stdbuf -oL cat $1 | while ! netcat $host $port; do sleep 1; done
fi
}
IP=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1)
broadcast=$(ip a | awk '/inet.*eth1/ {print $4}' | cut -d / -f 1)
subnet=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1 | cut -d . -f 1-3)
......@@ -29,23 +39,23 @@ port=9999
while true
do
MAC=`netcat -l $IP $port`
#echo "$MAC"
if [ $(echo "$MAC" | egrep -c "^([0-9a-f]{2}:?){6}$") -eq 1 ]
LINE=`netcat -l $IP $port`
#echo "$LINE"
if [ $(echo "$LINE" | egrep -c "^([0-9a-f]{2}:?){6}$") -eq 1 ]
then
wakeonlan -i $broadcast "$MAC"
wakeonlan -i $broadcast "$LINE"
sleep 3
IPS=`getip $MAC`
IPS=`getip $LINE`
for ip in $IPS
do
ping -c 3 $ip
if [ $? -eq 0 ]
then
echo "$ip" | netcat $host $port
echo "$ip" | answer
break
fi
done
elif [ $MAC == "getRegistry" ]
elif [ "$LINE" == "getRegistry" ]
then
hostfile="/etc/registry/hosts"
while read line
......@@ -58,7 +68,27 @@ do
fi
echo "$line $IPS" >> $hostfile-$$
done < $hostfile
stdbuf -oL cat $hostfile-$$ | while ! netcat $host $port; do sleep 1; done
answer $hostfile-$$
rm $hostfile-$$
elif [[ "$LINE" =~ "getLog" ]]
then
cmd=$(echo $LINE | cut -d ' ' -f 1)
name=$(echo $LINE | cut -d ' ' -f 2)
logfile=$(ls /var/log/upgrade_all.sh_* | sort | tail -n 1)
if [ "$name" == "$cmd" ]
then
answer $logfile
else
tempfile="/tmp/$$"
# Extract the pertinent part of the log
awk 'BEGIN{IN=0} /Begin host/{if($4=="'$name'"){IN=1}} {if(IN){print $0}} /End host/{if($4=="'$name'"){IN=0}}' \
$logfile > $tempfile
answer $tempfile
rm $tempfile
fi
elif [[ "$LINE" =~ "upgrade" ]]
then
#TODO call directly upgrade script
false
fi
done
......@@ -64,6 +64,8 @@ if(!isset($action)){
<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 trie
</p>
<div class="table-responsive">
<table class="table-striped table-bordered table-hover" style="text-align:center;">
......@@ -117,17 +119,17 @@ if(!isset($action)){
</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="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="mac" value="<?php echo $entry[1]?>;">
<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="mac" value="<?php echo $entry[1]?>;">
<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
......@@ -156,7 +158,12 @@ if(!isset($action)){
<?php
}else{
echo "<h2> Action en cours </h2>";
$lines = array();
$run=false;
if(!isset($name)){
$name="";
}
echo "<h2> Action en cours : $action $name</h2>";
switch($action){
case "wake" :
echo "<div id='result'><p>Démarrage demandé pour la machine $mac, veuillez patienter</p></div>";
......@@ -190,24 +197,45 @@ if(!isset($action)){
</script>
<?php
break;
case "upgradeAllApt" :
echo "Sending request to upgrade all machines with apt";
$run=true;
break;
case "upgradeAll" :
echo "Sending request to upgrade all machines";
echo "Todo see log";
case "upgradeAllApt" :
echo "Sending request to upgrade all machines with apt";
$run=true;
break;
case "getLogAll" :
echo "I should download all logs, not implemented yet";
exec("../scripts/action.sh $action", $lines, $code);
$emptymsg="<p>Pas de log globaux disponibles</p>";
$run=true;
break;
case "upgrade" :
echo "I should upgrade $mac, not implemented yet";
case "upgradeAPT" :
echo "I should upgrade $mac with apt, not implemented yet";
echo "I should upgrade $name with apt, not implemented yet";
$run=true;
break;
case "upgrade" :
echo "I should upgrade $name, not implemented yet";
$run=true;
break;
case "getLog" :
echo "I should download logs for $mac, not implemented yet";
exec("../scripts/action.sh $action ".escapeshellarg($mac), $lines, $code);
$emptymsg="<p>Pas de log disponibles pour $name</p>";
$run=true;
break;
}
if($run){
exec("../scripts/actions.sh .".escapeshellarg($action)." "
.escapeshellarg($name), $lines, $code);
if(!empty($lines)){
echo "<pre>";
foreach($lines as $line){
echo "$line\n";
}
echo "</pre>";
}else{
echo $emptymsg;
}
}
}
?>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment