[aedf2d5] | 1 | <?php |
---|
| 2 | |
---|
[a973fe7] | 3 | #no integrado parcialmente. Pendiente de ser llamado desde el EACserver |
---|
[aedf2d5] | 4 | function RegistryHost ($mac,$ip) |
---|
| 5 | { |
---|
| 6 | echo $mac . $ip; |
---|
[a973fe7] | 7 | $conexion=mysql_connect($_SERVER['SQL_HOST'], $_SERVER['SQL_USER'], $_SERVER['SQL_PASS']) or die ('no se ha podido conectar con mysql'); |
---|
| 8 | mysql_select_db($_SERVER['DATABASE'], $conexion); |
---|
| 9 | $insert="insert into infonetequipos (hostname, macaddress, ipaddress, startpage, aula, vga, acpi, pci) values ('" . $_SERVER['HOSTNAME'] . "', '" . $mac . "', '" . $ip . "' , 'default.sh' , '1', '788', '" . $_SERVER['acpi'] . "', '" . $_SERVER['pci'] . "')"; |
---|
[aedf2d5] | 10 | $resultado=mysql_query($insert); |
---|
| 11 | #ethtool -s eth0 wol g autoneg off speed 100 duplex full |
---|
| 12 | #} |
---|
| 13 | mysql_close($conexion); |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | |
---|
[a973fe7] | 20 | |
---|
[aedf2d5] | 21 | function BootServer ($boot,$ip) |
---|
| 22 | { |
---|
| 23 | #/** @function BootServer: @brief Configura el fichero de arranque remoto para el equipo, y actualiza la base de datos. |
---|
| 24 | #@param $1 str_LabelBootMenu |
---|
| 25 | #@param $2 str_IPHost |
---|
| 26 | #@return Mensaje informativo sobre dicho proceso |
---|
| 27 | #@warning Salidas de errores no determinada |
---|
| 28 | #@attention |
---|
| 29 | #@note Notas sin especificar |
---|
| 30 | #@version 1.0 Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 31 | #*/ |
---|
[a973fe7] | 32 | |
---|
[6de9ad29] | 33 | |
---|
[aedf2d5] | 34 | |
---|
| 35 | #actualizamos el menu de arranque para ese equipo |
---|
| 36 | $query3="update infonetequipos set arranque='" . $boot ."' where ipaddress='" .$ip . "'"; |
---|
| 37 | $resultado = mysql_query($query3) or die (mysql_error()); |
---|
[6de9ad29] | 38 | ############# Consultas SQL para obtener la informacion del ciente. varinfoaula, varinfoequipo, varinfoparameters |
---|
| 39 | ## varinfohost= toda la informacion de este equipo almacenado en el array infohost |
---|
[aedf2d5] | 40 | $peticion="select * from infonetequipos where ipaddress='".$ip . "'"; |
---|
| 41 | $rsinfohost = mysql_query($peticion); |
---|
| 42 | $infohost = mysql_fetch_array($rsinfohost); |
---|
| 43 | $aula= $infohost['aula']; |
---|
[6de9ad29] | 44 | #obtenemos los campos del host y los metemos dentro de la variable varinfohost |
---|
| 45 | $varinfohost=" "; |
---|
[aedf2d5] | 46 | $lastparameters=mysql_num_fields($rsinfohost); |
---|
[6de9ad29] | 47 | #for ($i=3; $i<$lastparameters; $i++) |
---|
| 48 | for ($i=0; $i<$lastparameters; $i++) |
---|
[aedf2d5] | 49 | { |
---|
| 50 | if ( mysql_field_name($rsinfohost, $i) == 'startpage' ) |
---|
| 51 | { |
---|
[6de9ad29] | 52 | $varinfohost = $varinfohost . " " . mysql_field_name($rsinfohost, $i) . "=A_id" . $aula . "_" . $infohost[$i] ; |
---|
[aedf2d5] | 53 | } |
---|
| 54 | else |
---|
| 55 | { |
---|
[6de9ad29] | 56 | $varinfohost = $varinfohost . " " . mysql_field_name($rsinfohost, $i) . "=" . $infohost[$i] ; |
---|
[aedf2d5] | 57 | #echo $infohost[$i] . "\n"; |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | #echo $parameters . "\n" ; |
---|
| 61 | mysql_free_result($rsinfohost); |
---|
[6de9ad29] | 62 | |
---|
| 63 | ## obtenemos el nombre del fichero pxe para este equipo |
---|
| 64 | $mac=$infohost['macaddress']; |
---|
| 65 | $macfile="01-" . str_replace(":","-",strtolower($mac)); |
---|
| 66 | $nombre_archivo="/tftpboot/pxelinux.cfg/" . $macfile; |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | ### varinfoaula= toda la informacion del aula al que pertenece el equipo infoaula. |
---|
[aedf2d5] | 70 | $peticion="select * from infonetaulas where id_aula='".$aula . "'"; |
---|
| 71 | $rsinfoaula = mysql_query($peticion); |
---|
[6de9ad29] | 72 | #$infoaula = mysql_fetch_assoc($rsinfoaula); |
---|
| 73 | $infoaula = mysql_fetch_array($rsinfoaula); |
---|
| 74 | $varinfoaula=" "; |
---|
| 75 | $lastparameters=mysql_num_fields($rsinfoaula); |
---|
| 76 | #for ($i=3; $i<$lastparameters; $i++) |
---|
| 77 | for ($i=0; $i<$lastparameters; $i++) |
---|
| 78 | { |
---|
| 79 | $varinfoaula = $varinfoaula . " " . mysql_field_name($rsinfoaula, $i) . "=" . $infoaula[$i] ; |
---|
| 80 | } |
---|
[aedf2d5] | 81 | mysql_free_result($rsinfoaula); |
---|
[6de9ad29] | 82 | |
---|
| 83 | $gateway=$infoaula['gateway']; |
---|
[aedf2d5] | 84 | $netmask=$infoaula['netmask']; |
---|
| 85 | $repo_client=$infoaula['repo_client']; |
---|
| 86 | $menu=$infohost['arranque']; |
---|
[6de9ad29] | 87 | |
---|
| 88 | ### varinfoparameters= toda la informacion generica de los clientes. |
---|
| 89 | $peticion="select variable, value from infoparametersclients"; |
---|
| 90 | $rsinfoparameters = mysql_query($peticion); |
---|
| 91 | #$infoparameters = mysql_fetch_assoc($rsinfoparameters); |
---|
| 92 | # $infoparameters = mysql_fetch_array($rsinfoparameters); |
---|
| 93 | $varinfoparameters=" "; |
---|
| 94 | # $lastparameters=mysql_num_fields($rsinfoparameters); |
---|
| 95 | # #for ($i=3; $i<$lastparameters; $i++) |
---|
| 96 | # for ($i=0; $i<$lastparameters; $i++) |
---|
| 97 | # { |
---|
| 98 | # $varinfoparameters = $varinfoparameters . " " . mysql_field_name($rsinfoparameters, $i) . "=" . $infoparameters[$i] ; |
---|
| 99 | # } |
---|
| 100 | while ($fila = mysql_fetch_row($rsinfoparameters)) |
---|
| 101 | { |
---|
| 102 | #foreach ($fila as $elemento) |
---|
| 103 | # { |
---|
| 104 | # $varinfoparameters = $varinfoparameters . "" . $elemento . "="; |
---|
| 105 | # } |
---|
| 106 | $varinfoparameters = $varinfoparameters . " " . $fila[0] . "=" . $fila[1]; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | mysql_free_result($rsinfoparameters); |
---|
| 110 | ################################################ Fin de consustar SQL |
---|
| 111 | |
---|
[aedf2d5] | 112 | if (!$gestion= fopen($nombre_archivo, 'w+')) |
---|
| 113 | { |
---|
| 114 | echo "No se puede abrir el archivo ($nombre_archivo)"; |
---|
| 115 | return; |
---|
| 116 | } |
---|
| 117 | # cuales son los parametros del menu |
---|
| 118 | fwrite($gestion, "DEFAULT syslinux/vesamenu.c32 \n"); |
---|
| 119 | fwrite($gestion, "MENU TITLE Aplicacion GNSYS \n"); |
---|
| 120 | # cuales son los elemtos del menu |
---|
| 121 | $peticion="select itemboot.label, itemboot.kernel, itemboot.append, menuboot.timeout, menuboot.prompt, menuboot.description, menuboot_itemboot.default from itemboot,menuboot_itemboot,menuboot where menuboot_itemboot.labelmenu=menuboot.label and menuboot_itemboot.labelitem=itemboot.label and menuboot.label='" . $menu . "'"; |
---|
| 122 | # echo $peticion; |
---|
| 123 | $rsbootoption = mysql_query($peticion); |
---|
| 124 | while($row = mysql_fetch_assoc($rsbootoption)) |
---|
| 125 | { |
---|
| 126 | fwrite($gestion, " \n"); |
---|
| 127 | fwrite($gestion, "LABEL " . $row['label'] . " \n"); |
---|
| 128 | fwrite($gestion, "MENU LABEL " . $row['label'] . " \n"); |
---|
| 129 | if ( $row['default'] == true) |
---|
| 130 | { |
---|
| 131 | fwrite($gestion, "MENU DEFAULT \n"); |
---|
| 132 | } |
---|
[2900730] | 133 | |
---|
| 134 | |
---|
| 135 | $iseac=substr_count($row['append'] , "ogclients"); |
---|
[aedf2d5] | 136 | echo $iseaci . " \n"; |
---|
| 137 | if ($iseac > 0) |
---|
| 138 | { |
---|
[2900730] | 139 | fwrite($gestion, $row['kernel'] . " EACregistred=YES " . $varinfoaula . "\n"); |
---|
[aedf2d5] | 140 | $append=str_replace("repo_client", $repo_client, $row['append']); |
---|
[6de9ad29] | 141 | ## echo $append . "\n"; |
---|
| 142 | fwrite($gestion, $append . " ip=" . $infohost['ipaddress'] .":" . $repo_client . ":" . $gateway . ":" . $netmask . ":" . $infohost['hostname'] . ":eth0 ro " . " " . $varinfohost . " ". $varinfoparameters . " \n"); |
---|
[aedf2d5] | 143 | } |
---|
| 144 | else |
---|
| 145 | { |
---|
[2900730] | 146 | fwrite($gestion, $row['kernel'] . " \n"); |
---|
[aedf2d5] | 147 | fwrite($gestion, $row['append'] . " \n"); |
---|
| 148 | } |
---|
| 149 | $prompt=$row['prompt']; |
---|
| 150 | $timeout=$row['timeout']; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | fwrite($gestion, " \n"); |
---|
| 154 | fwrite($gestion, "PROMPT " . $prompt ." \n"); |
---|
| 155 | fwrite($gestion, "TIMEOUT " . $timeout . " \n"); |
---|
| 156 | mysql_free_result($rsbootoption); |
---|
| 157 | fwrite($gestion, " \n"); |
---|
| 158 | fclose($gestion); |
---|
| 159 | exec("chown www-data:www-data /tftpboot/pxelinux.cfg/". $macfile); |
---|
| 160 | exec("chmod 777 /tftpboot/pxelinux.cfg/". $macfile); |
---|
| 161 | #return("ok"); |
---|
| 162 | # actualizando el boot del cliente |
---|
| 163 | #system(REPO . "admin/procedimientos/Log " . SQL_HOST . " ' 00:00 ' ' " . $ip . " solicita un SetDefaultBoot ' ' " . $boot . " " . $ip . " con resultado " . $bootstatus ."'"); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | # no integrado |
---|
| 167 | function Logger () |
---|
| 168 | { |
---|
| 169 | #include("/var/EAC/admin/config/EAC.conf"); |
---|
| 170 | # formato de entrada |
---|
| 171 | # 1IP ; 2tiempo proceso; 3comando; 4parametros |
---|
| 172 | #$hora=date("H:i:s"); |
---|
| 173 | #$dia=date("Y-m-d"); |
---|
| 174 | #formato del log |
---|
| 175 | # IPsolicitante ; dia ; hora ; tiempo proceso ; comando; parametros |
---|
| 176 | #formato del log |
---|
| 177 | #mensaje en ventana del solicitante. |
---|
| 178 | #echo($_SERVER['argv'][1] . " ; " . $dia . " ; " . $hora . " ; " . $_SERVER['argv'][2] . " ; " . $_SERVER['argv'][3] . " ; " . $_SERVER['argv'][4]); |
---|
| 179 | #$info=$_SERVER['argv'][1] . " ; " . $dia . " ; " . $hora . " ; " . $_SERVER['argv'][2] . " ; " . $_SERVER['argv'][3] . " ; " . $_SERVER['argv'][4] . "\n"; |
---|
| 180 | #echo($info); |
---|
| 181 | ## escritura en el ficheor /var/EAC/hosts/$IP-Log |
---|
| 182 | #$fp = fopen(REPO . "hosts/" . $_SERVER['argv'][1] ."-Log", "ab"); |
---|
| 183 | #fwrite($fp, $info); |
---|
| 184 | #fclose($fp); |
---|
| 185 | ## insertar la informacion en la base de datos |
---|
| 186 | #$conexion=mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die ('no se ha podido conectar con mysql'); |
---|
| 187 | #mysql_select_db(DATABASE, $conexion); |
---|
| 188 | #$insert="insert into log (ip, dia, hora, tiempo_proceso, comando, parametros) values ('".$_SERVER['argv'][1] . "','" . $dia . "','" .$hora . "','" .$_SERVER['argv'][2]."','".$_SERVER['argv'][3]."','".$_SERVER['argv'][4]."')"; |
---|
| 189 | #echo $insert . "\n"; |
---|
| 190 | #$resultado = mysql_query($insert) or die (mysql_error()); |
---|
| 191 | #mysql_close($conexion); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | #primera integracion |
---|
| 196 | function InsertClassrom ($descripcion,$subred,$netmask,$broadcast,$gateway,$repo_image,$repo_client) |
---|
| 197 | { |
---|
[6de9ad29] | 198 | |
---|
[aedf2d5] | 199 | $query="select * from infonetaulas where descripcion='" . $descripcion ."'"; |
---|
| 200 | echo $query; |
---|
| 201 | $rs=mysql_query($query); |
---|
| 202 | $num_rows = mysql_num_rows($rs); |
---|
| 203 | $row = mysql_fetch_assoc($rs); |
---|
| 204 | |
---|
| 205 | if ($num_rows == 0 ) |
---|
| 206 | { |
---|
| 207 | $insert="insert into infonetaulas (descripcion, subred, netmask, broadcast, gateway, repo_image, repo_client) values ('$descripcion', '$subred', '$netmask', '$broadcast', '$gateway', '$repo_image', '$repo_client')"; |
---|
| 208 | #echo $row['id_aula']; |
---|
| 209 | echo $insert; |
---|
| 210 | $resultado = mysql_query($insert) or die (mysql_error()); |
---|
| 211 | mysql_free_result($rs); |
---|
| 212 | $query="select * from infonetaulas where descripcion='" . $descripcion ."'"; |
---|
| 213 | #echo $query; |
---|
| 214 | $rs=mysql_query($query); |
---|
| 215 | $num_rows = mysql_num_rows($rs); |
---|
| 216 | $row = mysql_fetch_assoc($rs); |
---|
| 217 | if ($num_rows > 0 ) |
---|
| 218 | { |
---|
| 219 | echo "creando directorios"; |
---|
| 220 | $dir = REPOSTATIC . "client/etc/startpage/models"; |
---|
| 221 | $dh = opendir($dir); |
---|
| 222 | while (false !== ($nombre_archivo = readdir($dh))) |
---|
| 223 | { |
---|
| 224 | $archivos[] = $nombre_archivo; |
---|
| 225 | } |
---|
| 226 | foreach ($archivos as $directorio) |
---|
| 227 | { |
---|
| 228 | if ((strlen($directorio) >= 3) and ($directorio <> '.svn')) |
---|
| 229 | { |
---|
| 230 | #echo "creando " . $directorio; |
---|
| 231 | exec("touch /opt/opengnsys/client/etc/startpage/A_id". $row['id_aula'] ."_". $directorio); |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | |
---|
| 239 | } |
---|
| 240 | #mysql_close($conexion); |
---|
| 241 | } |
---|
| 242 | # no integrado |
---|
| 243 | function InsertDefaultClassrom ($descripcion,$subred,$netmask,$broadcast,$gateway,$repo_image,$repo_client) |
---|
| 244 | { |
---|
| 245 | #include ("/var/EAC/admin/config/EAC.conf"); |
---|
| 246 | $conexion=mysql_connect(SQL_HOST_LOCAL, SQL_USER, SQL_PASS) or die ('no se ha podido conectar con mysql'); |
---|
| 247 | mysql_select_db(DATABASE, $conexion); |
---|
| 248 | $query="select * from aulas"; |
---|
| 249 | $rs=mysql_query($query); |
---|
| 250 | $num_rows = mysql_num_rows($rs); |
---|
| 251 | echo $num_rows; |
---|
| 252 | if ($num_rows == 0 ) |
---|
| 253 | { |
---|
| 254 | $insert="insert into aulas (descripcion, subred, netmask, broadcast, gateway, repo_image, repo_client) values ('$descripcion', '$subred', '$netmask', '$broadcast', '$gateway', '$repo_image', '$repo_client')"; |
---|
| 255 | } |
---|
| 256 | else |
---|
| 257 | { |
---|
| 258 | $insert="update aulas SET descripcion='" . $descripcion . "', subred='". $subred . "', netmask='" . $netmask ."', broadcast='". $broadcast ."', gateway='" . $gateway . "', repo_image='" . $repo_image ."', repo_client='" . $repo_client ."' WHERE id_aula=1"; |
---|
| 259 | } |
---|
| 260 | echo $insert; |
---|
| 261 | $resultado = mysql_query($insert) or die (mysql_error()); |
---|
| 262 | mysql_free_result($rs); |
---|
| 263 | $query="select * from aulas where descripcion='" . $descripcion ."'"; |
---|
| 264 | echo $query; |
---|
| 265 | $rs=mysql_query($query); |
---|
| 266 | $num_rows = mysql_num_rows($rs); |
---|
| 267 | $row = mysql_fetch_assoc($rs); |
---|
| 268 | |
---|
| 269 | if ($num_rows > 0 ) |
---|
| 270 | { |
---|
| 271 | echo $row['id_aula']; |
---|
| 272 | echo "creando directorios"; |
---|
| 273 | $dir = REPO . "admin/startpage/models"; |
---|
| 274 | $dh = opendir($dir); |
---|
| 275 | while (false !== ($nombre_archivo = readdir($dh))) |
---|
| 276 | { |
---|
| 277 | $archivos[] = $nombre_archivo; |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | foreach ($archivos as $directorio) |
---|
| 281 | { |
---|
| 282 | if ((strlen($directorio) >= 3) and ($directorio <> '.svn')) |
---|
| 283 | { |
---|
| 284 | #echo "creando " . $directorio; |
---|
| 285 | exec("touch /var/EAC/admin/startpage/A_id". $row['id_aula'] ."_". $directorio); |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | } |
---|
| 290 | mysql_free_result($rs); |
---|
| 291 | |
---|
| 292 | mysql_close($conexion); |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | |
---|
| 296 | # no integrado |
---|
| 297 | function InsertItemtoMenu ($menu,$item) |
---|
| 298 | { |
---|
| 299 | #include ("/var/EAC/admin/config/EAC.conf"); |
---|
[2900730] | 300 | #echo $menu . $item . "\n"; |
---|
| 301 | # $conexion=mysql_connect(SQL_HOST_LOCAL, SQL_USER, SQL_PASS) or die ('no se ha podido conectar con mysql'); |
---|
| 302 | # mysql_select_db(DATABASE, $conexion); |
---|
[aedf2d5] | 303 | $query="select * from menuboot_itemboot where labelmenu='$menu' and labelitem='$item'"; |
---|
| 304 | echo " " . $query . " \n"; |
---|
| 305 | $rs=mysql_query($query); |
---|
| 306 | $num_rows = mysql_num_rows($rs); |
---|
| 307 | echo $num_rows; |
---|
| 308 | if ($num_rows < 1 ) |
---|
| 309 | { |
---|
| 310 | $insert="insert into menuboot_itemboot values ('$menu', '$item', 0)"; |
---|
| 311 | echo " ".$insert . " \n"; |
---|
| 312 | $resultado = mysql_query($insert) or die (mysql_error()); |
---|
| 313 | mysql_free_result($rs); |
---|
| 314 | mysql_close($conexion); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | ?> |
---|