<?php
/** **************************************************************************
 * Copyright (C) 2008-2014 Eric Seigne <eric.seigne@ryxeo.com>
 *
 * 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 2 of the License.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * ***************************************************************************
 * Author  : Eric SEIGNE
 * Licence : GNU/GPL Version 2
 *
 * Description:
 * ------------
 *
 * @modifier   Frucot Jean-Louis 16/07/2009 mailto:frucot.jeanlouis@pourlecole.net
 * ************************************************************************* */

include_once("AbE_API.php");
include_once("AbE_Users.php");
$page 	= new AbE_Webadmin_Page();

// same fields as in modifier.php, don't forget to update
// them there too.
$envoyer                = $_REQUEST["envoyer"];
$mac			= base64_decode($_REQUEST["mac"]);
$hostname		= $_REQUEST["hostname"];
$action			= $_REQUEST["action"];
$ip			= $_REQUEST["ip"];
$vlan			= $_REQUEST["vlan"];
$backupname		= $_REQUEST["backupname"];
$restaurename		= $_REQUEST["restaurename"];
$adminlocalpass		= $_REQUEST["adminlocalpass"];
$admindomainpass        = $_REQUEST["admindomainpass"];
$textelocal             = "";

//Si on a un VLAN il faut que le compte machine soit hostname.vlan901
if($vlan) {
  $comptemachine = $hostname . "." . $vlan;
}
else {
  $comptemachine = $hostname;
}

global $conf_rep_syslinux;
if(trim($hostname) != "") {
  $tabconftx = recup_infos($comptemachine);
  $computerarch = $tabconftx["computerarch"];
}

if(file_exists("/etc/" . $metamode . "/rvd") && ! file_exists("/etc/" . $metamode . "/wifi")) {
  $erreurs .= "<img src=\"/images/attention.png\" align=\"absmiddle\"> " . _("Attention, le système wifi n'est pas configuré et ne sera donc pas <a href=\"../internet/chip.php\">automatiquement déployé</a>.");
}

$textelocal .= "<form action=\"$PHP_SELF\" method=\"post\" name=\"form\">
<input type=\"hidden\" name=\"hostname\" value=\"$hostname\">
<input type=\"hidden\" name=\"vlan\" value=\"$vlan\">
<input type=\"hidden\" name=\"computerarch\" value=\"$computerarch\">
<input type=\"hidden\" name=\"mac\" value=\"" . base64_encode($mac) . "\">
<input type=\"hidden\" name=\"ip\" value=\"$ip\">\n";

