source: admin/WebConsole/principal/boot_grub4dos_crear.php @ 5d05b06

Last change on this file since 5d05b06 was 2ab002c2, checked in by Irina Gómez <irinagomez@…>, 6 years ago

#802 #888 When console create template, if in the other type (uefi|bios) exist a template with the same descriptión, uses his file name.

  • Property mode set to 100644
File size: 19.1 KB
Line 
1<?php
2include_once("../includes/ctrlacc.php");
3include_once("../clases/AdoPhp.php");
4include_once("../includes/CreaComando.php");
5include_once("../idiomas/php/".$idioma."/boot_grub4dos_".$idioma.".php");
6
7$cmd=CreaComando($cadenaconexion);
8if (!$cmd)
9        Header('Location: '.$pagerror.'?herror=2'); // Error de conexión con servidor B.D.
10//________________________________________________________________________________________________________
11
12if (isset($_POST["litambito"])) $litambito=$_POST["litambito"]; // Recoge parametros
13if (isset($_POST["idambito"])) $idambito=$_POST["idambito"];
14if (isset($_POST["nombreambito"])) $nombreambito=$_POST["nombreambito"];
15if (isset($_POST["opcion"])) $opcion=$_POST["opcion"];
16if (isset($_POST["opcioncrear"])) $opcioncrear=$_POST["opcioncrear"];
17$boton = isset ($_REQUEST["boton"]) ? $_REQUEST["boton"] : "";
18$confirmado = ($boton == $TbMsg[13] && ($opcioncrear == "crear" || $opcioncrear == "modificar")) ? "1" : "";
19$guarnomb = isset($_POST["nombrenuevoboot"]) ? ucfirst($_POST["nombrenuevoboot"]) : "";
20$admin = isset($_POST["modo"]) ? $_POST["modo"] : "";
21$selectfile = isset($_POST["selectfile"]) ? $_POST["selectfile"] : "";
22$boottype = isset($_POST["boottype"]) ? $_POST["boottype"] : "";
23$dirtemplates= ( $boottype === "uefi" ) ? "/var/lib/tftpboot/grub/templates/"  : "/var/lib/tftpboot/menu.lst/templates/";
24$otrodirtemplates= ( $boottype === "uefi" ) ? "/var/lib/tftpboot/menu.lst/templates/" : "/var/lib/tftpboot/grub/templates/";
25$descripcion = "";
26$modo = "";
27?>
28
29<html>
30<head>
31<TITLE>Administración web de aulas</TITLE>
32
33<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
34        <LINK rel="stylesheet" type="text/css" href="../estilos.css">
35        <SCRIPT language="javascript" src="../jscripts/propiedades_aulas.js"></SCRIPT>
36        <SCRIPT language="javascript" src="../jscripts/opciones.js"></SCRIPT>
37        <SCRIPT language="javascript" src="../jscripts/boot_grub4dos.js"></SCRIPT>
38        <SCRIPT language="javascript" src="../idiomas/javascripts/esp/propiedades_aulas_esp.js"></SCRIPT>
39</head>
40
41<body>
42<P align=center class=cabeceras><?php echo $TbMsg[42]; ?><BR>
43        <SPAN align=center class=subcabeceras> <?php echo $nombreambito; ?> </SPAN></P>
44<?php
45//##################################################################################################################################
46//###########  NUEVO COLUMNA ARRANQUE  #############################################################################################
47//##################################################################################################################################
48
49if ($opcioncrear == "crear")
50        {
51        if ($confirmado == 1)
52                {       
53                        $descripfich=preg_replace("/[^A-Za-z0-9]/", "-", $guarnomb);
54                        $guarnomb=preg_replace("/[^A-Za-z0-9]/", "", $descripfich);
55                        $action="./boot_grub4dos.php";
56
57                        if($guarnomb === "") {
58                                // Mensaje de error si no ha incluido descripción
59                                $action="./boot_grub4dos_crear.php";
60                                $mensaje="<br><br><SPAN align=center class=subcabeceras>".$TbMsg[14]."</span>";
61
62                        } else {
63                                // Nombre archivo: Si para el otro tipo de plantillas existe un fichero con igual descripción uso el nombre.
64                                $nombrenuevoboot=exec("grep -i -m 1 \"^##NO-TOCAR-ESTA-LINEA[[:blank:]]*$descripfich$\" $otrodirtemplates* |awk -F: '{print $1}'");
65                                if (isset($nombrenuevoboot) && $nombrenuevoboot != "") {
66                                        $nombrenuevoboot=basename($nombrenuevoboot);
67                                } else {
68                                        // Nombre archivo: numDescripción
69                                        // número: a todos los números posibles le quito los ya usados y me quedo con el primero
70                                        chdir($dirtemplates);
71                                        $pn=array_map("principio",glob("*"));
72                                        $todos=range(21,99);
73                                        $ultimonumero=current(array_diff($todos,$pn));
74
75                                        $nombrenuevoboot=$ultimonumero.$guarnomb;
76                                }
77
78                                $nuevoboot = $dirtemplates.$nombrenuevoboot;
79
80                                // Comprobamos que no exista
81                                if ( file_exists($nuevoboot)) {
82                                        $mensaje=$TbMsg["ERR_DUPLICADO"]."<br><br><SPAN align=center class=subcabeceras>".$nombrenuevoboot." - '".$guarnomb."' ($boottype)</span>";
83                                } else {
84                                        // Creo plantilla
85                                        $parametrosnuevoboot=$_POST["parametrosnuevoboot"];
86
87                                        $fp = fopen($nuevoboot, "w");
88                                        $string = $TbMsg[22].$descripfich."\n".$parametrosnuevoboot;
89                                        $write = fputs($fp, $string);
90                                        fclose($fp);
91
92                                        $mensaje=$TbMsg[6]."<br><br><SPAN align=center class=subcabeceras>".$descripfich."</span>";
93                                }
94                        }
95                        ?>
96                                                <form name="crearranque" method="post" action="<?php echo $action ?>">
97                                                <input type="hidden" name="confirmado" value="">
98                                                <input type="hidden" name="ultimonumero" value="<?php echo $ultimonumero?>">
99                                                <input type="hidden" name="litambito" value="<?php echo $litambito?>">
100                                                <input type="hidden" name="idambito" value="<?php echo $idambito?>">
101                                                <input type="hidden" name="nombreambito" value="<?php echo $nombreambito?>">
102                                                <input type="hidden" name="opcioncrear" value="crear">
103                                                <input type="hidden" name="boottype" value="<?php echo $boottype ?>">
104                                                <TABLE width="500" align=center border=1 >
105                                                <TR><TD align="center"><br><?php echo $mensaje;?></span><br><br><br>   
106                                                <input type="submit" value="Continuar" name="nuevoarran">
107                                                </TD></TR>
108                                                </TABLE>
109                                                </form>
110<?php }else{
111?>
112
113<form name="crearranque" method="post" action="./boot_grub4dos_crear.php">
114<input type="hidden" name="litambito" value="<?php echo $litambito?>">
115<input type="hidden" name="idambito" value="<?php echo $idambito?>">
116<input type="hidden" name="nombreambito" value="<?php echo $nombreambito?>">
117<input type="hidden" name="boottype" value="<?php echo $boottype ?>">
118<input type="hidden" name="opcioncrear" value="crear">
119<input type="hidden" name="modo" value="1">
120
121<TABLE width="650" align=CENTER border=1 cellPadding=1 cellSpacing=1 class=tabla_datos >
122
123<TR align=center>
124        <TD height="70" colspan="2" valign="middle">
125                <SPAN align=center class=cabeceras> <?php echo $TbMsg[3]?> </SPAN>
126        </TD>
127  </TR>
128<TR align=right>
129        <TD colspan="2" valign="middle">
130
131
132
133        </TD>
134  </TR>
135<TR>
136        <TD width="150" height="10" valign="middle">
137                <SPAN align=center class=subcabeceras><?php echo $TbMsg[12]." ($boottype)"?></SPAN>
138        </TD>
139
140        <TD width="500" height="10" valign="middle">
141                <input type="text" name="nombrenuevoboot" id="textfield" size="25" value="<?php echo $guarnomb ?>">
142        </TD>
143
144</TR>
145<TR>
146        <TD width="150" height="100" valign="middle">
147
148<SPAN align=center class=subcabeceras><?php echo $TbMsg[19]?><br></SPAN>
149<?php
150// Boton utilizar plantilla o no.
151if ($boton == $TbMsg[17]) {
152        echo '<input name=boton type=submit value="'.$TbMsg[18].'">';
153}else{
154        echo '<input name=boton type=submit value="'.$TbMsg[17].'">';
155}
156?>
157        </TD>
158
159        <TD width="500" height="100" valign="middle">
160
161
162        <textarea name="parametrosnuevoboot" id="parametrosnuevoboot" cols="60" rows="12">
163<?php
164if ($boton == $TbMsg[17])
165echo "timeout 3
166title FirstHardDisk-FirstPartition
167keeppxe
168root (hd0,0)
169chainloader (hd0,0)+1
170boot";
171?>
172        </textarea>             
173        </TD>
174</TR>
175<TR>
176        <TD width="150"  valign="middle">
177
178                <input type="submit" name="boton" value="<?php echo $TbMsg[13]?>">
179        </TD>
180
181<TD width="500"  valign="middle">
182                <!-- Cancelar: vuelvo a página de netbootavanzado -->
183                <input type="submit" value="<?php echo $TbMsg[16]?>" onclick='document.forms[0].action="./boot_grub4dos.php";'>
184        </TD>
185</TR>
186</TABLE>
187</form>
188<?php
189//##################################################################################################################################
190//###########  NUEVO COLUMNA ARRANQUE  #############################################################################################
191//##################################################################################################################################
192}}?>
193
194
195<?php
196//##################################################################################################################################
197//###########  MODIFICAR COLUMNA ARRANQUE  #########################################################################################
198//##################################################################################################################################
199if ($opcioncrear == "modificar")
200        {
201        $action="./boot_grub4dos_crear.php";
202        $confirmado=isset($_POST["confirmado"]) ? $_POST["confirmado"] : "";
203        // Realizamos los cambios en el fichero
204        if ($confirmado == 1)
205                {
206                                $modificadescripcion=ucfirst($_POST["modificadescripcion"]);
207                                $descripfich=$modificadescripcion;$descripfich=preg_replace("/[^A-Za-z0-9]/", "-", $descripfich);
208                                $ficherow=$dirtemplates.$_POST["nombrefichero"];//echo $ficherow."<br>";
209                                $parametrosmodifica=$_POST["parametrosmodifica"];
210
211                                if(empty($modificadescripcion)) {
212                                        $mensaje=$TbMsg[14];
213                                }else{
214
215                                $fp = fopen($ficherow, "w");
216                                $string = $TbMsg[22].$descripfich."\n".$parametrosmodifica;
217                                $write = fputs($fp, $string);//Escribe la primera linea
218                                fclose($fp);
219
220                                        $action="./boot_grub4dos.php";
221                                        $mensaje=$TbMsg[7];
222                                }
223                ?>
224                <TABLE width="500" align=center border=1 >
225                <TR><TD align="center"><br><?php echo $mensaje;?><br><br><SPAN align=center class=subcabeceras><?php echo $modificadescripcion;?></span><br><br><br>
226                <form name="crearranque" method="post" action="<?php echo $action ?>">
227                <input type="hidden" name="litambito" value="<?php echo $litambito?>">
228                <input type="hidden" name="idambito" value="<?php echo $idambito?>">
229                <input type="hidden" name="nombreambito" value="<?php echo $nombreambito?>">
230                <input type="hidden" name="confirmado" value="0">
231                <input type="hidden" name="opcioncrear" value="modificar">
232                <input type="hidden" name="modo" value="0">
233                <input type="submit" value="Continuar" name="nuevoarran">
234                </form>
235                </TD></TR>
236                </TABLE>
237<?php
238//#########################################################################
239// MODO USUARIO
240//#########################################################################
241    // Mostramos las plantillas a modificar
242    } else {
243        $select="";
244        $input="";
245        $textoboton="";
246        // No hay plantilla elegida
247        if ($selectfile === "") {
248            // LEYENDO EL DIRECTORIO
249            // /var/lib/tftboot/menu.lst/templates o /var/lib/tftboot/grub/templates
250            chdir($dirtemplates);
251            $pn=glob("*");
252            // ordenamos
253            sort($pn);
254
255            if (empty($admin)) {
256                // Si el modo es usuario eliminamos las plantillas de la instalación
257                unset ($pn[array_search("pxe", $pn)]);
258                foreach ($pn as $key => $valor) {
259                    if (strnatcmp ( $valor , "20" ) > 0) break;
260                    unset($pn[$key]);
261
262                }
263
264                // Botón cambio de modo
265                $textoboton = '         <input type="submit" value='.$TbMsg[11].'  name="nuevoarran" onclick=\'document.forms[0].modo.value=1;\' >'."\n";
266            } else {
267                $textoboton = '         <input type="submit" value='.$TbMsg[10].'  name="nuevoarran" onclick=\'document.forms[0].modo.value=0;\'>'."\n";
268            }
269
270            // Opciones del select
271            $select = '  <select name="selectfile" id="selectfile" onChange="document.actualiza.submit()">'."\n".
272                      '              <option value=""></option>'."\n";
273            foreach ($pn as $valor) {
274                $descripcion=exec("awk 'NR==1 {print $2}' ".$dirtemplates.$valor);
275                $select.= '              <option value='.$valor.'>'.$descripcion.'</option>'."\n";
276            }
277            $select.= '          </select>'."\n";
278
279        // Hay una plantilla seleccionada para modificar
280        } else {
281            $file=$dirtemplates.$selectfile;
282            $descripcion=exec("awk 'NR==1 {print $2}' ".$dirtemplates.$selectfile);
283            $parametros=file_get_contents ($file);
284            // Elimino cabecera anterior
285            $parametros=preg_replace ("/$TbMsg[22].*\n/",'', $parametros);
286
287            // Campos de formulario especificos de esta opción
288            $input .= '<input type="hidden" name="nombrefichero" id="nombrefichero" value="'.$selectfile.'">'."\n".
289                      '<input type="hidden" name="confirmado" value="1" >'."\n";
290        }
291
292// Parte del formulario comun
293?>
294<form name="actualiza" method="post" action="<?php echo $action ?>">
295    <input type="hidden" name="litambito" value="<?php echo $litambito ?>">
296    <input type="hidden" name="idambito" value="<?php echo $idambito ?>">
297    <input type="hidden" name="nombreambito" value="<?php echo $nombreambito ?>">
298    <input type="hidden" name="opcioncrear" value="modificar">
299    <input type="hidden" name="boottype" value="<?php echo $boottype ?>">
300    <input type="hidden" name="modo" value="<?php echo $modo ?>">
301    <?php echo  $input;
302
303    // Cabecera de la tabla ?>
304    <table width="850" align="center" border="1" cellPadding="1" cellSpacing="1" class="tabla_datos" >
305      <tr>
306        <td height="70" colspan="3" valign="middle"><p align=center class=cabeceras><?php echo $TbMsg[4] ?></p>
307        <?php echo $textoboton ?>
308      </tr>
309   
310      <?php  // Lista de selección de plantillas
311        if ($selectfile === "") { ?>
312
313      <tr>
314        <td height="10" colspan="2" valign="middle"><span align=center class=subcabeceras><?php echo $TbMsg[9]." (".$boottype.")" ?></span></td>
315        <td height="10" valign="middle" align="right">
316        <?php echo $select ?>
317        </td>
318      </tr>
319   
320      <?php // Formulario con datos de la plantilla a cambiar
321        } else { ?>
322
323      <tr>
324        <td height="10" valign="middle">
325            <SPAN align=center class=subcabeceras><?php echo $TbMsg[21]." (".$boottype.")" ?></SPAN>
326        </td>
327        <td width="249" height="10" valign="middle"><?php echo $selectfile ?></td>
328        <td width="100" valign="middle" align="right">
329            <span align=center class=subcabeceras><?php echo $TbMsg[12] ?></span>
330            <input type="text" name="modificadescripcion" id="modificadescripcion" size="25" value="<?php echo $descripcion ?>">
331        </td>
332      </tr>
333      <tr>
334        <td width="500" height="100" valign="middle"> <span align=center class=subcabeceras><?php echo $TbMsg[19] ?></span></td>
335        <td width="500" height="100" colspan="2" valign="middle">
336            <textarea name="parametrosmodifica" id="parametrosmodifica" cols="95" rows="17"><?php echo $parametros ?></textarea>
337        </td>
338      </tr>
339      <tr>
340        <td width="500"  valign="middle"><input type="submit" value="<?php echo $TbMsg[13] ?>" name="nuevoarran"></td>
341        <td width="500" colspan="2"  valign="middle"><input type="submit" value="<?php echo $TbMsg[16] ?>" name="nuevoarran"  onclick='document.forms[0].action="./boot_grub4dos.php";'>
342      <tr>
343   
344       <?php  }
345        // Final pagina ?>
346    </table>
347</form>
348
349    <?php
350    }
351//##################################################################################################################################
352//###########  MODIFICAR COLUMNA ARRANQUE  #########################################################################################
353//##################################################################################################################################
354}
355
356
357//##################################################################################################################################
358//###########  ELIMINAR COLUMNA ARRANQUE  ##########################################################################################
359//##################################################################################################################################
360
361if ($opcioncrear == "eliminar" )
362        {
363        $confirmado=isset($_POST["confirmado"]) ? $_POST["confirmado"] : "";
364        if ($confirmado == 1)
365                {
366                        $eliminafichero=$_POST["eliminafichero"];
367                        $resul=actualizaequipos($cmd,$eliminafichero);
368                        $fichero = $dirtemplates.$eliminafichero;
369                        unlink($fichero);
370
371                ?>
372                <TABLE width="500" align=center border=1 >
373                <TR><TD align="center"><br><?php if($eliminafichero != null) echo $TbMsg[8];?><br><br><SPAN align=center class=subcabeceras><?php echo substr($eliminafichero,2)." (".$boottype.")"; ?></span><br><br><br>
374                <form name="crearranque" method="post" action="./boot_grub4dos.php">
375                <input type="hidden" name="litambito" value="<?php echo $litambito?>">
376                <input type="hidden" name="idambito" value="<?php echo $idambito?>">
377                <input type="hidden" name="nombreambito" value="<?php echo $nombreambito?>">
378                <input type="submit" value="Continuar" name="nuevoarran">
379                </form>
380                </TD></TR>
381</TABLE>
382
383                <?php }else{
384?>
385<?php
386//#########################################################################
387// LEYENDO EL DIRECTORIO
388// /var/lib/tftboot/menu.lst/templates o /var/lib/tftpboot/grub/templates/
389//#########################################################################
390//$dirtemplates= "/var/lib/tftpboot/menu.lst/templates/";
391chdir($dirtemplates);
392
393$pn=glob("*");//pila de nombres
394// No mostramos archivo pxe
395unset($pn[array_search("pxe", $pn)]);
396//ordenar las pilas segun la pila de nombres
397sort($pn);
398?>
399
400<form name="eliminaarranque" method="post" action="./boot_grub4dos_crear.php">
401<input type="hidden" name="litambito" value="<?php echo $litambito?>">
402<input type="hidden" name="idambito" value="<?php echo $idambito?>">
403<input type="hidden" name="nombreambito" value="<?php echo $nombreambito?>">
404<input type="hidden" name="confirmado" value="1">
405<input type="hidden" name="opcioncrear" value="eliminar">
406<input type="hidden" name="boottype" value="<?php echo $boottype ?>">
407<TABLE width="650" align=CENTER border=1 cellPadding=1 cellSpacing=1 class=tabla_datos >
408<TR align=center>
409        <TD height="70" colspan="2" valign="middle">
410                <SPAN align=center class=cabeceras> <?php echo $TbMsg[5]?> </SPAN>
411        </TD>
412  </TR>
413<TR>
414        <TD width="150" height="10" valign="middle">
415                <SPAN align=center class=subcabeceras><?php echo $TbMsg[12]." (".$boottype.")" ?></SPAN>
416        </TD>
417
418        <TD width="500" height="10" valign="middle">
419          <select name="eliminafichero" id="eliminafichero">
420        <?php
421                for ($z=0;$z<count($pn);$z++)
422                {
423                // Sólo se pueden borrar plantillas que empiecen >19
424                if((substr($pn[$z],0,2)) > 19)
425                        {
426                        $description=exec("awk 'NR==1 {print $2}' ".$dirtemplates.$pn[$z]);
427                        echo '<option value='.$pn[$z].'>'.$description.'</option>';
428                        }
429                }
430        ?>   
431      </select>
432        </TD>
433</TR>
434
435<TR>
436        <TD width="150"  valign="middle">
437                <input type="submit" value="<?php echo $TbMsg[13]?>" name="nuevoarra">
438               
439        </TD>
440
441        <TD width="500"  valign="middle">
442                <input type="submit" value="<?php echo $TbMsg[16]?>" name="nuevoarran" onclick='document.forms[0].action="./boot_grub4dos.php";'>
443        </TD>
444</TR>
445</TABLE>
446</form>
447<?php
448//##################################################################################################################################
449//###########  ELIMINAR COLUMNA ARRANQUE  ##########################################################################################
450//##################################################################################################################################
451}}?>
452
453</body>
454</html>
455
456<?php
457// Los equipos que tienen asignada la plantilla a eliminar se actualizan con el valor desconocido.
458// cmd: manejador de la base de datos
459// eliminafichero: plantilla a eliminar
460function actualizaequipos($cmd,$eliminafichero) {
461        $nombrefich="00unknown";
462        $cmd->texto="UPDATE ordenadores SET arranque='".$nombrefich."' WHERE arranque='".$eliminafichero."';";
463        $resul=$cmd->Ejecutar();
464        return $resul;
465}
466
467// Extrae los dos primeros caracteres de una cadena
468function principio($valor) {
469    return substr($valor,0,2);
470}
471?>
472
Note: See TracBrowser for help on using the repository browser.