[58d08a2] | 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("../includes/constantes.php"); |
---|
| 7 | include_once("../includes/comunes.php"); |
---|
| 8 | include_once("../includes/CreaComando.php"); |
---|
| 9 | include_once("../idiomas/php/".$idioma."/aulas_".$idioma.".php"); |
---|
| 10 | |
---|
| 11 | $cmd=CreaComando($cadenaconexion); |
---|
| 12 | if (!$cmd) |
---|
| 13 | Header('Location: '.$pagerror.'?herror=2'); // Error de conexión con servidor B.D. |
---|
| 14 | //________________________________________________________________________________________________________ |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | echo "<html>"; |
---|
| 18 | echo "<head>"; |
---|
| 19 | echo "<meta http-equiv='Refresh' content='1;URL=../principal/boot.php?idambito=". $_GET['idaula'] ."&nombreambito=" . $_GET['nombreambito'] . "&litambito=" . $_GET['litambito'] . "'>"; |
---|
| 20 | echo "<title> gestion de equipos </title>"; |
---|
| 21 | echo "<base target='principal'>"; |
---|
| 22 | echo "</head>"; |
---|
| 23 | echo "<body>"; |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | #echo('litambito con valor: '. $_GET['litambito']); |
---|
| 28 | #echo ('idambito con valor: ' . $_GET['idaula']); |
---|
| 29 | #echo ('nombreambito con valor: ' . $_GET['nombreambito']); |
---|
| 30 | |
---|
| 31 | $lista = explode(";",$_POST['listOfItems']); |
---|
| 32 | foreach ($lista as $sublista) { |
---|
| 33 | $elementos = explode("|",$sublista); |
---|
| 34 | $hostname=$elementos[1]; |
---|
| 35 | $optboot=$elementos[0]; |
---|
[eaf2e6e] | 36 | ogBootServer($cmd,$optboot,$hostname,$idioma); |
---|
[58d08a2] | 37 | } |
---|
| 38 | echo " </body>"; |
---|
| 39 | echo " </html> "; |
---|
| 40 | |
---|
[eaf2e6e] | 41 | function ogBootServer($cmd,$optboot,$hostname,$idioma) |
---|
[58d08a2] | 42 | { |
---|
| 43 | global $cmd; |
---|
| 44 | global $hostname; |
---|
| 45 | global $optboot; |
---|
| 46 | $cmd->CreaParametro("@optboot",$optboot,0); |
---|
| 47 | $cmd->CreaParametro("@hostname",$hostname,0); |
---|
| 48 | $cmd->texto="update ordenadores set arranque=@optboot where nombreordenador=@hostname"; |
---|
| 49 | $cmd->Ejecutar(); |
---|
| 50 | |
---|
| 51 | $cmd->texto="SELECT ordenadores.ip AS ip, ordenadores.mac AS mac, |
---|
[5bac736] | 52 | ordenadores.netiface AS netiface, aulas.netmask AS netmask, |
---|
| 53 | aulas.router AS router, repositorios.ip AS iprepo, |
---|
| 54 | aulas.nombreaula AS grupo, |
---|
| 55 | menus.resolucion AS vga |
---|
| 56 | FROM ordenadores |
---|
| 57 | JOIN aulas ON ordenadores.idaula=aulas.idaula |
---|
| 58 | JOIN repositorios ON ordenadores.idrepositorio=repositorios.idrepositorio |
---|
| 59 | LEFT JOIN menus ON ordenadores.idmenu=menus.idmenu |
---|
| 60 | WHERE ordenadores.nombreordenador='". $hostname ."'"; |
---|
| 61 | |
---|
| 62 | |
---|
[58d08a2] | 63 | $rs=new Recordset; |
---|
| 64 | $rs->Comando=&$cmd; |
---|
| 65 | if (!$rs->Abrir()) echo "error"; |
---|
| 66 | $rs->Primero(); |
---|
| 67 | $mac=$rs->campos["mac"]; |
---|
| 68 | $netiface=$rs->campos["netiface"]; |
---|
| 69 | $ip=$rs->campos["ip"]; |
---|
| 70 | $router=$rs->campos["router"]; |
---|
| 71 | $netmask=$rs->campos["netmask"]; |
---|
| 72 | $repo=$rs->campos["iprepo"]; |
---|
[5bac736] | 73 | $group=cleanString($rs->campos["grupo"]); |
---|
| 74 | if($rs->campos["vga"]== null) |
---|
| 75 | $vga="788"; |
---|
| 76 | else |
---|
| 77 | $vga=$rs->campos["vga"]; |
---|
| 78 | |
---|
[58d08a2] | 79 | $rs->Cerrar(); |
---|
| 80 | |
---|
[ea5fbb9] | 81 | $cmd->texto="SELECT ipserveradm from entornos"; |
---|
| 82 | $rs=new Recordset; |
---|
| 83 | $rs->Comando=&$cmd; |
---|
| 84 | if (!$rs->Abrir()) echo "error"; |
---|
| 85 | |
---|
| 86 | $rs->Primero(); |
---|
| 87 | $server=$rs->campos["ipserveradm"]; |
---|
| 88 | $rs->Cerrar(); |
---|
| 89 | |
---|
[eaf2e6e] | 90 | switch ($idioma) { |
---|
| 91 | case eng: |
---|
| 92 | $idioma=en_GB; |
---|
| 93 | break; |
---|
| 94 | case esp: |
---|
| 95 | $idioma=es_ES; |
---|
| 96 | break; |
---|
| 97 | case cat: |
---|
[09468cb] | 98 | $idioma=ca_ES; |
---|
[eaf2e6e] | 99 | break; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | |
---|
[5bac736] | 103 | $infohost="vga=$vga ". |
---|
| 104 | "LANG=$idioma ". |
---|
| 105 | "ip=$ip:$server:$router:$netmask:$hostname:$netiface:none" . |
---|
| 106 | " group=$group" . |
---|
| 107 | " ogrepo=$repo" . |
---|
| 108 | " oglive=$repo" . |
---|
| 109 | " oglog=$server" . |
---|
| 110 | " ogshare=$server"; |
---|
[ea5fbb9] | 111 | |
---|
[58d08a2] | 112 | ###################obtenemos las variables de red del aula. |
---|
| 113 | |
---|
| 114 | #02.1 obtenemos nombre fichero mac |
---|
[5bac736] | 115 | $pxedir="/opt/opengnsys/tftpboot/pxelinux.cfg"; |
---|
[58d08a2] | 116 | $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); |
---|
[5bac736] | 117 | $macfile="$pxedir/01-" . str_replace(":","-",strtolower($mac)); |
---|
[58d08a2] | 118 | |
---|
| 119 | |
---|
| 120 | ########## Escribimos el fichero mac |
---|
[5bac736] | 121 | if (!$gestion=fopen($macfile, 'w+')) |
---|
[58d08a2] | 122 | { |
---|
[5bac736] | 123 | echo "No se puede abrir el archivo ($macfile)"; |
---|
[58d08a2] | 124 | return; |
---|
| 125 | } |
---|
| 126 | # cuales son los parametros del menu |
---|
| 127 | fwrite($gestion, "DEFAULT syslinux/vesamenu.c32 \n"); |
---|
| 128 | fwrite($gestion, "MENU TITLE Aplicacion OpenGnsys \n"); |
---|
| 129 | |
---|
| 130 | $cmd->texto="SELECT itemboot.label, itemboot.kernel, |
---|
| 131 | itemboot.append, menuboot.timeout, menuboot.prompt, |
---|
| 132 | menuboot.description, menuboot_itemboot.default |
---|
| 133 | From itemboot,menuboot_itemboot,menuboot |
---|
| 134 | WHERE menuboot_itemboot.labelmenu=menuboot.label |
---|
| 135 | AND menuboot_itemboot.labelitem=itemboot.label |
---|
| 136 | AND menuboot.label='" . $optboot . "'"; |
---|
| 137 | |
---|
| 138 | $rs->Comando=&$cmd; |
---|
| 139 | if (!$rs->Abrir()) echo "error"; |
---|
| 140 | $rs->Primero(); |
---|
| 141 | while (!$rs->EOF) |
---|
| 142 | { |
---|
| 143 | fwrite($gestion, " \n"); |
---|
| 144 | fwrite($gestion, "LABEL " . $rs->campos['label'] . " \n"); |
---|
| 145 | fwrite($gestion, "MENU LABEL " . $rs->campos['label'] . " \n"); |
---|
| 146 | if ( $rs->campos["default"] == true) |
---|
| 147 | { |
---|
| 148 | fwrite($gestion, "MENU DEFAULT \n"); |
---|
| 149 | } |
---|
| 150 | fwrite($gestion, $rs->campos["kernel"] . " \n"); |
---|
| 151 | # set netmask cird para ogclient |
---|
| 152 | $isnfsroot=substr_count($rs->campos["append"] , "boot=oginit"); |
---|
| 153 | if ($isnfsroot > 0) |
---|
| 154 | { |
---|
| 155 | $netmask=$netmask; |
---|
| 156 | } |
---|
| 157 | else |
---|
| 158 | { |
---|
| 159 | $netmask=netmask2cidr($netmask); |
---|
| 160 | } |
---|
| 161 | |
---|
[70848f4] | 162 | $iseac=substr_count($rs->campos["append"] , "boot=oginit"); |
---|
[58d08a2] | 163 | $isinitrd=substr_count($rs->campos["append"] , "initrd.gz"); |
---|
| 164 | |
---|
[5bac736] | 165 | // delete vga value (included in the variable infohost) |
---|
| 166 | // borramos valor vga (incluido en la variable infohost) |
---|
| 167 | $append=preg_replace('/vga=.../','',$rs->campos["append"]); |
---|
[58d08a2] | 168 | if ($iseac > 0) |
---|
| 169 | { |
---|
| 170 | fwrite($gestion, $append . " " . $infohost . " \n "); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | elseif ($isinitrd > 0) |
---|
| 174 | { |
---|
[1452cbd] | 175 | fwrite($gestion, $append . " ogrepo=" . $repo . " \n"); |
---|
[58d08a2] | 176 | } |
---|
| 177 | else |
---|
| 178 | { |
---|
[5bac736] | 179 | fwrite($gestion, $append . " \n"); |
---|
[58d08a2] | 180 | } |
---|
| 181 | |
---|
| 182 | $prompt=$rs->campos["prompt"]; |
---|
| 183 | $timeout=$rs->campos["timeout"]; |
---|
| 184 | |
---|
| 185 | $rs->Siguiente(); |
---|
| 186 | } |
---|
| 187 | $rs->Cerrar(); |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | fwrite($gestion, " \n"); |
---|
| 191 | fwrite($gestion, "PROMPT " . $prompt ." \n"); |
---|
| 192 | fwrite($gestion, "TIMEOUT " . $timeout . " \n"); |
---|
| 193 | fwrite($gestion, " \n"); |
---|
| 194 | fclose($gestion); |
---|
[5bac736] | 195 | exec("chmod 777 $macfile"); |
---|
[58d08a2] | 196 | } |
---|
| 197 | |
---|
| 198 | function netmask2cidr($netmask) { |
---|
| 199 | $cidr = 0; |
---|
| 200 | foreach (explode('.', $netmask) as $number) { |
---|
| 201 | for (;$number> 0; $number = ($number <<1) % 256) { |
---|
| 202 | $cidr++; |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | return $cidr; |
---|
| 206 | } |
---|
| 207 | |
---|
[5bac736] | 208 | // Sustituye espacio por "_" y quita acentos y tildes. |
---|
| 209 | function cleanString ($cadena) { |
---|
| 210 | $patron = array ('/ /','/á/','/é/','/í/','/ó/','/ú/','/ñ/','/Á/','/É/','/Í/','/Ó/','/Ú/','/Ñ/'); |
---|
| 211 | $reemplazo = array ('_','a','e','i','o','u','n','A','E','I','O','U','N'); |
---|
| 212 | return preg_replace($patron,$reemplazo,$cadena); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | |
---|
[b6ec162] | 216 | |
---|