// Si c'est la 1ere fois qu'on passe sur cette page ...
if(!isset($envoyer)){
  $textelocal .= "$erreurs
<h3 style=\"text-align: justify;\">" . sprintf(_("Gestion du mode de démarrage du poste %s&nbsp;:"), $comptemachine) . "</h3>
<select name=\"action\">
  <option value=\"startx\" onClick=\"hide(document.getElementById('backupnamezone')); hide(document.getElementById('restaurenamezone'));\">" .   _("Démarrer l'ordinateur par le réseau en client léger - TX.") . "</option>
  <option value=\"hdd\" onClick=\"hide(document.getElementById('backupnamezone')); hide(document.getElementById('restaurenamezone'));\">" .      _("Démarrer l'ordinateur sur le système d'exploitation local (installé sur le disque dur).") . "</option>
  <option value=\"backup\" onClick=\"unhide(document.getElementById('backupnamezone')); hide(document.getElementById('restaurenamezone'));\">" .   _("Sauvegarder le disque dur du poste sur le serveur pour pouvoir le restaurer ultérieurement.") . "</option>
  <option value=\"backupparts\" onClick=\"unhide(document.getElementById('backupnamezone')); hide(document.getElementById('restaurenamezone'));\">" .   _("Sauvegarder les deux premieres partitions du disque dur du poste sur le serveur.") . "</option>
  <option value=\"restaure\" onClick=\"hide(document.getElementById('backupnamezone')); unhide(document.getElementById('restaurenamezone'));\">" . _("Restaurer le disque dur du poste depuis une image stockée sur le serveur.") . "</option>
  <option value=\"restaurelocal\" onClick=\"hide(document.getElementById('backupnamezone')); hide(document.getElementById('restaurenamezone'));\">" .   _("Restaurer le disque dur du poste depuis la partition cachée.") . "</option>
  <option value=\"\" onClick=\"hide(document.getElementById('backupnamezone')); hide(document.getElementById('restaurenamezone'));\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .   _("--------- ATTENTION, LES OPTIONS CI-DESSOUS SONT DANGEREUSES ---------") . "</option>
  <option value=\"installboot\" onClick=\"hide(document.getElementById('backupnamezone')); hide(document.getElementById('restaurenamezone'));\">" . _("Copier la disquette de démarrage sur le disque dur (écrasement du disque).") . "</option>
  <option value=\"backuplocal\" onClick=\"hide(document.getElementById('backupnamezone')); hide(document.getElementById('restaurenamezone'));\">" .   _("Sauvegarder le disque dur du poste sur la partition cachée (formatage brutal de la 4° partition).") . "</option>
</select>

<br />
<br />

<div id=\"backupnamezone\" style=\"display: none; visibility: hidden;\">" . _("Nom de la sauvegarde :") . "<input type=\"text\" name=\"backupname\" value=\"\"></div>

<div id=\"restaurenamezone\" style=\"display: none; visibility: hidden;\">
<table>
<tr>
  <td>" . _("Choisissez la sauvegarde à restaurer") . "</td>
  <td> <select name=\"restaurename\">\n";

  //Les images generiques
  $rep = "/home/machines/groups/default/";
  $handle=opendir($rep);
  while ($file = readdir($handle)){
    if(ereg("^imagegeneric",$file)) {
      $filename = $file;
      $tabimages[] = $filename;
    }
  }

  //On cherche toutes les images dispo
  $rep = "/home/machines/$comptemachine/";
  $handle=opendir($rep);
  while ($file = readdir($handle)){
    if(ereg("^imagedisque",$file)) {
      $filename = str_replace("imagedisque-","",$file);
      $tabimages[] = $filename;
    }
  }

  if(is_array($tabimages)) {
    sort($tabimages);
    for($i = 0;$i < count($tabimages); $i++)
      $textelocal .= "<option value=\"" . $tabimages[$i] . "\">" . $tabimages[$i] . "</option>\n";
  }

  $textelocal .= "
</select></td>
</tr>
<tr bgcolor=\"#eaeaea\">
  <td>Indiquez ici le mot de passe que vous voulez affecter à l'administrateur local:</td>
  <td><input type=\"text\" name=\"adminlocalpass\"></td>
</tr>
<tr>
  <td>Mot de passe de l'administrateur du domaine (abuladmin) : </td>
  <td><input type=\"text\" name=\"admindomainpass\"></td>
</tr>
</table>
</div>

<br />

<input type=\"submit\" name=\"envoyer\" value=\"" . _("Suivant >>") . "\">\n";
 }
