Skip to content
Snippets Groups Projects
Verified Commit 559e9fb3 authored by David Beniamine's avatar David Beniamine
Browse files

Comment code

parent f2b5ee19
No related branches found
No related tags found
No related merge requests found
...@@ -19,22 +19,27 @@ ...@@ -19,22 +19,27 @@
<?php <?php
extract($_POST); extract($_POST);
$args = escapeshellarg($mac); $args = escapeshellarg($mac);
# Verify MAC format
if(!preg_match('/^([0-9a-f]{2}:?){6}$/',$mac)){ if(!preg_match('/^([0-9a-f]{2}:?){6}$/',$mac)){
echo "<p>Adresse MAC invalide : ".$args."</p>"; echo "<p>Adresse MAC invalide : ".$args."</p>";
}else{ }else{
# Boot machine
$cmd = "../scripts/sendmac.sh"; $cmd = "../scripts/sendmac.sh";
$ip=shell_exec("$cmd $args"); $ip=shell_exec("$cmd $args");
if(!empty(trim($ip))){ if(!empty(trim($ip))){
echo "<p> Démarrage de la machine ".$args." terminé !</p>"; # Prepare .rdp file for connection
echo "<p>Pour vous y connecter, téléchargez ";
system("cp www/config.rdp.sample www/config.rdp"); system("cp www/config.rdp.sample www/config.rdp");
system("echo \"full address:s:\"".$_SERVER["HTTP_HOST"]." >> config.rdp"); system("echo \"full address:s:\"".$_SERVER["HTTP_HOST"]." >> config.rdp");
# Output text
echo "<p> Démarrage de la machine ".$args." terminé !</p>";
echo "<p>Pour vous y connecter, téléchargez ";
echo '<a href="config.rdp'; echo '<a href="config.rdp';
echo '">ce fichier</a> et lancez le.<br />'; echo '">ce fichier</a> et lancez le.<br />';
echo "Cela ouvrira XRDP, il vous suffira alors d'indiquer l'adresse IP <span style='color:blue;font-weight:bold'>".$ip."</span>"; echo "Cela ouvrira XRDP, il vous suffira alors d'indiquer l'adresse IP <span style='color:blue;font-weight:bold'>".$ip."</span>";
echo "et le mot de passe adéquat"; echo "et le mot de passe adéquat";
echo "</p>"; echo "</p>";
}else{ }else{
# No IP found, we return an error, the client will choose to retry or give up
header('HTTP/1.1 500 Internal Server Error'); header('HTTP/1.1 500 Internal Server Error');
} }
} }
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
echo "<div id='result'><p>Démarrage demandé pour la machine $mac, veuillez patienter</p></div>"; echo "<div id='result'><p>Démarrage demandé pour la machine $mac, veuillez patienter</p></div>";
?> ?>
<script language="javascript"> <script language="javascript">
// the wakeonlan is handled via ajax to show timeout progress
function sendpost(retry){ function sendpost(retry){
$.ajax({ $.ajax({
type: "POST", type: "POST",
...@@ -44,17 +45,21 @@ ...@@ -44,17 +45,21 @@
timeout: 30000, timeout: 30000,
error: function(reponse){ error: function(reponse){
if(retry > 0){ if(retry > 0){
$("#result").html("Veuillez patienter encore un peu (max "+retry*4+" sec)") ; // We probably have not waited long enough, let retry
$("#result").html("Rcherche de la machine sur le réseau, merci de patienter encore un peu (max "+retry*5+" sec)") ;
sendpost(retry-1); sendpost(retry-1);
}else{ }else{
$("#result").html("Erreur : IP non trouvée après 120 secondes") ; // Actual fail
$("#result").html("Erreur : machine absente du réseau après 120 secondes") ;
} }
}, },
success: function(response) { success: function(response) {
// All good !
$("#result").html(response) ; $("#result").html(response) ;
} }
}); });
} }
// Ask for machine boot with timeout 24*5 = 120 seconds
sendpost(24); sendpost(24);
</script> </script>
<?php <?php
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment