source: admin/WebConsole/principal/boot_grub4dos_crear.php @ 8c88e08

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Last change on this file since 8c88e08 was 8c88e08, checked in by Irina Gómez <irinagomez@…>, 6 years ago

#802 #888 Console: in management of NetBootAvanzado? can use bios and uefi templates.

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