else {
  $specialcase = "";
  if($action == "hdd") {
    //modifier le fichier de pxeboot pour avoir
    //localboot 0x80

    $syslinuxfile = "$conf_rep_syslinux/01-" . strtolower(strtr($mac,":","-"));
    $syslinux = "default local
    label local
      kernel chain.c32
      append hd0
";

    if ((!isset($installation_name)) || ($installation_name == "")) {
      $installation_name="non_defini";
    }
    
    $cmd .= "
#on copie le syslinux original
if [ -f \"/home/machines/" . $comptemachine . "/boot.pxe\" ]; then
  cp /home/machines/" . $comptemachine . "/boot.pxe /home/machines/" . $comptemachine . "/boot.normal
  rm -f /home/machines/" . $comptemachine . "/boot.pxe
fi
";

$syslinuxsymlink = "/home/machines/" . $comptemachine . "/boot.pxe";

$cmd .= "
if [ ! -e $syslinuxsymlink ]; then
   ln $syslinuxfile $syslinuxsymlink
fi

#on ecrase le syslinux [$syslinuxfile] dans tous les cas (nouveau ou modif)
echo \"$syslinux\" > $syslinuxfile || true
chown " . $comptemachine . " /home/machines/" . $comptemachine . "/boot.*
#on pose le flag pour confirmer le backup
touch /home/machines/" . $comptemachine . "/make_backup
chown " . $comptemachine . " /home/machines/" . $comptemachine . "/make_backup
";

    fichier_script($cmd,"ltsconf",$textelocal);
  }
  else {
    $imagename = "imagedisque";
    if($action == "backup" || $action == "backupparts" ) {
      $specialcase = "backup-restaure";
      if(trim($backupname) != "") {
	$imagename .= "-" . trim($backupname);
      }
    }
    if($action == "restaure") {
      $specialcase = "backup-restaure";
      if(trim($restaurename) != "") {
	//on restaure une image generique
	if(ereg("^imagegeneric",$restaurename)) {
	  $imagename = $restaurename;
	  
	  //le script a lancer après avoir restauré l'image maquette
	  //pour l'instant on utilise les partitions qu'on a décidé au départ
	  //dans l'avenir il faudra scanner à la recherche de la partition qui
	  //héberge le windows ...
	  if($metamode == "abuledu") {
	    $windowsdomain = "ABULEDU";
	    $admindomainlogin = "abuladmin";
	  }	    
	  else {
	    $windowsdomain = "NOUVA";
	    $admindomainlogin = "servadmin";
	  }
	  
	  $windowskey =   $tabconftx['windowslicence'];
	  $sha512pass = exec("mkpasswd -m sha-512 " . $adminlocalpass);
	  
	  //On fait le symlink pour que cette image soit accessible
	  //informations: 
	  //BTT* etant le bug des bluetooth des lenovo et acer
	  $cmd .= "rm -f /home/machines/" . $comptemachine . "/" . $imagename . " || true
(
cd /home/machines/" . $comptemachine . "
ln -s ../groups/default/" . $imagename . " $imagename
)

cat > /home/machines/" . $comptemachine . "/.maquette << EOF
$imagename
EOF

cat > /home/machines/" . $comptemachine . "/horizon.postrestaure << EOF
#!/bin/bash

mkdir /mnt/windows

if [ -f /home/partimag/$comptemachine/$imagename/sda1.ntfs* -o -f /home/partimag/$comptemachine/$imagename/sda3.ntfs* ]; then
# on est sur un seven (sda1 ou GPT -> sda3)
  if [ -e /dev/sda ]; then
    if [ -f /home/partimag/$comptemachine/$imagename/sda1.ntfs* ]; then
      mount.ntfs-3g /dev/sda1 /mnt/windows
    elif [ -f /home/partimag/$comptemachine/$imagename/sda3.ntfs* ]; then
      mount.ntfs-3g /dev/sda3 /mnt/windows
    fi
  elif [ -e /dev/hda ]; then
    mount.ntfs-3g /dev/hda1 /mnt/windows
  fi
  #sur un seven avec une partition de 100Mo en debut de disque
  if [ ! -d /mnt/windows/Windows/System32/sysprep/ ]; then
    umount /mnt/windows
    if [ -e /dev/sda ]; then
      mount.ntfs-3g /dev/sda2 /mnt/windows
    elif [ -e /dev/hda ]; then
      mount.ntfs-3g /dev/hda2 /mnt/windows
    fi
  fi

  if [ -d /mnt/windows/Windows/System32/sysprep/ ]; then
    #windows seven
    rm /mnt/windows/Windows/Panther/unattend.xml
    cd /mnt/windows/Windows/System32/sysprep/
    cp -f /home/partimag/$comptemachine/$imagename/unattend.xml unattend.xml
    sed -i -e s/HORIZONDOMAIN/" . $windowsdomain . "/ unattend.xml
    sed -i -e s/DOMAINPASS/" . $admindomainpass . "/ unattend.xml
    sed -i -e s/DOMAINADMIN/" . $admindomainlogin . "/ unattend.xml
    sed -i -e s/HORIZONADMINPASS/" . $adminlocalpass . "/ unattend.xml
    sed -i -e s/HORIZONWINDOWSKEY/" . $windowskey . "/ unattend.xml
    sed -i -e s/HORIZONCOMPUTERNAME/" . $hostname . "/ unattend.xml
    sed -i -e s/HZNCOMPUTERNAME/" . $hostname . "/ unattend.xml
    sed -i -e s/HORIZONINSTALLATIONNAME/\\\"" . str_replace(" ","-",$installation_name) . "\\\"/ unattend.xml
    #    cp -f Unattend.xml save.txt
    cd /mnt/windows/Windows/Setup/Scripts/
    cp -f /home/partimag/$comptemachine/$imagename/SetupComplete.cmd .
    sed -i -e s/HORIZONDOMAIN/" . $windowsdomain . "/g SetupComplete.cmd
    sed -i -e s/DOMAINPASS/" . $admindomainpass . "/ SetupComplete.cmd
    sed -i -e s/DOMAINADMIN/" . $admindomainlogin . "/ SetupComplete.cmd
    cp -f /home/partimag/$comptemachine/$imagename/netdom.exe /mnt/windows/Windows/System32/
    cp -f /home/partimag/$comptemachine/$imagename/netdom.exe.mui /mnt/windows/Windows/System32/fr-FR/
    cd /
  elif [ -d /mnt/windows/sysprep ]; then
    #windows xp
    if [ -e /dev/sda ]; then
      mount.ntfs-3g /dev/sda1 /mnt/windows
    elif [ -e /dev/hda ]; then
      mount.ntfs-3g /dev/hda1 /mnt/windows
    fi
    if [ -d /mnt/windows/sysprep ]; then
      cd /mnt/windows/sysprep
      if [ ! -f sysprep.inf -a -f /home/partimag/$comptemachine/$imagename/sysprep.inf ]; then
         cp -f /home/partimag/$comptemachine/$imagename/sysprep.inf .
      fi
      sed -i -e s/'^\([[:space:]]*\)AdminPassword=.'*/'\\1AdminPassword=\"" . $adminlocalpass . "\"'/ sysprep.inf
      sed -i -e s/ProductKey=.*/ProductKey=" . $windowskey . "/ sysprep.inf
      sed -i -e s/ComputerName=.*/ComputerName=" . $hostname . "/ sysprep.inf
      sed -i -e s/JoinDomain=.*/JoinDomain=" . $windowsdomain . "/ sysprep.inf
      sed -i -e s/DomainAdmin=.*/DomainAdmin=" . $admindomainlogin . "/ sysprep.inf
      sed -i -e s/DomainAdminPassword=.*/DomainAdminPassword=" . $admindomainpass . "/ sysprep.inf
      sed -i -e s/'OrgName=.*'/'OrgName=\\\"" . $installation_name . "\\\"'/ sysprep.inf
      sed -i -e s/'FullName=.*'/'FullName=\\\"" . $installation_name . "\\\"'/ sysprep.inf
      cd /mnt/windows
      find Docu* -name BTT* -exec rm -rf {} \;
      find Docu* -name McAfee* -exec rm -rf {} \;
      cd /
    fi
    umount /mnt/windows
  fi
fi

mkdir /mnt/linux

if [ -f /home/partimag/$comptemachine/$imagename/sda1.ext3* ]; then
  if [ -e /dev/sda ]; then
    mount -t ext3 /dev/sda1 /mnt/linux
  elif [ -e /dev/hda ]; then
    mount -t ext3 /dev/hda1 /mnt/linux
  fi
  PLINUX=1
elif [ -f /home/partimag/$comptemachine/$imagename/sda1.ext* ]; then
  if [ -e /dev/sda ]; then
    mount -t ext4 /dev/sda1 /mnt/linux
  elif [ -e /dev/hda ]; then
    mount -t ext4 /dev/hda1 /mnt/linux
  fi
  PLINUX=1
elif [ -f /home/partimag/$comptemachine/$imagename/sda2.ext3* ]; then
  if [ -e /dev/sda ]; then
    mount -t ext3 /dev/sda2 /mnt/linux
  elif [ -e /dev/hda ]; then
    mount -t ext3 /dev/hda2 /mnt/linux
  fi
  PLINUX=2
elif [ -f /home/partimag/$comptemachine/$imagename/sda2.ext* ]; then
  if [ -e /dev/sda ]; then
    mount -t ext4 /dev/sda2 /mnt/linux
  elif [ -e /dev/hda ]; then
    mount -t ext3 /dev/hda2 /mnt/linux
  fi
  PLINUX=2
elif [ -f /home/partimag/$comptemachine/$imagename/sda3.ext3* ]; then
  if [ -e /dev/sda ]; then
    mount -t ext3 /dev/sda3 /mnt/linux
  elif [ -e /dev/hda ]; then
    mount -t ext3 /dev/hda3 /mnt/linux
  fi
  PLINUX=3
elif [ -f /home/partimag/$comptemachine/$imagename/sda3.ext* ]; then
  if [ -e /dev/sda ]; then
    mount -t ext4 /dev/sda3 /mnt/linux
  elif [ -e /dev/hda ]; then
    mount -t ext3 /dev/hda3 /mnt/linux
  fi
  PLINUX=3
elif [ -f /home/partimag/$comptemachine/$imagename/sda4.ext3* ]; then
  if [ -e /dev/sda ]; then
    mount -t ext3 /dev/sda4 /mnt/linux
  elif [ -e /dev/hda ]; then
    mount -t ext3 /dev/hda4 /mnt/linux
  fi
  PLINUX=4
elif [ -f /home/partimag/$comptemachine/$imagename/sda4.ext* ]; then
  if [ -e /dev/sda ]; then
    mount -t ext4 /dev/sda4 /mnt/linux
  elif [ -e /dev/hda ]; then
    mount -t ext3 /dev/hda4 /mnt/linux
  fi
  PLINUX=4
fi
if [ ! -z \"\\\${PLINUX}\" ]; then
  rm -f /mnt/linux/etc/udev/rules.d/*persist*
  if [ -f /mnt/linux/etc/abuledu/wifi ]; then
    rm -f /mnt/linux/etc/abuledu/wifi
  fi
  if [ -f /mnt/linux/etc/abuledu/upgradeversion ]; then
    rm -f /mnt/linux/etc/abuledu/upgradeversion
  fi
  if [ -d /mnt/linux/etc ]; then
    cd /mnt/linux/etc
    cp -a /home/partimag/$comptemachine/$imagename/linux/etc/* .
    sed -i -e s\"%\\\(^root\\\):[^:]*\"%\"\\\\1:\"" . escapeshellarg(escapeshellcmd($sha512pass)) . "% shadow
    cd /mnt/linux/boot/grub
    sed -i -e s%\"^default.*\"%\"default	saved\"% menu.lst
    sed -i -e s%\"savedefault=.*\"%\"savedefault=true\"% menu.lst
    sed -i -e s%\"howmany=.*\"%\"howmany=2\"% menu.lst
    cd /
  fi
  umount /mnt/linux
fi

EOF

chmod +rx /home/machines/" . $comptemachine . "/horizon.postrestaure || true
chmod og+r /home/machines/" . $comptemachine . "/" . $imagename . "/*
chmod +x /home/machines/" . $comptemachine . "/" . $imagename . "/horizon.postrestaure || true
";
	  //On copie les fichiers de conf pour linux ... horizon-autoboot se chargera de faire le boulot suivant
	  //sur le principe identique windows: 1er reboot en filaire et ensuite wifi configuré
	  //attention comme on risque d'avoir oublie le fichier wifi dans certaines maquettes on l'a supprime avant ...
	  $cmd .= "mkdir -p /home/machines/" . $comptemachine . "/" . $imagename . "/linux/etc/" . $metamode . "
chmod 755 /home/machines/" . $comptemachine . "/" . $imagename . "/linux -R
if [ -f /etc/" . $metamode . "/wifi ]; then
  cp -a /etc/" . $metamode . "/wifi /home/machines/" . $comptemachine . "/" . $imagename . "/linux/etc/" . $metamode . "/
  chown root:machines /home/machines/" . $comptemachine . "/" . $imagename . "/linux/etc/" . $metamode . "/wifi
  chmod 640 /home/machines/" . $comptemachine . "/" . $imagename . "/linux/etc/" . $metamode . "/wifi
fi

chown " . $comptemachine . ":machines /home/machines/" . $comptemachine . "/" . $imagename . "/ -R

";
	}
	//ou une image normale
	else {
	  $imagename .= "-" . trim($restaurename);
	}
	
	//Dans tous les cas, si on restaure une image on demande probablement a booter sur le disque local par defaut ?
	$syslinuxfile = "$conf_rep_syslinux/01-" . strtolower(strtr($mac,":","-"));
	$syslinux = "default local
    label local
      kernel chain.c32
      append hd0
";
	
	$syslinuxsymlink = "/home/machines/" . $comptemachine . "/boot.pxe";
	
	$cmd .= "
if [ ! -e $syslinuxsymlink ]; then
   ln $syslinuxfile $syslinuxsymlink
fi";
	
	$cmd .= "
#on ecrase le syslinux dans tous les cas (nouveau ou modif)
echo \"$syslinux\" > $syslinuxfile || true
";
      }
    }
    
    
    $tabconftx["screen_01"] = "startx";
    
    //On desactive le stockage local pour ce poste -> udev et ltsp-device scannent les partitions
    //et ca plante tout pendant la restauration
    $tabconftx["localstorage"] = "N";
    $textelocal .= fixe_tx($tabconftx, $mac, $ip, "", $hostname, 0, 0,"ltsp44");
    $passwordpc = trim(`apg -a1 -m 6 -x 8 -n 1 -M NCL -q 2>&1`);
    //passage en sshfs -> generation d'une cle ssh sans mot de passe (!?!)
    $cmd .= "
if [ -f /home/machines/" . $comptemachine . "/.ssh/id_rsa ]; then
   rm -f /home/machines/" . $comptemachine . "/.ssh/id_rsa*
fi
if [ ! -d /opt/ltsp44/i386/etc/ryxeo/$comptemachine ]; then
  mkdir -p /opt/ltsp44/i386/etc/ryxeo/$comptemachine
fi
if [ ! -f /home/machines/" . $comptemachine . "/.machinepass ]; then
  echo \"" . $passwordpc . "\" > /home/machines/" . $comptemachine . "/.machinepass
  chmod 600 /home/machines/" . $comptemachine . "/.machinepass
  horizon-modify user --login=" . $comptemachine . " --password=" . $passwordpc . " || true
fi
if [ ! -d /home/machines/" . $comptemachine . "/.ssh ]; then
   mkdir /home/machines/" . $comptemachine . "/.ssh
fi

ssh-keygen -t rsa -N '' -f /home/machines/$comptemachine/.ssh/id_rsa
if [ -f /home/machines/" . $comptemachine . "/.ssh/id_rsa ]; then
  cp /home/machines/" . $comptemachine . "/.ssh/id_rsa /opt/ltsp44/i386/etc/ryxeo/" . $comptemachine . "/id_rsa
  cp /home/machines/" . $comptemachine . "/.ssh/id_rsa.pub /opt/ltsp44/i386/etc/ryxeo/" . $comptemachine . "/id_rsa.pub
  cp /home/machines/" . $comptemachine . "/.ssh/id_rsa.pub /home/machines/" . $comptemachine . "/.ssh/authorized_keys
fi

 setfacl -b /home/machines/" . $comptemachine . "/.ssh
 chown $comptemachine /home/machines/" . $comptemachine . "/.ssh -R
 chmod 700 /home/machines/" . $comptemachine . "/.ssh
";
    
    //ajouter si l'utilisateur n'existe pas deja
    $cmd .= "
rm -f /opt/ltsp44/i386/etc/ryxeo/$comptemachine/backup
echo \"" . $comptemachine . ";nesertplusguylarrieudedicace;" . $imagename . "\" > /opt/ltsp44/i386/etc/ryxeo/$comptemachine/backup
chmod 700 /opt/ltsp44/i386/etc/ryxeo/$comptemachine
chmod 600 /opt/ltsp44/i386/etc/ryxeo/$comptemachine/*
chown $comptemachine /opt/ltsp44/i386/etc/ryxeo/$comptemachine -R
";
    
    //Es-ce qu'on est en mode backup ou restaure ?
    $appendopt = " SCREEN_01=" . $action;
    
    $syslinuxfile = "$conf_rep_syslinux/01-" . strtolower(strtr($mac,":","-"));
    $syslinux = make_syslinux_block($computerarch,$tabconftx["appendopt"] . $appendopt, $specialcase, $imagename, $action);

    $cmd .= "
#on copie le syslinux original
if [ -f \"/home/machines/" . $comptemachine . "/boot.pxe\" ]; then
  cp /home/machines/" . $comptemachine . "/boot.pxe /home/machines/" . $comptemachine . "/boot.normal
fi
";
    
    $syslinuxsymlink = "/home/machines/" . $comptemachine . "/boot.pxe";
    
    $cmd .= "
if [ ! -e $syslinuxsymlink ]; then
   ln $syslinuxfile $syslinuxsymlink
fi

#on ecrase le syslinux dans tous les cas (nouveau ou modif)
echo \"$syslinux\" > $syslinuxfile || true

#gestion des droits ad-hoc
chown " . $comptemachine . ":machines /home/machines/" . $comptemachine . "/boot.*
horizon-check user $comptemachine -b
";
    
    fichier_script($cmd,"ltsconf",$textelocal);
  }
  $textelocal .= "<p>" . _("Veuillez redémarrer votre ordinateur en amorçage réseau...") . "</p>\n";
  $textelocal .= "<p><a href=\"./\">" . _("Cliquez ici pour retourner au menu de gestion des postes clients.") . "</a></p>\n";
 }

$textelocal .= "</form>";

$page->addCentralFrame($textelocal);
$page->render();
?>
