| 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, 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 | switch ($idioma) { | 
|---|
| 80 | case eng: | 
|---|
| 81 | $idioma=en_GB; | 
|---|
| 82 | break; | 
|---|
| 83 | case esp: | 
|---|
| 84 | $idioma=es_ES; | 
|---|
| 85 | break; | 
|---|
| 86 | case cat: | 
|---|
| 87 | $idioma=ca_ES; | 
|---|
| 88 | break; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 |  | 
|---|
| 92 | $infohost="LANG=" .$idioma . " ip=" | 
|---|
| 93 | . $ip . ":" | 
|---|
| 94 | . $server .":" | 
|---|
| 95 | . $router . ":" | 
|---|
| 96 | . $netmask .":" | 
|---|
| 97 | . $hostname .":" | 
|---|
| 98 | . $netiface . ":none ogrepo=" | 
|---|
| 99 | . $repo . " oglive=" | 
|---|
| 100 | . $repo . " oglog=" | 
|---|
| 101 | . $server . " ogshare=" | 
|---|
| 102 | . $repo; | 
|---|
| 103 |  | 
|---|
| 104 | ###################obtenemos las variables de red del aula. | 
|---|
| 105 |  | 
|---|
| 106 | #02.1 obtenemos nombre fichero mac | 
|---|
| 107 | $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); | 
|---|
| 108 | $macfile="01-" . str_replace(":","-",strtolower($mac)); | 
|---|
| 109 | $nombre_archivo="/var/lib/tftpboot/pxelinux.cfg/" . $macfile; | 
|---|
| 110 |  | 
|---|
| 111 |  | 
|---|
| 112 | ########## Escribimos el fichero mac | 
|---|
| 113 | if (!$gestion=fopen($nombre_archivo, 'w+')) | 
|---|
| 114 | { | 
|---|
| 115 | echo "No se puede abrir el archivo ($nombre_archivo)"; | 
|---|
| 116 | return; | 
|---|
| 117 | } | 
|---|
| 118 | # cuales son los parametros del menu | 
|---|
| 119 | fwrite($gestion, "DEFAULT syslinux/vesamenu.c32 \n"); | 
|---|
| 120 | fwrite($gestion, "MENU TITLE Aplicacion OpenGnsys \n"); | 
|---|
| 121 |  | 
|---|
| 122 | $cmd->texto="SELECT itemboot.label, itemboot.kernel, | 
|---|
| 123 | itemboot.append, menuboot.timeout, menuboot.prompt, | 
|---|
| 124 | menuboot.description, menuboot_itemboot.default | 
|---|
| 125 | From itemboot,menuboot_itemboot,menuboot | 
|---|
| 126 | WHERE menuboot_itemboot.labelmenu=menuboot.label | 
|---|
| 127 | AND menuboot_itemboot.labelitem=itemboot.label | 
|---|
| 128 | AND menuboot.label='" . $optboot   . "'"; | 
|---|
| 129 |  | 
|---|
| 130 | $rs->Comando=&$cmd; | 
|---|
| 131 | if (!$rs->Abrir()) echo "error"; | 
|---|
| 132 | $rs->Primero(); | 
|---|
| 133 | while (!$rs->EOF) | 
|---|
| 134 | { | 
|---|
| 135 | fwrite($gestion, " \n"); | 
|---|
| 136 | fwrite($gestion, "LABEL " .  $rs->campos['label'] . " \n"); | 
|---|
| 137 | fwrite($gestion, "MENU LABEL " . $rs->campos['label'] . " \n"); | 
|---|
| 138 | if ( $rs->campos["default"] == true) | 
|---|
| 139 | { | 
|---|
| 140 | fwrite($gestion, "MENU DEFAULT \n"); | 
|---|
| 141 | } | 
|---|
| 142 | fwrite($gestion, $rs->campos["kernel"] . " \n"); | 
|---|
| 143 | # set netmask cird para ogclient | 
|---|
| 144 | $isnfsroot=substr_count($rs->campos["append"] , "boot=oginit"); | 
|---|
| 145 | if ($isnfsroot > 0) | 
|---|
| 146 | { | 
|---|
| 147 | $netmask=$netmask; | 
|---|
| 148 | } | 
|---|
| 149 | else | 
|---|
| 150 | { | 
|---|
| 151 | $netmask=netmask2cidr($netmask); | 
|---|
| 152 | } | 
|---|
| 153 |  | 
|---|
| 154 | $iseac=substr_count($rs->campos["append"] , "boot=oginit"); | 
|---|
| 155 | $isinitrd=substr_count($rs->campos["append"] , "initrd.gz"); | 
|---|
| 156 |  | 
|---|
| 157 | if ($iseac > 0) | 
|---|
| 158 | { | 
|---|
| 159 | $append=$rs->campos["append"]; | 
|---|
| 160 | fwrite($gestion, $append . " " . $infohost . " \n "); | 
|---|
| 161 | } | 
|---|
| 162 |  | 
|---|
| 163 | elseif ($isinitrd > 0) | 
|---|
| 164 | { | 
|---|
| 165 | $append=$rs->campos["append"]; | 
|---|
| 166 | fwrite($gestion, $append . " ogrepo=" . $repo . " \n"); | 
|---|
| 167 | } | 
|---|
| 168 | else | 
|---|
| 169 | { | 
|---|
| 170 | fwrite($gestion, $rs->campos["append"] . " \n"); | 
|---|
| 171 | } | 
|---|
| 172 |  | 
|---|
| 173 | $prompt=$rs->campos["prompt"]; | 
|---|
| 174 | $timeout=$rs->campos["timeout"]; | 
|---|
| 175 |  | 
|---|
| 176 | $rs->Siguiente(); | 
|---|
| 177 | } | 
|---|
| 178 | $rs->Cerrar(); | 
|---|
| 179 |  | 
|---|
| 180 |  | 
|---|
| 181 |  | 
|---|
| 182 | fwrite($gestion, " \n"); | 
|---|
| 183 | fwrite($gestion, "PROMPT " . $prompt ." \n"); | 
|---|
| 184 | fwrite($gestion, "TIMEOUT " . $timeout . " \n"); | 
|---|
| 185 | fwrite($gestion, " \n"); | 
|---|
| 186 | fclose($gestion); | 
|---|
| 187 | exec("chown www-data:www-data /var/lib/tftpboot/pxelinux.cfg/". $macfile); | 
|---|
| 188 | exec("chmod 777 /var/lib/tftpboot/pxelinux.cfg/". $macfile); | 
|---|
| 189 |  | 
|---|
| 190 |  | 
|---|
| 191 |  | 
|---|
| 192 |  | 
|---|
| 193 | } | 
|---|
| 194 |  | 
|---|
| 195 | function netmask2cidr($netmask) { | 
|---|
| 196 | $cidr = 0; | 
|---|
| 197 | foreach (explode('.', $netmask) as $number) { | 
|---|
| 198 | for (;$number> 0; $number = ($number <<1) % 256) { | 
|---|
| 199 | $cidr++; | 
|---|
| 200 | } | 
|---|
| 201 | } | 
|---|
| 202 | return $cidr; | 
|---|
| 203 | } | 
|---|
| 204 |  | 
|---|
| 205 | ?> | 
|---|