source: admin/WebConsole/gestores/gestor_pxe.php @ cd95622

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-instalacionwebconsole3
Last change on this file since cd95622 was ea5fbb9, checked in by adv <adv@…>, 14 years ago

version 1.0.2 #423 netboot servicios distribuidos

git-svn-id: https://opengnsys.es/svn/branches/version1.0@2112 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100644
File size: 5.3 KB
Line 
1<?php
2include_once("../includes/ctrlacc.php");
3include_once("../clases/AdoPhp.php");
4include_once("../clases/XmlPhp.php");
5include_once("../clases/MenuContextual.php");
6include_once("../clases/SockHidra.php");
7include_once("../includes/constantes.php");
8include_once("../includes/comunes.php");
9include_once("../includes/CreaComando.php");
10include_once("../idiomas/php/".$idioma."/aulas_".$idioma.".php");
11
12$cmd=CreaComando($cadenaconexion);
13if (!$cmd)
14        Header('Location: '.$pagerror.'?herror=2'); // Error de conexión con servidor B.D.
15//________________________________________________________________________________________________________
16
17
18echo "<html>";
19echo "<head>";
20echo "<meta http-equiv='Refresh' content='1;URL=../principal/boot.php?idambito=". $_GET['idaula'] ."&nombreambito=" . $_GET['nombreambito'] . "&litambito=" . $_GET['litambito'] . "'>";
21echo "<title> gestion de equipos </title>";
22echo "<base target='principal'>";
23echo "</head>";
24echo "<body>";
25
26
27
28#echo('litambito con valor:     '. $_GET['litambito']);
29#echo ('idambito con valor:      ' . $_GET['idaula']);
30#echo ('nombreambito con valor:      ' . $_GET['nombreambito']);
31
32$lista = explode(";",$_POST['listOfItems']);
33foreach ($lista as $sublista) {
34        $elementos = explode("|",$sublista);
35        $hostname=$elementos[1];
36        $optboot=$elementos[0];
37        ogBootServer($cmd,$optboot,$hostname);
38}
39echo " </body>";
40echo " </html> ";
41
42function ogBootServer($cmd,$optboot,$hostname)
43{       
44global $cmd;
45global $hostname;
46global $optboot;
47$cmd->CreaParametro("@optboot",$optboot,0);
48$cmd->CreaParametro("@hostname",$hostname,0);
49$cmd->texto="update ordenadores set arranque=@optboot where nombreordenador=@hostname";
50$cmd->Ejecutar();
51
52$cmd->texto="SELECT ordenadores.ip AS ip, ordenadores.mac AS mac,
53                        ordenadores.netiface AS netiface, aulas.netmask AS netmask, aulas.router AS router,
54                        repositorios.ip AS iprepo FROM ordenadores
55                        join aulas on ordenadores.idaula=aulas.idaula
56                        join repositorios on ordenadores.idrepositorio=repositorios.idrepositorio
57                        where ordenadores.nombreordenador='". $hostname ."'";
58$rs=new Recordset;
59$rs->Comando=&$cmd;
60if (!$rs->Abrir()) echo "error";
61$rs->Primero();
62        $mac=$rs->campos["mac"];
63        $netiface=$rs->campos["netiface"];
64        $ip=$rs->campos["ip"];
65        $router=$rs->campos["router"];
66        $netmask=$rs->campos["netmask"];
67        $repo=$rs->campos["iprepo"];                   
68$rs->Cerrar();
69
70$cmd->texto="SELECT ipserveradm from entornos";
71$rs=new Recordset;
72$rs->Comando=&$cmd;
73if (!$rs->Abrir()) echo "error";
74
75$rs->Primero();
76        $server=$rs->campos["ipserveradm"];
77$rs->Cerrar();
78
79$infohost=" ip="
80. $ip . ":"
81. $server .":"
82. $router . ":"
83. $netmask .":"
84. $hostname .":"
85. $netiface . ":none ogrepo="
86. $repo;
87
88###################obtenemos las variables de red del aula.
89
90        #02.1 obtenemos nombre fichero mac
91        $mac=  substr($mac,0,2) . ":" . substr($mac,2,2) . ":" . substr($mac,4,2) . ":" . substr($mac,6,2) . ":" . substr($mac,8,2) . ":" . substr($mac,10,2);
92        $macfile="01-" . str_replace(":","-",strtolower($mac));
93        $nombre_archivo="/var/lib/tftpboot/pxelinux.cfg/" . $macfile;
94
95
96########## Escribimos el fichero mac
97if (!$gestion=fopen($nombre_archivo, 'w+'))
98{
99        echo "No se puede abrir el archivo ($nombre_archivo)";
100        return;
101}       
102# cuales son los parametros del menu
103fwrite($gestion, "DEFAULT syslinux/vesamenu.c32 \n");
104fwrite($gestion, "MENU TITLE Aplicacion OpenGnsys \n");
105
106$cmd->texto="SELECT itemboot.label, itemboot.kernel,
107                        itemboot.append, menuboot.timeout, menuboot.prompt,
108                         menuboot.description, menuboot_itemboot.default
109                        From itemboot,menuboot_itemboot,menuboot
110                        WHERE menuboot_itemboot.labelmenu=menuboot.label
111                        AND menuboot_itemboot.labelitem=itemboot.label
112                        AND menuboot.label='" . $optboot   . "'";
113 
114$rs->Comando=&$cmd;
115if (!$rs->Abrir()) echo "error";
116$rs->Primero();
117while (!$rs->EOF)
118{
119                fwrite($gestion, " \n");     
120                fwrite($gestion, "LABEL " .  $rs->campos['label'] . " \n");
121                fwrite($gestion, "MENU LABEL " . $rs->campos['label'] . " \n");
122                if ( $rs->campos["default"] == true)
123                {
124                        fwrite($gestion, "MENU DEFAULT \n");
125                }
126                fwrite($gestion, $rs->campos["kernel"] . " \n");
127                # set netmask cird para ogclient
128                $isnfsroot=substr_count($rs->campos["append"] , "boot=oginit");
129                if ($isnfsroot > 0)
130                {
131                        $netmask=$netmask;
132                }       
133                else
134                {
135                        $netmask=netmask2cidr($netmask);
136                }
137
138                $iseac=substr_count($rs->campos["append"] , "boot=oginit");
139                $isinitrd=substr_count($rs->campos["append"] , "initrd.gz");
140               
141                if ($iseac > 0)
142                {
143                        $append=$rs->campos["append"];
144                        fwrite($gestion, $append . " " . $infohost . " \n ");
145                }
146
147                elseif ($isinitrd > 0)
148                {
149                $append=$rs->campos["append"];
150                fwrite($gestion, $append . " ogrepo=" . $repo . " \n");
151                }
152                else
153                {
154                        fwrite($gestion, $rs->campos["append"] . " \n");
155                }
156
157                $prompt=$rs->campos["prompt"];
158                $timeout=$rs->campos["timeout"];
159
160                $rs->Siguiente();
161}
162$rs->Cerrar();
163
164                       
165
166        fwrite($gestion, " \n"); 
167        fwrite($gestion, "PROMPT " . $prompt ." \n");
168        fwrite($gestion, "TIMEOUT " . $timeout . " \n");
169        fwrite($gestion, " \n"); 
170        fclose($gestion);
171        exec("chown www-data:www-data /var/lib/tftpboot/pxelinux.cfg/". $macfile);
172        exec("chmod 777 /var/lib/tftpboot/pxelinux.cfg/". $macfile);
173       
174
175
176
177}
178
179function netmask2cidr($netmask) {
180          $cidr = 0;
181          foreach (explode('.', $netmask) as $number) {
182              for (;$number> 0; $number = ($number <<1) % 256) {
183                  $cidr++;
184               }
185           }
186           return $cidr;
187 }
188
189?>
Note: See TracBrowser for help on using the repository browser.