1 | <?php |
---|
2 | include_once("../includes/ctrlacc.php"); |
---|
3 | include_once("../clases/AdoPhp.php"); |
---|
4 | include_once("../clases/XmlPhp.php"); |
---|
5 | include_once("../clases/MenuContextual.php"); |
---|
6 | include_once("../clases/SockHidra.php"); |
---|
7 | include_once("../includes/constantes.php"); |
---|
8 | include_once("../includes/comunes.php"); |
---|
9 | include_once("../includes/CreaComando.php"); |
---|
10 | include_once("../idiomas/php/".$idioma."/aulas_".$idioma.".php"); |
---|
11 | |
---|
12 | $cmd=CreaComando($cadenaconexion); |
---|
13 | if (!$cmd) |
---|
14 | Header('Location: '.$pagerror.'?herror=2'); // Error de conexión con servidor B.D. |
---|
15 | //________________________________________________________________________________________________________ |
---|
16 | |
---|
17 | |
---|
18 | echo "<html>"; |
---|
19 | echo "<head>"; |
---|
20 | echo "<meta http-equiv='Refresh' content='1;URL=../principal/boot.php?idambito=". $_GET['idaula'] ."&nombreambito=" . $_GET['nombreambito'] . "&litambito=" . $_GET['litambito'] . "'>"; |
---|
21 | echo "<title> gestion de equipos </title>"; |
---|
22 | echo "<base target='principal'>"; |
---|
23 | echo "</head>"; |
---|
24 | echo "<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']); |
---|
33 | foreach ($lista as $sublista) { |
---|
34 | $elementos = explode("|",$sublista); |
---|
35 | $hostname=$elementos[1]; |
---|
36 | $optboot=$elementos[0]; |
---|
37 | ogBootServer($cmd,$optboot,$hostname); |
---|
38 | } |
---|
39 | echo " </body>"; |
---|
40 | echo " </html> "; |
---|
41 | |
---|
42 | function ogBootServer($cmd,$optboot,$hostname) |
---|
43 | { |
---|
44 | global $cmd; |
---|
45 | global $hostname; |
---|
46 | global $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; |
---|
60 | if (!$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; |
---|
73 | if (!$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 |
---|
97 | if (!$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 |
---|
103 | fwrite($gestion, "DEFAULT syslinux/vesamenu.c32 \n"); |
---|
104 | fwrite($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; |
---|
115 | if (!$rs->Abrir()) echo "error"; |
---|
116 | $rs->Primero(); |
---|
117 | while (!$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 | |
---|
179 | function 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 | ?> |
---|