| 1 | <? |
|---|
| 2 | // ************************************************************************************************************************************************* |
|---|
| 3 | // Aplicación WEB: ogAdmWebCon |
|---|
| 4 | // Autor: José Manuel Alonso (E.T.S.I.I.) Universidad de Sevilla |
|---|
| 5 | // Fecha Creación: Año 2009-2010 |
|---|
| 6 | // Fecha Última modificación: Agosto-2010 |
|---|
| 7 | // Nombre del fichero: incorporaordenadores.php |
|---|
| 8 | // Descripción : |
|---|
| 9 | // Da de alta en la base de datos nuevos ordenadores desde un fichero de configuración dhcp |
|---|
| 10 | // ************************************************************************************************************************************************* |
|---|
| 11 | include_once("../includes/ctrlacc.php"); |
|---|
| 12 | include_once("../clases/AdoPhp.php"); |
|---|
| 13 | include_once("../includes/CreaComando.php"); |
|---|
| 14 | include_once("../idiomas/php/".$idioma."/incorporaordenadores_".$idioma.".php"); |
|---|
| 15 | include_once("../idiomas/php/".$idioma."/avisos_".$idioma.".php"); |
|---|
| 16 | //________________________________________________________________________________________________________ |
|---|
| 17 | $cmd=CreaComando($cadenaconexion); |
|---|
| 18 | if (!$cmd) |
|---|
| 19 | Header('Location: '.$pagerror.'?herror=2'); // Error de conexión con servidor B.D. |
|---|
| 20 | //___________________________________________________________________________________________________ |
|---|
| 21 | $swf=0; |
|---|
| 22 | $idaula=0; |
|---|
| 23 | $nombreaula=""; |
|---|
| 24 | $contenido=""; |
|---|
| 25 | |
|---|
| 26 | if (isset($_GET["idaula"])) $idaula=$_GET["idaula"]; |
|---|
| 27 | if (isset($_GET["nombreaula"])) $nombreaula=$_GET["nombreaula"]; |
|---|
| 28 | |
|---|
| 29 | if (isset($_POST["swf"])) $swf=$_POST["swf"]; // Recoge parametros |
|---|
| 30 | if (isset($_POST["contenido"])) $contenido=$_POST["contenido"]; |
|---|
| 31 | if (isset($_POST["idaula"])) $idaula=$_POST["idaula"]; |
|---|
| 32 | if (isset($_POST["nombreaula"])) $nombreaula=$_POST["nombreaula"]; |
|---|
| 33 | |
|---|
| 34 | $resul=0; |
|---|
| 35 | $ordDup=""; |
|---|
| 36 | |
|---|
| 37 | if(!empty($contenido)){ // Se ha introducido contenido en lugar de fichero |
|---|
| 38 | $resul=procesaLineas($cmd,$idaula,$contenido); |
|---|
| 39 | } |
|---|
| 40 | //___________________________________________________________________________________________________ |
|---|
| 41 | ?> |
|---|
| 42 | <HTML> |
|---|
| 43 | <TITLE>Administración web de aulas</TITLE> |
|---|
| 44 | <HEAD> |
|---|
| 45 | <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
|---|
| 46 | <LINK rel="stylesheet" type="text/css" href="../estilos.css"> |
|---|
| 47 | </HEAD> |
|---|
| 48 | <BODY> |
|---|
| 49 | <FORM action="incorporaordenadores.php" method="post" name="fdatos"> |
|---|
| 50 | <INPUT type=hidden name=swf value=1> |
|---|
| 51 | <INPUT type=hidden name=idaula value=<?echo $idaula?>> |
|---|
| 52 | <INPUT type=hidden name=nombreaula value=<?echo $nombreaula?>> |
|---|
| 53 | <BR> |
|---|
| 54 | <P align=center class=cabeceras><?echo $TbMsg[0]?><BR> |
|---|
| 55 | <SPAN align=center class=subcabeceras><IMG src="../images/iconos/aula.gif"> <?echo $TbMsg[1].":".$nombreaula ?></SPAN></P> |
|---|
| 56 | <!-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------> |
|---|
| 57 | <table align="center" class="tabla_datos" border="0" cellpadding="0" cellspacing="1"> |
|---|
| 58 | <!-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------> |
|---|
| 59 | <tr> |
|---|
| 60 | <th> <?php echo $TbMsg[2]?> </th> |
|---|
| 61 | <td><textarea class="cajatexto" name="contenido" cols="70" rows="18"></textarea></td></tr> |
|---|
| 62 | <tr><th colspan="2"> <?php echo $TbMsg["WARN_NETBOOT"]?> </th></tr> |
|---|
| 63 | <!-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------> |
|---|
| 64 | </table> |
|---|
| 65 | </FORM> |
|---|
| 66 | <TABLE align=center> |
|---|
| 67 | <TR> |
|---|
| 68 | <TD><IMG src="../images/boton_cancelar.gif" style="cursor:hand" onclick=""></TD> |
|---|
| 69 | <TD width=20></TD> |
|---|
| 70 | <TD><IMG src="../images/boton_confirmar.gif" style="cursor:hand" onclick="javascript:document.fdatos.submit();"></TD> |
|---|
| 71 | </TR> |
|---|
| 72 | </TABLE> |
|---|
| 73 | <? |
|---|
| 74 | //________________________________________________________________________________________________________ |
|---|
| 75 | // Mensaje con el resultado del proceso |
|---|
| 76 | echo '<SCRIPT LANGUAGE="javascript">'; |
|---|
| 77 | if (!empty($resul)) |
|---|
| 78 | echo " alert('".$TbMsg[$resul]."');"; |
|---|
| 79 | if (!empty($ordDup)) |
|---|
| 80 | echo " alert('".$TbMsg[5]."\\n".$ordDup."');"; |
|---|
| 81 | echo '</SCRIPT>'; |
|---|
| 82 | //________________________________________________________________________________________________________ |
|---|
| 83 | ?> |
|---|
| 84 | </BODY> |
|---|
| 85 | </HTML> |
|---|
| 86 | <? |
|---|
| 87 | // ************************************************************************************************************************************************* |
|---|
| 88 | function procesaLineas($cmd,$idaula,$buffer) |
|---|
| 89 | { |
|---|
| 90 | $nombre=""; |
|---|
| 91 | $MAC=""; |
|---|
| 92 | $IP=""; |
|---|
| 93 | $sw=false; |
|---|
| 94 | $posa=-1; |
|---|
| 95 | |
|---|
| 96 | while($posa<strlen($buffer)){ |
|---|
| 97 | if ('host'==substr($buffer,$posa,4)){ |
|---|
| 98 | $posa=$posa+4; |
|---|
| 99 | $posb=$posa; |
|---|
| 100 | while( substr($buffer,$posb,1)!="{") $posb++; |
|---|
| 101 | $nombre=substr($buffer,$posa,$posb-$posa); |
|---|
| 102 | } |
|---|
| 103 | if ('hardware ethernet'==substr($buffer,$posa,17)){ |
|---|
| 104 | $posa=$posa+17; |
|---|
| 105 | $posb=$posa; |
|---|
| 106 | while( substr($buffer,$posb,1)!=";") $posb++; |
|---|
| 107 | $MAC=substr($buffer,$posa,$posb-$posa); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | if ('fixed-address'==substr($buffer,$posa,13)){ |
|---|
| 111 | $posa=$posa+13; |
|---|
| 112 | $posb=$posa; |
|---|
| 113 | while( substr($buffer,$posb,1)!=";") $posb++; |
|---|
| 114 | $IP=substr($buffer,$posa,$posb-$posa); |
|---|
| 115 | } |
|---|
| 116 | if(!empty($nombre) && !empty($MAC) && !empty($IP)){ |
|---|
| 117 | if(!Inserta($cmd,$idaula,$nombre,$MAC,$IP)) return(4); |
|---|
| 118 | $sw=true; |
|---|
| 119 | $nombre=""; |
|---|
| 120 | $MAC=""; |
|---|
| 121 | $IP=""; |
|---|
| 122 | $resul=true; |
|---|
| 123 | } |
|---|
| 124 | $posa++; |
|---|
| 125 | } |
|---|
| 126 | if($sw) |
|---|
| 127 | return(3); |
|---|
| 128 | else |
|---|
| 129 | return(4); |
|---|
| 130 | |
|---|
| 131 | } |
|---|
| 132 | //________________________________________________________________________________________________________ |
|---|
| 133 | function Inserta($cmd,$idaula,$nombre,$lamac,$laip) |
|---|
| 134 | { |
|---|
| 135 | global $ordDup; |
|---|
| 136 | |
|---|
| 137 | $grupoid=0; |
|---|
| 138 | $nombreordenador=trim($nombre); |
|---|
| 139 | $ip=trim($laip); |
|---|
| 140 | $auxmac=trim($lamac); |
|---|
| 141 | $mac=""; |
|---|
| 142 | for($i=0;$i<strlen($auxmac);$i++) |
|---|
| 143 | if(substr($auxmac,$i,1)!=":") |
|---|
| 144 | $mac.=substr($auxmac,$i,1); |
|---|
| 145 | |
|---|
| 146 | if(existeOrdenador($cmd,$nombreordenador,$mac,$ip)){ |
|---|
| 147 | $ordDup.="Nombre=".$nombre.",Mac=".$mac.",Dirección ip=".$ip." \\n"; |
|---|
| 148 | return(true); |
|---|
| 149 | } |
|---|
| 150 | $idperfilhard=0; |
|---|
| 151 | ## ADV: modificacion para asignar a los ordenadores, cuando se crean desde "incorpoar ordenadores" el repositorio "default" |
|---|
| 152 | $idrepositorio=1; |
|---|
| 153 | $idconfiguracion=0; |
|---|
| 154 | $cmd->CreaParametro("@grupoid",$grupoid,1); |
|---|
| 155 | $cmd->CreaParametro("@idaula",$idaula,1); |
|---|
| 156 | $cmd->CreaParametro("@nombreordenador",$nombreordenador,0); |
|---|
| 157 | $cmd->CreaParametro("@ip",$ip,0); |
|---|
| 158 | $cmd->CreaParametro("@mac",$mac,0); |
|---|
| 159 | $cmd->CreaParametro("@idperfilhard",$idperfilhard,1); |
|---|
| 160 | $cmd->CreaParametro("@idrepositorio",$idrepositorio,1); |
|---|
| 161 | $cmd->CreaParametro("@idconfiguracion",$idconfiguracion,1); |
|---|
| 162 | |
|---|
| 163 | $cmd->texto="INSERT INTO ordenadores(nombreordenador,ip,mac,idperfilhard,idrepositorio,idaula,grupoid) VALUES (@nombreordenador,@ip,@mac,@idperfilhard,@idrepositorio,@idaula,@grupoid)"; |
|---|
| 164 | $resul=$cmd->Ejecutar(); |
|---|
| 165 | return($resul); |
|---|
| 166 | } |
|---|
| 167 | //________________________________________________________________________________________________________ |
|---|
| 168 | // Recupera los datos de un ordenador |
|---|
| 169 | // Parametros: |
|---|
| 170 | // - cmd: Una comando ya operativo (con conexión abierta) |
|---|
| 171 | // - ip: Dirección IP |
|---|
| 172 | //________________________________________________________________________________________________________ |
|---|
| 173 | function existeOrdenador($cmd,$nombre,$MAC,$IP){ |
|---|
| 174 | $rs=new Recordset; |
|---|
| 175 | $cmd->texto="SELECT * FROM ordenadores WHERE nombreordenador='".$nombre."' OR mac='".$MAC."' OR ip='".$IP."'"; |
|---|
| 176 | $rs->Comando=&$cmd; |
|---|
| 177 | if (!$rs->Abrir()) return(false); // Error al abrir recordset |
|---|
| 178 | $rs->Primero(); |
|---|
| 179 | if (!$rs->EOF){ |
|---|
| 180 | $rs->Cerrar(); |
|---|
| 181 | return(true); |
|---|
| 182 | } |
|---|
| 183 | else |
|---|
| 184 | return(false); |
|---|
| 185 | } |
|---|
| 186 | ?> |
|---|