| 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,$idioma); |
|---|
| 38 | } |
|---|
| 39 | echo " </body>"; |
|---|
| 40 | echo " </html> "; |
|---|
| 41 | |
|---|
| 42 | function ogBootServer($cmd,$optboot,$hostname,$idioma) |
|---|
| 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, |
|---|
| 54 | aulas.router AS router, repositorios.ip AS iprepo, |
|---|
| 55 | aulas.nombreaula AS grupo, |
|---|
| 56 | menus.resolucion AS vga |
|---|
| 57 | FROM ordenadores |
|---|
| 58 | JOIN aulas ON ordenadores.idaula=aulas.idaula |
|---|
| 59 | JOIN repositorios ON ordenadores.idrepositorio=repositorios.idrepositorio |
|---|
| 60 | LEFT JOIN menus ON ordenadores.idmenu=menus.idmenu |
|---|
| 61 | WHERE ordenadores.nombreordenador='". $hostname ."'"; |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | $rs=new Recordset; |
|---|
| 65 | $rs->Comando=&$cmd; |
|---|
| 66 | if (!$rs->Abrir()) echo "error"; |
|---|
| 67 | $rs->Primero(); |
|---|
| 68 | $mac=$rs->campos["mac"]; |
|---|
| 69 | $netiface=$rs->campos["netiface"]; |
|---|
| 70 | $ip=$rs->campos["ip"]; |
|---|
| 71 | $router=$rs->campos["router"]; |
|---|
| 72 | $netmask=$rs->campos["netmask"]; |
|---|
| 73 | $repo=$rs->campos["iprepo"]; |
|---|
| 74 | $group=cleanString($rs->campos["grupo"]); |
|---|
| 75 | if($rs->campos["vga"]== null) |
|---|
| 76 | $vga="788"; |
|---|
| 77 | else |
|---|
| 78 | $vga=$rs->campos["vga"]; |
|---|
| 79 | |
|---|
| 80 | $rs->Cerrar(); |
|---|
| 81 | |
|---|
| 82 | $cmd->texto="SELECT ipserveradm from entornos"; |
|---|
| 83 | $rs=new Recordset; |
|---|
| 84 | $rs->Comando=&$cmd; |
|---|
| 85 | if (!$rs->Abrir()) echo "error"; |
|---|
| 86 | |
|---|
| 87 | $rs->Primero(); |
|---|
| 88 | $server=$rs->campos["ipserveradm"]; |
|---|
| 89 | $rs->Cerrar(); |
|---|
| 90 | |
|---|
| 91 | switch ($idioma) { |
|---|
| 92 | case eng: |
|---|
| 93 | $idioma=en_GB; |
|---|
| 94 | break; |
|---|
| 95 | case esp: |
|---|
| 96 | $idioma=es_ES; |
|---|
| 97 | break; |
|---|
| 98 | case cat: |
|---|
| 99 | $idioma=ca_ES; |
|---|
| 100 | break; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | $infohost="vga=$vga ". |
|---|
| 105 | "LANG=$idioma ". |
|---|
| 106 | "ip=$ip:$server:$router:$netmask:$hostname:$netiface:none" . |
|---|
| 107 | " group=$group" . |
|---|
| 108 | " ogrepo=$repo" . |
|---|
| 109 | " oglive=$repo" . |
|---|
| 110 | " oglog=$server" . |
|---|
| 111 | " ogshare=$server"; |
|---|
| 112 | |
|---|
| 113 | ###################obtenemos las variables de red del aula. |
|---|
| 114 | |
|---|
| 115 | #02.1 obtenemos nombre fichero mac |
|---|
| 116 | $pxedir="/opt/opengnsys/tftpboot/pxelinux.cfg"; |
|---|
| 117 | $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); |
|---|
| 118 | $macfile="$pxedir/01-" . str_replace(":","-",strtolower($mac)); |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | ########## Escribimos el fichero mac |
|---|
| 122 | if (!$gestion=fopen($macfile, 'w+')) |
|---|
| 123 | { |
|---|
| 124 | echo "No se puede abrir el archivo ($macfile)"; |
|---|
| 125 | return; |
|---|
| 126 | } |
|---|
| 127 | # cuales son los parametros del menu |
|---|
| 128 | fwrite($gestion, "DEFAULT syslinux/vesamenu.c32 \n"); |
|---|
| 129 | fwrite($gestion, "MENU TITLE Aplicacion OpenGnsys \n"); |
|---|
| 130 | |
|---|
| 131 | $cmd->texto="SELECT itemboot.label, itemboot.kernel, |
|---|
| 132 | itemboot.append, menuboot.timeout, menuboot.prompt, |
|---|
| 133 | menuboot.description, menuboot_itemboot.default |
|---|
| 134 | From itemboot,menuboot_itemboot,menuboot |
|---|
| 135 | WHERE menuboot_itemboot.labelmenu=menuboot.label |
|---|
| 136 | AND menuboot_itemboot.labelitem=itemboot.label |
|---|
| 137 | AND menuboot.label='" . $optboot . "'"; |
|---|
| 138 | |
|---|
| 139 | $rs->Comando=&$cmd; |
|---|
| 140 | if (!$rs->Abrir()) echo "error"; |
|---|
| 141 | $rs->Primero(); |
|---|
| 142 | while (!$rs->EOF) |
|---|
| 143 | { |
|---|
| 144 | fwrite($gestion, " \n"); |
|---|
| 145 | fwrite($gestion, "LABEL " . $rs->campos['label'] . " \n"); |
|---|
| 146 | fwrite($gestion, "MENU LABEL " . $rs->campos['label'] . " \n"); |
|---|
| 147 | if ( $rs->campos["default"] == true) |
|---|
| 148 | { |
|---|
| 149 | fwrite($gestion, "MENU DEFAULT \n"); |
|---|
| 150 | } |
|---|
| 151 | fwrite($gestion, $rs->campos["kernel"] . " \n"); |
|---|
| 152 | # set netmask cird para ogclient |
|---|
| 153 | $isnfsroot=substr_count($rs->campos["append"] , "boot=oginit"); |
|---|
| 154 | if ($isnfsroot > 0) |
|---|
| 155 | { |
|---|
| 156 | $netmask=$netmask; |
|---|
| 157 | } |
|---|
| 158 | else |
|---|
| 159 | { |
|---|
| 160 | $netmask=netmask2cidr($netmask); |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | $iseac=substr_count($rs->campos["append"] , "boot=oginit"); |
|---|
| 164 | $isinitrd=substr_count($rs->campos["append"] , "initrd.gz"); |
|---|
| 165 | |
|---|
| 166 | // delete vga value (included in the variable infohost) |
|---|
| 167 | // borramos valor vga (incluido en la variable infohost) |
|---|
| 168 | $append=preg_replace('/vga=.../','',$rs->campos["append"]); |
|---|
| 169 | if ($iseac > 0) |
|---|
| 170 | { |
|---|
| 171 | fwrite($gestion, $append . " " . $infohost . " \n "); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | elseif ($isinitrd > 0) |
|---|
| 175 | { |
|---|
| 176 | fwrite($gestion, $append . " ogrepo=" . $repo . " \n"); |
|---|
| 177 | } |
|---|
| 178 | else |
|---|
| 179 | { |
|---|
| 180 | fwrite($gestion, $append . " \n"); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | $prompt=$rs->campos["prompt"]; |
|---|
| 184 | $timeout=$rs->campos["timeout"]; |
|---|
| 185 | |
|---|
| 186 | $rs->Siguiente(); |
|---|
| 187 | } |
|---|
| 188 | $rs->Cerrar(); |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | fwrite($gestion, " \n"); |
|---|
| 192 | fwrite($gestion, "PROMPT " . $prompt ." \n"); |
|---|
| 193 | fwrite($gestion, "TIMEOUT " . $timeout . " \n"); |
|---|
| 194 | fwrite($gestion, " \n"); |
|---|
| 195 | fclose($gestion); |
|---|
| 196 | exec("chmod 777 $macfile"); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | function netmask2cidr($netmask) { |
|---|
| 200 | $cidr = 0; |
|---|
| 201 | foreach (explode('.', $netmask) as $number) { |
|---|
| 202 | for (;$number> 0; $number = ($number <<1) % 256) { |
|---|
| 203 | $cidr++; |
|---|
| 204 | } |
|---|
| 205 | } |
|---|
| 206 | return $cidr; |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | // Sustituye espacio por "_" y quita acentos y tildes. |
|---|
| 210 | function cleanString ($cadena) { |
|---|
| 211 | $patron = array ('/ /','/á/','/é/','/í/','/ó/','/ú/','/ñ/','/Á/','/É/','/Í/','/Ó/','/Ú/','/Ñ/'); |
|---|
| 212 | $reemplazo = array ('_','a','e','i','o','u','n','A','E','I','O','U','N'); |
|---|
| 213 | return preg_replace($patron,$reemplazo,$cadena); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | ?> |
|---|